dtTerrain::Terrain Class Reference

This is the base terrain class that provides most of the functionlity required for terrain rendering. More...

#include <terrain.h>

Inheritance diagram for dtTerrain::Terrain:

dtCore::Physical dtCore::Transformable dtCore::DeltaDrawable dtCore::Base

List of all members.

Public Member Functions

 Terrain (const std::string &name="Terrain")
 Default Constructor - Sets the name and performs some routine registration.
void AddResourcePath (const std::string &path)
 Adds a search path to the list of file paths to search for when loading terrain data or other resources.
void RemoveResourcePath (const std::string &path)
 Removes a resource path from the list of known resource paths.
const std::list< std::string > & GetResourcePathList () const
 Gets the terrain's current list of resource search paths.
const std::string FindResource (const std::string &path)
 Searches the terrains resource path list for the specified resource.
void FindAllResources (const std::string &path, std::vector< std::string > &resourcePaths)
 Searches the terrain resources path list for all resources matching the specified path.
float GetHeight (float x, float y)
 Gets the height of the terrain at the given (x,y) coordinates.
bool IsClearLineOfSight (const osg::Vec3 &pointOne, const osg::Vec3 &pointTwo)
 Given pointOne and pointTwo, both in world space and with all coordinates in Cartesian space (essentially in meters along X, Y and Z), returns true if there is a clear line of sight and false if the view is blocked.
void SetLineOfSightSpacing (float spacing)
float GetLineOfSightSpacing () const
virtual void LoadTerrainTile (PagedTerrainTile &newTile)
virtual void UnloadTerrainTile (PagedTerrainTile &toRemove)
virtual void UnloadAllTerrainTiles ()
virtual PagedTerrainTileCreateTerrainTile (const GeoCoordinates &coords)
virtual bool IsTerrainTileResident (const GeoCoordinates &coords)
virtual void EnsureTileVisibility (const std::set< GeoCoordinates > &coordList)
bool SetCachePath (const std::string &path)
 Sets the path of the terrain cache.
const std::string & GetCachePath () const
 Gets the current terrain cache.
void SetLoadDistance (float value)
float GetLoadDistance () const
void SetDataReader (TerrainDataReader *reader)
 Sets the terrain data reader.
TerrainDataReaderGetDataReader ()
 Gets the current terrain data reader.
const TerrainDataReaderGetDataReader () const
 Gets the current terrain data reader.
void SetDataRenderer (TerrainDataRenderer *renderer)
 Sets the terrain data renderer.
TerrainDataRendererGetDataRenderer ()
 Gets the current terrain data renderer.
const TerrainDataRendererGetDataRenderer () const
 Gets the current terrain data renderer.
void AddDecorationLayer (TerrainDecorationLayer *newLayer)
 Adds a new decoration layer to this terrain.
void RemoveDecorationLayer (TerrainDecorationLayer *toRemove)
 Removes the specified decoration layer from this terrain.
void RemoveDecorationLayer (const std::string &name)
 Removes a decoration layer matching the specified name.
TerrainDecorationLayerGetDecorationLayer (const std::string &name)
 Gets the decoration layer whos name matches the specified parameter.
const TerrainDecorationLayerGetDecorationLayer (const std::string &name) const
 Gets the decoration layer who's name matches the specified parameter.
unsigned int GetNumDecorationLayers () const
 Gets the number of decorator layers currently overlaid on this terrain.
void ClearDecorationLayers ()
 Removes all the decorator layers from this terrain.
void HideDecorationLayer (const std::string &name)
 Hides the decoration layer that matches the specified name.
void HideDecorationLayer (TerrainDecorationLayer *toHide)
 Hides the specified decoration layer.
void ShowDecorationLayer (const std::string &name)
 Makes the decoration layer matching the specified name visible.
void ShowDecorationLayer (TerrainDecorationLayer *toShow)
 Makes the specified decoration layer visible in the scene.
void GetDecorationLayers (std::vector< dtCore::RefPtr< TerrainDecorationLayer > > &layers)
 Fills a vector with the decoration layers currently attached to this terrain.
void SetTerrainTileFactory (PagedTerrainTileFactory &factory)
PagedTerrainTileFactoryGetTerrainTileFactory ()
virtual void OnMessage (dtCore::Base::MessageData *data)
 Override to receive messages.

Protected Member Functions

virtual ~Terrain ()
 Cleans up the terrain and its components.
virtual void PreFrame (double frameTime)
virtual void PostFrame (double frameTime)

Protected Attributes

std::queue< dtCore::RefPtr
< PagedTerrainTile > > 
mTilesToLoadQ
 List of terrain tiles currently queued up for loading.
TerrainTileMap mResidentTiles
 List of terrain tiles which are currently loaded into memory.
std::queue< dtCore::RefPtr
< PagedTerrainTile > > 
mTilesToUnloadQ
 Queue of terrain tiles that need to be cached or destroyed.


Detailed Description

This is the base terrain class that provides most of the functionlity required for terrain rendering.

This class uses a component or aggregate based design philosophy by utilizing terrain data readers and terrain data renderers. Each reader loads a specific type of terrain data and the renderer implements a particular terrain rendering algorithm. Each of these components can be dynamically changed on each instance of this terrain class.


Constructor & Destructor Documentation

dtTerrain::Terrain::Terrain ( const std::string &  name = "Terrain"  ) 

Default Constructor - Sets the name and performs some routine registration.

Parameters:
name The name of this terrain object.

dtTerrain::Terrain::~Terrain (  )  [protected, virtual]

Cleans up the terrain and its components.


Member Function Documentation

void dtTerrain::Terrain::AddResourcePath ( const std::string &  path  ) 

Adds a search path to the list of file paths to search for when loading terrain data or other resources.

This path must be relative to a path in the Delta3D data path list.

Parameters:
The new search path.

void dtTerrain::Terrain::RemoveResourcePath ( const std::string &  path  ) 

Removes a resource path from the list of known resource paths.

Parameters:
path The path to remove. If it is not currently in the list this method does nothing.

const std::list<std::string>& dtTerrain::Terrain::GetResourcePathList (  )  const [inline]

Gets the terrain's current list of resource search paths.

Returns:
The list of string paths.

const std::string dtTerrain::Terrain::FindResource ( const std::string &  path  ) 

Searches the terrains resource path list for the specified resource.

The first resource matching the specified path is returned.

Parameters:
The path to the resource to load. This should be either a filename or a path relative to the resource paths registered with the terrain.
Returns:
An absolute path to the specified resource. If the resource was not found, an empty string is returned.

void dtTerrain::Terrain::FindAllResources ( const std::string &  path,
std::vector< std::string > &  resourcePaths 
)

Searches the terrain resources path list for all resources matching the specified path.

The path to the resource to load. This should be either a filename or a path relative to the resource paths registered with the terrain. The result list filled with absolute paths to all resources matching the specified path.

float dtTerrain::Terrain::GetHeight ( float  x,
float  y 
)

Gets the height of the terrain at the given (x,y) coordinates.

Note:
This just calls the current terrain renderer's GetHeight method. If the renderer is invalid, the height returned is 0.0f.

bool dtTerrain::Terrain::IsClearLineOfSight ( const osg::Vec3 &  pointOne,
const osg::Vec3 &  pointTwo 
)

Given pointOne and pointTwo, both in world space and with all coordinates in Cartesian space (essentially in meters along X, Y and Z), returns true if there is a clear line of sight and false if the view is blocked.

Parameters:
pointOne The start point.
pointTwo The end point.
Returns:
Returns true if there is a clear line of sight from pointOne to pointTwo and false if the view is blocked.

void dtTerrain::Terrain::SetLineOfSightSpacing ( float  spacing  )  [inline]

float dtTerrain::Terrain::GetLineOfSightSpacing (  )  const [inline]

void dtTerrain::Terrain::LoadTerrainTile ( PagedTerrainTile newTile  )  [virtual]

void dtTerrain::Terrain::UnloadTerrainTile ( PagedTerrainTile toRemove  )  [virtual]

void dtTerrain::Terrain::UnloadAllTerrainTiles (  )  [virtual]

PagedTerrainTile * dtTerrain::Terrain::CreateTerrainTile ( const GeoCoordinates coords  )  [virtual]

bool dtTerrain::Terrain::IsTerrainTileResident ( const GeoCoordinates coords  )  [virtual]

void dtTerrain::Terrain::EnsureTileVisibility ( const std::set< GeoCoordinates > &  coordList  )  [virtual]

bool dtTerrain::Terrain::SetCachePath ( const std::string &  path  ) 

Sets the path of the terrain cache.

The terrain cache is a directory somewhere on the hard drive which is used to store on the fly data calculations which can then be reused on successive runs. If this path is not set, no data caching will occur.

Note:
The directory will be created if it does not already exist.

This path will be the root cache path for any terrain tiles that need to have their data cached. Each tile's cache path is a subdirectory of this one.

This path should only be used directly when data needs to be cached that is independant of a particular terrain tile. Tile specific data should be cached in the tile's cache directory.

Parameters:
path The path to use for the terrain cache.
Exceptions:
Exception if the path does not exist and cannot be created.

const std::string& dtTerrain::Terrain::GetCachePath (  )  const [inline]

Gets the current terrain cache.

Returns:
The base cache path for this terrain.

void dtTerrain::Terrain::SetLoadDistance ( float  value  )  [inline]

float dtTerrain::Terrain::GetLoadDistance (  )  const [inline]

void dtTerrain::Terrain::SetDataReader ( TerrainDataReader reader  ) 

Sets the terrain data reader.

This must be set before any terrain can be loaded.

TerrainDataReader* dtTerrain::Terrain::GetDataReader (  )  [inline]

Gets the current terrain data reader.

Returns:
A data reader object.

const TerrainDataReader* dtTerrain::Terrain::GetDataReader (  )  const [inline]

Gets the current terrain data reader.

Returns:
A const data reader object.

void dtTerrain::Terrain::SetDataRenderer ( TerrainDataRenderer renderer  ) 

Sets the terrain data renderer.

This must be set before any terrain can be loaded and rendered.

TerrainDataRenderer* dtTerrain::Terrain::GetDataRenderer (  )  [inline]

Gets the current terrain data renderer.

Returns:
A data renderer object.

const TerrainDataRenderer* dtTerrain::Terrain::GetDataRenderer (  )  const [inline]

Gets the current terrain data renderer.

Returns:
A const data renderer object.

void dtTerrain::Terrain::AddDecorationLayer ( TerrainDecorationLayer newLayer  ) 

Adds a new decoration layer to this terrain.

Parameters:
newLayer The new layer to add.
Note:
This will also ask the layer for its scene node (GetOSGNode()) and add it as a child to the terrain.

If the new layer's name is not unique, the name is appended with a unique identifier and a warning is logged.

void dtTerrain::Terrain::RemoveDecorationLayer ( TerrainDecorationLayer toRemove  ) 

Removes the specified decoration layer from this terrain.

Parameters:
toRemove The layer to remove.
Note:
This will also remove the scene node for the decoration layer from this terrain.

void dtTerrain::Terrain::RemoveDecorationLayer ( const std::string &  name  ) 

Removes a decoration layer matching the specified name.

Parameters:
name The name of the terrain layer to remove.

TerrainDecorationLayer * dtTerrain::Terrain::GetDecorationLayer ( const std::string &  name  ) 

Gets the decoration layer whos name matches the specified parameter.

Parameters:
name The name of the layer to retrieve.
Returns:
A valid decoration layer or NULL if the layer could not be found.

const TerrainDecorationLayer * dtTerrain::Terrain::GetDecorationLayer ( const std::string &  name  )  const

Gets the decoration layer who's name matches the specified parameter.

Parameters:
name The name of the layer to retrieve.
Returns:
A valid decoration layer or NULL if the layer could not be found.

unsigned int dtTerrain::Terrain::GetNumDecorationLayers (  )  const [inline]

Gets the number of decorator layers currently overlaid on this terrain.

Returns:
The number of layers.

void dtTerrain::Terrain::ClearDecorationLayers (  ) 

Removes all the decorator layers from this terrain.

void dtTerrain::Terrain::HideDecorationLayer ( const std::string &  name  ) 

Hides the decoration layer that matches the specified name.

Parameters:
name The name of the layer to hide.

void dtTerrain::Terrain::HideDecorationLayer ( TerrainDecorationLayer toHide  ) 

Hides the specified decoration layer.

Parameters:
toHide The layer to hide.

void dtTerrain::Terrain::ShowDecorationLayer ( const std::string &  name  ) 

Makes the decoration layer matching the specified name visible.

Parameters:
name The name of the layer to show.

void dtTerrain::Terrain::ShowDecorationLayer ( TerrainDecorationLayer toShow  ) 

Makes the specified decoration layer visible in the scene.

Parameters:
The layer to make visible.

void dtTerrain::Terrain::GetDecorationLayers ( std::vector< dtCore::RefPtr< TerrainDecorationLayer > > &  layers  ) 

Fills a vector with the decoration layers currently attached to this terrain.

Parameters:
layers The vector to be filled.
Note:
The vector is cleared before it is filled so any data that is passed to this method will be destroyed.

void dtTerrain::Terrain::SetTerrainTileFactory ( PagedTerrainTileFactory factory  )  [inline]

PagedTerrainTileFactory* dtTerrain::Terrain::GetTerrainTileFactory (  )  [inline]

void dtTerrain::Terrain::OnMessage ( dtCore::Base::MessageData data  )  [virtual]

Override to receive messages.

Reimplemented from dtCore::Base.

void dtTerrain::Terrain::PreFrame ( double  frameTime  )  [protected, virtual]

void dtTerrain::Terrain::PostFrame ( double  frameTime  )  [protected, virtual]


Member Data Documentation

std::queue<dtCore::RefPtr<PagedTerrainTile> > dtTerrain::Terrain::mTilesToLoadQ [protected]

List of terrain tiles currently queued up for loading.

TerrainTileMap dtTerrain::Terrain::mResidentTiles [protected]

List of terrain tiles which are currently loaded into memory.

std::queue<dtCore::RefPtr<PagedTerrainTile> > dtTerrain::Terrain::mTilesToUnloadQ [protected]

Queue of terrain tiles that need to be cached or destroyed.


http://www.delta3d.org
2.0.0 generated 14 Feb 2008