Cafu Engine
TerrainT Class Reference

This class represents terrains, offering methods for LoD rendering and collision detection. More...

#include "Terrain.hpp"

Classes

class  CVS_VertexT
 This is the processed, ready to use vertex data. More...
 
class  InitError
 An error class that is thrown upon init errors in the constructor. More...
 
struct  VertexT
 
struct  ViewInfoT
 

Public Member Functions

 TerrainT ()
 Constructor for creating a simple dummy terrain. More...
 
 TerrainT (const char *FileNameHeightMap, const BoundingBox3fT &BB_, bool FailSafe=true)
 The constructor for creating and initializing the terrain from the file specified by FileNameHeightMap. More...
 
 TerrainT (const char *FileNameHeightMap, const Vector3fT &Resolution, bool FailSafe=true)
 Constructor as above, except that instead of the bounding box, a Resolution vector is passed in. More...
 
 TerrainT (const unsigned short *HeightData, unsigned long SideLength, const BoundingBox3fT &BB_)
 The constructor for creating and initializing the terrain from the data specified in HeightData. More...
 
void UpdateHeights (const unsigned short *HeightData, unsigned long PosX, unsigned long PosY, unsigned long SizeX, unsigned long SizeY)
 Updates the vertices in the given rectangle with new heights from the given height field. More...
 
const VertexTGetVertices () const
 This functions returns a pointer to the vertices of the terrain, intended for use with the ComputeIndexStripByRefinement() function. More...
 
unsigned long GetSize () const
 Returns the number of vertices along one side of the terrain/heightmap, e.g. 257, 513, 1025, ... More...
 
const BoundingBox3fTGetBB () const
 Returns the bounding-box (i.e. the lateral dimensions) of the terrain/heightmap. More...
 
ArrayT< Vector3fT > & ComputeVectorStrip (const TerrainT::ViewInfoT &VI) const
 This function computes a triangle strip of vertices that approximates the terrain according to the parameters in VI. More...
 
ArrayT< unsigned long > & ComputeIndexStripByRefinement (const ViewInfoT &VI) const
 This function computes a triangle strip that approximates the terrain according to the parameters in VI. More...
 
ArrayT< Vector3fT > & ComputeVectorStripByMorphing (const ViewInfoT &VI) const
 This function computes a triangle strip of vectors that approximates the terrain according to the parameters in VI. More...
 
void TraceBoundingBox (const BoundingBox3dT &TraceBB, const VectorT &Origin, const VectorT &Dir, VB_Trace3T< double > &Trace) const
 Traces the (relative) bounding box TraceBB from the (absolute) Origin along Dir towards the end position Origin+VectorScale(Dir, Trace.Fraction). More...
 

Friends

class QuadTreeT
 

Detailed Description

This class represents terrains, offering methods for LoD rendering and collision detection.

Constructor & Destructor Documentation

TerrainT::TerrainT ( )

Constructor for creating a simple dummy terrain.

The main purpose is to be able to store TerrainTs in container classes.

TerrainT::TerrainT ( const char *  FileNameHeightMap,
const BoundingBox3fT BB_,
bool  FailSafe = true 
)

The constructor for creating and initializing the terrain from the file specified by FileNameHeightMap.

FileNameHeightMap should be the file name of a gray-scale heightmap in bmp, tga, or png file format. The heightmap must be square, and the side lengths be of the form (2^n)+1, where n is in range 1...15. (Thus, the smallest permissible heightmap has size 3x3, the largest 32769x32769.) The bounding box BB determines the lateral dimensions of the terrain. If FailSafe is set to false, InitError is thrown on problems reading the file or violation of the above constraints. Otherwise, a simple default heightmap is substituted.

TerrainT::TerrainT ( const char *  FileNameHeightMap,
const Vector3fT Resolution,
bool  FailSafe = true 
)

Constructor as above, except that instead of the bounding box, a Resolution vector is passed in.

The resolution describes the distance between two elements of the height map in x- and y-direction, as well as the distance between two height values (z-direction). The resulting terrain is centered at the origin.

TerrainT::TerrainT ( const unsigned short *  HeightData,
unsigned long  SideLength,
const BoundingBox3fT BB_ 
)

The constructor for creating and initializing the terrain from the data specified in HeightData.

The heightmap must be square, and the side lengths be of the form (2^n)+1, where n is in range 1...15. (Thus, the smallest permissible heightmap has size 3x3, the largest 32769x32769.) The bounding box BB determines the lateral dimensions of the terrain.

Member Function Documentation

ArrayT< unsigned long > & TerrainT::ComputeIndexStripByRefinement ( const ViewInfoT VI) const

This function computes a triangle strip that approximates the terrain according to the parameters in VI.

For this purpose, the method of refinement is employed, and there is no geo-morphing to prevent sudden popping. The returned triangle strip consists of indices into the array of terrain vertices, which in turn can be obtained by calling the GetVertices() function. Note that the real strip index data starts at index 1 of the returned array, and thus the first entry (at array index 0) should be skipped or ignored. Also, the returned array is global and thus mutable. It will change upon the next call to this function of any terrain object.

ArrayT< Vector3fT > & TerrainT::ComputeVectorStrip ( const TerrainT::ViewInfoT VI) const

This function computes a triangle strip of vertices that approximates the terrain according to the parameters in VI.

For this purpose, geo-morphing is employed in order to prevent sudden popping and to simultaneously allow for greater error tolerances. The returned array is global and thus mutable. It will change upon the next call to this function of any terrain object.

ArrayT< Vector3fT > & TerrainT::ComputeVectorStripByMorphing ( const ViewInfoT VI) const

This function computes a triangle strip of vectors that approximates the terrain according to the parameters in VI.

For this purpose, geo-morphing is employed in order to prevent sudden popping and simultaneously allow for greater error tolerances. Note that the real strip vector data starts at index 1 of the returned array, and thus the first entry (at array index 0) should be skipped or ignored. Also, the returned array is global and thus mutable. It will change upon the next call to this function of any terrain object.

const BoundingBox3fT& TerrainT::GetBB ( ) const
inline

Returns the bounding-box (i.e. the lateral dimensions) of the terrain/heightmap.

unsigned long TerrainT::GetSize ( ) const
inline

Returns the number of vertices along one side of the terrain/heightmap, e.g. 257, 513, 1025, ...

const TerrainT::VertexT * TerrainT::GetVertices ( ) const

This functions returns a pointer to the vertices of the terrain, intended for use with the ComputeIndexStripByRefinement() function.

void TerrainT::TraceBoundingBox ( const BoundingBox3dT TraceBB,
const VectorT Origin,
const VectorT Dir,
VB_Trace3T< double > &  Trace 
) const

Traces the (relative) bounding box TraceBB from the (absolute) Origin along Dir towards the end position Origin+VectorScale(Dir, Trace.Fraction).

The result is returned in Trace, indicating if and where the trace was stopped.

void TerrainT::UpdateHeights ( const unsigned short *  HeightData,
unsigned long  PosX,
unsigned long  PosY,
unsigned long  SizeX,
unsigned long  SizeY 
)

Updates the vertices in the given rectangle with new heights from the given height field.

Note that this method is a HACK, because it INVALIDATES the auxiliary data that is computed in the constructor; the nested error metrics, radii and collision data in the quad-tree all become INVALID after a call to this method. The purpose of this method is to allow for quick but temporary changes in terrain heights of small magnitude, e.g. while the mouse button is held down for a single tool application in a terrain editor.

Parameters
HeightDataA pointer to a new heightmap of dimensions GetSize()*GetSize() from which the new heights are taken.
PosXThe x-origin of the rectangle in which the vertices are updated.
PosYThe y-origin of the rectangle in which the vertices are updated.
SizeXThe width of the rectangle in which the vertices are updated.
SizeYThe height of the rectangle in which the vertices are updated.

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