-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use grid size based arithmetics for offsets in hex tile layout #463
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This math has changed quite a bit from when I first wrote it. Arguably for the better. I can't say I know enough about the math specifically or have the time to dive in to see if this is correct in all user cases. If someone else is willing to review this PR we can merge it assuming it looks good to go.
ef865a8
to
72e4777
Compare
I've updated the patch and resolved the conflict. |
6b15399
to
6ed627d
Compare
By refraining from using sqrt(3) based arithmetics we get the tiles aligned to the provided textures and grid size. This is not mathematically exact, but arguably what the user wants when providing tiles of specific size. The central realization here is that neighboring tiles on the "diagonal" axis are always offset by a half tile size in one direction and a 3/4 tile size in the other. So, by providing tiles with sizes divisible by 4, you can get pixel perfect alignment of tiles. The calculations are also quite a bit simpler this way. See StarArawn#456 for some further comments on this.
6ed627d
to
b581c5c
Compare
@@ -5,13 +5,7 @@ | |||
|
|||
// Gets the screen space coordinates of the bottom left of an isometric tile position. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR, but all the comments seem to be copy and paste... Haha.
|
||
let unscaled_pos = pos.x * ROW_BASIS_X + pos.y * ROW_BASIS_Y; | ||
return vec2<f32>(grid_width * unscaled_pos.x, ROW_BASIS_Y.y * grid_height * unscaled_pos.y); | ||
return vec2<f32>(grid_width * (pos.x + pos.y / 2.0), grid_height * pos.y * 0.75); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think naming these in variables as before would help, e.g.
return vec2<f32>(grid_width * (pos.x + pos.y / 2.0), grid_height * pos.y * 0.75); | |
let ROW_BASIS_X: f32 = 0.5; | |
let ROW_BASIS_Y: f32 = 0.75; | |
return vec2<f32>(grid_width * (pos.x + pos.y * ROW_BASIS_X), grid_height * pos.y * ROW_BASIS_Y); |
By refraining from using sqrt(3) based arithmetics we get the tiles aligned to the provided textures and grid size. This is not mathematically exact, but arguably what the user wants when providing tiles of specific size.
The central realization here is that neighboring tiles on the "diagonal" axis are always offset by a half tile size in one direction and a 3/4 tile size in the other. So, by providing tiles with sizes divisible by 4, you can get pixel perfect alignment of tiles.
The calculations are also quite a bit simpler this way.
See #456 for some further comments on this.