AI_SDB_VisitorBase.h

Go to the documentation of this file.
00001 #ifndef AI_SDB_VISITORBASE_H
00002 #define AI_SDB_VISITORBASE_H
00003 
00004 // header file for the basic visibility and spatial visitor classes
00005 
00006 #include "../AI_Global.h"
00007 #include "../math/AI_Vector.h"
00008 #include "../math/AI_Matrix.h"
00009 #include "../math/AI_BBox.h"
00010 #include "../math/AI_Sphere.h"
00011 #include "../utils/AI_Array.h"
00012 
00013 class AI_SDB_SpatialElement;
00014 class AI_SDB_PlaneClipper;
00015 
00038 struct AI_SDB_VisitorFlags {
00039 
00041     AI_SDB_VisitorFlags(bool c=true, bool d=false, int initflags=~0) : m_test(c), m_antitest(d), m_activeflags(initflags) {}
00042     AI_SDB_VisitorFlags(const AI_SDB_VisitorFlags &copyme) 
00043         : m_test(copyme.m_test), m_antitest(copyme.m_antitest), m_activeflags(copyme.m_activeflags) {}
00044 
00045     bool TestResult() { return m_test; }
00046     bool AntiTestResult() { return m_antitest; }
00047 
00048     bool m_test, m_antitest;
00049     unsigned short m_activeflags;
00050 
00051     enum { MAXVISITORFLAGS = 15 };
00052 };
00053 
00076 class AI_SDB_VisibilityVisitor {
00077 public:
00078     typedef AI_Array<AI_SDB_SpatialElement *> VisibleElements;
00079 
00080     AI_SDB_VisibilityVisitor(const AI_Vector3 &viewpoint);
00081     virtual ~AI_SDB_VisibilityVisitor();
00082 
00085     virtual void Reset();
00086     virtual void Reset(const AI_Vector3 &newviewpoint);
00087 
00089     virtual void Visit(AI_SDB_SpatialElement *visitee)=0;
00090 
00094     virtual AI_SDB_VisitorFlags VisibilityTest(const AI_BBox &testbox, AI_SDB_VisitorFlags flags)=0;
00095     virtual AI_SDB_VisitorFlags VisibilityTest(const AI_Sphere &testsphere, AI_SDB_VisitorFlags flags)=0;
00096 
00099     AI_Vector3 &GetViewPoint() const;
00100 
00110     float GetMinimumDetailRatio() const;
00111     
00118     virtual void EnterLocalSpace(AI_Matrix44 &warp);
00119 
00121     virtual void LeaveLocalSpace();
00122 
00123 protected:
00125     AI_Array<AI_Vector3> m_viewpointstack;
00126 
00128     AI_Array<float>   m_minimumdetailratiostack;
00129 };
00130 
00137 class AI_SDB_SpatialVisitor {
00138 public:
00139     typedef AI_Array<AI_SDB_SpatialElement *> SpatialElements;
00140 
00141     AI_SDB_SpatialVisitor() {
00142     }
00143     virtual ~AI_SDB_SpatialVisitor() {
00144     }
00145 
00146     virtual void Reset();
00147 
00149     virtual void Visit(AI_SDB_SpatialElement *visitee)=0;
00150 
00160     virtual AI_SDB_VisitorFlags ContainmentTest(const AI_BBox &testbox, AI_SDB_VisitorFlags flags) = 0;
00161     virtual AI_SDB_VisitorFlags ContainmentTest(const AI_Sphere &testsphere, AI_SDB_VisitorFlags flags) = 0;
00162 
00169     virtual void EnterLocalSpace(AI_Matrix44 &warp) = 0;
00170 
00172     virtual void LeaveLocalSpace() = 0;
00173 };
00174 
00211 class AI_SDB_OcclusionVisitor : public AI_SDB_VisibilityVisitor {
00212 public:
00213     AI_SDB_OcclusionVisitor(const AI_Vector3 &viewpoint);
00214     virtual ~AI_SDB_OcclusionVisitor();
00215 
00216     void SetRestrictingVisitor(AI_SDB_VisibilityVisitor *vv) { m_restrictingvisitor = vv; }
00217 
00219     virtual void AddBBoxOccluder(const AI_BBox &boxoccluder)=0;
00221     virtual void AddSphereOccluder(const AI_Sphere &sphereoccluder)=0;
00223     virtual void AddHullOccluder(const AI_SDB_PlaneClipper &hulloccluder)=0;
00224 
00226     virtual AI_SDB_VisitorFlags VisibilityTest(const AI_BBox &testbox, AI_SDB_VisitorFlags flags)=0;
00228     virtual AI_SDB_VisitorFlags VisibilityTest(const AI_Sphere &testsphere, AI_SDB_VisitorFlags flags)=0;
00229 
00230 protected:
00231     // optional visibility visitor used to restrict our occlusion gathering
00232     AI_SDB_VisibilityVisitor *m_restrictingvisitor;
00233 };
00234 
00235 #endif
00236