SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
Terrain.h
1#ifndef Terrain_H
2#define Terrain_H
3
4#include "AzulCore.h"
5class Collidable;
8
17class Terrain
18{
19public:
20 Terrain() = delete;
21 Terrain(const Terrain&) = delete;
22 Terrain& operator=(const Terrain&) = delete;
23 ~Terrain();
24
35 Terrain(const char* heightmapFile, float sideLength, float maxHeight, float worldZeroAltitude, std::string texture, float uRep, float vRep);
36
41 void ShowCellBelow(const Vect& pos) const;
42
48 Vect GetHeight(const Vect& pos);
49
56 Vect GetHeightAndNormal(const Vect& pos, Vect& outNormal);
57
64 const CollisionVolumeAABB& GetCellAABB(int x, int z) const;
65
74 void GetCoveredCells(const CollisionVolume& vol, int& xMin, int& zMin, int& xMax, int& zMax) const;
75
80 int GetMaxCellIndex() const;
81
86 float GetSideLen() const;
87
92 int GetImgSize() const;
93
98 void EnableWireframe(bool enable);
99
104 void EnableMinMax(bool enable);
105
106private:
107 friend class TerrainAttorney;
108
112 void Draw();
113
120 int VertexIndex(int i, int j);
121
128 int PixelIndex(int i, int j);
129
136 int TriIndex(int i, int j);
137
138 float GetCellX(int j) const;
139 float GetCellZ(int i) const;
140 float GetCellLength() const;
141
142 GraphicsObject_WireframeAutoColor* pWireframe;
143 GraphicsObject_TextureFlat* pGOTerrain;
145
146 VertexStride_VUN* pVerts;
147 TriangleIndex* tlist;
149 float sideLen;
150
152 {
153 float minY;
154 float maxY;
155 };
160};
161
162#endif
Base class for objects that can participate in collision detection.
Definition Collidable.h:26
Represents an axis-aligned bounding box (AABB) collision volume.
Definition CollisionVolumeAABB.h:23
Base class for collision volumes.
Definition CollisionVolume.h:19
void Draw()
Renders the terrain.
Definition Terrain.cpp:307
int GetImgSize() const
Gets the size of the heightmap image (number of pixels per side).
Definition Terrain.cpp:292
void EnableMinMax(bool enable)
Enables or disables MinMax visualization for terrain cells.
Definition Terrain.cpp:302
const CollisionVolumeAABB & GetCellAABB(int x, int z) const
Gets the AABB for a specific terrain cell.
Definition Terrain.cpp:233
int GetMaxCellIndex() const
Gets the maximum valid cell index (for both X and Z).
Definition Terrain.cpp:281
Vect GetHeightAndNormal(const Vect &pos, Vect &outNormal)
Gets the height and normal at a given world position.
Definition Terrain.cpp:199
bool wireframeEnabled
Flag to enable/disable wireframe rendering.
Definition Terrain.h:158
int TriIndex(int i, int j)
Computes the triangle index for grid coordinates.
Definition Terrain.cpp:356
int PixelIndex(int i, int j)
Computes the pixel index for grid coordinates.
Definition Terrain.cpp:351
TriangleIndex * tlist
Triangle list for terrain.
Definition Terrain.h:147
int imgSize
Size of the heightmap image (number of pixels per side).
Definition Terrain.h:148
GraphicsObject_TextureFlat * pGOTerrain
Graphics object for terrain texture.
Definition Terrain.h:143
int VertexIndex(int i, int j)
Computes the vertex index for grid coordinates.
Definition Terrain.cpp:346
VertexStride_VUN * pVerts
Vertex data for terrain.
Definition Terrain.h:146
GraphicsObject_WireframeAutoColor * pWireframe
Wireframe object for terrain visualization.
Definition Terrain.h:142
void EnableWireframe(bool enable)
Enables or disables wireframe rendering for the terrain.
Definition Terrain.cpp:297
float GetSideLen() const
Gets the side length of the terrain.
Definition Terrain.cpp:287
void ShowCellBelow(const Vect &pos) const
Visualizes the cell below a given world position.
Definition Terrain.cpp:151
void GetCoveredCells(const CollisionVolume &vol, int &xMin, int &zMin, int &xMax, int &zMax) const
Computes the range of cells covered by a collision volume.
Definition Terrain.cpp:243
CellMinMax * cellBounds
Array of min/max Y values for terrain cells.
Definition Terrain.h:156
Vect GetHeight(const Vect &pos)
Gets the height at a given world position.
Definition Terrain.cpp:166
bool minmaxEnabled
Flag to enable/disable MinMax visualization.
Definition Terrain.h:159
float sideLen
Length of one side of the terrain (world units).
Definition Terrain.h:149
Model * pModelTerrain
Model object for terrain geometry.
Definition Terrain.h:144
CollisionVolumeAABB * cellAABBs
Array of AABBs for terrain cells.
Definition Terrain.h:157
< Structure to hold min and max Y values for terrain cells.
Definition Terrain.h:152