Changeset 94 for trunk


Ignore:
Timestamp:
05/12/05 18:55:25 (20 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp

    r87 r94  
    11#include "CoherentHierarchicalCullingManager.h" 
    2 #include <windows.h> 
     2#include <OgreLogManager.h> 
    33 
    44namespace GtpVisibility { 
     
    88{ 
    99        InitFrame(); 
     10        Ogre::LogManager::getSingleton().logMessage("**** CHCULL ****\n"); 
    1011 
    1112        QueryQueue queryQueue; 
     
    2021                                                                        mHierarchyInterface->GetQueue()->empty())) 
    2122                { 
    22             //if (mHierarchyInterface->GetQueue()->empty())OutputDebugString("empty\n"); 
    23                                                                  
    24                         HierarchyNode *node = queryQueue.front().first; 
     23                HierarchyNode *node = queryQueue.front().first; 
    2524                                                 
    2625                        queryQueue.pop(); 
  • trunk/VUT/GtpVisibility/src/FrustumCullingManager.cpp

    r87 r94  
    11#include "FrustumCullingManager.h" 
    2 #include <windows.h> 
     2#include <OgreLogManager.h> 
    33 
    44namespace GtpVisibility { 
     
    88{ 
    99        InitFrame(); 
    10  
     10        Ogre::LogManager::getSingleton().logMessage("**** Frustum Culling ****\n"); 
    1111        while (!mHierarchyInterface->GetQueue()->empty()) 
    1212        { 
  • trunk/VUT/GtpVisibility/src/StopAndWaitCullingManager.cpp

    r92 r94  
    11#include "StopAndWaitCullingManager.h" 
    2 #include <windows.h> 
     2#include <OgreLogManager.h> 
     3 
    34 
    45namespace GtpVisibility { 
     
    89{ 
    910        InitFrame(); 
    10                          
     11        Ogre::LogManager::getSingleton().logMessage("*** STOP AND WAIT CULL ****\n");    
     12 
    1113        while (!mHierarchyInterface->GetQueue()->empty()) 
    1214        { 
  • trunk/VUT/GtpVisibility/src/VisibilityManager.cpp

    r92 r94  
    99//----------------------------------------------------------------------- 
    1010VisibilityManager::VisibilityManager(VisibilityEnvironment *visEnvironment): 
    11 mVisibilityThreshold(0) 
     11mVisibilityThreshold(0), mCullingManager(NULL)  
    1212{ 
    1313        mVisibilityEnvironment = visEnvironment; 
    1414         
    15         mCullingManagerType = VisibilityEnvironment::STOP_AND_WAIT_CULLING; 
    16         mCullingManager = new StopAndWaitCullingManager(); 
     15        SetCullingManager(VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING); 
     16        //SetCullingManager(VisibilityEnvironment::FRUSTUM_CULLING); 
    1717 
    1818        mQueryManager = new DummyQueryManager(0); 
     
    2828        VisibilityEnvironment::CullingManagerType ocmType) 
    2929{ 
    30         if (mCullingManagerType != ocmType) 
     30        // change only if necessary 
     31        if (!mCullingManager || (mCullingManagerType != ocmType)) 
    3132        { 
    3233                // delete old culling manager 
    33                 delete mCullingManager; 
     34                if(mCullingManager) 
     35                        delete mCullingManager; 
    3436 
    3537                mCullingManagerType = ocmType; 
  • trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h

    r92 r94  
    3434        GtpVisibility::OcclusionQuery *GetNextOcclusionQuery(); 
    3535                 
    36         /** Sets the current camera. 
     36        /** Sets the current camera used for the rendering. 
    3737                @param cam the current camera 
    3838        */ 
    3939        void SetCamera(Camera *cam); 
    40                  
     40        /** Sets the current camera used for culling. 
     41                @param cam the current camera 
     42                @remark the default is the camera used for rendering 
     43        */ 
     44        void SetCullCamera(Camera *cullCam); 
    4145        /** Initialises this scene traverser for the current frame. 
    4246        @param root root of the hierarchy 
    4347                @param cam current camera 
     48                @param cullCam the camera used for culling. If null, the current camera is used 
    4449                @remark convenience method wich calls VisibilitySceneTraverser::initFrame, 
    4550                sets the current camera, and initialises the distance queue. 
    4651        */ 
    47         void InitFrame(GtpVisibility::HierarchyNode *root, Ogre::Camera *cam); 
     52        void InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam, Camera *cullCam = NULL); 
    4853        /** Checks if the node is visible from the current view frustum. 
    4954                @param node the current node 
     
    95100 
    96101        Camera *mCamera; 
     102        Camera *mCullCamera; 
     103 
    97104        AxisAlignedBox mBox; 
    98105         
  • trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp

    r93 r94  
    22#include "OgreVisibilityOctreeSceneManager.h" 
    33#include <OgreOctree.h> 
     4#include <OgreLogManager.h> 
     5 
    46#include <windows.h> 
    57 
    68namespace Ogre { 
    7 //namespace GtpVisibility { 
     9 
    810//----------------------------------------------------------------------- 
    911OctreeHierarchyInterface::OctreeHierarchyInterface(SceneManager *sm, RenderSystem *rsys):  
     
    2527         
    2628        // if not all subtrees are empty 
    27         if (octree->numNodes() > (int)octree->mNodes.size()) 
     29        //if (octree->numNodes() > (int)octree->mNodes.size()) 
     30        if (!IsLeaf(node)) 
    2831        { 
    2932                for(int i=0; i<8; ++i) 
     
    4245bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const 
    4346{ 
    44         Octree *octant = static_cast<Octree *>(node); 
    45  
    46         for(int i=0; i<8; i++) 
    47         { 
    48                 if (octant->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1]) 
    49                         return false; 
    50         } 
    51  
    52         return true; 
     47        Octree *octree = static_cast<Octree *>(node); 
     48        // HACK: if there are subtrees, they are empty => we are not interested in them 
     49        return octree->numNodes() == (int)octree->mNodes.size(); 
    5350} 
    5451//----------------------------------------------------------------------- 
     
    6865        Vector3 mid = ((box->getMinimum() - box->getMaximum()) * 0.5) + box->getMinimum(); 
    6966 
    70         return (mCamera->getDerivedPosition() - mid).squaredLength(); 
     67        return (mCullCamera->getDerivedPosition() - mid).squaredLength(); 
    7168} 
    7269//----------------------------------------------------------------------- 
  • trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp

    r93 r94  
    11#include <OgreCamera.h> 
    2  
     2#include <OgreLogManager.h> 
    33//#include "OgreSolidHalfBoundingBox.h" 
    44#include "OgreSolidBoundingBox.h" 
     
    1111//----------------------------------------------------------------------- 
    1212PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys): 
    13 mSceneManager(sm), mRenderSystem(rsys), mSolidBoundingBox(NULL)/*, mSolidHalfBoundingBox(NULL)*/ 
     13mSceneManager(sm), mRenderSystem(rsys), mSolidBoundingBox(NULL), 
     14mCamera(NULL), mCullCamera(NULL) 
    1415{ 
    1516} 
     
    6465} 
    6566//----------------------------------------------------------------------- 
     67void PlatformHierarchyInterface::SetCullCamera(Ogre::Camera *cullCam) 
     68{ 
     69        mCullCamera = cullCam; 
     70} 
     71//----------------------------------------------------------------------- 
    6672GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery() 
    6773{ 
     
    7480} 
    7581//----------------------------------------------------------------------- 
    76 void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam) 
     82void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam, Camera *cullCam) 
    7783{ 
    7884        GtpVisibility::HierarchyInterface::InitFrame(root); 
     
    8086 
    8187        SetCamera(cam); 
     88 
     89        if(cullCam) 
     90                SetCullCamera(cullCam); 
     91        else 
     92                SetCullCamera(cam); 
    8293} 
    8394//----------------------------------------------------------------------- 
     
    96107{ 
    97108#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    98         return mCamera->isVisible(*GetBoundingBox(node), intersects); 
     109        return mCullCamera->isVisible(*GetBoundingBox(node), intersects); 
    99110#else 
    100111        return true; 
     
    113124        // if node is leaf and was visible => will be rendered anyway. 
    114125        // In this case we can also test with the real geometry. 
    115         if(mUseOptimization && wasVisible && IsLeaf(node)) 
     126        // if camera for culling is different from camera for rendering => cannot optimize 
     127        if (mUseOptimization && wasVisible && IsLeaf(node) && (mCamera == mCullCamera)) 
    116128        { 
     129                //LogManager::getSingleton().logMessage("render node\n"); 
    117130                RenderNode(node); 
    118131        } 
    119132        else 
    120133        { 
     134                //LogManager::getSingleton().logMessage("render box\n"); 
    121135                RenderBoundingBox(GetBoundingBox(node)); 
    122136        } 
  • trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp

    r87 r94  
    33#include <OgreCamera.h> 
    44#include <OgreSceneNode.h> 
    5  
    6 //#include <windows.h> 
    75 
    86namespace Ogre { 
  • trunk/VUT/Ogre/src/OgreSolidBoundingBox.cpp

    r92 r94  
    66#include "OgreCamera.h" 
    77#include "OgreMaterialManager.h" 
    8 //#include <windows.h> 
     8 
    99 
    1010namespace Ogre { 
  • trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp

    r93 r94  
    66#include <OgreCamera.h> 
    77#include <OgreLogManager.h> 
    8  
    9 #include <windows.h> 
    108 
    119namespace Ogre { 
     
    1816        mHierarchyInterface =  
    1917                new OctreeHierarchyInterface(this, mDestRenderSystem); 
    20         //visManager->SetCullingManager(GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING); 
    21          
     18                 
    2219        //mDisplayNodes = true; 
    2320        //mShowBoundingBoxes = true; 
     
    3431void VisibilityOctreeSceneManager::_renderVisibleObjects() 
    3532{ 
    36         mHierarchyInterface->InitFrame(mOctree, mCameraInProgress); 
     33        Camera *cullCam = NULL; 
     34 
     35        if(mCullCamera) cullCam = getCamera("CullCamera"); 
     36         
     37        mHierarchyInterface->InitFrame(mOctree, mCameraInProgress, cullCam); 
    3738        mVisibilityManager->GetCullingManager()->InitFrame(); 
    3839 
  • trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp

    r87 r94  
    77#include "OgreVisibilityOptionsManager.h" 
    88 
    9 //#include <windows.h> 
    109 
    1110namespace Ogre { 
  • trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp

    r74 r94  
    3434#include <OgreRoot.h> 
    3535 
    36 //#include <windows.h> 
    3736GtpVisibility::VisibilityEnvironment *visEnv; 
    3837GtpVisibility::VisibilityManager *visManager; 
  • trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp

    r93 r94  
    3232void VisibilityTerrainSceneManager::_renderVisibleObjects() 
    3333{ 
    34         mHierarchyInterface->InitFrame(mOctree, mCameraInProgress); 
     34        Camera *cullCam = NULL; 
     35 
     36        // if two cameras (one for culling, one for visualization) 
     37        if(mCullCamera) 
     38                cullCam = getCamera("CullCamera"); 
     39         
     40        if(cullCam && (mCameraInProgress != cullCam)) 
     41                OutputDebugString("using cullcam\n"); 
     42        else 
     43                OutputDebugString("not using cullcam\n"); 
     44 
     45        mHierarchyInterface->InitFrame(mOctree, mCameraInProgress, cullCam); 
    3546        mVisibilityManager->GetCullingManager()->InitFrame(); 
    3647 
  • trunk/VUT/work/TestCulling/SceneContentGenerator.cpp

    r87 r94  
    66*/ 
    77#include "SceneContentGenerator.h" 
    8 #include <windows.h> 
    98 
    109namespace Ogre { 
  • trunk/VUT/work/TestCulling/TestCullingApplication.cpp

    r93 r94  
    1717 
    1818#define WIN32_LEAN_AND_MEAN 
    19 #include "windows.h" 
     19#include <windows.h> 
    2020 
    2121 
     
    2828{ 
    2929        // Create the camera 
    30         mCamera = mSceneMgr->createCamera("PlayerCam"); 
     30        mCamera = mSceneMgr->createCamera("CullCamera"); 
    3131 
    3232        // Position it at 500 in Z direction 
     
    112112mShowOctree(false), 
    113113mUseCulling(true), 
    114 mUseOptimization(false), 
     114mUseOptimization(true), 
    115115mUseCullCamera(false) 
    116116{ 
  • trunk/VUT/work/TestCulling/TestCullingApplication.h

    r93 r94  
    9797        bool mUseCullCamera; 
    9898 
    99         Camera *mCullCamera; 
     99        Camera *mVisualizationCamera; 
    100100}; 
    101101 
  • trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp

    r93 r94  
    1717 
    1818#define WIN32_LEAN_AND_MEAN 
    19 #include "windows.h" 
     19#include <windows.h> 
    2020 
    2121 
     
    2727        if(mTerrainContentGenerator) 
    2828                delete mTerrainContentGenerator; 
    29         //if(mCullCamera) delete mCullCamera; 
     29        //if(mVisualizationCamera) delete mVisualizationCamera; 
    3030} 
    3131//----------------------------------------------------------------------- 
     
    3333{ 
    3434        // Create the camera 
    35         mCamera = mSceneMgr->createCamera("PlayerCam"); 
     35        mCamera = mSceneMgr->createCamera("CullCamera"); 
    3636         
    3737        // Set a nice viewpoint 
     
    4040         
    4141        //--create cull camera 
    42         mCullCamera = mSceneMgr->createCamera("CullCamera"); 
    43         mCullCamera->setPosition(707, 2500, 528); 
    44         mCullCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 
    45  
    46         mCullCamera->setNearClipDistance(1); 
     42        mVisualizationCamera = mSceneMgr->createCamera("VisualizationCamera"); 
     43        mVisualizationCamera->setPosition(707, 2500, 528); 
     44        mVisualizationCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 
     45 
     46        mVisualizationCamera->setNearClipDistance(1); 
    4747        mCamera->setNearClipDistance(1); 
    4848 
     
    5050        if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE)) 
    5151        { 
    52                 mCullCamera->setFarClipDistance(0); 
     52                mVisualizationCamera->setFarClipDistance(0); 
    5353                mCamera->setFarClipDistance(0); 
    5454        } 
    5555        else 
    5656        { 
    57                  mCullCamera->setFarClipDistance(1000); 
     57                 mVisualizationCamera->setFarClipDistance(1000); 
    5858                 mCamera->setFarClipDistance(1000); 
    5959        } 
     
    7979        mWindow->getViewport(0)->setBackgroundColour(fadeColour); 
    8080        //mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000); 
    81         mWindow->addViewport(mCullCamera, 10, 0.5, 0.5, 1, 1); 
    82  
     81         
    8382        // Create a skybox 
    8483    mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 5000, false); 
     
    133132{ 
    134133        mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr,  
    135                 mGUIRenderer, mTerrainContentGenerator, mCullCamera); 
     134                mGUIRenderer, mTerrainContentGenerator, mVisualizationCamera); 
    136135        mFrameListener->showDebugOverlay(true); 
    137136        mRoot->addFrameListener(mFrameListener); 
     
    150149                                                                           CEGUI::Renderer *renderer, 
    151150                                                                           TerrainContentGenerator *sceneGenerator, 
    152                                                                            Camera *cullCamera):  
     151                                                                           Camera *vizCamera):  
    153152ExampleFrameListener(win, cam, false, true),  
    154153mGUIRenderer(renderer),  
     
    163162mShowOctree(false), 
    164163mUseCulling(true), 
    165 mUseOptimization(false), 
     164mUseOptimization(true), 
    166165mUseCullCamera(false), 
    167 mCullCamera(cullCamera) 
     166mVisualizationCamera(vizCamera) 
    168167{ 
    169168        // Reduce move speed 
     
    293292bool MouseQueryListener::frameStarted(const FrameEvent &evt) 
    294293{ 
     294        clamp2Terrain(mCamera); 
     295        clamp2Terrain(mVisualizationCamera); 
     296 
     297        return ExampleFrameListener::frameStarted(evt); 
     298} 
     299void MouseQueryListener::clamp2Terrain(Camera *cam) 
     300{ 
    295301        // clamp to terrain 
    296         Vector3 camPos = mCamera->getPosition(); 
     302        Vector3 camPos = cam->getPosition(); 
    297303        Vector3 queryResult; 
    298304 
    299     if(mRayQueryExecutor->executeRayQuery(&queryResult,  
    300                 Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y)) 
     305        if(mRayQueryExecutor->executeRayQuery(&queryResult,  
     306                        Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y)) 
    301307        { 
    302                 mCamera->setPosition(mCamera->getPosition().x, queryResult.y + 10,  
    303                         mCamera->getPosition().z); 
     308                cam->setPosition(cam->getPosition().x, queryResult.y + 10,  
     309                        cam->getPosition().z); 
    304310        } 
    305  
    306         camPos = mCullCamera->getPosition(); 
    307  
    308         if(mRayQueryExecutor->executeRayQuery(&queryResult,  
    309                 Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y)) 
    310         { 
    311                 mCullCamera->setPosition(mCullCamera->getPosition().x, queryResult.y + 10,  
    312                         mCullCamera->getPosition().z); 
    313         } 
    314  
    315         return ExampleFrameListener::frameStarted(evt); 
    316311} 
    317312//----------------------------------------------------------------------- 
     
    332327        KEY_PRESSED(KC_C, 0.3, toggleUseCulling()); 
    333328        KEY_PRESSED(KC_V, 0.3, toggleCullCamera()); 
    334         KEY_PRESSED(KC_X, 0.3, fixCullCamera()); 
     329        KEY_PRESSED(KC_X, 0.3, FixVizCamera()); 
    335330 
    336331        updateStats(); 
     332        //if(mWindow->getViewport(1))   mWindow->getViewport(1)->update(); 
    337333 
    338334    return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);         
     
    420416{ 
    421417        mUseCullCamera = !mUseCullCamera; 
     418 
     419        if(mUseCullCamera) 
     420        {        
     421                mWindow->addViewport(mVisualizationCamera, 10, 0.5, 0.5, 1, 1); 
     422                mWindow->getViewport(1)->setClearEveryFrame(true); 
     423        } 
     424        else 
     425                mWindow->removeViewport(10); 
     426 
    422427        mSceneMgr->setOption("CullCamera", &mUseCullCamera); 
    423428} 
    424429//----------------------------------------------------------------------- 
    425 void MouseQueryListener::fixCullCamera() 
    426 { 
    427         mCullCamera->setPosition(mCamera->getPosition()); 
    428         mCullCamera->setOrientation(mCamera->getOrientation()); 
     430void MouseQueryListener::FixVizCamera() 
     431{ 
     432        mVisualizationCamera->setPosition(mCamera->getPosition()); 
     433        mVisualizationCamera->setOrientation(mCamera->getOrientation()); 
     434        clamp2Terrain(mVisualizationCamera); 
    429435} 
    430436 
  • trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h

    r93 r94  
    3030 
    3131    MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager,  
    32                 CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *cullCamera); 
     32                CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera); 
    3333 
    3434    ~MouseQueryListener(); 
     
    6767        void toggleUseCulling(); 
    6868        void toggleCullCamera(); 
    69         void fixCullCamera(); 
     69        void FixVizCamera(); 
    7070 
    7171protected: 
     72        void clamp2Terrain(Camera *cam); 
     73 
    7274    bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down 
    7375    SceneManager *mSceneMgr;           // A pointer to the scene manager 
     
    101103        bool mUseCullCamera; 
    102104 
    103         Camera *mCullCamera; 
     105        Camera *mVisualizationCamera; 
    104106}; 
    105107 
     
    127129        TerrainContentGenerator *mTerrainContentGenerator; 
    128130 
    129         Camera *mCullCamera; 
     131        Camera *mVisualizationCamera; 
    130132         
    131133private: 
Note: See TracChangeset for help on using the changeset viewer.