Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef PortalSceneManager_INCLUDE_ONCE
00033 #define PortalSceneManager_INCLUDE_ONCE
00034
00035 #include <vlGraphics/Actor.hpp>
00036 #include <vlCore/Vector4.hpp>
00037 #include <vlCore/Vector3.hpp>
00038 #include <vlGraphics/SceneManager.hpp>
00039 #include <vlCore/Log.hpp>
00040 #include <vlGraphics/Frustum.hpp>
00041
00042 namespace vl
00043 {
00044
00045 class Sector;
00046 class SceneManagerPortals;
00047
00053 class VLGRAPHICS_EXPORT Portal: public Object
00054 {
00055 VL_INSTRUMENT_CLASS(vl::Portal, Object)
00056
00057 friend class SceneManagerPortals;
00058
00059 public:
00061 Portal()
00062 {
00063 VL_DEBUG_SET_OBJECT_NAME()
00064 mIsOpen = true;
00065 mVisitTick = 0;
00066 }
00067
00069 std::vector<fvec3>& geometry() { return mPortalGeometry; }
00071 const std::vector<fvec3>& geometry() const { return mPortalGeometry; }
00072
00074 void setTargetSector(Sector* sector) { mTargetSector = sector; }
00076 Sector* targetSector() { return mTargetSector; }
00078 const Sector* targetSector() const { return mTargetSector; }
00079
00081 bool isOpen() const { return mIsOpen; }
00083 void setIsOpen(bool is_open) { mIsOpen = is_open; }
00084
00085 protected:
00087 void setNormal(const fvec3& n) { mNormal = n; }
00089 const fvec3& normal() const { return mNormal; }
00090
00093 bool computeNormal();
00094
00095 protected:
00096 std::vector<fvec3> mPortalGeometry;
00097 Sector* mTargetSector;
00098 fvec3 mNormal;
00099 unsigned int mVisitTick;
00100 bool mIsOpen;
00101 };
00102
00109 class VLGRAPHICS_EXPORT Sector: public Object
00110 {
00111 VL_INSTRUMENT_CLASS(vl::Sector, Object)
00112
00113 public:
00119 class VisibilityCallback: public Object
00120 {
00121 public:
00130 virtual void operator()(const Camera* cam, SceneManagerPortals* psm, Sector* s, Portal* p) = 0;
00131 };
00132 public:
00134 Sector()
00135 {
00136 VL_DEBUG_SET_OBJECT_NAME()
00137 mActors = new ActorCollection;
00138 }
00139
00141 ActorCollection* actors() { return mActors.get(); }
00143 const ActorCollection* actors() const { return mActors.get(); }
00144
00146 std::vector< ref<Portal> >& portals() { return mPortals; }
00148 const std::vector< ref<Portal> >& portals() const { return mPortals; }
00149
00152 std::vector< AABB >& volumes() { return mVolumes; }
00155 const std::vector< AABB >& volumes() const { return mVolumes; }
00156
00158 AABB computeBoundingBox();
00159
00160 std::vector< ref<VisibilityCallback> >& callbacks() { return mCallbacks; }
00161 const std::vector< ref<VisibilityCallback> >& callbacks() const { return mCallbacks; }
00162 void executeCallbacks(const Camera*cam,SceneManagerPortals* psm, Portal*p);
00163
00164 protected:
00165 std::vector< ref<Portal> > mPortals;
00166 std::vector< AABB > mVolumes;
00167 ref< ActorCollection > mActors;
00168 std::vector< ref<VisibilityCallback> > mCallbacks;
00169 };
00170
00184 class VLGRAPHICS_EXPORT SceneManagerPortals: public SceneManager
00185 {
00186 VL_INSTRUMENT_CLASS(vl::SceneManagerPortals, SceneManager)
00187
00188 public:
00190 SceneManagerPortals(): mExternalSector(new Sector), mVisitTick(1), mShowPortals(false)
00191 {
00192 VL_DEBUG_SET_OBJECT_NAME()
00193 }
00194
00196 void extractActors(ActorCollection& list);
00198 void extractVisibleActors(ActorCollection& list, const Camera* camera);
00199
00201 std::vector< ref<Sector> >& sectors() { return mSectors; }
00203 const std::vector< ref<Sector> >& sectors() const { return mSectors; }
00204
00212 Sector* externalSector() { return mExternalSector.get(); }
00214 const Sector* externalSector() const { return mExternalSector.get(); }
00215
00217 void computePortalNormals();
00218
00220 void initialize();
00221
00223 bool showPortals() const { return mShowPortals; }
00225 void setShowPortals(bool show) { mShowPortals = show; }
00227 void invalidatePortalActors() { mPortalActorMap.clear(); }
00228
00230 const std::vector<Frustum>& frustumStack() const { return mFrustumStack; }
00231
00232 protected:
00233 void renderPortal(Portal* portal);
00234 void visitSector(Sector* prev, Sector* sector, const vec3& eye, const Camera* camera);
00235 Sector* computeStartingSector(const Camera* camera);
00236
00237 protected:
00238 ref<Sector> mExternalSector;
00239 std::vector< ref<Sector> > mSectors;
00240 std::vector< ref<Actor> > mTempActors;
00241 std::map<Portal*, ref<Actor> > mPortalActorMap;
00242 std::vector<Frustum> mFrustumStack;
00243 unsigned mVisitTick;
00244 bool mShowPortals;
00245 };
00246
00247 }
00248
00249 #endif