Gizmo3D

gzShadowVolume.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzShadowVolume.h
00003 // Module       : 
00004 // Description  : Class definition of the gzShadowVolume class
00005 // Author       : Anders Modén      
00006 // Product      : Gizmo3D 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden   
00009 //          
00010 // NOTE:    Gizmo3D is a high performance 3D Scene Graph and effect visualisation 
00011 //          C++ toolkit for Linux, Mac OS X, Windows (Win32) and IRIX® for  
00012 //          usage in Game or VisSim development.
00013 //
00014 //
00015 // Revision History...                          
00016 //                                  
00017 // Who  Date    Description                     
00018 //                                  
00019 // AMO  000115  Created file    
00020 //
00021 //******************************************************************************
00022 #ifndef __GZ_SHADOW_VOLUME_H__
00023 #define __GZ_SHADOW_VOLUME_H__
00024 
00030 #include "gzRecursive.h"
00031 #include "gzGeometry.h"
00032 #include "gzNodeAction.h"
00033 #include "gzLight.h"
00034 #include "gzShadowGeometry.h"
00035 
00036 //******************************************************************************
00037 // Class    : gzShadowVolume
00038 //                                  
00039 // Purpose  : Base class for all volumetric shadows
00040 //                                  
00041 // Notes    : - 
00042 //                                  
00043 // Revision History...                          
00044 //                                  
00045 // Who  Date    Description                     
00046 //                                  
00047 // AMO  010101  Created 
00048 //                                  
00049 //******************************************************************************
00050 class gzShadowVolume : public gzBaseGeometry
00051 {
00052 public:
00053 
00054     GZ_GRAPH_EXPORT gzShadowVolume(gzLight *shadowlight=NULL,gzULong softPasses=0,gzFloat softScale=1.0f,const gzString & name=GZ_EMPTY_STRING);
00055 
00056     GZ_GRAPH_EXPORT virtual ~gzShadowVolume(){};
00057 
00058     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00059 
00060     // ---------- Clone interface ---------------------------------------
00061     
00062     GZ_GRAPH_EXPORT virtual gzReference* clone() const=0;
00063 
00064     // ---------- Shadow Volume settings --------------------------------
00065 
00066     GZ_GRAPH_EXPORT gzLight *getShadowLight();
00067 
00068     GZ_GRAPH_EXPORT gzVoid setShadowLight(gzLight *shadowLight);
00069 
00070     // --------- Transform of shadow volume -----------------------------
00071 
00072     GZ_GRAPH_EXPORT gzVoid setTransformIndex(gzULong index);    // Default 0;
00073 
00074     GZ_GRAPH_EXPORT gzULong getTransformIndex();
00075 
00076     // --------- Pass activation IDs ------------------------------------
00077 
00078     GZ_GRAPH_EXPORT gzVoid  useRenderID(gzBool on);
00079     GZ_GRAPH_EXPORT gzBool  useRenderID();
00080 
00081     GZ_GRAPH_EXPORT gzVoid  setRenderID(gzULong id);
00082     GZ_GRAPH_EXPORT gzULong getRenderID();
00083 
00084     // ---------- Soft shadow control -----------------------------------
00085 
00086     GZ_GRAPH_EXPORT gzVoid  setPrimaryDirection(const gzVec3 &direction,const gzVec3 &base);
00087     GZ_GRAPH_EXPORT gzVec3  getPrimaryDirection();
00088     GZ_GRAPH_EXPORT gzVec3  getPrimaryBase();
00089 
00090     GZ_GRAPH_EXPORT gzVoid  setNumberOfSoftPasses(gzULong passes);
00091     GZ_GRAPH_EXPORT gzULong getNumberOfSoftPasses();
00092 
00093     GZ_GRAPH_EXPORT gzVoid  setSoftScale(gzFloat scale);
00094     GZ_GRAPH_EXPORT gzFloat getSoftScale();
00095 
00096     GZ_GRAPH_EXPORT gzVoid updateSoftScaleMatrix();
00097 
00098     GZ_GRAPH_EXPORT const gzMatrix4 &getSoftScaleMatrix();
00099 
00100 private:
00101 
00102     
00103 
00104     gzLight *   m_shadowLight;
00105 
00106     gzULong     m_transformIndex;
00107 
00108     gzBool      m_useRenderID;
00109 
00110     gzULong     m_renderID;
00111 
00112     gzVec3      m_primaryDirection;
00113 
00114     gzVec3      m_primaryBase;
00115 
00116     gzFloat     m_scaleFactor;
00117 
00118     gzULong     m_softPasses;   
00119 
00120     gzMatrix4   m_scaleMatrix;
00121 };
00122 
00123 //******************************************************************************
00124 // Class    : gzShadowVolumeGeometry
00125 //                                  
00126 // Purpose  : Special volume shadow using a base geometry as volume
00127 //                                  
00128 // Notes    : - 
00129 //                                  
00130 // Revision History...                          
00131 //                                  
00132 // Who  Date    Description                     
00133 //                                  
00134 // AMO  010101  Created 
00135 //                                  
00136 //******************************************************************************
00137 class gzShadowVolumeGeometry : public gzShadowVolume
00138 {
00139 public:
00140 
00141     GZ_GRAPH_EXPORT gzShadowVolumeGeometry( gzLight *shadowlight=NULL,gzBaseGeometry *geom=NULL,gzULong softPasses=0,gzFloat softScale=1.0f,const gzString & name=GZ_EMPTY_STRING);
00142 
00143     GZ_GRAPH_EXPORT virtual ~gzShadowVolumeGeometry(){};
00144 
00145     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00146 
00147     // ---------- Clone interface ---------------------------------------
00148     
00149     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00150 
00151     // ---------- Action interface --------------------------------------
00152 
00153     GZ_GRAPH_EXPORT virtual gzVoid preTraverseAction( gzTraverseAction *actionclass , gzContext *context);
00154 
00155     // ---------- Common graph functions --------------------------------
00156 
00157     GZ_GRAPH_EXPORT virtual gzVoid updateNode();
00158 
00159 
00160     // ---------- ShadowVolumeGeom interface ----------------------------
00161 
00162     GZ_GRAPH_EXPORT gzVoid setGeometry(gzBaseGeometry *geometry);
00163 
00164     GZ_GRAPH_EXPORT gzBaseGeometry *getGeometry();
00165 
00166 private:
00167 
00168     gzRefPointer<gzBaseGeometry>    m_geometry;                     
00169 
00170 };
00171 
00172 //******************************************************************************
00173 // Class    : gzIndexBaseGeometry
00174 //                                  
00175 // Purpose  : -
00176 //                                  
00177 // Notes    : Private usage 
00178 //                                  
00179 // Revision History...                          
00180 //                                  
00181 // Who  Date    Description                     
00182 //                                  
00183 // AMO  010101  Created 
00184 //                                  
00185 //******************************************************************************
00186 class gzIndexBaseGeometry : public gzReference
00187 {
00188 private:
00189 
00190     gzIndexBaseGeometry(){};
00191 
00192     friend class gzShadowRender;
00193 
00194     gzRefPointer<gzBaseGeometry>    geometry;
00195 
00196     gzULong                         index;
00197 
00198     gzBool                          equalIndex;
00199 };
00200 
00201 
00202 //******************************************************************************
00203 // Class    : gzShadowRender
00204 //                                  
00205 // Purpose  : The actual shadow render class. Add child nodes to render in shadow
00206 //                                  
00207 // Notes    : - 
00208 //                                  
00209 // Revision History...                          
00210 //                                  
00211 // Who  Date    Description                     
00212 //                                  
00213 // AMO  010101  Created 
00214 //                                  
00215 //******************************************************************************
00216 class gzShadowRender : public gzRecursive
00217 {
00218 public:
00219     GZ_GRAPH_EXPORT gzShadowRender(const gzString & name=GZ_EMPTY_STRING);
00220     GZ_GRAPH_EXPORT virtual ~gzShadowRender(){};
00221 
00222     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00223 
00224 
00225     // ---------- Clone interface ---------------------------------------
00226     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00227 
00228     // ---------- Action Interface --------------------------------------
00229 
00230     GZ_GRAPH_EXPORT virtual gzVoid preTraverseAction( gzTraverseAction *actionclass , gzContext *context);
00231     GZ_GRAPH_EXPORT virtual gzVoid postTraverseAction( gzTraverseAction *actionclass , gzContext *context);
00232     GZ_GRAPH_EXPORT virtual gzActionStage useActionStage( gzTraverseAction *actionclass , gzContext *context);
00233 
00234     // ---------- Render Volume API --------------------------------------
00235 
00236     GZ_GRAPH_EXPORT gzVoid addShadowVolume (gzShadowVolume *mask, gzBool addToRender=FALSE);
00237 
00238     GZ_GRAPH_EXPORT gzVoid removeShadowVolume (gzShadowVolume *mask);
00239 
00240     GZ_GRAPH_EXPORT gzVoid addGeometryMask (gzBaseGeometry *render, gzULong index=0,gzBool equalIndex=FALSE);
00241 
00242     GZ_GRAPH_EXPORT gzVoid showVolumes (gzBool show);
00243 
00244     GZ_GRAPH_EXPORT gzVoid useClearing(gzBool on);
00245 
00246     GZ_GRAPH_EXPORT gzVoid setPassOffset(gzULong offset);
00247 
00248 
00249 protected:
00250 
00251     GZ_GRAPH_EXPORT virtual gzVoid calculateTransform(gzContext *context);  // Override to calculate other transform
00252 
00253     gzRefList<gzShadowVolume>   m_volumes;
00254 
00255     gzRefList<gzIndexBaseGeometry>  m_geometryMasks;
00256 
00257     gzULong                     m_passOffset;
00258 
00259     gzBool                      m_showVolumes:1;
00260 
00261     gzBool                      m_useClearing:1;
00262 };
00263 
00264 enum gzShadowGeneratorType
00265 {
00266     GZ_SHADOW_GEOMETRY,
00267     GZ_SHADOW_DEPTHMAP
00268 };
00269 
00270 
00271 //******************************************************************************
00272 // Class    : gzShadowGenerator
00273 //                                  
00274 // Purpose  : Generates and detects shadow changes from each rendering pass.
00275 //                                  
00276 // Notes    : - 
00277 //                                  
00278 // Revision History...                          
00279 //                                  
00280 // Who  Date    Description                     
00281 //                                  
00282 // AMO  010101  Created 
00283 //                                  
00284 //******************************************************************************
00285 class gzShadowGenerator : public gzNode
00286 {
00287 public:
00288     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00289 
00290     GZ_GRAPH_EXPORT gzShadowGenerator(gzNode *node , gzShadowVolumeGeometry *shadowVolume , const gzDouble &lengthFactor , gzShadowGeneratorType type, const gzString & name=GZ_EMPTY_STRING);
00291 
00292     GZ_GRAPH_EXPORT virtual ~gzShadowGenerator(){};
00293 
00294     // ---------- clone interface ---------------------------------------
00295 
00296     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00297 
00298     // ---------- Action interface --------------------------------------
00299 
00300     GZ_GRAPH_EXPORT virtual gzVoid preTraverseAction( gzTraverseAction *actionclass , gzContext *context);
00301 
00303 
00320     GZ_GRAPH_EXPORT static gzVoid addShadowGenerators(  gzNode *scene,
00321                                                         gzShadowRender *render,
00322                                                         gzLight *light , 
00323                                                         gzBool useShadowTag=FALSE,
00324                                                         const gzDouble &lengthFactor=5.0,
00325                                                         const gzULong &softPasses=0, 
00326                                                         const gzFloat &softScale=1.0f,
00327                                                         gzRefList<gzShadowGenerator> *addedGenerators=NULL,
00328                                                         gzShadowGeneratorType type=GZ_SHADOW_GEOMETRY, 
00329                                                         gzULong maxTraverseDepth=0xffffffffUL,
00330                                                         gzBool inShadowTag=FALSE);
00331 
00333 
00341     GZ_GRAPH_EXPORT static gzBool removeShadowGenerators(   gzNode *scene , gzShadowRender *render , gzNode *item=NULL);
00342 
00344     GZ_GRAPH_EXPORT gzShadowVolumeGeometry *getShadowVolumeGeometry();
00345 
00347     GZ_GRAPH_EXPORT gzNode *getNode();
00348 
00349 private:
00350 
00351     gzDouble                                m_lengthFactor;
00352 
00353     gzRefPointer<gzNode>                    m_node;
00354 
00355     gzRefPointer<gzShadowVolumeGeometry>    m_shadowVolume;
00356     
00357     gzULong                                 m_transformUpdateDiff;
00358 
00359     gzULong                                 m_lightUpdateID;
00360 
00361     gzULong                                 m_nodeUpdateID;
00362 
00363     gzULong                                 m_weightUpdateID;
00364 
00365     gzArray<gzTriConnectivity>              m_triConnectivity;
00366 
00367     gzULong                                 m_currentUpdate;
00368 
00369     gzULong                                 m_updateCount;
00370 
00371     gzShadowGeneratorType                   m_type;
00372 };
00373 
00374 //---------------------------- User defined mask geometry -------------------------------
00375 
00376 const gzString  GZ_USERDATA_MASK_GEOMETRY       ="_mskG";
00377 
00378 class gzShadowGeometryMask : public gzUserData
00379 {
00380 public:
00381 
00382     gzRefPointer<gzGeometry>    maskData;
00383 };
00384 
00385 #endif

Documentation for Gizmo3D generated at Wed Feb 20 11:54:09 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond