#include <Hex.h>
Public Member Functions | |
Hex () | |
Pulic constructor. | |
Hex (int x, int y) | |
Creates hex at given location. | |
~Hex () | |
Virtual destructor. | |
Hex | NeighborHex (int dir) const |
Gets neighbor hex in given direction. | |
int | HexRange (Hex hex) const |
Gets range to given hex. | |
void | NextHexes (Hex h0, Hex h1, Hex prev1, Hex prev2, Hex &next1, Hex &next2) const |
Gets next hexes between two hexes. | |
bool | IntersectsLine (double x0, double y0, double x1, double y1) const |
Checks if line intersects hex. | |
bool | IsEmpty () const |
Checks if hex is empty. | |
void | SetEmpty () |
Mark hex as empty. | |
bool | operator== (const Hex &hex) const |
Checks for equality with another hex. | |
bool | operator!= (const Hex &hex) const |
Checks for inequality with another hex. | |
int | GetHexX () |
Gets X coordinate in hex units. | |
int | GetHexY () |
Gets Y coordinate in hex coordinates. | |
Private Attributes | |
bool | m_IsEmpty |
Indicates that hex is empty. | |
int | m_HexX |
X coordinate in hex units. | |
int | m_HexY |
Y coordinate in hex units. | |
double | m_CenterX |
X coordinate of hex center. | |
double | m_CenterY |
Y coordinate of hex center. | |
double | m_PointX [6] |
Array of X coordinates for hex corners. | |
double | m_PointY [6] |
Array of Y coordinates for hex corners. |
Hex | ( | ) | [inline] |
Pulic constructor.
Hex | ( | int | x, | |
int | y | |||
) |
Creates hex at given location.
-x\__/ \__/ \__/ \__/+y <-- 'hy' axis __/-x\__/ \__/ \__/+y\__ \__/-x\__/ \__/+y\__/ __/ \__/-x\__/+y\__/ \__ \__/ \__/00\__/ \__/ __/ \__/-y\__/+x\__/ \__ \__/-y\__/ \__/+x\__/ __/-y\__/ \__/ \__/+x\__ -y\ / \ / \ / \ /+x <-- 'hx' axis
The vertices are stored counter-clockwise as follows:
2---1 x / \ x 3 0 x \ / x 4---5 x
The center point of hex(0,0) is at cartesian coordinate (0,0). The cartesian coordinate system is scaled such that all centers and vertex coordinates lie on integral values to eliminate precision loss during cross-product calculations.
x | X coordinate in hex units. |
y | Y coordinate in hex units. |
~Hex | ( | ) |
Virtual destructor.
Hex NeighborHex | ( | int | dir | ) | const |
Gets neighbor hex in given direction.
\__/ dir pa pb dx dy \__/1 \__/ _/2 \__/0 \_ 0 0 1 0 +1 \__/ \__/ 1 1 2 -1 +1 _/3 \__/5 \_ 2 2 3 -1 0 \__/4 \__/ 3 3 4 0 -1 / \__/ \ 4 4 5 +1 -1 / \ 5 5 0 +1 0
Where 'dir' is the direction, 'pa' and 'pb' are the indexes of the endpoints of the face seperating the hexes, and 'dx' and 'dy' are the hex coordinate deltas.
Note that the index of the first endpoint of a face is equal to the direction used to exit through that face.
dir | direction of neighboring hex. |
int HexRange | ( | Hex | hex | ) | const |
Gets range to given hex.
hex | Target hex for range calculations. |
Gets next hexes between two hexes.
h0 | Start hex. |
h1 | End hex. |
prev1 | First previous hex. |
prev2 | Second previous hex. |
next1 | First next hex. |
next2 | Second next hex. |
bool IntersectsLine | ( | double | x0, | |
double | y0, | |||
double | x1, | |||
double | y1 | |||
) | const |
Checks if line intersects hex.
x0 | First X coordinate. |
y0 | First Y coordinate. |
x1 | Second X coordinate. |
y1 | Second Y coordinate. |
bool IsEmpty | ( | ) | const [inline] |
Checks if hex is empty.
void SetEmpty | ( | ) | [inline] |
Mark hex as empty.
bool operator== | ( | const Hex & | hex | ) | const [inline] |
Checks for equality with another hex.
bool operator!= | ( | const Hex & | hex | ) | const [inline] |
Checks for inequality with another hex.
int GetHexX | ( | ) | [inline] |
Gets X coordinate in hex units.
int GetHexY | ( | ) | [inline] |
Gets Y coordinate in hex coordinates.
bool m_IsEmpty [private] |
Indicates that hex is empty.
int m_HexX [private] |
X coordinate in hex units.
int m_HexY [private] |
Y coordinate in hex units.
double m_CenterX [private] |
X coordinate of hex center.
double m_CenterY [private] |
Y coordinate of hex center.
double m_PointX[6] [private] |
Array of X coordinates for hex corners.
double m_PointY[6] [private] |
Array of Y coordinates for hex corners.
Navigation
Home Page
Screen Shots
Developers
Documentation
Doxygen
Namespace List
Class List
Class Hierarchy
File List
Todo List
Links
SDL Library
License
SourceForge Project
Forums
Download
Regimental Command
Copyright © 2008
Randi J. Relander