Step 2: The MapGrid coordinates
The MapGrid converts pixels into hexagons and hexparts coordinates.
The Hexagon object has a
name ( 0101, A12, etc ) and a MapGrid x, y coordinate.
The Hexpart object also has a MapGrid x, y
coordinate. The Hexpart is either the hexagon center, or a hexside. The Hexpart has a hexpartType number.
The HexpartTypes are center = 0, bottom = 1, lowerLeft = 2, upperLeft = 3. The Hexpart also has the
MapGrid x, y coordinate of it's reference Hexagon.
range, bearing, and
line of sight methods.
The big challange: the hexagon map
Every wargame numbering system does not work for
programming. Another coordinate system needs to be used.
Screen pixels do not work
the mouse events return screen pixels.
This is not useful in any wargame calculations.
Cartesian coordinates do not work well
Geometry coordinates
Using the triangle as a reference, create a grid where
the bottom of the triangle is 2 units long. Using trigonometry, the height
of the triangle is sqrt( 42 - 22) = 2 √ 3
These coordinates are difficult to use.
Geometry coordinates do not work well
The solution: get rid of the √ 3
By creating another Y-axis that divides the √ 3, a new axis can be used that
has just integer numbers, and still can be reference the real cartesian
coordinate system and follow the rules of analytic geometry.
The
X-axis is NOT divided by √ 3. That's ok.
The X-axis and Y-axis are not on the same scale.
The mapGrid function calculates a grid over the map that identifies a hexpart and hexagon coordinate.
The hexpart coordinates just factors out
the √ 3 on the Y-axis.The hexpart coordinates adjust the X-axis by dividing by 3.
Notice that the hexagon with the triangle has:
24, 16 √ 3 = 8, 16 hexpartsThe hexparts are used to calculate movement, rane, bearing and line of sight.
This works !
how mapGrid works
Although the hexagon numbering system has been abandoned for calculations, we still need to display the hexagon name to the wargamer. The Hexagon function converts the hexagon coordinates into a wargame numbering system, such as 0101 or A1. This preserves the wargame playing system.
| North | x + 0, y - 4 |
| Northeast | x + 2, y - 2 |
| Southeast | x + 2, y + 2 |
| South | x + 0, y + 4 |
| Southwest | x - 2, y + 2 |
| Northwest | x - 2, y - 2 |