Files
Ascent-of-Man/terrain.h
T
2026-11-08 15:42:54 +01:00

59 lines
1.8 KiB
C

#ifndef TERRAIN_H
#define TERRAIN_H
#define MAP_WIDTH 300
#define MAP_HEIGHT 125
#define NUM_TRIANGLES_0 6
#define NUM_TRIANGLES_SUB 4
#define NUM_TRIANGLE_VERTICES 3
#define LOD_0_SIZE 1.0f
#define LOD_0_SIZE_Y 0.4328799197461722f
//#define LOD_0_S 0.75f
//#define NUM_POINTS_05f 10
//#define NUM_POINTS_WIDTH (NUM_POINTS_05f * 3 * MAP_WIDTH*2)
//#define NUM_POINTS_HEIGHT (NUM_POINTS_05f * MAP_HEIGHT)
#define NUM_TRIANGLES NUM_TRIANGLES_0*NUM_TRIANGLES_SUB * NUM_TRIANGLES_SUB
#define PI 3.14159265359f
#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