Skip to content
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

Helpers overhaul #268

Merged
merged 27 commits into from
Sep 22, 2022
Merged

Helpers overhaul #268

merged 27 commits into from
Sep 22, 2022

Conversation

bzm3r
Copy link
Collaborator

@bzm3r bzm3r commented Sep 13, 2022

Per discussions, an overhaul of helpers that also with the following issues:

It provides the ground work for dealing with (but does not yet generate mouse events):

What remains before the PR can move out of draft stage:

  • docs need to be updated/cleaned up (there are a lot of docs around that no longer belong where they are, or need to be simplified)

  • update hex shader code to use new tile position to world position code for hexagons

  • create an example that uses the new code, and confirms that world position -> tile position works correctly

An extension to this PR would create mouse events as requested in #40

@bzm3r bzm3r marked this pull request as draft September 13, 2022 19:11
@StarArawn StarArawn mentioned this pull request Sep 15, 2022
@bzm3r bzm3r marked this pull request as ready for review September 19, 2022 13:17
@bzm3r
Copy link
Collaborator Author

bzm3r commented Sep 19, 2022

Brief overview:

  • helpers have been re-organized so that they are not in a single file

  • for hex grids: added support for conversion between axial coordinate system (the coordinate system used by Row and Column hex coord system) and offset coordinate systems (RowEven, RowOdd, ColumnEven, ColumnOdd)

  • for hex grids: added support for conversion between axial coodinate system (the coordinate system used by Row and Column hex coord system) and cube coordinate systems

  • for hex grids: added support for conversion between axial/cube/offset coordinates and TilePos

  • for hex grids: note that all these conversions between coordinate systems are cheap and require only a couple of arithmetic operations at most (maybe I should be adding the #[inline] hint everywhere, but I'll make a future issue for that)

  • for hex grids: supporting cube positions allows us to convert a Vec2 world space position into a TilePos; suppose you are using RowOdd coordinate system, and you have a world_pos, then: world_pos is mapped to a FractionalAxialPos, which is then rounded (requires conversion to FractionalCubePos at this stage) into an AxialPos (this rounding is actually the heavyweight bit), which is then converted into a RowOddPos, which is converted into a result TilePos

  • for hex grids: floor/ceil are no longer used to lay out the tiles (I think this was responsible for the layout error accumulation?)

  • for isometric grids: simplified how the math around tile layout by capturing the square -> isometric projection as a matrix, this allows us to apply a matrix inverse to easily calculate which tile a Vec2 world position belongs to (essentially, the squishes the isometric grid back to a square grid) ---- this process is also quite similar to what is happening for hex grids, so there is some unification of code between hex grid/iso grid shaders!

  • for squares/isometric grids: tile center is now at (0, 0)

  • a lot of the shaders are now quite similar, because ultimately, the math behind them has deep similarities

  • for neighbor helpers: made lots of private functions public because Make neighbour helpers public #278

examples/mouse_to_tile.rs Outdated Show resolved Hide resolved
examples/mouse_to_tile.rs Outdated Show resolved Hide resolved

/// Calculates a [`Vec2`] position for a tilemap so that when set to this position, it shows up
/// centered on the screen.
pub fn get_tilemap_center(size: &TilemapSize, tile_size: &TilemapTileSize) -> Vec2 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If our tiles are centered now do we need this? Or is that only the case for hex/iso?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, but I think so? This is for centering the whole tilemap, right? Currently, our tiles are "centered" in the sense that the center of a tile with TilePos(0, 0) lies at [0, 0] in world space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants