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

sglDistanceSwitch Class Reference

#include <sglDistanceSwitch.hpp>

Inheritance diagram for sglDistanceSwitch::

sglGroup sglNode sglObject List of all members.

Public Methods

 sglDistanceSwitch ()
virtual ~sglDistanceSwitch ()
void setRange (float range)
float getRange () const
void setCenter (const sglVec3f &center)
const sglVec3f& getCenter () const
void setLODState (sglLODState *lod_state)
sglLODStategetLODState () const
virtual sglBound::IntersectResultEnum intersect (sglIntersectf &isector) const
virtual sglBound::IntersectResultEnum intersect (sglIntersectd &isector) const
virtual void pick (sglPickf &pick_state, unsigned int cull_flags) const
virtual void pick (sglPickd &pick_state, unsigned int cull_flags) const
virtual sglNodeclone (unsigned int mode) const
virtual void printInfo (ostream &ostrm, const char *indent_string) const

Static Public Methods

void setScaleFactor (float scale)
float getScaleFactor ()

Protected Methods

virtual void cull (sglCull< float > &trav_state, unsigned int cull_flags) const
virtual void cull (sglCull< double > &trav_state, unsigned int cull_flags) const
virtual float computeRange (float trav_lod_scale, float trav_lod_offset, const sglMat4f &view_matrix) const
virtual float computeRange (float trav_lod_scale, float trav_lod_offset, const sglMat4d &view_matrix) const
void copyTo (sglDistanceSwitch *dst, unsigned int mode) const

Protected Attributes

sglVec3f m_center
float m_range
sglLODStatem_lod_state

Static Protected Attributes

float s_range_scale

Detailed Description

This subclass of sglGroup will select all or none of its children to be traversed based on a function of its range from the eye point (the "origin" of the view frustum) and what is defined as the center of this node. This acts like a simplified LOD node where there is a single range threshold.

After the children have been added, the user specifies the range and specifies the center point which is a reference point relative to the origin of the local coordinate system of this node used to compute the range to the viewpoint. This range value can also be scaled and biased to change which child is selected. Unlike LOD, the order that the children are added to the node is NOT significant.

The children are selected for further traversal according to the following table:

  Range Value, x    Child selected:
 -----------------  ---------------
   x <= distance    all children
   x >  distance    none

This node is designed to make a specific construct more efficient. With the sglLOD node you might have the following subgraph to switch a set of children with a single range (i.e., turn them off if they are too far away):

      sglLOD (range[0] = 0, range[1] = view_distance)
         |
     sglGroup
     /   |   \
 Node1 Node2 Node3

This can be replaced with a more efficient construct as follows:

 sglSwitchDistance (range = view_distance)
      /  |  \
     /   |   \
 Node1 Node2 Node3

Scale and Bias

See sglLOD documentation for details.

Special behaviour for intersect and pick traversals

This node uses the same flags as sglLOD. See sglLOD documentation for details. Note that the default behaviour for sglLOD (to intersect against range zero only) is equivalent to using the eLOD_ALL flag in this node.

Example:

   sglDistanceSwitch *ds_node = new sglDistanceSwitch;
   ds_node->setLODState(new sglLODState);

   sglGeode *geode1 = new sglGeode;
   sglGeode *geode2 = new sglGeode;
   sglGeode *geode3 = new sglGeode;

   ds_node->addChild(geode1);     // finest resolution
   ds_node->addChild(geode2);
   ds_node->addChild(geode3);     // coarsest resolution

   ds_node->setRange(50.0f);      // deselect all above 50.

   // double computed range for all sglDistanceSwitch nodes: has effect of
   // halving the switch range.
   sglDistanceSwitch::setScaleFactor(2.0f);

   // halve the computed range and add a bias for this LOD only: has effect
   // of selecting finer resolution children
   sglLODState *lod_state = ds_node->getLODState();
   if (lod_state)
   {
      lod_state->setRangeScale(0.5f);
      lod_state->setRangeOffset(-2.0f);
   }

Definition at line 123 of file sglDistanceSwitch.hpp.


Constructor & Destructor Documentation

sglDistanceSwitch::sglDistanceSwitch ( )
 

default constructor.

sglDistanceSwitch::~sglDistanceSwitch ( ) [virtual]
 

virtual destructor.


Member Function Documentation

void sglDistanceSwitch::setRange ( float range )
 

Set a range value. Distances computed outside this range will result in all children being culled.

Parameters:
range   The distance switch range. Negative values is equivalent to zero (the default) and result in children being culled all the time.

float sglDistanceSwitch::getRange ( ) const [inline]
 

Get a range value.

Returns:
range value.

Definition at line 141 of file sglDistanceSwitch.hpp.

void sglDistanceSwitch::setCenter ( const sglVec3f & center ) [inline]
 

Set the reference position for computing a range to. This defaults to the origin of this node's local coordinate system.

Parameters:
center   The reference position.

Definition at line 147 of file sglDistanceSwitch.hpp.

const sglVec3f & sglDistanceSwitch::getCenter ( ) const [inline]
 

Get the current reference position.

Returns:
The current reference position.

Definition at line 152 of file sglDistanceSwitch.hpp.

void sglDistanceSwitch::setScaleFactor ( float scale ) [inline, static]
 

Set a global scale factor used to affect transitions of groups of ALL SwitchDistance nodes (this is a separate factor from sglLOD -- should they share the same value?).

Parameters:
scale   The scale factor (should be positive).

Definition at line 159 of file sglDistanceSwitch.hpp.

float sglDistanceSwitch::getScaleFactor ( ) [inline, static]
 

Get the current global scale factor.

Returns:
The current scale factor.

Definition at line 164 of file sglDistanceSwitch.hpp.

void sglDistanceSwitch::setLODState ( sglLODState * lod_state )
 

Specify a scale and bias to affect transitions of this SwitchDistance node. By using the same sglLODState object for more than one sglDistanceSwitch (and sglLOD) node, a group of sglDistanceSwitch's range calculation can be affected simultaneously. These objects are reference counted with this function. New objects are ref()-ed while previous objects are deref()-ed. If an sglLODState object's reference count goes to zero when it is replaced by this function, it will be deleted.

Parameters:
lod_scale   The new sglLODState object.
See also:
sglLODState

sglLODState * sglDistanceSwitch::getLODState ( ) const [inline]
 

Get a pointer to the current sglLODState object.

Returns:
Pointer to the current sglLODState object. NULL if no object has be assigned.

Definition at line 183 of file sglDistanceSwitch.hpp.

virtual sglBound::IntersectResultEnum sglDistanceSwitch::intersect ( sglIntersectf & isector ) const [virtual]
 

The single precision intersection traversal function which returns the closest object (bounding volume and/or triangle) that intersects with the given intersect segment.

Parameters:
isector   A reference to a single precision intersection state

Reimplemented from sglGroup.

virtual sglBound::IntersectResultEnum sglDistanceSwitch::intersect ( sglIntersectd & isector ) const [virtual]
 

The double precision intersection traversal function which returns the closest object (bounding volume and/or triangle) that intersects with the given intersect segment.

Parameters:
isector   A reference to a double precision intersection state

Reimplemented from sglGroup.

virtual void sglDistanceSwitch::pick ( sglPickf & pick_state,
unsigned int cull_flags ) const [virtual]
 

The single precision pick traversal function which returns all objects that fall within the pick frustum.

Parameters:
pick_state   A reference to a single precision pick state.
cull_flags   Bit flags that indicate which planes of the pick frustum (polytope) still need to be tested to determine if bounding spheres and boxes lie within the frustum. Cull-free picking can be accomplished by setting this to 0.

Reimplemented from sglGroup.

virtual void sglDistanceSwitch::pick ( sglPickd & pick_state,
unsigned int cull_flags ) const [virtual]
 

The double precision pick traversal function which returns all objects that fall within the pick frustum.

Parameters:
pick_state   A reference to a double precision pick state.
cull_flags   Bit flags that indicate which planes of the pick frustum (polytope) still need to be tested to determine if bounding spheres and boxes lie within the frustum. Cull-free picking can be accomplished by setting this to 0.

Reimplemented from sglGroup.

virtual sglNode* sglDistanceSwitch::clone ( unsigned int mode ) const [virtual]
 

Make a copy of the scenegraph rooted at this node.

Parameters:
mode   Bit masks to control the behaviour of the clone. These are OR-ed together from the mode values in sglObject::CloneModeEnum.
Returns:
Pointer to root of cloned scene graph.

Reimplemented from sglGroup.

virtual void sglDistanceSwitch::printInfo ( ostream & ostrm,
const char * indent_string ) const [virtual]
 

Output the state of this node to the specified ostream.

Parameters:
ostrm   the ostream to which the output is sent
indent_string   the string (usually spaces) that is output at the beginning of every line of output

Reimplemented from sglGroup.

virtual void sglDistanceSwitch::cull ( sglCull< float > & trav_state,
unsigned int cull_flags ) const [protected, virtual]
 

The single precision cull traversal function that culls out subgraphs that do not lie in the view frustum (stored in the sglCull parameter). Subclasses must implement this function. The entry point for user-friendly culling is in the sglScene class.

Parameters:
trav_state   The single precision traversal state that collects all the state and geometry information that passes the cull.
cull_flags   Bit flags that indicate which planes of the view frustum (polytope) still need to be tested to determine if bounding spheres and boxes lie within the frustum. Cull-free drawing can be accomplished with cull_flags = 0.

Reimplemented from sglGroup.

virtual void sglDistanceSwitch::cull ( sglCull< double > & trav_state,
unsigned int cull_flags ) const [protected, virtual]
 

The double precision cull traversal function that culls out subgraphs that do not lie in the view frustum (stored in the sglCull parameter). Subclasses must implement this function. The entry point for user-friendly culling is in the sglScene class.

Parameters:
trav_state   The single precision traversal state that collects all the state and geometry information that passes the cull.
cull_flags   Bit flags that indicate which planes of the view frustum (polytope) still need to be tested to determine if bounding spheres and boxes lie within the frustum. Cull-free drawing can be accomplished with cull_flags = 0.

Reimplemented from sglGroup.


The documentation for this class was generated from the following file:
Generated at Mon Jul 1 18:00:07 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001