units
This commit is contained in:
@@ -20,9 +20,39 @@
|
||||
|
||||
#define PI 3.14159265359f
|
||||
|
||||
struct TerrainPoint {
|
||||
char height;
|
||||
#include <QVector2D>
|
||||
|
||||
struct TerrainPoint {
|
||||
unsigned char height;
|
||||
unsigned char type;
|
||||
unsigned char river;
|
||||
};
|
||||
|
||||
// Returns the 6 edge midpoints in local tile coordinates (radius = 0.5)
|
||||
inline QVector2D getHexEdgeMidpoint(int edge) {
|
||||
static const QVector2D midpoints[6] = {
|
||||
QVector2D(-0.375f, 0.21650635f), // Edge 0 (Top-Left)
|
||||
QVector2D( 0.0f, 0.43301270f), // Edge 1 (Top)
|
||||
QVector2D( 0.375f, 0.21650635f), // Edge 2 (Top-Right)
|
||||
QVector2D( 0.375f, -0.21650635f), // Edge 3 (Bottom-Right)
|
||||
QVector2D( 0.0f, -0.43301270f), // Edge 4 (Bottom)
|
||||
QVector2D(-0.375f, -0.21650635f) // Edge 5 (Bottom-Left)
|
||||
};
|
||||
return midpoints[(edge % 6 + 6) % 6];
|
||||
}
|
||||
|
||||
// Returns the coordinates of the neighbor tile sharing the given edge
|
||||
inline void getHexNeighbor(int x, int y, int edge, int &nx, int &ny) {
|
||||
bool even = (x % 2 == 0);
|
||||
switch ((edge % 6 + 6) % 6) {
|
||||
case 0: nx = x - 1; ny = even ? y : y + 1; break;
|
||||
case 1: nx = x; ny = y + 1; break;
|
||||
case 2: nx = x + 1; ny = even ? y : y + 1; break;
|
||||
case 3: nx = x + 1; ny = even ? y - 1 : y; break;
|
||||
case 4: nx = x; ny = y - 1; break;
|
||||
case 5: nx = x - 1; ny = even ? y - 1 : y; break;
|
||||
default: nx = x; ny = y; break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TERRAIN_H
|
||||
|
||||
Reference in New Issue
Block a user