ShadowManager.h

Go to the documentation of this file.
00001 
00007 /* ---------------------------------------------------------------------------
00008  * Authors:      Tomáš Burian (tburian _AT centrum.cz)            
00009  * Thanks to:    PCJohn (peciva _AT fit.vutbr.cz)
00010  * Contributors: 
00011  *
00012  * THIS SOFTWARE IS NOT COPYRIGHTED
00013  *
00014  * This source code is offered for use in the public domain.
00015  * You may use, modify or distribute it freely.
00016  *
00017  * This source code is distributed in the hope that it will be useful but
00018  * WITHOUT ANY WARRANTY.  ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
00019  * DISCLAIMED.  This includes but is not limited to warranties of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00021  *
00022  * If you find the source code useful, authors will kindly welcome
00023  * if you give them credit and keep their names with their source code,
00024  * but do not feel to be forced to do so.
00025  * ---------------------------------------------------------------------------
00026  */
00027 
00028 #ifndef SHADOW_MANAGER__H
00029 #define SHADOW_MANAGER__H
00030 
00032 #ifndef DODEBUG 
00033 #define DODEBUG 0
00034 #endif 
00035 #if DODEBUG
00036 
00037 #define ONDEBUG(x) x 
00038 #else
00039 
00040 #define ONDEBUG(x) 
00041 #endif 
00042 
00044 #define SHOWFACEMODEL 0 
00045 
00046 #ifndef SE_VERSION  
00047 #define SE_VERSION "0.6.2"
00048 #endif 
00049 
00050 //----------------------------------------------------------------------------
00051 // INCLUDEs
00052 //----------------------------------------------------------------------------
00053 
00054 #include "DataStructures.h"
00055 //
00056 #include <Inventor/nodes/SoSeparator.h>
00057 #include <Inventor/nodes/SoSwitch.h>
00058 #include <Inventor/nodes/SoCallback.h>
00059 #include <Inventor/nodes/SoPolygonOffset.h>
00060 #include <Inventor/nodes/SoTransformation.h>
00061 #include <Inventor/nodes/SoEnvironment.h>
00062 //
00063 #include <Inventor/nodes/SoLight.h>
00064 #include <Inventor/nodes/SoDirectionalLight.h> 
00065 #include <Inventor/nodes/SoPointLight.h>
00066 #include <Inventor/nodes/SoSpotLight.h> 
00067 //
00068 #include <Inventor/manips/SoDirectionalLightManip.h> 
00069 #include <Inventor/manips/SoPointLightManip.h> 
00070 #include <Inventor/manips/SoSpotLightManip.h> 
00071 //
00072 #include <Inventor/sensors/SoFieldSensor.h> 
00073 #include <Inventor/sensors/SoNodeSensor.h> 
00074 #include <Inventor/sensors/SoPathSensor.h>
00075 //
00076 #include <Inventor/actions/SoSearchAction.h>
00077 #include <Inventor/actions/SoGLRenderAction.h>
00078 //
00079 #include <Inventor/lists/SbList.h> 
00080 
00081 //----------------------------------------------------------------------------
00082 // IMPLEMENTATION
00083 //----------------------------------------------------------------------------
00084 
00096 class CShadowManager
00097 {
00098 
00099   public:
00100   
00102     enum SCENE_TYPE {  
00103              SHADOWS = 0, 
00104                SCENE = 1  
00105 //      SHADOW_VOLUMES = 2  /**< User scene with shadow volumes. */ // to do
00106     };
00107 
00108 
00109   private:
00111     SoSeparator * shadowCastersRoot;
00113     SoSeparator * shadowSceneRoot;
00115     SoSeparator * shadowLightsRoot;
00116 
00118     SoSeparator * sceneRoot;
00120     struct TShadowSettings * settings;
00122     enum TShadowAlgorithm algorithm;
00124     int lightIndex;
00126     int objectIndex;
00128     bool first;
00130     SoEnvironment * environment;
00132     static float envIntensity;    
00133 
00135     SoSwitch * switchNode;
00137     SoSeparator * sceneNoShadows;
00139     SoSeparator * sceneWithShadows;
00141     SoSeparator * sceneWithShadowVolumes;
00142 
00143 // shadows    
00144     void createShadowScene();        
00145 
00146 // environment
00147     SoEnvironment * findEnvironmentNode();
00148 
00149 // lights
00150     static void lightMoveCallback (void * userdata, SoSensor *);    
00151     void checkLights();
00152 
00153 // shadow casters / objects
00154     static void objectMoveCallback(void * userdata, SoSensor * s);
00155     static void objectShapeCallback(void * userdata, SoSensor * s);
00156     int findObject(SoSeparator * object);
00157     void checkObjects();    
00158     
00159 // rendering callbacks
00160     // without shadows    
00161     static void nslightsOffCB(void * userdata, SoAction * action);
00162     static void nslightsOnCB(void * userdata, SoAction * action);
00163     static void nsambientOffCB(void * userdata, SoAction * action);
00164     static void nsambientOnCB(void * userdata, SoAction * action);
00165     // shadows
00166     static void initCB(void * userdata, SoAction * action);
00167     static void endCB(void * userdata, SoAction * action);
00168 
00169 // messages
00170     void printMsg(const char * msg);
00171     void printError(const char * msg);
00172 
00173   public:
00174     CShadowManager(SoSeparator * sr, SoEnvironment * env);
00175     ~CShadowManager();
00176 
00177 // scene types
00178     void setSceneType(enum CShadowManager::SCENE_TYPE type);
00179 
00180 // method
00181     enum TShadowAlgorithm * getAlgorithm();
00182     void method2algorithm();
00183     
00184 // settings
00185     void setManager(TShadowSettings * s);
00186     const struct TShadowSettings * readSettings();
00187     void setMethod(enum TShadowMethod newMethod);
00188     void setSVDepth(float newfDepth);
00189     void printSettings();
00190     void enableSensors();
00191     void disableSensors();
00192 
00193 // shadows
00194     void createShadows();
00195     void createCasterVolumes(int index);
00196     SoSeparator * getSceneRoot();
00197     SoSeparator * getShadowSceneRoot();
00198 
00199 // environment
00200     SoEnvironment * getEnvironmentNode(); 
00201     void setAmbientIntensity(float val);
00202 
00203 // scene lights
00204     void addLight(SoLight * light);
00205     void removeLight(SoLight * light);
00206     
00207 // scene objects    
00208     void addObject(SoSeparator * object);
00209     void removeObject(SoSeparator * object);
00210     void createObjectsShadows(SoSeparator * object);
00211 
00212 // export / import
00213     void export(const char * filename);
00214 //    void import(const char * filename);
00215 };
00216 
00217 
00218 #endif

Generated on Wed May 17 17:27:52 2006 for Shadow Engine by  doxygen 1.4.6-NO