# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/SceneManagerPortals.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.com                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    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     friend class SceneManagerPortals;
    00056   public:
    00057     virtual const char* className() { return "vl::Portal"; }
    00058
    00060     Portal()
    00061     {
    00062       VL_DEBUG_SET_OBJECT_NAME()
    00063       mIsOpen = true;
    00064       mVisitTick = 0;
    00065     }
    00066
    00068     std::vector<fvec3>& geometry() { return mPortalGeometry; }
    00070     const std::vector<fvec3>& geometry() const { return mPortalGeometry; }
    00071
    00073     void setTargetSector(Sector* sector) { mTargetSector = sector; }
    00075     Sector* targetSector() { return mTargetSector; }
    00077     const Sector* targetSector() const { return mTargetSector; }
    00078
    00080     bool isOpen() const { return mIsOpen; }
    00082     void setIsOpen(bool is_open) { mIsOpen = is_open; }
    00083
    00084   protected:
    00086     void setNormal(const fvec3& n) { mNormal = n; }
    00088     const fvec3& normal() const { return mNormal; }
    00089
    00092     bool computeNormal();
    00093
    00094   protected:
    00095     std::vector<fvec3> mPortalGeometry;
    00096     Sector* mTargetSector;
    00097     fvec3 mNormal;
    00098     unsigned int mVisitTick;
    00099     bool mIsOpen;
    00100   };
    00101 //-----------------------------------------------------------------------------
    00108   class VLGRAPHICS_EXPORT Sector: public Object
    00109   {
    00110   public:
    00111     virtual const char* className() { return "vl::Sector"; }
    00112
    00118     class VisibilityCallback: public Object
    00119     {
    00120     public:
    00129         virtual void operator()(const Camera* cam, SceneManagerPortals* psm, Sector* s, Portal* p) = 0;
    00130     };
    00131   public:
    00133     Sector()
    00134     {
    00135       VL_DEBUG_SET_OBJECT_NAME()
    00136       mActors = new ActorCollection;
    00137     }
    00138
    00140     ActorCollection* actors() { return mActors.get(); }
    00142     const ActorCollection* actors() const { return mActors.get(); }
    00143
    00145     std::vector< ref<Portal> >& portals() { return mPortals; }
    00147     const std::vector< ref<Portal> >& portals() const { return mPortals; }
    00148
    00151     std::vector< AABB >& volumes() { return mVolumes; }
    00154     const std::vector< AABB >& volumes() const { return mVolumes; }
    00155
    00157     AABB computeBoundingBox();
    00158
    00159     std::vector< ref<VisibilityCallback> >& callbacks() { return mCallbacks; }
    00160     const std::vector< ref<VisibilityCallback> >& callbacks() const { return mCallbacks; }
    00161     void executeCallbacks(const Camera*cam,SceneManagerPortals* psm, Portal*p);
    00162
    00163   protected:
    00164     std::vector< ref<Portal> > mPortals;
    00165     std::vector< AABB > mVolumes;
    00166     ref< ActorCollection > mActors;
    00167     std::vector< ref<VisibilityCallback> > mCallbacks;
    00168   };
    00169 //-----------------------------------------------------------------------------
    00183   class VLGRAPHICS_EXPORT SceneManagerPortals: public SceneManager
    00184   {
    00185   public:
    00186     virtual const char* className() { return "vl::SceneManagerPortals"; }
    00187
    00189     SceneManagerPortals(): mExternalSector(new Sector), mVisitTick(1), mShowPortals(false)
    00190     {
    00191       VL_DEBUG_SET_OBJECT_NAME()
    00192     }
    00193
    00195     void extractActors(ActorCollection& list);
    00197     void extractVisibleActors(ActorCollection& list, const Camera* camera);
    00198
    00200     std::vector< ref<Sector> >& sectors() { return mSectors; }
    00202     const std::vector< ref<Sector> >& sectors() const { return mSectors; }
    00203
    00211     Sector* externalSector() { return mExternalSector.get(); }
    00213     const Sector* externalSector() const { return mExternalSector.get(); }
    00214
    00216     void computePortalNormals();
    00217
    00219     void initialize();
    00220
    00222     bool showPortals() const { return mShowPortals; }
    00224     void setShowPortals(bool show) { mShowPortals = show; }
    00225
    00227     const std::vector<Frustum>& frustumStack() const { return mFrustumStack; }
    00228
    00229   protected:
    00230     void renderPortal(Portal* portal);
    00231     void visitSector(Sector* prev, Sector* sector, const vec3& eye, const Camera* camera);
    00232     Sector* computeStartingSector(const Camera* camera);
    00233
    00234   protected:
    00235     ref<Sector> mExternalSector;
    00236     std::vector< ref<Sector> > mSectors;
    00237     std::vector< ref<Actor> > mTempActors;
    00238     std::map<Portal*, ref<Actor> > mPortalActorMap;
    00239     std::vector<Frustum> mFrustumStack;
    00240     unsigned mVisitTick;
    00241     bool mShowPortals;
    00242   };
    00243 //-----------------------------------------------------------------------------
    00244 }
    00245
    00246 #endif

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:25.
Permission is granted to use this page to write and publish articles regarding Visualization Library.