TerrainBase Class Reference
[Game Data]

basic terrain class More...

#include <terrain_base.h>

Inherited by TerrainServer.

Inheritance diagram for TerrainBase:

Inheritance graph
[legend]
List of all members.

Public Types

typedef Uint8 THeightMapValue

Public Member Functions

 TerrainBase ()
virtual ~TerrainBase ()
bool loadHeightmap (const std::string fileName)
 Loads heightmap.
void getExtents (int &x, int &y)
 Obtains terrain size (heightmap extents).
double getHeight (double x, double y)
 Height at given point (interpolated, continuous case).
THeightMapValue getTrueHeight (int x, int y)
 Height at given point (heightmap value, discrete case).
double getScaledHeight (int x, int y)
 Height at given point (heightmap scaled value, discrete case).
double getScaledMaxHeight (void)
 Obtains the maximal height scale.
GLVector3d & getScale (GLVector3d &scale)
 Obtains the current scale vector.
GLVector3d getScale (void)
 Obtains a scale vector (vector, that describes the terrain extent).
void setScale (const GLVector3d &scale)
 Sets a scale vector (vector, that describes the terrain extent).
GLVector3d & getRealScale (GLVector3d &scale)
 obtains the real scale-vector.
GLVector3d getRealScale (void)
 obtains the real scale-vector.
GLVector3d & getRealScaleInv (GLVector3d &scaleInv)
 obtains the real scale-vector inverted.
GLVector3d getRealScaleInv (void)
 obtains the real scale-vector inverted.

Protected Member Functions

virtual bool allocateHeightmap (int sizeX, int sizeY)
 allocates memory and sets the heightmap pointer.

Protected Attributes

THeightMapValuemHeightMap
 heightmap values, mSizeX * mSizeY bytes.

Private Member Functions

THeightMapValue createHeightValueFromColor (SDL_Color *col)
 color-to-height value transform routine Calculates intensity (Uint8) from the RGB triplet and rounds it.

Private Attributes

int mSizeX
int mSizeY
 terrain extents (physical size of the heightmap).
GLVector3d mScale
 height and extents scale.
GLVector3d mScaleInv
 inverted height and extents scale.

Detailed Description

basic terrain class

Provides heightmap and extents manipulation routines.

Definition at line 18 of file terrain_base.h.


Member Typedef Documentation

typedef Uint8 TerrainBase::THeightMapValue
 

Definition at line 21 of file terrain_base.h.


Constructor & Destructor Documentation

TerrainBase::TerrainBase  ) 
 

Definition at line 8 of file terrain_base.cpp.

TerrainBase::~TerrainBase  )  [virtual]
 

Definition at line 16 of file terrain_base.cpp.

References mHeightMap.


Member Function Documentation

bool TerrainBase::allocateHeightmap int  sizeX,
int  sizeY
[protected, virtual]
 

allocates memory and sets the heightmap pointer.

Parameters:
sizeX the size of the heightmap in x axis
sizeY the size of the heightmap in y axis
Returns:
false, if there is not enough memory ;-)
Note:
If the heightmap was already allocated, it is deleted.

Reimplemented in TerrainRoetger.

Definition at line 52 of file terrain_base.cpp.

References mHeightMap, mSizeX, and mSizeY.

Referenced by TerrainRoetger::allocateHeightmap(), and loadHeightmap().

TerrainBase::THeightMapValue TerrainBase::createHeightValueFromColor SDL_Color *  col  )  [inline, private]
 

color-to-height value transform routine Calculates intensity (Uint8) from the RGB triplet and rounds it.

Parameters:
col RGB triplet.
Returns:
8-bit unsigned height value

Definition at line 279 of file terrain_base.h.

Referenced by loadHeightmap().

void TerrainBase::getExtents int &  x,
int &  y
[inline]
 

Obtains terrain size (heightmap extents).

Parameters:
x heightmap extent in x axis
y heightmap extent in y axis

Definition at line 210 of file terrain_base.h.

References mSizeX, and mSizeY.

Referenced by TerrainRoetger::calculate_roughness(), TerrainServer::createBlocks(), TerrainGeoMipMap::createBlocks(), TerrainServer::getDescriptor(), Terrain::getExtents(), TerrainRoetger::index(), TerrainSimple::render(), TerrainRoetger::render(), TerrainGeoMipMap::render(), and TerrainGeoMipMap::setDescriptor().

double TerrainBase::getHeight double  x,
double  y
 

Height at given point (interpolated, continuous case).

It scales x, y to Terrain's extent, determines height values of closest neighbours (given by integer part of translated x, y) and returns interpolated height from them (using non-integer part). Heightmap values can be stored in the range of <0, 255>. However, this function returns scaled height - height is scaled to <0.0, 1.0> and multiplied by previously set scale-factor.

Parameters:
x x-coordinate of point - should be in terrain's scaled extent
y y-coordinate of point - should be in terrain's scaled extent
Returns:
interpolated height or some constant value if unknown

Definition at line 21 of file terrain_base.cpp.

References getTrueHeight(), mScale, and mScaleInv.

Referenced by Terrain::getHeight().

Here is the call graph for this function:

GLVector3d TerrainBase::getRealScale void   )  [inline]
 

obtains the real scale-vector.

Returns:
vector that scales terrain from its heightmap extents to virtual extents.
See also:
getRealScale(GLVector3d &scale)

Definition at line 252 of file terrain_base.h.

Referenced by TerrainSimple::render(), TerrainRoetger::render(), TerrainGeoMipMap::render(), TerrainRoetger::update(), and TerrainGeoMipMap::update().

GLVector3d & TerrainBase::getRealScale GLVector3d &  scale  )  [inline]
 

obtains the real scale-vector.

This is mainly for rendering purposes. Others will use public getScale that is derived from normalized extent.

Returns:
vector that scales terrain from its heightmap extents to virtual extents.
Note:
This difers from public getScale which returns scale that is derived from normalized (1, 1, 1) extent.

Definition at line 247 of file terrain_base.h.

References mScale.

Referenced by TerrainServer::TerrainBlock::createTriMeshData(), and TerrainGeoMipMap::TerrainBlock::initLevels().

GLVector3d TerrainBase::getRealScaleInv void   )  [inline]
 

obtains the real scale-vector inverted.

Returns:
vector that scales terrain from its virtual extents to heightmap extents.
See also:
getRealScale(GLVector3d &scale)

Definition at line 263 of file terrain_base.h.

Referenced by TerrainRoetger::update(), and TerrainGeoMipMap::update().

GLVector3d & TerrainBase::getRealScaleInv GLVector3d &  scaleInv  )  [inline]
 

obtains the real scale-vector inverted.

Returns:
vector that scales terrain from its virtual extents to heightmap extents.
See also:
getRealScale(GLVector3d &scale)

Definition at line 258 of file terrain_base.h.

References mScaleInv.

GLVector3d TerrainBase::getScale void   )  [inline]
 

Obtains a scale vector (vector, that describes the terrain extent).

Returns:
current scale vector
See also:
getScale(GLVector3d &scale)

Definition at line 241 of file terrain_base.h.

GLVector3d & TerrainBase::getScale GLVector3d &  scale  )  [inline]
 

Obtains the current scale vector.

Current scale vector is a vector that describes the "public extents" of the terrain.

Parameters:
scale 3D scale vector (where to store result)
Returns:
current scale vector
Note:
The scale vector describes, how much to scale the terrian's normalized extent <<0.0, 1.0>, <0.0, 1.0>, <0.0, 1.0>>. One should take care of aspect ratio when setting the scale.

Definition at line 233 of file terrain_base.h.

References mScale, mSizeX, and mSizeY.

Referenced by Terrain::getScale().

double TerrainBase::getScaledHeight int  x,
int  y
[inline]
 

Height at given point (heightmap scaled value, discrete case).

Does the same as getTrueHeightAt(int x, int y) but scales the returned value.

Parameters:
x x-coord of point - should be in terrain's non-scaled extent
y y-coord of point - should be in terrain's non-scaled extent
Returns:
scaled heightmap value at x, y or some constant if unknown
See also:
getTrueHeight

Definition at line 223 of file terrain_base.h.

References getTrueHeight(), and mScale.

Referenced by TerrainRoetger::add_height_error(), and Terrain::getScaledHeight().

Here is the call graph for this function:

double TerrainBase::getScaledMaxHeight void   )  [inline]
 

Obtains the maximal height scale.

Returns:
maximal height scale

Definition at line 228 of file terrain_base.h.

References mScale.

Referenced by Terrain::getScaledMaxHeight().

TerrainBase::THeightMapValue TerrainBase::getTrueHeight int  x,
int  y
[inline]
 

Height at given point (heightmap value, discrete case).

Performs heightmap lookup at map's x, y coordinates. If terrain paging is implemented, the page that contains x, y is determined first and the lookup is delegated to it.

Parameters:
x x-coord of point - should be in terrain's non-scaled extent
y y-coord of point - should be in terrain's non-scaled extent
Returns:
heightmap value at x, y or some constant if unknown

Definition at line 215 of file terrain_base.h.

References mHeightMap, mSizeX, and mSizeY.

Referenced by TerrainServer::TerrainBlock::createTriMeshData(), TerrainGeoMipMap::TerrainBlock::getDelta(), getHeight(), getScaledHeight(), Terrain::getTrueHeight(), TerrainGeoMipMap::TerrainBlock::initLevels(), TerrainGeoMipMap::NodeDelegate::nodeCreation(), TerrainSimple::render(), TerrainGeoMipMap::TerrainBlock::render(), TerrainRoetger::render_quadtree(), TerrainGeoMipMap::TerrainBlock::renderTriFanA(), and TerrainGeoMipMap::TerrainBlock::renderTriFanB().

bool TerrainBase::loadHeightmap const std::string  fileName  ) 
 

Loads heightmap.

Performs following steps: 1) Loads picture given by FileName using SDL_Image, saves it temporary in SDL_Surface 2) Converts to compact-form (1-byte-height-value) 3) Frees SDL_Surface

Parameters:
fileName SDL_Image's supported picture format (*.BMP, *.PNG, ...)
Returns:
true on success, otherwise false

Definition at line 69 of file terrain_base.cpp.

References allocateHeightmap(), createHeightValueFromColor(), LOGD, LOGE, mHeightMap, mSizeX, mSizeY, and TIN.

Referenced by Terrain::loadHeightmap().

Here is the call graph for this function:

void TerrainBase::setScale const GLVector3d &  scale  )  [inline]
 

Sets a scale vector (vector, that describes the terrain extent).

        // An example of setting "my own" scale in meters:
        // for example in meters (m)
        const double ToMyUnits = 5;     // "one heightmap pixel is a 5 m"
        double desiredTerrainHeightInMyUnits = 100;     // "maximal height will be 100 m"
        
        terrain.GetExtents(extX, extY); 
        terrain.setScale(GLVector3d(extX*ToMyUnits, extY*ToMyUnits, desiredTerrainHeightInMyUnits)) 

Note that rendered output will be scaled by the scale vector.

Parameters:
scale 3D scale vector
Note:
The scale vector describes, how much to scale the terrian's normalized extent <<0.0, 1.0>, <0.0, 1.0>, <0.0, 1.0>>. One should take care of aspect ratio when setting the scale.

Definition at line 269 of file terrain_base.h.

References mScale, mScaleInv, and mSizeX.

Referenced by Terrain::setScale().


Member Data Documentation

THeightMapValue* TerrainBase::mHeightMap [protected]
 

heightmap values, mSizeX * mSizeY bytes.

Definition at line 154 of file terrain_base.h.

Referenced by allocateHeightmap(), getTrueHeight(), loadHeightmap(), and ~TerrainBase().

GLVector3d TerrainBase::mScale [private]
 

height and extents scale.

Definition at line 150 of file terrain_base.h.

Referenced by getHeight(), getRealScale(), getScale(), getScaledHeight(), getScaledMaxHeight(), and setScale().

GLVector3d TerrainBase::mScaleInv [private]
 

inverted height and extents scale.

Definition at line 151 of file terrain_base.h.

Referenced by getHeight(), getRealScaleInv(), and setScale().

int TerrainBase::mSizeX [private]
 

Definition at line 148 of file terrain_base.h.

Referenced by allocateHeightmap(), getExtents(), getScale(), getTrueHeight(), loadHeightmap(), and setScale().

int TerrainBase::mSizeY [private]
 

terrain extents (physical size of the heightmap).

Definition at line 148 of file terrain_base.h.

Referenced by allocateHeightmap(), getExtents(), getScale(), getTrueHeight(), and loadHeightmap().


The documentation for this class was generated from the following files:
Generated on Wed Apr 12 14:27:36 2006 for bjs by  doxygen 1.4.5