CShadowManager Class Reference

List of all members.

Detailed Description

The Manager of shadows in Open Inventor scene.

Provides simple API for adding shadows to any scene object. Shadow Manager has methods to add lights and scene objects for which shadows should be created. Automatically handles lights or objects movements and shape changes of shadow casting objects.

Compilation note: Must be linked with glu32.lib opengl32.lib.

Definition at line 96 of file ShadowManager.h.

Public Types

enum  SCENE_TYPE { SHADOWS = 0, SCENE = 1 }
 Enumeration of showed scene types. More...

Public Member Functions

 CShadowManager (SoSeparator *sr, SoEnvironment *env)
 Constructor.
 ~CShadowManager ()
 Destructor.
void setSceneType (enum CShadowManager::SCENE_TYPE type)
 Sets which type of scene will be shown.
enum TShadowAlgorithmgetAlgorithm ()
 Get shadow volumes computing algorithm.
void method2algorithm ()
 Set shadow algorithm according to the chosen method.
void setManager (TShadowSettings *s)
 Set up whole shadow manager settings in one step.
const struct TShadowSettingsreadSettings ()
 Read shadow manager settings.
void setMethod (enum TShadowMethod newMethod)
 Set shadow computation method.
void setSVDepth (float newfDepth)
 Set shadow volumes depth.
void printSettings ()
 Print shadow manager's settings.
void enableSensors ()
 Enable objects' sensors.
void disableSensors ()
 Disable objects' sensors.
void createShadows ()
 Recompute shadow volumes for all objects and all lights.
void createCasterVolumes (int index)
 Re-computes shadow volumes of a selected caster.
SoSeparator * getSceneRoot ()
 Returns the root node of the user's scene.
SoSeparator * getShadowSceneRoot ()
 Returns the root node of the user scene with shadows.
SoEnvironment * getEnvironmentNode ()
 Get environment node registered in Shadow Manager.
void setAmbientIntensity (float val)
 Sets global ambient light intensity.
void addLight (SoLight *light)
 Adds a new light to the scene light manager.
void removeLight (SoLight *light)
 Removes light from Shadow Manager and deletes all shadows that are cast by this light.
void addObject (SoSeparator *object)
 Adds a new object to the scene object manager.
void removeObject (SoSeparator *object)
 Removes the first occurence of the object from Shadow Manager.
void createObjectsShadows (SoSeparator *object)
 Forces recomputation of shadows of an object.
void export (const char *filename)
 Export shadow scene graph into a file.

Private Member Functions

void createShadowScene ()
 Creates scene graph with shadows.
SoEnvironment * findEnvironmentNode ()
 Looks for user's environment node in the user's scene.
void checkLights ()
 Check all lights.
int findObject (SoSeparator *object)
 Looks for a SoShadowCaster node for this object inside shadow manager.
void checkObjects ()
 Check all objects under SVN node.
void printMsg (const char *msg)
 Prints information to stdout.
void printError (const char *msg)
 Error printing method.

Static Private Member Functions

static void lightMoveCallback (void *userdata, SoSensor *)
 Action called when any light changes its position.
static void objectMoveCallback (void *userdata, SoSensor *s)
 Action called when something has changed in the path to the object node.
static void objectShapeCallback (void *userdata, SoSensor *s)
 Action called when the object changes its shape.
static void nslightsOffCB (void *userdata, SoAction *action)
 Rendering ambient CB.
static void nslightsOnCB (void *userdata, SoAction *action)
 Rendering ambient end CB.
static void nsambientOffCB (void *userdata, SoAction *action)
 Rendering no shadows light CB.
static void nsambientOnCB (void *userdata, SoAction *action)
 Rendering no shadow end CB.
static void initCB (void *userdata, SoAction *action)
 Rendering preset CB.
static void endCB (void *userdata, SoAction *action)
 Rendering end CB.

Private Attributes

SoSeparator * shadowCastersRoot
 Shadow casters root node.
SoSeparator * shadowSceneRoot
 Shadow scene root node.
SoSeparator * shadowLightsRoot
 Root node of all scene shadow volumes.
SoSeparator * sceneRoot
 Scene root node.
TShadowSettingssettings
 Shadow settings data structure.
enum TShadowAlgorithm algorithm
 Shadow algorithm.
int lightIndex
 Auto incremental index (name) of the light.
int objectIndex
 Auto incremental index (name) of the object.
bool first
 Is it the first call of create shadow scene?.
SoEnvironment * environment
 Environment node to set ambient light.
SoSwitch * switchNode
 Node to switch between scene types.
SoSeparator * sceneNoShadows
 Root node of scene without shadows.
SoSeparator * sceneWithShadows
 Root node of scene with shadows.
SoSeparator * sceneWithShadowVolumes
 Root node of scene with shadow volumes.

Static Private Attributes

static float envIntensity = 0.0f
 Ambient light intensity saved value.


Member Enumeration Documentation

enum CShadowManager::SCENE_TYPE
 

Enumeration of showed scene types.

Enumerator:
SHADOWS  User scene with shadows.
SCENE  User scene.

Definition at line 102 of file ShadowManager.h.


Constructor & Destructor Documentation

CShadowManager::CShadowManager SoSeparator *  sr,
SoEnvironment *  env
 

Constructor.

Needs to know the pointers to the user's scene graph and a global environment node.

If environment node is NULL, Shadow Manager will try to look for it under the scene root first and if none is fount, it creates its own. The darkness of shadows can be controlled trough the scene ambient light intensity of the user's SoEnvironment node.

User MUST ENABLE STENCIL BUFFER to see shadows on his/her own by

 viewer->setStencilBuffer(TRUE); 

Parameters:
sr Pointer connection to the scene root node.
env Pointer connection to the scene global environment node.

Definition at line 68 of file ShadowManager.cpp.

References TShadowSettings::dropShadows, environment, TShadowSettings::fDepth, findEnvironmentNode(), first, lightIndex, TShadowSettings::method, method2algorithm(), objectIndex, ONDEBUG, printError(), sceneNoShadows, sceneRoot, sceneWithShadows, sceneWithShadowVolumes, SE_VERSION, setSceneType(), settings, shadowCastersRoot, shadowLightsRoot, SHADOWS, shadowSceneRoot, switchNode, and zpass.

CShadowManager::~CShadowManager  ) 
 

Destructor.

Definition at line 149 of file ShadowManager.cpp.

References environment, ONDEBUG, sceneRoot, shadowCastersRoot, shadowLightsRoot, shadowSceneRoot, and switchNode.


Member Function Documentation

void CShadowManager::createShadowScene  )  [private]
 

Creates scene graph with shadows.

Creates scene graph with shadows under the CShadowManager.

Definition at line 1046 of file ShadowManager.cpp.

References endCB(), initCB(), nsambientOffCB(), nsambientOnCB(), nslightsOffCB(), nslightsOnCB(), ONDEBUG, sceneNoShadows, sceneWithShadows, and shadowLightsRoot.

Referenced by getShadowSceneRoot().

SoEnvironment * CShadowManager::findEnvironmentNode  )  [private]
 

Looks for user's environment node in the user's scene.

If the node is found in the user's scene graph (first occurence only), its pointer is passed to the Shadow Manager. There should be only one instance of SoEnvironment in the whole user's scene graph. It is used to set the darkness of shadows according to the ambient light intensity.

Definition at line 401 of file ShadowManager.cpp.

References ONDEBUG.

Referenced by CShadowManager().

void CShadowManager::lightMoveCallback void *  userdata,
SoSensor *  s
[static, private]
 

Action called when any light changes its position.

Parameters:
userdata Pointer to the shadow volume node.
s Light sensor.

Definition at line 437 of file ShadowManager.cpp.

References SoShadowLight::createShadowVolumes(), and ONDEBUG.

void CShadowManager::checkLights  )  [private]
 

Check all lights.

Definition at line 601 of file ShadowManager.cpp.

References SoShadowLight::getLight(), ONDEBUG, and shadowLightsRoot.

void CShadowManager::objectMoveCallback void *  userdata,
SoSensor *  s
[static, private]
 

Action called when something has changed in the path to the object node.

For example, the light position has changed or any node has been added to the scene graph before object node.

The shadow volume of the object must be recalculated.

Parameters:
userdata Shadow caster.
s Object sensor.

Definition at line 652 of file ShadowManager.cpp.

References SoShadowCaster::createFaceModel(), SoShadowCaster::createShadowVolumes(), ONDEBUG, and SoShadowCaster::setMoved().

void CShadowManager::objectShapeCallback void *  userdata,
SoSensor *  s
[static, private]
 

Action called when the object changes its shape.

Parameters:
userdata Shadow caster.
s Object node sensor.

Definition at line 737 of file ShadowManager.cpp.

References SoShadowCaster::createFaceModel(), SoShadowCaster::createShadowVolumes(), SoShadowCaster::getCasterName(), and ONDEBUG.

int CShadowManager::findObject SoSeparator *  object  )  [private]
 

Looks for a SoShadowCaster node for this object inside shadow manager.

Parameters:
object A scene object node.
Returns:
-1 if object was not found, object name index otherwise

Definition at line 779 of file ShadowManager.cpp.

References ONDEBUG, and shadowCastersRoot.

Referenced by addObject().

void CShadowManager::checkObjects  )  [private]
 

Check all objects under SVN node.

Definition at line 992 of file ShadowManager.cpp.

References ONDEBUG, and shadowCastersRoot.

void CShadowManager::nslightsOffCB void *  userdata,
SoAction *  action
[static, private]
 

Rendering ambient CB.

Turns off lights.

Parameters:
userdata Pointer to the root of shadow lights.
action Pointer to the callback action.

Definition at line 1243 of file ShadowManager.cpp.

References SoShadowLight::getLight(), ONDEBUG, and SoShadowLight::status.

Referenced by createShadowScene().

void CShadowManager::nslightsOnCB void *  userdata,
SoAction *  action
[static, private]
 

Rendering ambient end CB.

Turns on lights.

Parameters:
userdata Pointer to the root of shadow lights.
action Pointer to the callback action.

Definition at line 1288 of file ShadowManager.cpp.

References SoShadowLight::getLight(), ONDEBUG, and SoShadowLight::status.

Referenced by createShadowScene().

void CShadowManager::nsambientOffCB void *  userdata,
SoAction *  action
[static, private]
 

Rendering no shadows light CB.

Turns off and save ambient intensity value. Sets additive blending.

Parameters:
userdata Pointer to environment node in the Shadow Manager.
action Pointer to the callback action.

Definition at line 1316 of file ShadowManager.cpp.

References envIntensity, and ONDEBUG.

Referenced by createShadowScene().

void CShadowManager::nsambientOnCB void *  userdata,
SoAction *  action
[static, private]
 

Rendering no shadow end CB.

Closes the whole rendering action. Sets default value of ambient light intensity.

Parameters:
userdata Pointer to environment node in the Shadow Manager.
action Pointer to the callback action.

Definition at line 1348 of file ShadowManager.cpp.

References envIntensity, and ONDEBUG.

Referenced by createShadowScene().

void CShadowManager::initCB void *  userdata,
SoAction *  action
[static, private]
 

Rendering preset CB.

Starts the whole rendering action. Saves light status values and cleares buffers.

Parameters:
userdata Pointer to root of all lights in the Shadow Manager.
action Pointer to the callback action.

Definition at line 1384 of file ShadowManager.cpp.

References SoShadowLight::getLight(), ONDEBUG, and SoShadowLight::status.

Referenced by createShadowScene().

void CShadowManager::endCB void *  userdata,
SoAction *  action
[static, private]
 

Rendering end CB.

Closes the whole rendering action. Sets default values and resets the light state according to the saved values.

Parameters:
userdata Pointer to root of all lights in the Shadow Manager.
action Pointer to the callback action.

Definition at line 1428 of file ShadowManager.cpp.

References SoShadowLight::getLight(), ONDEBUG, and SoShadowLight::status.

Referenced by createShadowScene().

void CShadowManager::printMsg const char *  msg  )  [private]
 

Prints information to stdout.

Parameters:
msg Message.

Definition at line 1149 of file ShadowManager.cpp.

void CShadowManager::printError const char *  msg  )  [private]
 

Error printing method.

Parameters:
msg Error message.

Definition at line 1160 of file ShadowManager.cpp.

Referenced by addLight(), addObject(), CShadowManager(), and removeLight().

void CShadowManager::setSceneType enum CShadowManager::SCENE_TYPE  type  ) 
 

Sets which type of scene will be shown.

Parameters:
type Enum of scene types.

Definition at line 199 of file ShadowManager.cpp.

References switchNode.

Referenced by CShadowManager().

TShadowAlgorithm * CShadowManager::getAlgorithm  ) 
 

Get shadow volumes computing algorithm.

Returns:
Pointer to algorithm. Do not change the value, use method instead.

Definition at line 297 of file ShadowManager.cpp.

References algorithm.

void CShadowManager::method2algorithm  ) 
 

Set shadow algorithm according to the chosen method.

Definition at line 306 of file ShadowManager.cpp.

References algorithm, autoset, TShadowSettings::method, ONDEBUG, settings, zfail, zfailAlg, zpass, and zpassAlg.

Referenced by CShadowManager(), setManager(), and setMethod().

void CShadowManager::setManager TShadowSettings s  ) 
 

Set up whole shadow manager settings in one step.

Parameters:
s New settings data structure.

Definition at line 211 of file ShadowManager.cpp.

References createShadows(), method2algorithm(), and settings.

const struct TShadowSettings * CShadowManager::readSettings  ) 
 

Read shadow manager settings.

Returns:
Settings data structure.

Definition at line 224 of file ShadowManager.cpp.

References settings.

void CShadowManager::setMethod enum TShadowMethod  newMethod  ) 
 

Set shadow computation method.

Parameters:
newMethod A new method.

Definition at line 235 of file ShadowManager.cpp.

References algorithm, createShadows(), TShadowSettings::method, method2algorithm(), ONDEBUG, printSettings(), and settings.

void CShadowManager::setSVDepth float  newfDepth  ) 
 

Set shadow volumes depth.

Parameters:
newfDepth A new SV depth.

Definition at line 258 of file ShadowManager.cpp.

References createShadows(), TShadowSettings::fDepth, ONDEBUG, printSettings(), and settings.

void CShadowManager::printSettings  ) 
 

Print shadow manager's settings.

Definition at line 269 of file ShadowManager.cpp.

References algorithm, autoset, TShadowSettings::dropShadows, TShadowSettings::fDepth, TShadowSettings::method, settings, zfail, zpass, and zpassAlg.

Referenced by setMethod(), and setSVDepth().

void CShadowManager::enableSensors  ) 
 

Enable objects' sensors.

Definition at line 351 of file ShadowManager.cpp.

References ONDEBUG, and shadowCastersRoot.

void CShadowManager::disableSensors  ) 
 

Disable objects' sensors.

This method is useful when an user want to change something (that is normally) detected by sensors and causes re-computation of shadows) in his existing scene graph and do not want to re-compute shadows. Just disable sensors, do what you want and enable sensors afterwards.

Definition at line 333 of file ShadowManager.cpp.

References ONDEBUG, and shadowCastersRoot.

void CShadowManager::createShadows  ) 
 

Recompute shadow volumes for all objects and all lights.

Definition at line 177 of file ShadowManager.cpp.

References ONDEBUG, and shadowLightsRoot.

Referenced by removeLight(), setManager(), setMethod(), and setSVDepth().

void CShadowManager::createCasterVolumes int  index  ) 
 

Re-computes shadow volumes of a selected caster.

Parameters:
index Caster name.

Definition at line 1011 of file ShadowManager.cpp.

References SoShadowVolume::create(), SoShadowVolume::getCasterName(), SoShadowLight::getNumVolumes(), SoShadowLight::getVolume(), and shadowLightsRoot.

Referenced by SoShadowCaster::createShadowVolumes().

SoSeparator * CShadowManager::getSceneRoot  ) 
 

Returns the root node of the user's scene.

Returns:
SoSeparator * Pointer to the root node of scene.

Definition at line 1135 of file ShadowManager.cpp.

References sceneRoot.

Referenced by SoShadowCaster::showFaceModel().

SoSeparator * CShadowManager::getShadowSceneRoot  ) 
 

Returns the root node of the user scene with shadows.

Returns:
SoSeparator * Pointer to the root node of shadow scene.

Definition at line 1120 of file ShadowManager.cpp.

References createShadowScene(), first, and shadowSceneRoot.

SoEnvironment * CShadowManager::getEnvironmentNode  ) 
 

Get environment node registered in Shadow Manager.

Returns:
Pointer to the global environment node.

Definition at line 374 of file ShadowManager.cpp.

References environment.

Referenced by SoShadowLight::init().

void CShadowManager::setAmbientIntensity float  val  ) 
 

Sets global ambient light intensity.

Default value of Shadow Manager's own environment node is 0.2.

Parameters:
val Float number between 0 and 1.

Definition at line 387 of file ShadowManager.cpp.

References environment.

void CShadowManager::addLight SoLight *  light  ) 
 

Adds a new light to the scene light manager.

Parameters:
light One scene light.

Definition at line 451 of file ShadowManager.cpp.

References ONDEBUG, printError(), and shadowLightsRoot.

void CShadowManager::removeLight SoLight *  light  ) 
 

Removes light from Shadow Manager and deletes all shadows that are cast by this light.

Note: Remove light from Shadow Manager using this method and after that you can remove it from your scene graph. Otherwise it will not work properly.

Parameters:
light One scene light.

Definition at line 558 of file ShadowManager.cpp.

References createShadows(), SoShadowLight::getLight(), ONDEBUG, printError(), and shadowLightsRoot.

void CShadowManager::addObject SoSeparator *  object  ) 
 

Adds a new object to the scene object manager.

Parameters:
object A scene object node.
An object is assumed to be a SoSeparator node under which a complete object definition (coordinates, indices, materials...) is placed. Any change below this node (a shape change) is detected and shadows for this object are updated. Object's transformations placed in the scene graph above the object root node are detected as well.

Each user object can be added into the Shadow Manger only once!

Definition at line 814 of file ShadowManager.cpp.

References SoShadowLight::addVolume(), findObject(), SoShadowCaster::getCasterName(), SoShadowLight::getLightName(), objectIndex, ONDEBUG, SoShadowCaster::path, printError(), SoShadowCaster::setCasterName(), SoShadowCaster::setMoveSensor(), SoShadowCaster::setShapeSensor(), shadowCastersRoot, and shadowLightsRoot.

void CShadowManager::removeObject SoSeparator *  object  ) 
 

Removes the first occurence of the object from Shadow Manager.

When object is found in the Shadow Manager, its shadows are destroyed. Also the sensor is detached and deleted.

Parameters:
object Pointer to a scene object node.

Definition at line 911 of file ShadowManager.cpp.

References SoShadowLight::deleteVolume(), ONDEBUG, shadowCastersRoot, and shadowLightsRoot.

void CShadowManager::createObjectsShadows SoSeparator *  object  ) 
 

Forces recomputation of shadows of an object.

This method is useful when something changes in the scene graph that affects object's shadows and none of Shadow Manager's internal callbacks is trigerred.

Parameters:
object Pointer to a scene object node.

Definition at line 963 of file ShadowManager.cpp.

References ONDEBUG, and shadowCastersRoot.

void CShadowManager::export const char *  filename  ) 
 

Export shadow scene graph into a file.

Parameters:
filename Filename of exported scene.

Definition at line 1171 of file ShadowManager.cpp.


Member Data Documentation

SoSeparator* CShadowManager::shadowCastersRoot [private]
 

Shadow casters root node.

Definition at line 111 of file ShadowManager.h.

Referenced by addObject(), checkObjects(), createObjectsShadows(), CShadowManager(), disableSensors(), enableSensors(), findObject(), removeObject(), and ~CShadowManager().

SoSeparator* CShadowManager::shadowSceneRoot [private]
 

Shadow scene root node.

Definition at line 113 of file ShadowManager.h.

Referenced by CShadowManager(), getShadowSceneRoot(), and ~CShadowManager().

SoSeparator* CShadowManager::shadowLightsRoot [private]
 

Root node of all scene shadow volumes.

Definition at line 115 of file ShadowManager.h.

Referenced by addLight(), addObject(), checkLights(), createCasterVolumes(), createShadows(), createShadowScene(), CShadowManager(), removeLight(), removeObject(), and ~CShadowManager().

SoSeparator* CShadowManager::sceneRoot [private]
 

Scene root node.

Definition at line 118 of file ShadowManager.h.

Referenced by CShadowManager(), getSceneRoot(), and ~CShadowManager().

struct TShadowSettings* CShadowManager::settings [private]
 

Shadow settings data structure.

Definition at line 120 of file ShadowManager.h.

Referenced by CShadowManager(), method2algorithm(), printSettings(), readSettings(), setManager(), setMethod(), and setSVDepth().

enum TShadowAlgorithm CShadowManager::algorithm [private]
 

Shadow algorithm.

Definition at line 122 of file ShadowManager.h.

Referenced by getAlgorithm(), method2algorithm(), printSettings(), and setMethod().

int CShadowManager::lightIndex [private]
 

Auto incremental index (name) of the light.

Definition at line 124 of file ShadowManager.h.

Referenced by CShadowManager().

int CShadowManager::objectIndex [private]
 

Auto incremental index (name) of the object.

Definition at line 126 of file ShadowManager.h.

Referenced by addObject(), and CShadowManager().

bool CShadowManager::first [private]
 

Is it the first call of create shadow scene?.

Definition at line 128 of file ShadowManager.h.

Referenced by CShadowManager(), and getShadowSceneRoot().

SoEnvironment* CShadowManager::environment [private]
 

Environment node to set ambient light.

Definition at line 130 of file ShadowManager.h.

Referenced by CShadowManager(), getEnvironmentNode(), setAmbientIntensity(), and ~CShadowManager().

float CShadowManager::envIntensity = 0.0f [static, private]
 

Ambient light intensity saved value.

Definition at line 132 of file ShadowManager.h.

Referenced by nsambientOffCB(), and nsambientOnCB().

SoSwitch* CShadowManager::switchNode [private]
 

Node to switch between scene types.

Definition at line 135 of file ShadowManager.h.

Referenced by CShadowManager(), setSceneType(), and ~CShadowManager().

SoSeparator* CShadowManager::sceneNoShadows [private]
 

Root node of scene without shadows.

Definition at line 137 of file ShadowManager.h.

Referenced by createShadowScene(), and CShadowManager().

SoSeparator* CShadowManager::sceneWithShadows [private]
 

Root node of scene with shadows.

Definition at line 139 of file ShadowManager.h.

Referenced by createShadowScene(), and CShadowManager().

SoSeparator* CShadowManager::sceneWithShadowVolumes [private]
 

Root node of scene with shadow volumes.

Definition at line 141 of file ShadowManager.h.

Referenced by CShadowManager().


The documentation for this class was generated from the following files:
Generated on Wed May 17 17:27:52 2006 for Shadow Engine by  doxygen 1.4.6-NO