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.1" 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 enum SCENE_TYPE sceneType; 00133 00135 SoSwitch * switchNode; 00137 SoSeparator * sceneNoShadows; 00139 SoSeparator * sceneWithShadows; 00141 SoSeparator * sceneWithShadowVolumes; 00142 00143 00144 // shadows 00145 void createShadowScene(); 00146 00147 // environment 00148 SoEnvironment * findEnvironmentNode(); 00149 00150 // lights 00151 static void lightMoveCallback (void * userdata, SoSensor *); 00152 void checkLights(); 00153 00154 // shadow casters / objects 00155 static void objectMoveCallback(void * userdata, SoSensor * s); 00156 static void objectShapeCallback(void * userdata, SoSensor * s); 00157 int findObject(SoSeparator * object); 00158 void checkObjects(); 00159 00160 // shadow rendering callbacks 00161 static void initCB(void * userdata, SoAction * action); 00162 static void endCB(void * userdata, SoAction * action); 00163 00164 // messages 00165 void printMsg(const char * msg); 00166 void printError(const char * msg); 00167 00168 public: 00169 CShadowManager(SoSeparator * sr, SoEnvironment * env); 00170 ~CShadowManager(); 00171 00172 // scene types 00173 void setSceneType(enum CShadowManager::SCENE_TYPE type); 00174 enum CShadowManager::SCENE_TYPE getSceneType(); 00175 enum SCENE_TYPE * psceneType; 00176 00177 // method 00178 enum TShadowAlgorithm * getAlgorithm(); 00179 void method2algorithm(); 00180 00181 // settings 00182 void setManager(TShadowSettings * s); 00183 const struct TShadowSettings * readSettings(); 00184 void setMethod(enum TShadowMethod newMethod); 00185 void setSVDepth(float newfDepth); 00186 void printSettings(); 00187 void enableSensors(); 00188 void disableSensors(); 00189 00190 // shadows 00191 void createShadows(); 00192 void createCasterVolumes(int index); 00193 SoSeparator * getSceneRoot(); 00194 SoSeparator * getShadowSceneRoot(); 00195 00196 // environment 00197 SoEnvironment * getEnvironmentNode(); 00198 void setAmbientIntensity(float val); 00199 00200 // scene lights 00201 void addLight(SoLight * light); 00202 void removeLight(SoLight * light); 00203 00204 // scene objects 00205 void addObject(SoSeparator * object); 00206 void removeObject(SoSeparator * object); 00207 void createObjectsShadows(SoSeparator * object); 00208 00209 // export / import 00210 void export(const char * filename); 00211 // void import(const char * filename); 00212 }; 00213 00214 00215 #endif