Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

TeEngine Class Reference

#include <TeEngine.h>

List of all members.


Detailed Description

Class that represents 3D engine.

Terrain Engine is responsible for several things:

This engine is suitable for two completely different tasks:


Public Types

enum  GenMethod { FAULT_FORMATION = 0 }
enum  FilterMethod { NONE = 0, LINEAR = 1 }

Public Member Functions

 TeEngine (SbVec2s hmapResolution=SbVec2s(65, 65), SbVec2f patch0Size=SbVec2f(64.f, 64.f))
 ~TeEngine ()
const SbVec2s & getHMapResolution () const
SbVec2s getBuildMapResolution () const
const SbVec2f & getPatch0Size () const
GenMethod getCurrGen ()
void setCurrGen (GenMethod m)
FilterMethod getCurrFilter ()
void setCurrFilter (FilterMethod m)
void addObject (TeObject *obj)
TeObjectgetObject (int idx)
void removeObject (TeObject *obj)
void setActiveObject (TeObject *obj)
TeObjectgetActiveObject ()
void setSceneRoot (SoSeparator *sep)
SoSeparator * getSceneRoot ()
void addNode (SoNode *node)
void removeNode (SoNode *node)
void removePatch (TePatch *p)
void setHUDRoot (SoSeparator *sep)
SoSeparator * getHUDRoot ()
void setSceneCamera (SoPerspectiveCamera *c)
SoPerspectiveCamera * getSceneCamera ()
void setHUDCamera (SoPerspectiveCamera *c)
SoPerspectiveCamera * getHUDCamera ()
TePatchgetPatch (const SbVec2f &pos, const int level=0, TePatch::PatchMissedPolicy policy=TePatch::CREATE)
TePatchgetRootPatch ()
int getRootLevel () const
void advanceRootToPos (const SbVec2f &pos)
TeHeightMapgenerateHMap (const SbVec2s &res)
TeHeightMapgenerateHMapFF ()
TeHeightMapgenerateHMapFF (const SbVec2s &res)
TeHeightMapgenerateHMapFF (const SbVec2s &res, const unsigned int seed, const int num_faults, const float min_delta, const float max_delta)
void initialize ()
void timeTick (const SbTime delta)
SbBool genTick ()
void onRootDestroy ()

Public Attributes

TeFaultFormation faultFormation
float fps
unsigned int tasksInQueue
unsigned int patchesNum

Private Member Functions

SbBool isReady (SbVec2f patchPos)
SbBool isScheduled (SbVec2f patchPos)
void schedule (SbVec2f patchPos)
void done ()
void prepareNeighbours (SbVec2f patchPos)
void updateGraph (TeObject *obj)
SbVec2f computePatchPosUnderPoint (SbVec3f pt)
SbVec2f computeNeighbourPos (SbVec2f patchPos, TePatch::Direction which)
TePatch::Direction computePosInsidePatch (SbVec2f patchPos, SbVec3f pt)

Private Attributes

TePatchroot
int rootLevel
SbVec2s hmapResolution
SbVec2f patch0Size
TeLinearFilter linearFilter
TeGeneratorgenerator
GenMethod currGen
FilterMethod currFilter
SbList< TeETasktaskQueue
SbList< TeObject * > objectList
TeObjectactiveObject
SoSeparator * sceneRoot
SoPerspectiveCamera * sceneCamera
SoSeparator * HUDRoot
SoPerspectiveCamera * HUDCamera
SbBSPTree patchReadyTree
SbBSPTree patchScheduledTree

Classes

struct  TeETask
 Struct that holds patch generating task status. More...


Member Enumeration Documentation

enum TeEngine::FilterMethod
 

Enumeration of all heightmap filtration methods.

This corresponds with TeGenerator derived classes in order to use them in the engine.

Enumeration values:
NONE  No filtering will be applied.
LINEAR  Linear filter; corresponds with TeLinearFilter generator.

enum TeEngine::GenMethod
 

Enumeration of all heightmap generation methods.

This corresponds with TeGenerator derived classes in order to use them in the engine.

Enumeration values:
FAULT_FORMATION  Fault-formation algorithm; corresponds with TeFaultFormation generator.


Constructor & Destructor Documentation

TeEngine::TeEngine SbVec2s  hmapResolution = SbVec2s(65,65),
SbVec2f  patch0Size = SbVec2f(64.f,64.f)
 

Default constructor.

Does some default choices, that can be modified later. TeEngine::FAULT_FORMATION is selected as a generator and TeEngine::LINEAR as a filter.

Parameters:
hmapResolution Resolution of the patches' heightmaps. If left blank, default value is used.
patch0Size Area occupied by the patch in the world-space. If left blank, default value is used.

TeEngine::~TeEngine  ) 
 

Destructor.


Member Function Documentation

void TeEngine::addNode SoNode *  node  ) 
 

Adds node to scene.

This function checks, whether the node is already present. If it is, nothing happens. This prevents from adding the same node into the scene several times. Helpful when adding seams into the scene graph.

Note, that modifications to the scene graph are not allowed during the rendering traversal of the tree. Violation of this condition results usually in application crash.

Parameters:
node Node to be added to the scene.
See also:
sceneRoot, removeNode()

void TeEngine::addObject TeObject obj  ) 
 

Adds object into the engine.

Parameters:
obj Object to be added to the object list.
See also:
objectList, getObject(), removeObject()

void TeEngine::advanceRootToPos const SbVec2f &  pos  ) 
 

Documentation not available.

Todo:
More detailed documentation.

SbVec2f TeEngine::computeNeighbourPos SbVec2f  patchPos,
TePatch::Direction  which
[private]
 

Computes position of the selected neighbour of the patch.

The position can be used to get the neighbour using getPatch() method.

Parameters:
patchPos Position of the center of the patch in world-space.
which Neighbour selector.
Returns:
Position of the selected neighbour.
See also:
getPatch(), computePatchPosUnderPoint()

SbVec2f TeEngine::computePatchPosUnderPoint SbVec3f  pt  )  [private]
 

Computes position of the patch that is right under the point pt.

The position can be used to get the patch using getPatch() method.

Parameters:
pt Point in 3D space.
Returns:
Position of the patch under the point pt.
See also:
getPatch(), computeNeighbourPos()

TePatch::Direction TeEngine::computePosInsidePatch SbVec2f  patchPos,
SbVec3f  pt
[private]
 

Computes position of the point pt above patch at patchPos relatively to the patch borders.

The position can be used to determine the direction the object is moving.

Parameters:
patchPos Position of the center of the patch in world-space.
pt Point in 3D space.
Returns:
TePatch::Direction, if above the central area, returns Direction(-1).

void TeEngine::done  )  [private]
 

Removes task from the queue and marks the patch as ready.

Called after succesfull completion of each task.

See also:
taskQueue

TeHeightMap * TeEngine::generateHMap const SbVec2s &  res  ) 
 

Generates new height map of the given resolution.

The appearance of the result can be influenced by choosing the generation and filtering method before calling this function. Note, that all generator parameters (including the random seed) can be set in order to customize the process of generating the result.

Parameters:
res Desired resolution of the map.
Returns:
Pointer to the new height map object.
See also:
setCurrGen(), setCurrFilter(), TeGenerator

TeHeightMap * TeEngine::generateHMapFF const SbVec2s &  res,
const unsigned int  seed,
const int  num_faults,
const float  min_delta,
const float  max_delta
 

Generates new height map using fault-formation algorithm.

This method is obsolete and should be removed. Use generateHMap() instead.

Parameters:
res Desired resolution of the map.
seed Random seed that defines terrain shape.
num_faults Number of faults to be generated (number of iterations).
min_delta Minimal fault height.
max_delta Maximal fault height.
Returns:
Pointer to the new height map object.

Todo:
This method is obsolete and should be removed.

TeHeightMap * TeEngine::generateHMapFF const SbVec2s &  res  ) 
 

Generates new height map using fault-formation algorithm.

This method is obsolete and should be removed. Use generateHMap() instead.

Parameters:
res Desired resolution of the map.
Returns:
Pointer to the new height map object.

Todo:
This method is obsolete and should be removed.

TeHeightMap * TeEngine::generateHMapFF  ) 
 

Generates new height map using fault-formation algorithm.

This method is obsolete and should be removed. Use generateHMap() instead.

Returns:
Pointer to the new height map object.

Todo:
This method is obsolete and should be removed.

SbBool TeEngine::genTick  ) 
 

Internal patch generator tick function.

This method performs one TeGenerator::genStep() for the 1st task in the queue. Process is controlled by the TeETask::TeETaskStatus values.

Returns:
TRUE if task finished and result is ready; done() should be called in this case.

Todo:
Consider creating high-level "TePatchGenerator" that will do this work and make this function obsolete.

TeObject * TeEngine::getActiveObject  ) 
 

Gets active object.

Returns:
Currently active object.
See also:
activeObject, setActiveObject()

SbVec2s TeEngine::getBuildMapResolution  )  const
 

Computes patch build maps resolution.

Build maps have to have double sized dimensions than the resulting height map (minus 1).

Returns:
Patch build map resolution.

TeEngine::FilterMethod TeEngine::getCurrFilter  ) 
 

Private attribute accessor.

Returns:
Currently selected filtration method.
See also:
currFilter, setCurrFilter()

TeEngine::GenMethod TeEngine::getCurrGen  ) 
 

Private attribute accessor.

Returns:
Currently selected generation method.
See also:
currGen, setCurrGen()

const SbVec2s & TeEngine::getHMapResolution  )  const
 

Private attribute accessor.

Returns:
Patch height map resolution.
See also:
hmapResolution

SoPerspectiveCamera * TeEngine::getHUDCamera  ) 
 

Private attribute accessor.

Returns:
Camera used to display the HUD.
See also:
HUDCamera, setHUDCamera()

SoSeparator * TeEngine::getHUDRoot  ) 
 

Private attribute accessor.

Returns:
HUD scene root.
See also:
HUDRoot, setHUDRoot()

TeObject * TeEngine::getObject int  idx  ) 
 

Gets object from the object list.

Parameters:
idx Index into the object list.
Returns:
Object at index idx in the object list
See also:
objectList, addObject(), removeObject()

TePatch * TeEngine::getPatch const SbVec2f &  pos,
const int  level = 0,
TePatch::PatchMissedPolicy  policy = TePatch::CREATE
 

Documentation not available.

Todo:
More detailed documentation.

const SbVec2f & TeEngine::getPatch0Size  )  const
 

Private attribute accessor.

Returns:
Patch height map resolution.
See also:
patch0Size

int TeEngine::getRootLevel  )  const
 

Private attribute accessor.

Returns:
Level of the patch hierarchy root.
See also:
rootLevel, getRootPatch()

TePatch * TeEngine::getRootPatch  ) 
 

Private attribute accessor.

Returns:
Patch hierarchy root.
See also:
root

SoPerspectiveCamera * TeEngine::getSceneCamera  ) 
 

Private attribute accessor.

Returns:
Camera used to observe the scene.
See also:
sceneCamera, setSceneCamera()

SoSeparator * TeEngine::getSceneRoot  ) 
 

Private attribute accessor.

Returns:
Whole scene root.
See also:
sceneRoot, setSceneRoot()

void TeEngine::initialize  ) 
 

Initializes the engine.

Checks if all necessary attributes are set, generates initial patches and creates HUD.

If something is wrong terminates the execution and echoes the error.

This function can be called only once and this should be done after adding all desired objects and correctly setting the active one, after attaching scene and HUD cameras. Repeated calls are simply ignored.

SbBool TeEngine::isReady SbVec2f  patchPos  )  [private]
 

Tests whether the patch is already generated or not.

Patch is specified by its center in the world-space coordinates passed to this function in the patchPos argument. This is way how to uniquely describe each patch.

Parameters:
patchPos Position of the center of the patch in world-space.
Returns:
TRUE if the specified patch is ready, FALSE if it isn't

Todo:
Is the attribute TeEngine::patchReadyTree necessary? Try to use getPatch() with TePatch::DONT_CREATE policy instead.
See also:
patchReadyTree

SbBool TeEngine::isScheduled SbVec2f  patchPos  )  [private]
 

Tests whether the patch is scheduled for generating or not.

Patch is specified by its center in the world-space coordinates passed to this function in the patchPos argument. This is way how to uniquely describe each patch.

Parameters:
patchPos Position of the center of the patch in world-space.
Returns:
TRUE if the specified patch is scheduled, FALSE if it isn't
See also:
schedule(), patchScheduledTree

void TeEngine::onRootDestroy  )  [inline]
 

Internal function.

Todo:
More detailed documentation.

void TeEngine::prepareNeighbours SbVec2f  patchPos  )  [private]
 

Schedules generation of all not existing neighbours of the patch at patchPos.

Patch at patchPos is likely to be under camera in a few moments, so look in scheduled and ready patches and schedule generation of all necessary neighbours.

Little trick is used in this method: Count from 7 backwards is here because NORTH neighbour is represented by nr.7 and with the camera currently pointing to the north it is good to create north neighbour as the first one.

Parameters:
patchPos Position of the center of the patch in world-space.

Todo:
Additional logic to assure that patches will be in the queue in optimal order (according to the movement speed vector). This will make the trick mentioned above obsolete.

void TeEngine::removeNode SoNode *  node  ) 
 

Removes node from scene.

This function checks, whether the node is truly present. If it isn't, nothing happens.

Note, that modifications to the scene graph are not allowed during the rendering traversal of the tree. Violation of this condition results usually in application crash.

Parameters:
node Node to be removed from the scene.
See also:
sceneRoot, addNode(), removePatch()

void TeEngine::removeObject TeObject obj  ) 
 

Removes the object from engine.

Parameters:
obj Object to be removed from the object list.
See also:
objectList, addObject(), getObject()

void TeEngine::removePatch TePatch p  ) 
 

Removes patch p and its seams from the scene.

Parameters:
p Pointer to the patch; its graph is going to be removed from the scene.
See also:
removeNode()

void TeEngine::schedule SbVec2f  patchPos  )  [private]
 

Schedule generation of patch at patchPos.

This function creates TeETask object, fills all its attributes and inserts it into the TeEngine::taskQueue. To control the generation process, modify TeEngine::currGen and TeEngine::currFilter attributes before calling this method.

Parameters:
patchPos Position of the center of the patch in world-space.
See also:
TeETask, setCurrGen(), setCurrFilter()

void TeEngine::setActiveObject TeObject obj  ) 
 

Sets active object.

Parameters:
obj Object to be set as active.
See also:
activeObject, getActiveObject()

void TeEngine::setCurrFilter FilterMethod  m  ) 
 

Sets currently selected filtration method to m.

This method will be used when new task is scheduled or when generateHMap() method is called.

Parameters:
m Selected filtration method.
See also:
currFilter, getCurrFilter(), schedule()

void TeEngine::setCurrGen GenMethod  m  ) 
 

Sets currently selected generation method to m.

This method will be used when new task is scheduled or when generateHMap() method is called.

Parameters:
m Selected generation method.
See also:
currGen, getCurrGen(), schedule()

void TeEngine::setHUDCamera SoPerspectiveCamera *  c  ) 
 

Sets camera to be used to display the HUD.

Parameters:
c Camera.
See also:
HUDCamera, getHUDCamera()

void TeEngine::setHUDRoot SoSeparator *  sep  ) 
 

Sets HUD scene root.

Parameters:
sep Selected HUD scene root.
See also:
HUDRoot, getHUDRoot()

void TeEngine::setSceneCamera SoPerspectiveCamera *  c  ) 
 

Sets camera to be used to observe the scene.

Parameters:
c Camera.
See also:
sceneCamera, getSceneCamera()

void TeEngine::setSceneRoot SoSeparator *  sep  ) 
 

Sets whole scene root.

All objects managed by the engine will be added to the scene as children of this node.

Parameters:
sep Selected scene root.
See also:
sceneRoot, getSceneRoot()

void TeEngine::timeTick const SbTime  delta  ) 
 

Time tick function of the engine.

This function has to be called continuously by application that uses engine in order to have chance to do its work. This function is responsible for giving generators chance to work (it calls genTick() method) and checking if all cameras have whole visible terain ready to render (it calls updateGraph() for all engine objects and TeObject::timeTick() as well).

Parameters:
delta Time elapsed since last call.

void TeEngine::updateGraph TeObject obj  )  [private]
 

Updates scene graph to match object needs.

This function is called continuously from the timeTick() method and works in three steps:

  • Pre-generating: schedules patches that are going to be visible shortly.
  • Removes the patches that moved out of camera's field of view.
  • Checks if all visible terrain components (patches and seams) are in the scene graph.
Parameters:
obj Object used for visibility checking.

Todo:
Some optimization should be done here.


Member Data Documentation

TeObject* TeEngine::activeObject [private]
 

Currently active object.

This is the object, that manages main camera, HUD camera and handles input events. This pointer is used for polymorph calls.

FilterMethod TeEngine::currFilter [private]
 

Currently selected filtration method.

See also:
getCurrFilter(), setCurrFilter()

GenMethod TeEngine::currGen [private]
 

Currently selected generation method.

See also:
getCurrGen(), setCurrGen()

TeFaultFormation TeEngine::faultFormation
 

Instance of the fault-formation generator.

Todo:
This attribute is temporarily public, should be private and accesible using some get...() method.

float TeEngine::fps
 

Current FPS number.

Todo:
This is temporary solution. Consider doing its job some other way.

TeGenerator* TeEngine::generator [private]
 

Currently used generator.

This attribute is used for polymorph calls.

SbVec2s TeEngine::hmapResolution [private]
 

Default heightmap resolution.

SbVec2s(65,65) by default.

See also:
getHMapResolution(), getBuildMapResolution()

SoPerspectiveCamera* TeEngine::HUDCamera [private]
 

Camera for displaying HUD.

It will be managed by the active object.

See also:
setHUDCamera(), getHUDCamera()

SoSeparator* TeEngine::HUDRoot [private]
 

HUD static geometry root.

See also:
setHUDRoot(), getHUDRoot()

TeLinearFilter TeEngine::linearFilter [private]
 

Instance of the linear filter generator.

SbList<TeObject *> TeEngine::objectList [private]
 

List that holds pointers of attached objects.

See also:
addObject(), getObject(), removeObject()

SbVec2f TeEngine::patch0Size [private]
 

Default size of the area occupied by the patch.

SbVec2f(64.f,64.f) by default.

See also:
getPatch0Size()

unsigned int TeEngine::patchesNum
 

Total number of already generated patches.

Todo:
This is temporary solution. Consider doing its job some other way.

SbBSPTree TeEngine::patchReadyTree [private]
 

List of already generated patches.

See also:
isReady()
Todo:
Is this necessary? Try to use getPatch() with TePatch::DONT_CREATE policy instead.

SbBSPTree TeEngine::patchScheduledTree [private]
 

List of scheduled patches.

It is probably faster than searching in the taskQueue.

See also:
isScheduled()

TePatch* TeEngine::root [private]
 

Root of whole patch tree.

See also:
getRootPatch()

int TeEngine::rootLevel [private]
 

Level of the root of whole patch tree.

See also:
getRootLevel()

SoPerspectiveCamera* TeEngine::sceneCamera [private]
 

Camera that will be used to view the scene.

It will be managed by the active object.

See also:
setSceneCamera(), getSceneCamera()

SoSeparator* TeEngine::sceneRoot [private]
 

Whole scene root.

Aditional patches are always added as a children of this root.

See also:
setSceneRoot(), getSceneRoot(), addNode(), removeNode()

SbList<TeETask> TeEngine::taskQueue [private]
 

Scheduled tasks queue.

It holds all the tasks that are currently under construction. Task at the front of the queue gets CPU-time and has the chance to be finished.

See also:
schedule(), done()

unsigned int TeEngine::tasksInQueue
 

Current number of tasks in the queue.

Todo:
This is temporary solution. Consider doing its job some other way.


Generated on Sun May 8 16:45:06 2005 for TerrainEngine by Doxygen 1.4.1