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

sglScene Class Reference

#include <sglScene.hpp>

Inheritance diagram for sglScene::

sglGroup sglNode sglObject List of all members.

Public Methods

 sglScene ()
virtual ~sglScene ()
void preDraw ()
void preDraw (const sglTimespec &frame_time, unsigned int frame_count)
virtual void preDraw (const PreDrawStruct &trav)
unsigned int getFrameCount () const
const sglTimespec& getFrameTime () const
void cull (sglCullf &trav_state, float fov_x, float fov_y, unsigned int viewport_x, unsigned int viewport_y, const sglFrustumf &orig_frustum, const sglMat4f &view_matrix, const deque< const sglStatelet *> &override_statelets, unsigned int discriminator_mask=0, unsigned int state_mask=0) const
void cull (sglCullf &trav_state, unsigned int viewport_x, unsigned int viewport_y, const sglViewPlatform &view_platform, const deque< const sglStatelet *> &override_statelets, unsigned int discriminator_mask=0, unsigned int state_mask=0) const
void drawCulled (float fov_x, float fov_y, unsigned int viewport_x, unsigned int viewport_y, const sglFrustumf &orig_frustum, const sglMat4f &view_matrix, const deque< const sglStatelet *> &override_statelets, unsigned int discriminator_mask=0, unsigned int state_mask=0) const
void cull (sglCulld &trav_state, float fov_x, float fov_y, unsigned int viewport_x, unsigned int viewport_y, const sglFrustumd &orig_frustum, const sglMat4d &view_matrix, const deque< const sglStatelet *> &override_statelets, unsigned int discriminator_mask=0, unsigned int state_mask=0) const
void cull (sglCulld &trav_state, unsigned int viewport_x, unsigned int viewport_y, const sglViewPlatform &view_platform, const deque< const sglStatelet *> &override_statelets, unsigned int discriminator_mask=0, unsigned int state_mask=0) const
void drawCulled (float fov_x, float fov_y, unsigned int viewport_x, unsigned int viewport_y, const sglFrustumd &orig_frustum, const sglMat4d &view_matrix, const deque< const sglStatelet *> &override_statelets, unsigned int discriminator_mask=0, unsigned int state_mask=0) const
virtual sglNodeclone (unsigned int mode) const
virtual void printInfo (ostream &ostrm, const char *indent_string) const

Static Public Methods

float computeLODScale (float fov_x, float fov_y, unsigned int viewport_x, unsigned int viewport_y)
void createDefaultStatelets (vector< const sglStatelet *> &def)

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
void copyTo (sglScene *dst, unsigned int mode) const

Detailed Description

Under normal circumstances, the sglScene node is the root of the scene graph. It contains cull functions that initialize the cull traversal. One version of this function takes arguments that define the view frustum, window size (in pixels), the initial view matrix, a list (actually an STL deque) of override statelets, discriminator mask, and state mask. Another version of this function uses the sglViewPlatform class to define the FOVs, view frustum, and view matrix (all other parameters are the same).

The computeLODScale helper function determines a scale to be applied to the level-of-detail (sglLOD) range calculations. It is a function of the size of the window in pixels and the field of view (FOV). This function does not need to be called if you call the cull entry points in this class. See sglLOD for an explanation for this function.

The createDefaultStatelets helper function fills the provided vector with dynamically allocated statelets set to their default values. The is used internally with the cull traversal, but has been exposed for SGL users as well.

Example:

   // Must come before sglScene and sglCull classes are constructed
   sgl::initialize();

    // Add all geometry below this node.
   sglScene *root = new sglScene;

        :
        :

   // Reuse the same traversal state node from frame to frame for better
   // performance.
   sglCullf trav_state;

   while (!quit_flag)
   {
      // Do application specific work
      doAppStuff();

      // Adjust internal data-structures (display lists, bounding volumes,
      // etc...) for the parts of the scene graph that may have changed
      // since last frame.
      root->preDraw();

      // Collect the geometry intersecting the given frustum &amp; view_matrix.
      root->cull(trav_state, fov_x, fov_y, win_x, win_y,
                 frustum, view_matrix, override_statelets,
                 disc_mask, state_mask);

      // Render the visible geometry.
      trav_state.draw();
   }

Example using the sglViewPlatform:

   // Must come before sglScene and sglCull classes are constructed
   sgl::initialize();

   // Add all geometry below this node.
   sglScene *root = new sglScene;

   // used to move the camera around
   sglTransformf view_trans = new sglTransformf;
   root->addChild(view_trans);

   // set up the view platform and camera
   sglPerspectiveCamera *view_camera = new sglPerspectiveCamera;
   view_camera->setFOV(M_PI*0.25, (double)win_x/(double)win_y, 1.0, 200.0);

   sglViewPlatform *view_platform = new sglViewPlatform(*view_camera);
   view_platform->setEnableZUp(true);
   view_trans->addChild(view_platform);

        :
        :

   // Reuse the same traversal state node from frame to frame for better
   // performance.
   sglCullf trav_state;

   while (!quit_flag)
   {
      // Do application specific work
      doAppStuff();

      // Adjust internal data-structures (display lists, bounding volumes,
      // etc...) for the parts of the scene graph that may have changed
      // since last frame.
      root->preDraw();

      // Collect the geometry intersecting the given frustum &amp; view_matrix.
      root->cull(trav_state,
                 win_x, win_y,
                 *view_platform,
                 override_statelets, disc_mask, state_mask);

      // setup OpenGL projection matrix
      (view_platform->getCamera()).applyProjection();

      // Render the visible geometry.
      trav_state.draw();
   }

Definition at line 148 of file sglScene.hpp.


Constructor & Destructor Documentation

sglScene::sglScene ( )
 

Default constructor. Must be called only after sgl::initialize().

sglScene::~sglScene ( ) [virtual]
 

virtual destructor.


Member Function Documentation

float sglScene::computeLODScale ( float fov_x,
float fov_y,
unsigned int viewport_x,
unsigned int viewport_y ) [static]
 

Helper function to compute an LOD scale value based on the current field of view, and window size. This is used to select higher detail children of sglLOD nodes in larger windows and/or smaller fields of view.

Parameters:
fov_x   Horizontal field of view in radians
fov_y   Vertical field of view in radians
viewport_x   Horizontal dimension of viewport in pixels
viewport_y   Vertical dimension of viewport in pixels
Returns:
An LOD scale factor.

void sglScene::createDefaultStatelets ( vector< const sglStatelet *> & def ) [static]
 

Helper function to fill a vector with all of the default statelet nodes in the correct order (used by the state sorting mechanism).

Parameters:
def   A vector which will be filled with the statelets. It is assumed to be empty before calling this function. All statelets placed in this vector are dynamically allocated (with new) and it is the responsibility of the user of the function to delete the statelets when no longer needed.

void sglScene::preDraw ( )
 

This functions must be called with a valid OpenGL graphics context current. Must be called once before each "frame" to increment the frame count and frame time. If necessary it will also traverse the scene graph and "clean" it (clear the dirty bits) by creating any needed display lists, binding any textures(?), recomputing any bounding boxes, and reconfiguring animation nodes.

void sglScene::preDraw ( const sglTimespec & frame_time,
unsigned int frame_count )
 

An alternative to the preDraw() function in which the user may specify the current frame time and frame count. This functions must be called with a valid OpenGL graphics context current. Must be called once before each "frame" to increment the frame count and frame time. If necessary it will also traverse the scene graph and "clean" it (clear the dirty bits) by creating any needed display lists, binding any textures(?), recomputing any bounding boxes, and reconfiguring animation nodes.

Parameters:
frame_time   The time for the next cull/draw traversal.
frame_count   The count for the next cull/draw traversal.

void sglScene::preDraw ( const PreDrawStruct & trav ) [inline, virtual]
 

To prevent ambiguity on SGI's MIPSPro 7.3.x compilers. See sglNode.

Reimplemented from sglGroup.

Definition at line 202 of file sglScene.hpp.

unsigned int sglScene::getFrameCount ( ) const [inline]
 

Get the current frame count (used in sglKeyFrameAnimation nodes).

Returns:
The current frame count.

Definition at line 207 of file sglScene.hpp.

const sglTimespec & sglScene::getFrameTime ( ) const [inline]
 

Get the current frame time (used in sglTimedAnimation nodes).

Returns:
The current frame time in an sglTimespec

Definition at line 212 of file sglScene.hpp.

void sglScene::cull ( sglCullf & trav_state,
float fov_x,
float fov_y,
unsigned int viewport_x,
unsigned int viewport_y,
const sglFrustumf & orig_frustum,
const sglMat4f & view_matrix,
const deque< const sglStatelet *> & override_statelets,
unsigned int discriminator_mask = 0,
unsigned int state_mask = 0 ) const
 

An entry point for the single precision cull traversal to perform view frustum culling (before rendering occurs).

Parameters:
trav_state   The object that will collect all the state and geometry information that will be rendered.
fov_x   The horizontal field of view in radians.
fov_y   The vertical field of view in radians.
viewport_x   The horizontal size of the viewport in pixels.
viewport_y   The vertical size of the viewport in pixels.
orig_frustum   The sglFrustum representing the view frustum defined relative to the current eye point.
view_matrix   The sglMat4 that is the inverse of the matrix representing the current position and orientation of the eye point relative to the rendering origin. The origin of the orig_frustum is at the position defined by this matrix, and the frustum lies along the Z-axis, the X-axis points to the right, and the Y-axis points up.
override_statelets   An STL deque (double-ended queue?) that contains any override statelets the user may want to apply during the current frame.
discriminator_mask   A 32-bit (unsigned int) bit mask representing the discriminator mask (affects the behaviour of sglDiscriminator nodes).
state_mask   A 32-bit (unsigned int) bit mask representing the state mask (affects the selection of states in sglDrawable nodes).

void sglScene::cull ( sglCullf & trav_state,
unsigned int viewport_x,
unsigned int viewport_y,
const sglViewPlatform & view_platform,
const deque< const sglStatelet *> & override_statelets,
unsigned int discriminator_mask = 0,
unsigned int state_mask = 0 ) const
 

An second entry point for the single precision cull traversal to perform view frustum culling (before rendering occurs) using an sglViewPlatform.

Parameters:
trav_state   The object that will collect all the state and geometry information that will be rendered.
viewport_x   The horizontal size of the viewport in pixels.
viewport_y   The vertical size of the viewport in pixels.
view_platform   The sglViewPlatform (which should be contained in the scene graph rooted by this sglScene node) that defines the view frustum, view matrix, and fields of view (if perspective).
override_statelets   An STL deque (double-ended queue?) that contains any override statelets the user may want to apply during the current frame.
discriminator_mask   A 32-bit (unsigned int) bit mask representing the discriminator mask (affects the behaviour of sglDiscriminator nodes).
state_mask   A 32-bit (unsigned int) bit mask representing the state mask (affects the selection of states in sglDrawable nodes).

void sglScene::drawCulled ( float fov_x,
float fov_y,
unsigned int viewport_x,
unsigned int viewport_y,
const sglFrustumf & orig_frustum,
const sglMat4f & view_matrix,
const deque< const sglStatelet *> & override_statelets,
unsigned int discriminator_mask = 0,
unsigned int state_mask = 0 ) const
 

A deprecated entry point for the single precision cull traversal to perform view frustum culling AND rendering. This function provides its own sglCull object for culling and drawing and destructs it before returning.

Parameters:
fov_x   The horizontal field of view in radians.
fov_y   The vertical field of view in radians.
viewport_x   The horizontal size of the viewport in pixels.
viewport_y   The vertical size of the viewport in pixels.
orig_frustum   The sglFrustum representing the view frustum defined relative to the current eye point.
view_matrix   The sglMat4 that is the inverse of the matrix representing the current position and orientation of the eye point relative to the rendering origin. The origin of the orig_frustum is at the position defined by this matrix, and the frustum lies along the Z-axis, the X-axis points to the right, and the Y-axis points up.
override_statelets   An STL deque (double-ended queue?) that contains any override statelets the user may want to apply during the current frame.
discriminator_mask   A 32-bit (unsigned int) bit mask representing the discriminator mask (affects the behaviour of sglDiscriminator nodes).
state_mask   A 32-bit (unsigned int) bit mask representing the state mask (affects the selection of states in sglDrawable nodes).
Deprecated:

void sglScene::cull ( sglCulld & trav_state,
float fov_x,
float fov_y,
unsigned int viewport_x,
unsigned int viewport_y,
const sglFrustumd & orig_frustum,
const sglMat4d & view_matrix,
const deque< const sglStatelet *> & override_statelets,
unsigned int discriminator_mask = 0,
unsigned int state_mask = 0 ) const
 

An entry point for the double precision cull traversal to perform view frustum culling (before rendering occurs). See single precision version for an explanation of the parameters.

void sglScene::cull ( sglCulld & trav_state,
unsigned int viewport_x,
unsigned int viewport_y,
const sglViewPlatform & view_platform,
const deque< const sglStatelet *> & override_statelets,
unsigned int discriminator_mask = 0,
unsigned int state_mask = 0 ) const
 

An entry point for the double precision cull traversal to perform view frustum culling (before rendering occurs). See single precision version for an explanation of the parameters.

void sglScene::drawCulled ( float fov_x,
float fov_y,
unsigned int viewport_x,
unsigned int viewport_y,
const sglFrustumd & orig_frustum,
const sglMat4d & view_matrix,
const deque< const sglStatelet *> & override_statelets,
unsigned int discriminator_mask = 0,
unsigned int state_mask = 0 ) const
 

A deprecated entry point for the double precision cull traversal to perform view frustum culling (before rendering occurs). See single precision version for an explanation of the parameters.

virtual sglNode* sglScene::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 sglScene::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.

void sglScene::cull ( sglCull< float > & trav_state,
unsigned int cull_flags ) const [inline, 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.

Definition at line 356 of file sglScene.hpp.

void sglScene::cull ( sglCull< double > & trav_state,
unsigned int cull_flags ) const [inline, 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.

Definition at line 363 of file sglScene.hpp.


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