SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
Terrain Class Reference

Represents a 3D terrain generated from a heightmap. More...

#include <Terrain.h>

Classes

struct  CellMinMax
 < Structure to hold min and max Y values for terrain cells. More...
 

Public Member Functions

 Terrain (const Terrain &)=delete
 
Terrainoperator= (const Terrain &)=delete
 
 Terrain (const char *heightmapFile, float sideLength, float maxHeight, float worldZeroAltitude, std::string texture, float uRep, float vRep)
 Constructs a Terrain from a heightmap file.
 
void ShowCellBelow (const Vect &pos) const
 Visualizes the cell below a given world position.
 
Vect GetHeight (const Vect &pos)
 Gets the height at a given world position.
 
Vect GetHeightAndNormal (const Vect &pos, Vect &outNormal)
 Gets the height and normal at a given world position.
 
const CollisionVolumeAABBGetCellAABB (int x, int z) const
 Gets the AABB for a specific terrain cell.
 
void GetCoveredCells (const CollisionVolume &vol, int &xMin, int &zMin, int &xMax, int &zMax) const
 Computes the range of cells covered by a collision volume.
 
int GetMaxCellIndex () const
 Gets the maximum valid cell index (for both X and Z).
 
float GetSideLen () const
 Gets the side length of the terrain.
 
int GetImgSize () const
 Gets the size of the heightmap image (number of pixels per side).
 
void EnableWireframe (bool enable)
 Enables or disables wireframe rendering for the terrain.
 
void EnableMinMax (bool enable)
 Enables or disables MinMax visualization for terrain cells.
 

Private Member Functions

void Draw ()
 Renders the terrain.
 
int VertexIndex (int i, int j)
 Computes the vertex index for grid coordinates.
 
int PixelIndex (int i, int j)
 Computes the pixel index for grid coordinates.
 
int TriIndex (int i, int j)
 Computes the triangle index for grid coordinates.
 
float GetCellX (int j) const
 
float GetCellZ (int i) const
 
float GetCellLength () const
 

Private Attributes

GraphicsObject_WireframeAutoColor * pWireframe
 Wireframe object for terrain visualization.
 
GraphicsObject_TextureFlat * pGOTerrain
 Graphics object for terrain texture.
 
Model * pModelTerrain
 Model object for terrain geometry.
 
VertexStride_VUN * pVerts
 Vertex data for terrain.
 
TriangleIndex * tlist
 Triangle list for terrain.
 
int imgSize
 Size of the heightmap image (number of pixels per side).
 
float sideLen
 Length of one side of the terrain (world units).
 
CellMinMaxcellBounds
 Array of min/max Y values for terrain cells.
 
CollisionVolumeAABBcellAABBs
 Array of AABBs for terrain cells.
 
bool wireframeEnabled
 Flag to enable/disable wireframe rendering.
 
bool minmaxEnabled
 Flag to enable/disable MinMax visualization.
 

Friends

class TerrainAttorney
 

Detailed Description

Represents a 3D terrain generated from a heightmap.

The Terrain class encapsulates the data and operations for a 3D terrain, including geometry generation, collision detection, and rendering. It provides methods to query height and normal at a position, visualize cells, and interact with collidable objects.

Constructor & Destructor Documentation

◆ Terrain()

Terrain::Terrain ( const char * heightmapFile,
float sideLength,
float maxHeight,
float worldZeroAltitude,
std::string texture,
float uRep,
float vRep )

Constructs a Terrain from a heightmap file.

Parameters
heightmapFilePath to the heightmap image file.
sideLengthLength of one side of the terrain (world units).
maxHeightMaximum height of the terrain (world units).
worldZeroAltitudeAltitude in world space corresponding to heightmap zero.
texturePath to the texture file.
uRepU texture repeat factor.
vRepV texture repeat factor.
Here is the call graph for this function:

Member Function Documentation

◆ EnableMinMax()

void Terrain::EnableMinMax ( bool enable)

Enables or disables MinMax visualization for terrain cells.

Parameters
enableTrue to enable MinMax visualization, false to disable.

◆ EnableWireframe()

void Terrain::EnableWireframe ( bool enable)

Enables or disables wireframe rendering for the terrain.

Parameters
enableTrue to enable wireframe, false to disable.

◆ GetCellAABB()

const CollisionVolumeAABB & Terrain::GetCellAABB ( int x,
int z ) const

Gets the AABB for a specific terrain cell.

Parameters
xCell X index.
zCell Z index.
Returns
Reference to the cell's CollisionVolumeAABB.

◆ GetCoveredCells()

void Terrain::GetCoveredCells ( const CollisionVolume & vol,
int & xMin,
int & zMin,
int & xMax,
int & zMax ) const

Computes the range of cells covered by a collision volume.

Parameters
volCollision volume.
xMinOutput minimum X index.
zMinOutput minimum Z index.
xMaxOutput maximum X index.
zMaxOutput maximum Z index.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHeight()

Vect Terrain::GetHeight ( const Vect & pos)

Gets the height at a given world position.

Parameters
posWorld position to query.
Returns
Height as a Vect.
Here is the call graph for this function:

◆ GetHeightAndNormal()

Vect Terrain::GetHeightAndNormal ( const Vect & pos,
Vect & outNormal )

Gets the height and normal at a given world position.

Parameters
posWorld position to query.
outNormalOutput parameter for the normal vector.
Returns
Height as a Vect.
Here is the call graph for this function:

◆ GetImgSize()

int Terrain::GetImgSize ( ) const

Gets the size of the heightmap image (number of pixels per side).

Returns
Image size.
Here is the caller graph for this function:

◆ GetMaxCellIndex()

int Terrain::GetMaxCellIndex ( ) const

Gets the maximum valid cell index (for both X and Z).

Returns
Maximum cell index.

◆ GetSideLen()

float Terrain::GetSideLen ( ) const

Gets the side length of the terrain.

Returns
Side length.

◆ PixelIndex()

int Terrain::PixelIndex ( int i,
int j )
private

Computes the pixel index for grid coordinates.

Parameters
iRow index.
jColumn index.
Returns
Pixel index.
Here is the caller graph for this function:

◆ ShowCellBelow()

void Terrain::ShowCellBelow ( const Vect & pos) const

Visualizes the cell below a given world position.

Parameters
posWorld position to query.
Here is the call graph for this function:

◆ TriIndex()

int Terrain::TriIndex ( int i,
int j )
private

Computes the triangle index for grid coordinates.

Parameters
iRow index.
jColumn index.
Returns
Triangle index.
Here is the caller graph for this function:

◆ VertexIndex()

int Terrain::VertexIndex ( int i,
int j )
private

Computes the vertex index for grid coordinates.

Parameters
iRow index.
jColumn index.
Returns
Vertex index.
Here is the caller graph for this function:

The documentation for this class was generated from the following files: