


However, an alternate design choice is to reuse a standard vector library for all of these types, and then use standard matrix multiply for the layout. I use structs instead of arrays of numbers because giving a name to things helps me understand them, and also helps with type checking.

Later on the page, FractionalHex is double, and OffsetCoord is int. Orientation is an angle, a double, and two matrices, each double or double. Side note: observe how many of these are arrays of numbers underneath. This is confusing, I know, but the alternative was to use Hex(q, s, r) which I think is also confusing. Note the order is different: on the main page, axial r corresponds to cube z, so Hex(q, r, s) is the same as Cube(q, s, r). Here’s a class that represents cube coordinates, but uses names q, r, s instead of the x, z, y I use on the main page. Axial coordinates have two axes q,r that are 60° or 120° apart. Cube coordinates are a plane in x,y,z space, where x+y+z = 0. On the main page, I treat Cube and Axial systems separately.
#Easy to use hex map maker code
I’m going to use C++ for the code samples, but I also have Java, C#, Python, Javascript, Haxe, and Lua versions of the code. I cover pathfinding for graphs on another page and won’t duplicate that code here. Once I have coordinates and the neighbors function implemented I can use all graph algorithms including movement range and pathfinding.I’ll define a second class FractionalHex for the two algorithms where I want to have floating point coordinates: linear interpolation and rounding. The main article doesn’t distinguish hexes that have integer coordinates from those with fractional coordinates.The same things I need to deal with for hex to screen (y-axis direction, stretch/squash, origin) have to be dealt with for screen to hex, so it makes sense to put them together. I also need a way to convert mouse clicks and other pixel coordinates back into hex coordinates.The main article always places the 0,0 hex at x=0, y=0. Support the 0,0 hex being located on the screen anywhere.The main article only supports equilateral hexes. Support stretched or squashed hexes, which are common with pixel graphics.The main article only covers y-axis pointing down.

