Use grid size based arithmetics for offsets in hex tile layout#463
Open
ulfhermann wants to merge 1 commit intoStarArawn:mainfrom
Open
Use grid size based arithmetics for offsets in hex tile layout#463ulfhermann wants to merge 1 commit intoStarArawn:mainfrom
ulfhermann wants to merge 1 commit intoStarArawn:mainfrom
Conversation
StarArawn
reviewed
Dec 17, 2023
Owner
StarArawn
left a comment
There was a problem hiding this comment.
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
Author
|
I've updated the patch and resolved the conflict. |
6b15399 to
6ed627d
Compare
6ed627d to
b581c5c
Compare
teohhanhui
reviewed
Nov 3, 2024
| @@ -5,13 +5,7 @@ | |||
|
|
|||
| // Gets the screen space coordinates of the bottom left of an isometric tile position. | |||
Contributor
There was a problem hiding this comment.
Not related to this PR, but all the comments seem to be copy and paste... Haha.
teohhanhui
reviewed
Nov 3, 2024
|
|
||
| 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); |
Contributor
There was a problem hiding this comment.
I think naming these in variables as before would help, e.g.
Suggested change
| 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); |
b581c5c to
9cfad5c
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.
9cfad5c to
d7c38ec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.