Torque3D Documentation / _generateds / shadowVolumeBSP.h

shadowVolumeBSP.h

Engine/source/lighting/common/shadowVolumeBSP.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _SHADOWVOLUMEBSP_H_
 25#define _SHADOWVOLUMEBSP_H_
 26
 27#ifndef _TVECTOR_H_
 28#include "core/util/tVector.h"
 29#endif
 30#ifndef _MMATH_H_
 31#include "math/mMath.h"
 32#endif
 33#ifndef _DATACHUNKER_H_
 34#include "core/dataChunker.h"
 35#endif
 36#ifndef _LIGHTMANAGER_H_
 37#include "lighting/lightManager.h"
 38#endif
 39
 40/// Used to calculate shadows.
 41class ShadowVolumeBSP
 42{
 43   public:
 44      ShadowVolumeBSP();
 45      ~ShadowVolumeBSP();
 46
 47      struct SVNode;
 48      struct SurfaceInfo
 49      {
 50         U32               mSurfaceIndex;
 51         U32               mPlaneIndex;
 52         Vector<U32>       mShadowed;
 53         SVNode *          mShadowVolume;
 54      };
 55
 56      struct SVNode
 57      {
 58         enum Side
 59         {
 60            Front       = 0,
 61            Back        = 1,
 62            On          = 2,
 63            Split       = 3
 64         };
 65
 66         SVNode *       mFront;
 67         SVNode *       mBack;
 68         U32            mPlaneIndex;
 69         U32            mShadowVolume;
 70
 71         /// Used with shadowed interiors.
 72         SurfaceInfo *  mSurfaceInfo;
 73      };
 74
 75      struct SVPoly
 76      {
 77         enum {
 78            MaxWinding  = 32
 79         };
 80
 81         U32               mWindingCount;
 82         Point3F           mWinding[MaxWinding];
 83
 84         PlaneF            mPlane;
 85         SVNode *          mTarget;
 86         U32               mShadowVolume;
 87         SVPoly *          mNext;
 88         SurfaceInfo *     mSurfaceInfo;
 89      };
 90
 91      void insertPoly(SVNode **, SVPoly *);
 92      void insertPolyFront(SVNode **, SVPoly *);
 93      void insertPolyBack(SVNode **, SVPoly *);
 94
 95      void splitPoly(SVPoly *, const PlaneF &, SVPoly **, SVPoly **);
 96      void insertShadowVolume(SVNode **, U32);
 97      void addUniqueVolume(SurfaceInfo *, U32);
 98
 99      SVNode::Side whichSide(SVPoly *, const PlaneF &) const;
100
101      //
102      bool testPoint(SVNode *, const Point3F &);
103      bool testPoly(SVNode *, SVPoly *);
104      void addToPolyList(SVPoly **, SVPoly *) const;
105      void clipPoly(SVNode *, SVPoly **, SVPoly *);
106      void clipToSelf(SVNode *, SVPoly **, SVPoly *);
107      F32 getPolySurfaceArea(SVPoly *) const;
108      F32 getClippedSurfaceArea(SVNode *, SVPoly *);
109      void movePolyList(SVPoly **, SVPoly *) const;
110      F32 getLitSurfaceArea(SVPoly *, SurfaceInfo *);
111
112      Vector<SurfaceInfo*>   mSurfaces;
113
114      Chunker<SVNode>         mNodeChunker;
115      Chunker<SVPoly>         mPolyChunker;
116
117      SVNode * createNode();
118      void recycleNode(SVNode *);
119
120      SVPoly * createPoly();
121      void recyclePoly(SVPoly *);
122
123      U32 insertPlane(const PlaneF &);
124      const PlaneF & getPlane(U32) const;
125
126      //
127      SVNode *          mSVRoot;
128      Vector<SVNode*>   mShadowVolumes;
129      SVNode * getShadowVolume(U32);
130
131      Vector<PlaneF>    mPlanes;
132      SVNode *          mNodeStore;
133      SVPoly *          mPolyStore;
134
135      // used to remove the last inserted interior from the tree
136      Vector<SVNode*>   mParentNodes;
137      SVNode *          mFirstInteriorNode;
138      void removeLastInterior();
139
140      /// @name  Access functions
141      /// @{
142      void insertPoly(SVPoly * poly) {insertPoly(&mSVRoot, poly);}
143      bool testPoint(Point3F & pnt) {return(testPoint(mSVRoot, pnt));}
144      bool testPoly(SVPoly * poly) {return(testPoly(mSVRoot, poly));}
145      F32 getClippedSurfaceArea(SVPoly * poly) {return(getClippedSurfaceArea(mSVRoot, poly));}
146      /// @}
147
148      /// @name Helpers
149      /// @{
150      void buildPolyVolume(SVPoly *, LightInfo *);
151      SVPoly * copyPoly(SVPoly *);
152      /// @}
153};
154
155#endif
156