Ignore:
Timestamp:
05/30/05 03:20:23 (19 years ago)
Author:
mattausch
Message:

added depth pass algorithm + delayed transparent object rendering (so depth ordering is right)

Location:
trunk/VUT/work/TestCullingTerrain
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/work/TestCullingTerrain/TestCullingTerrain.vcproj

    r107 r115  
    3434                        <Tool 
    3535                                Name="VCLinkerTool" 
    36                                 AdditionalDependencies="Plugin_OctreeSceneManager.lib OGREMain_d.LIB CEGUIBase_d.lib OgreGUIRenderer_d.lib Plugin_DotSceneManager.lib" 
     36                                AdditionalDependencies="Plugin_OctreeSceneManager.lib Plugin_VisibilitySceneManager.lib OGREMain_d.LIB CEGUIBase_d.lib OgreGUIRenderer_d.lib Plugin_DotSceneManager.lib" 
    3737                                OutputFile="$(OGRE_PATH)/Samples/Common/bin/Debug/TestCullingTerrain.exe" 
    3838                                LinkIncremental="2" 
    39                                 AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\Dependencies\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;" 
     39                                AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\Dependencies\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_ADDONS_PATH)\dotsceneoctree\PlugIns\DotSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(GAMETOOLS_PATH)\trunk\VUT\Ogre\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\Lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;" 
    4040                                GenerateDebugInformation="TRUE" 
    4141                                ProgramDatabaseFile="$(OutDir)/TestCullingTerrain.pdb" 
     
    122122                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> 
    123123                        <File 
     124                                RelativePath=".\TerrainMouseQueryListener.cpp"> 
     125                        </File> 
     126                        <File 
    124127                                RelativePath=".\TestCullingTerrainApplication.cpp"> 
    125128                        </File> 
     
    130133                        UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> 
    131134                        <File 
     135                                RelativePath=".\TerrainMouseQueryListener.h"> 
     136                        </File> 
     137                        <File 
    132138                                RelativePath=".\TestCullingTerrainApplication.h"> 
    133139                        </File> 
  • trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp

    r114 r115  
    1 /** 
    2     \file  
    3         TestCullingTerrainApplication.cpp 
    4     \brief 
    5         Tests the visibility culling algorithm 
    6 */ 
    7  
    81#include <OgreNoMemoryMacros.h> 
    92#include <CEGUI/CEGUI.h> 
     
    147 
    158#include <Ogre.h> 
    16 #include "OgreReferenceAppLayer.h" 
     9//#include "OgreReferenceAppLayer.h" 
    1710//#include "OgreRefAppWorld.h" 
    1811#include "TestCullingTerrainApplication.h" 
    1912 
     13 
    2014#define WIN32_LEAN_AND_MEAN 
    2115#include <windows.h> 
    22  
    23 #define VIZ_VIEWPORT_Z_ORDER 10 
    24  
    25 const char* frame_outfile = "frame.out"; 
    26 const char* objects_outfile = "objects.out"; 
    2716 
    2817/*******************************************************/ 
     
    201190void TestCullingTerrainApplication::createFrameListener() 
    202191{ 
    203         mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr,  
     192        mTerrainFrameListener = new TerrainMouseQueryListener(mWindow, mCamera, mSceneMgr,  
    204193                mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode); 
    205         mFrameListener->showDebugOverlay(true); 
    206         mRoot->addFrameListener(mFrameListener); 
     194        mTerrainFrameListener->showDebugOverlay(true); 
     195        mRoot->addFrameListener(mTerrainFrameListener); 
    207196} 
    208197//----------------------------------------------------------------------- 
     
    211200        mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE); 
    212201} 
    213 /***********************************************/ 
    214 /*      MouseQueryListener implementation      */ 
    215 /***********************************************/ 
    216 //----------------------------------------------------------------------- 
    217 MouseQueryListener::MouseQueryListener(RenderWindow* win, Camera* cam,  
    218                                                                            SceneManager *sceneManager,  
    219                                                                            CEGUI::Renderer *renderer, 
    220                                                                            TerrainContentGenerator *sceneGenerator, 
    221                                                                            Camera *vizCamera, 
    222                                                                            SceneNode *camNode):  
    223 ExampleFrameListener(win, cam, false, true),  
    224 mGUIRenderer(renderer),  
    225 mShutdownRequested(false),  
    226 mLMouseDown(false), 
    227 mRMouseDown(false), 
    228 mSceneMgr(sceneManager), 
    229 mCurrentObject(NULL), 
    230 mTerrainContentGenerator(sceneGenerator), 
    231 mVisibilityThreshold(0), 
    232 mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING), 
    233 mShowOctree(false), 
    234 mUseVisibilityCulling(true), 
    235 mUseOptimization(true), 
    236 mVizCamera(vizCamera), 
    237 mShowVisualization(false), 
    238 mNodeVizMode(NODEVIZ_NONE), 
    239 mVizCameraHeight(Real(2500.0)), 
    240 mCamNode(camNode), 
    241 mCullCamera(false), 
    242 mAppState(WALKTHROUGH), 
    243 mCurrentFrame(0), 
    244 mRecord(false), 
    245 mTimeElapsed(0), 
    246 mUseShadows(false), 
    247 mVisualizeCulledNodes(false) 
    248 { 
    249         // Reduce move speed 
    250         mMoveSpeed = 50; 
    251         mRotateSpeed *= 2; 
    252      
    253         // Register this so that we get mouse events. 
    254         mEventProcessor->addMouseListener(this); 
    255         mEventProcessor->addMouseMotionListener(this); 
    256         mEventProcessor->addKeyListener(this); 
    257  
    258         mRayQueryExecutor = new RayQueryExecutor(mSceneMgr); 
    259          
    260         // show overlay 
    261         Overlay* pOver = OverlayManager::getSingleton().getByName("Example/VisibilityDemoOverlay");  
    262  
    263         mAlgorithmInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/AlgorithmInfo"); 
    264         mThresholdInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ThresholdInfo"); 
    265          
    266         mFrustumCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/FrustumCulledNodesInfo"); 
    267         mQueryCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueryCulledNodesInfo"); 
    268     mTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/TraversedNodesInfo"); 
    269         mHierarchyNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/HierarchyNodesInfo"); 
    270         mRenderedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/RenderedNodesInfo"); 
    271         mObjectsInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ObjectsInfo"); 
    272         mUseOptimizationInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/UseOptimizationInfo"); 
    273         mQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueriesIssuedInfo"); 
    274          
    275         mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]); 
    276         mThresholdInfo->setCaption(": 0"); 
    277         mFrustumCulledNodesInfo->setCaption(": 0"); 
    278         mQueryCulledNodesInfo->setCaption(": 0"); 
    279         mTraversedNodesInfo->setCaption(": 0"); 
    280         mHierarchyNodesInfo->setCaption(": 0"); 
    281         mRenderedNodesInfo->setCaption(": 0"); 
    282         mObjectsInfo->setCaption(": 0"); 
    283         mUseOptimizationInfo->setCaption(": true"); 
    284         mQueriesIssuedInfo->setCaption(": 0"); 
    285  
    286         setAlgorithm(mCurrentAlgorithm); 
    287  
    288         mSceneMgr->setOption("UseOptimization", &mUseOptimization); 
    289         mSceneMgr->setOption("UseVisibilityCulling", &mUseVisibilityCulling); 
    290         mSceneMgr->setOption("ShowOctree", &mShowOctree); 
    291         mSceneMgr->setOption("CullCamera", &mCullCamera); 
    292         mSceneMgr->setOption("ShowVisualization", &mShowVisualization); 
    293          
    294         pOver->show(); 
    295 }  
    296 //----------------------------------------------------------------------- 
    297 MouseQueryListener::~MouseQueryListener() 
    298 { 
    299         delete mRayQueryExecutor; 
    300 } 
    301 //----------------------------------------------------------------------- 
    302 void MouseQueryListener::mouseMoved(MouseEvent *e) 
    303 { 
    304         // Update CEGUI with the mouse motion 
    305     CEGUI::System::getSingleton().injectMouseMove(e->getRelX() *  
    306                 mGUIRenderer->getWidth(), e->getRelY() * mGUIRenderer->getHeight()); 
    307 } 
    308 //----------------------------------------------------------------------- 
    309 void MouseQueryListener::mousePressed(MouseEvent* e) 
    310 { 
    311      // Left mouse button down 
    312      if (e->getButtonID() & InputEvent::BUTTON0_MASK) 
    313      { 
    314                  CEGUI::MouseCursor::getSingleton().hide(); 
    315  
    316                  // Setup the ray scene query 
    317          Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY()); 
    318     
    319                  Vector3 queryResult; 
    320                   
    321                  // Get results, create a node/entity on the position 
    322                  mCurrentObject = mTerrainContentGenerator->GenerateSceneObject( 
    323                          mouseRay.getOrigin(), Vector3(0,0,0), "robot"); 
    324                  
    325          mLMouseDown = true;  
    326      } 
    327      // Right mouse button down 
    328      else if (e->getButtonID() & InputEvent::BUTTON1_MASK) 
    329      { 
    330          CEGUI::MouseCursor::getSingleton().hide(); 
    331          mRMouseDown = true; 
    332      } 
    333 } // mousePressed 
    334 //----------------------------------------------------------------------- 
    335 void MouseQueryListener::mouseReleased(MouseEvent* e) 
    336 { 
    337     // Left mouse button up 
    338     if (e->getButtonID() & InputEvent::BUTTON0_MASK) 
    339     { 
    340                 CEGUI::MouseCursor::getSingleton().show(); 
    341         mLMouseDown = false; 
    342     } 
    343     // Right mouse button up 
    344     else if (e->getButtonID() & InputEvent::BUTTON1_MASK) 
    345     { 
    346         CEGUI::MouseCursor::getSingleton().show(); 
    347         mRMouseDown = false; 
    348     } 
    349 }  
    350 //----------------------------------------------------------------------- 
    351 void MouseQueryListener::mouseDragged(MouseEvent *e) 
    352  { 
    353          // If we are dragging the left mouse button.             
    354          if (mLMouseDown) 
    355      { 
    356                  Vector3 queryResult; 
    357                  Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY()); 
    358  
    359                  if (mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay)) 
    360                  { 
    361                          if (mCurrentObject) 
    362                          { 
    363                                  mCurrentObject->setPosition(queryResult); 
    364                          } 
    365                  } 
    366      } 
    367          // If we are dragging the right mouse button. 
    368          if (mRMouseDown) 
    369          { 
    370                  //mCamera->yaw(-e->getRelX() * mRotateSpeed); 
    371                  //mCamera->pitch(-e->getRelY() * mRotateSpeed); 
    372                  mCamNode->yaw(-e->getRelX() * mRotateSpeed); 
    373                  mCamNode->pitch(-e->getRelY() * mRotateSpeed); 
    374          } 
    375 } 
    376 //----------------------------------------------------------------------- 
    377 bool MouseQueryListener::frameStarted(const FrameEvent &evt) 
    378 { 
    379         switch (mAppState) 
    380         { 
    381         case REPLAY: 
    382                 setCurrentFrameInfo(evt.timeSinceLastFrame); 
    383                 break; 
    384         case WALKTHROUGH: 
    385                 if (mRecord) 
    386                 { 
    387                         addFrameInfo(mCamNode, evt.timeSinceLastFrame); 
    388                         // print recording message 
    389                         mWindow->setDebugText("Recording frame " +  
    390                                 StringConverter::toString(mFrameInfo.size() - 1)); 
    391                 }        
    392          
    393                 Clamp2Terrain(); 
    394                 break; 
    395         default: 
    396                 break; 
    397         };       
    398          
    399         if (mShowVisualization) 
    400         { 
    401                 // important for visualization => draw octree bounding boxes 
    402                 mSceneMgr->setOption("ShowOctree", &mShowVisualization); 
    403                 // also render nodew content? 
    404                 //mSceneMgr->setOption("RenderNodesForViz", &mRenderNodesForViz); 
    405  
    406                 // -- setup visualization camera 
    407                 mVizCamera->setPosition(0, 0, 0); 
    408                 mVizCamera->setOrientation(Quaternion::IDENTITY); 
    409  
    410                 Vector3 camPos = mCamNode->getPosition(); 
    411                 mVizCamera->setPosition(camPos.x, mVizCameraHeight, camPos.z); 
    412  
    413                 // point down -Z axis 
    414                 mVizCamera->pitch(Radian(Degree(270.0))); 
    415          
    416                 // rotation arounnd X axis 
    417                 mVizCamera->yaw(Math::ATan2(-mCamera->getDerivedDirection().x,  
    418                         -mCamera->getDerivedDirection().z)); 
    419                  
    420                 // move by a constant so view plane is on bottom of viewport 
    421                 mVizCamera->moveRelative(Vector3(0, 800, 0)); 
    422         } 
    423  
    424         return ExampleFrameListener::frameStarted(evt); 
    425 } 
    426 //----------------------------------------------------------------------- 
    427 void MouseQueryListener::Clamp2Terrain() 
    428 { 
    429         // clamp to terrain 
    430         Vector3 camPos = mCamNode->getPosition(); 
    431         Vector3 queryResult; 
    432  
    433         if (mRayQueryExecutor->executeRayQuery(&queryResult,  
    434                         Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y)) 
    435         { 
    436                 mCamNode->setPosition(camPos.x, queryResult.y + 10, camPos.z); 
    437         } 
    438 } 
    439 //----------------------------------------------------------------------- 
    440 bool MouseQueryListener::frameEnded(const FrameEvent& evt) 
    441 { 
    442         if (mShutdownRequested) 
    443                 return false; 
    444  
    445     if (timeDelay >= 0)  
    446         timeDelay -= evt.timeSinceLastFrame; 
    447  
    448         KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm()); 
    449  
    450         KEY_PRESSED(KC_O, 0.3, toggleUseOptimization()); 
    451         KEY_PRESSED(KC_T, 0.3, toggleShowOctree()); 
    452         KEY_PRESSED(KC_C, 0.3, toggleUseVisibilityCulling()); 
    453         KEY_PRESSED(KC_1, 0.3, toggleShowViz()); 
    454         KEY_PRESSED(KC_2, 0.3, nextNodeVizMode()); 
    455          
    456         KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10)); 
    457         KEY_PRESSED(KC_ADD, 0, changeThreshold(10)); 
    458          
    459         KEY_PRESSED(KC_4, 0, zoomVizCamera(50)); 
    460         KEY_PRESSED(KC_5, 0, zoomVizCamera(-50)); 
    461  
    462         KEY_PRESSED(KC_F1, 0.3, nextAppState()); 
    463         KEY_PRESSED(KC_F2, 0.3, toggleRecord()); 
    464         KEY_PRESSED(KC_F3, 0.3, mTerrainContentGenerator->WriteObjects(objects_outfile)); 
    465         KEY_PRESSED(KC_F4, 0.3, toggleUseShadows()); 
    466         //KEY_PRESSED(KC_F3, 0.3, writeFrames()); 
    467         //KEY_PRESSED(KC_F4, 0.3, loadFrames()); 
    468  
    469         updateStats(); 
    470  
    471         //return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt); 
    472         return ExampleFrameListener::frameEnded(evt); 
    473 } 
    474 //----------------------------------------------------------------------- 
    475 void MouseQueryListener::moveCamera() 
    476 { 
    477         mCamNode->yaw(mRotX); 
    478         mCamNode->pitch(mRotY); 
    479         mCamNode->translate(mCamNode->getLocalAxes(), mTranslateVector); 
    480 } 
    481 //----------------------------------------------------------------------- 
    482 void MouseQueryListener::writeFrames() 
    483 { 
    484         std::ofstream ofstr(frame_outfile); 
    485          
    486         std::vector<frame_info>::const_iterator it, it_end; 
    487  
    488         it_end = mFrameInfo.end(); 
    489         for(it = mFrameInfo.begin(); it < it_end; ++it) 
    490         { 
    491                 ofstr << StringConverter::toString((*it).position) << " "  
    492                         << StringConverter::toString((*it).orientation) << " " 
    493                         << StringConverter::toString((*it).timeElapsed) << "\n"; 
    494         } 
    495         ofstr.close(); 
    496 } 
    497 //----------------------------------------------------------------------- 
    498 void MouseQueryListener::loadFrames() 
    499 { 
    500         std::ifstream ifstr(frame_outfile); 
    501         char line[256]; 
    502         frame_info info; 
    503  
    504         // reset current values 
    505         mFrameInfo.clear(); 
    506         mCurrentFrame = 0; 
    507          
    508         while (!ifstr.eof())  
    509         { 
    510                 ifstr.getline(line, 256); 
    511                 sscanf(line, "%f %f %f %f %f %f %f %f", &info.position.x, &info.position.y, &info.position.z, 
    512                                 &info.orientation.w, &info.orientation.x, &info.orientation.y, &info.orientation.z, 
    513                                 &info.timeElapsed); 
    514                  
    515                 mFrameInfo.push_back(info); 
    516                  
    517                 /* 
    518                 std::stringstream d; 
    519                 d << StringConverter::toString(info.position) << " " << StringConverter::toString(info.orientation); 
    520                 LogManager::getSingleton().logMessage(d.str()); 
    521                 */ 
    522         } 
    523         ifstr.close(); 
    524 } 
    525 //----------------------------------------------------------------------- 
    526 void MouseQueryListener::setAppState(int state) 
    527 { 
    528         mAppState = state; 
    529 } 
    530 //----------------------------------------------------------------------- 
    531 void MouseQueryListener::nextAppState() 
    532 { 
    533         mCurrentFrame = 0; 
    534  
    535         // if last state was replay state 
    536         if (mAppState == REPLAY) 
    537         { 
    538                 // reset debug text and write frame info to file 
    539                 mWindow->setDebugText(""); 
    540                 writeFrames(); 
    541                  
    542                 //-- write out stats 
    543                 std::stringstream d; 
    544                 d << "Algorithm: " << mCurrentAlgorithmCaptions[mCurrentAlgorithm] << "\n" 
    545                   << "avg. FPS: " << mWindow->getAverageFPS() << "\n" 
    546                   << "best FPS: " << mWindow->getBestFPS() << "\n" 
    547                   << "worst FPS: " << mWindow->getWorstFPS() << "\n" 
    548                   << "best frame time: " <<     mWindow->getBestFrameTime() << "\n" 
    549                   << "worst frame time: " << mWindow->getWorstFrameTime(); 
    550                  
    551                 LogManager::getSingleton().logMessage(d.str()); 
    552         } 
    553          
    554         //-- set the next státe 
    555         mAppState = (mAppState + 1) % STATE_NUM; 
    556  
    557         // replay recorded walkthrough 
    558         if (mAppState == REPLAY) 
    559         { 
    560                 // no recording during replay 
    561                 mRecord = false; 
    562  
    563                 // load recorded walkthrough 
    564                 if (mFrameInfo.size() == 0) 
    565                 { 
    566                         loadFrames(); 
    567                 } 
    568  
    569                 // if there are no recorded frames => set next state 
    570                 if (mFrameInfo.size() == 0)  
    571                 { 
    572                         nextAppState(); 
    573                 } 
    574                 else 
    575                 { 
    576                         mWindow->setDebugText("Replay"); 
    577                          
    578                         // reset, because we measure fps stats during walkthrough 
    579                         mWindow->resetStatistics(); 
    580  
    581                         //-- initialise frame data 
    582                         mTimeElapsed = 0; 
    583  
    584                         mCamNode->setPosition(mFrameInfo[0].position); 
    585                         mCamNode->setOrientation(mFrameInfo[0].orientation); 
    586                 } 
    587         } 
    588  
    589 } 
    590 //----------------------------------------------------------------------- 
    591 void MouseQueryListener::toggleRecord() 
    592 { 
    593         mRecord = !mRecord; 
    594  
    595         // clear previous camera path 
    596         if (mRecord) 
    597                 mFrameInfo.clear(); 
    598         else 
    599                 mWindow->setDebugText(""); 
    600 } 
    601 //----------------------------------------------------------------------- 
    602 void MouseQueryListener::changeThreshold(int incr) 
    603 { 
    604         mVisibilityThreshold += incr;  
    605         if(mVisibilityThreshold < 0) mVisibilityThreshold = 0; 
    606          
    607         char str[100]; sprintf(str,": %d", mVisibilityThreshold); 
    608  
    609         mSceneMgr->setOption("Threshold", &mVisibilityThreshold);  
    610         mThresholdInfo->setCaption(str); 
    611 } 
    612 //----------------------------------------------------------------------- 
    613 bool MouseQueryListener::processUnbufferedKeyInput(const FrameEvent& evt) 
    614 {     
    615         if (mInputDevice->isKeyDown(KC_RIGHT)) 
    616         { 
    617                 mCamNode->yaw(-mRotScale); 
    618                 return true; 
    619         } 
    620         if (mInputDevice->isKeyDown(KC_LEFT)) 
    621         { 
    622                 mCamNode->yaw(mRotScale); 
    623                 return true; 
    624         } 
    625  
    626         return ExampleFrameListener::processUnbufferedKeyInput(evt); 
    627 } 
    628 //----------------------------------------------------------------------- 
    629 void MouseQueryListener::zoomVizCamera(int zoom) 
    630 { 
    631         mVizCameraHeight += zoom;  
    632         if(mVizCameraHeight < 0) mVizCameraHeight = 0; 
    633 } 
    634 //----------------------------------------------------------------------- 
    635 void MouseQueryListener::nextAlgorithm() 
    636 { 
    637         mCurrentAlgorithm = (mCurrentAlgorithm + 1) %  
    638                 GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS, 
    639  
    640         setAlgorithm(mCurrentAlgorithm); 
    641 } 
    642 //----------------------------------------------------------------------- 
    643 void MouseQueryListener::setAlgorithm(int algorithm) 
    644 { 
    645         mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]); 
    646         mSceneMgr->setOption("Algorithm", &mCurrentAlgorithm); 
    647 } 
    648 //----------------------------------------------------------------------- 
    649 void MouseQueryListener::updateStats() 
    650 { 
    651         unsigned int opt = 0; 
    652         char str[100]; 
    653          
    654         mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,": %d", opt);  
    655         mFrustumCulledNodesInfo->setCaption(str); 
    656          
    657         mSceneMgr->getOption("NumQueriesIssued", &opt); sprintf(str,": %d", opt);  
    658         mQueriesIssuedInfo->setCaption(str); 
    659          
    660         mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,": %d", opt);  
    661         mQueryCulledNodesInfo->setCaption(str); 
    662          
    663         mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,": %d", opt);  
    664         mTraversedNodesInfo->setCaption(str); 
    665  
    666         mSceneMgr->getOption("NumHierarchyNodes", &opt); sprintf(str,": %d", opt);  
    667         mHierarchyNodesInfo->setCaption(str); 
    668  
    669         mSceneMgr->getOption("NumRenderedNodes", &opt); sprintf(str,": %d", opt);  
    670         mRenderedNodesInfo->setCaption(str); 
    671  
    672         sprintf(str,": %d", mTerrainContentGenerator->GetObjectCount());  
    673         mObjectsInfo->setCaption(str); 
    674 } 
    675 //----------------------------------------------------------------------- 
    676 void MouseQueryListener::toggleUseOptimization() 
    677 { 
    678         mUseOptimization = !mUseOptimization; 
    679  
    680         mSceneMgr->setOption("UseOptimization", &mUseOptimization); 
    681  
    682         if (mUseOptimization) 
    683                 mUseOptimizationInfo->setCaption(": true"); 
    684         else 
    685                 mUseOptimizationInfo->setCaption(": false"); 
    686 } 
    687 //----------------------------------------------------------------------- 
    688 void MouseQueryListener::toggleShowOctree() 
    689 { 
    690         mShowOctree = !mShowOctree; 
    691  
    692         mSceneMgr->setOption("ShowOctree", &mShowOctree); 
    693 } 
    694 //----------------------------------------------------------------------- 
    695 void MouseQueryListener::toggleUseVisibilityCulling() 
    696 { 
    697         mUseVisibilityCulling = !mUseVisibilityCulling; 
    698  
    699         mSceneMgr->setOption("UseVisibilityCulling", &mUseVisibilityCulling); 
    700 } 
    701 //----------------------------------------------------------------------- 
    702 void MouseQueryListener::toggleShowViz() 
    703 { 
    704         mShowVisualization = !mShowVisualization; 
    705         mVisualizeCulledNodes = !mVisualizeCulledNodes; 
    706  
    707         // create viewport with priority VIZ_VIEWPORT_Z_ORDER:  
    708         // will be rendered over standard viewport 
    709         if (mShowVisualization) 
    710         {        
    711                 Viewport *vizvp = mWindow->addViewport(mVizCamera,  
    712                         VIZ_VIEWPORT_Z_ORDER, 0.6, 0.6, 0.4, 0.4);  
    713                                  
    714                 vizvp->setBackgroundColour(ColourValue(0.0, 0.3, 0.2, 1)); 
    715  
    716                 vizvp->setOverlaysEnabled(false); 
    717                 // Alter the camera aspect ratio to match the viewport 
    718         mVizCamera->setAspectRatio(Real(vizvp->getActualWidth()) /  
    719                         Real(vizvp->getActualHeight())); 
    720                  
    721                 mSceneMgr->setOption("VisualizeCulledNodes", &mVisualizeCulledNodes); 
    722                 //vizvp->setClearEveryFrame(false); 
    723  
    724                 // Create a skyplane (for visualization background) 
    725                 /* 
    726                 Plane plane; 
    727                 plane.d = -1000; 
    728                 plane.normal = Vector3::UNIT_Y; 
    729                 mSceneMgr->setSkyPlane(true, plane, "Examples/TransparentTest", 4000, 75, false); 
    730                 */ 
    731                  
    732         } 
    733         else 
    734         { 
    735                 mWindow->removeViewport(VIZ_VIEWPORT_Z_ORDER); 
    736                 // if octree was enabled for visualization purpose, reset now 
    737                 mSceneMgr->setOption("ShowOctree", &mShowOctree); 
    738         } 
    739 } 
    740 //----------------------------------------------------------------------- 
    741 void MouseQueryListener::toggleUseShadows() 
    742 { 
    743         mUseShadows = !mUseShadows; 
    744  
    745         //mSunLight->setCastShadows(mUseShadows); 
    746  
    747         if (mUseShadows) 
    748         { 
    749                 mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE); 
    750         } 
    751         else 
    752         { 
    753                 mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); 
    754         } 
    755  
    756 } 
    757 //----------------------------------------------------------------------- 
    758 void MouseQueryListener::nextNodeVizMode() 
    759 { 
    760         mNodeVizMode = (mNodeVizMode + 1) % NODEVIZ_MODES_NUM; 
    761  
    762         //bool renderNodesForViz = (mNodeVizMode == NODEVIZ_RENDER_NODES) || (mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT); 
    763         bool renderNodesContentForViz = mNodeVizMode == NODEVIZ_RENDER_GEOMETRY; 
    764  
    765         //mSceneMgr->setOption("RenderNodesForViz", &renderNodesForViz); 
    766         mSceneMgr->setOption("RenderNodesContentForViz", &renderNodesContentForViz); 
    767 } 
    768 //----------------------------------------------------------------------- 
    769 void MouseQueryListener::keyPressed(KeyEvent* e) 
    770 { 
    771         if(e->getKey() == KC_ESCAPE) 
    772     { 
    773                 mShutdownRequested = true; 
    774                 e->consume(); 
    775                 return; 
    776         } 
    777  
    778         CEGUI::System::getSingleton().injectKeyDown(e->getKey()); 
    779         CEGUI::System::getSingleton().injectChar(e->getKeyChar()); 
    780         e->consume(); 
    781 } 
    782 //----------------------------------------------------------------------- 
    783 void MouseQueryListener::keyReleased(KeyEvent* e) 
    784 { 
    785         CEGUI::System::getSingleton().injectKeyUp(e->getKey()); 
    786         e->consume(); 
    787 } 
    788 //----------------------------------------------------------------------- 
    789 void MouseQueryListener::keyClicked(KeyEvent* e)  
    790 { 
    791         // Do nothing 
    792         e->consume(); 
    793 } 
    794 //----------------------------------------------------------------------- 
    795 void MouseQueryListener::addFrameInfo(SceneNode *camNode, Real timeElapsed) 
    796 { 
    797         frame_info info; 
    798         info.orientation = mCamNode->getOrientation(); 
    799         info.position = mCamNode->getPosition(); 
    800         info.timeElapsed = timeElapsed; 
    801  
    802         mFrameInfo.push_back(info); 
    803 } 
    804 //----------------------------------------------------------------------- 
    805 void MouseQueryListener::setCurrentFrameInfo(Real timeElapsed) 
    806 { 
    807         //-- find current frame relative to elapsed frame time           
    808         mTimeElapsed -= timeElapsed; 
    809  
    810         while ((mTimeElapsed <= 0) && (mCurrentFrame < (int)mFrameInfo.size() - 1)) 
    811         { 
    812                 mTimeElapsed += mFrameInfo[mCurrentFrame ++].timeElapsed; 
    813         } 
    814  
    815         frame_info new_frame = mFrameInfo[mCurrentFrame]; 
    816         frame_info old_frame = mFrameInfo[mCurrentFrame - 1]; 
    817                  
    818         //-- interpolate frames 
    819         Real factor = 1; 
    820  
    821         if (old_frame.timeElapsed > 0) 
    822                 factor = mTimeElapsed / old_frame.timeElapsed; 
    823  
    824         Vector3 camPos = old_frame.position + factor * (new_frame.position - old_frame.position); 
    825         Quaternion camOrienation = Quaternion::Slerp(factor, old_frame.orientation,  
    826                 new_frame.orientation, true); 
    827  
    828         mCamNode->setPosition(camPos); 
    829         mCamNode->setOrientation(camOrienation); 
    830          
    831         // stop replay after a full walkthrough 
    832         if (mCurrentFrame == (int)mFrameInfo.size() - 1) 
    833         { 
    834                 nextAppState(); 
    835         } 
    836 } 
     202 
    837203 
    838204/**************************************************************/ 
  • trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h

    r114 r115  
    1 /** 
    2     \file  
    3         TestCullingTerrainApplication.h 
    4 */ 
     1#ifndef _TestCullingTerrainApplication_H__ 
     2#define _TestCullingTerrainApplication_H__ 
     3 
    54#include "CEGUIForwardRefs.h" 
    65#include "ExampleApplication.h" 
    76#include "OgreTerrainContentGenerator.h" 
    8 #include "VisibilityEnvironment.h" 
     7 
    98#include <OgreRenderTargetListener.h> 
    10 #include <vector> 
    11  
    12 Real timeDelay = 0; 
    13 #define KEY_PRESSED(_key,_timeDelay, _macro) \ 
    14 { \ 
    15     if (mInputDevice->isKeyDown(_key) && timeDelay <= 0) \ 
    16 { \ 
    17     timeDelay = _timeDelay; \ 
    18     _macro ; \ 
    19 } \ 
    20 } 
    21  
    22 String mCurrentAlgorithmCaptions[GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS] =  
    23 { 
    24     "View Frustum Culling",  
    25         "Stop and Wait Culling",  
    26         "Coherent Hierarchical Culling" 
    27 }; 
    28  
    29 /** The information about camera position and orienation per frame */ 
    30 typedef struct 
    31 { 
    32         Vector3 position; 
    33         Quaternion orientation; 
    34         Real timeElapsed; 
    35 } frame_info; 
    36  
     9#include "TerrainMouseQueryListener.h" 
    3710 
    3811class VisualizationRenderTargetListener: public RenderTargetListener 
     
    4619 
    4720        SceneManager *mSceneMgr; 
    48 }; 
    49  
    50 class MouseQueryListener : public ExampleFrameListener, public MouseListener, public MouseMotionListener 
    51 { 
    52 public: 
    53          
    54     MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager,  
    55                 CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera, 
    56                 SceneNode *camNode); 
    57  
    58     ~MouseQueryListener(); 
    59  
    60         bool frameStarted(const FrameEvent& evt); 
    61         bool frameEnded(const FrameEvent& evt); 
    62         bool processUnbufferedKeyInput(const FrameEvent& evt); 
    63      
    64  
    65     /* MouseListener callbacks. */ 
    66     virtual void mouseClicked(MouseEvent* e) { } 
    67     virtual void mouseEntered(MouseEvent* e) { } 
    68     virtual void mouseExited(MouseEvent* e)  { } 
    69  
    70     // This is when the mouse button goes DOWN. 
    71     virtual void mousePressed(MouseEvent* e); 
    72  
    73     // This is when the mouse button is let UP. 
    74     virtual void mouseReleased(MouseEvent* e); 
    75  
    76     /* MouseMotionListener callbacks */ 
    77     virtual void mouseMoved (MouseEvent *e); 
    78     
    79     // This is when the mouse is clicked, held and dragged. 
    80     virtual void mouseDragged (MouseEvent *e); 
    81  
    82     void keyPressed(KeyEvent* e); 
    83  
    84         void keyReleased(KeyEvent* e); 
    85         void keyClicked(KeyEvent* e); 
    86  
    87         enum  {WALKTHROUGH, REPLAY, STATE_NUM}; 
    88  
    89         // visualization modes for scene nodes 
    90         //enum {NODEVIZ_NONE, NODEVIZ_RENDER_NODES,  
    91         //        NODEVIZ_RENDER_NODES_AND_CONTENT, NODEVIZ_MODES_NUM}; 
    92         enum {NODEVIZ_NONE, NODEVIZ_RENDER_GEOMETRY, NODEVIZ_MODES_NUM}; 
    93  
    94         void nextAlgorithm(); 
    95         void changeThreshold(int incr); 
    96         void updateStats(); 
    97  
    98         void toggleUseOptimization(); 
    99         void toggleShowOctree(); 
    100         void toggleUseVisibilityCulling(); 
    101         void toggleShowViz(); 
    102         void nextNodeVizMode(); 
    103         void toggleRecord(); 
    104  
    105         void zoomVizCamera(int zoom); 
    106          
    107         void addFrameInfo(SceneNode *camNode, Real timeElapsed); 
    108         void setCurrentFrameInfo(Real timeElapsed); 
    109  
    110         void setAppState(int state); 
    111         void nextAppState(); 
    112  
    113         void setAlgorithm(int algorithm); 
    114  
    115         void moveCamera(); 
    116          
    117         void writeFrames(); 
    118         void loadFrames(); 
    119  
    120         void toggleUseShadows(); 
    121  
    122 protected: 
    123         void Clamp2Terrain(); 
    124          
    125     bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down 
    126     SceneManager *mSceneMgr;           // A pointer to the scene manager 
    127      
    128         CEGUI::Renderer *mGUIRenderer;     // cegui renderer 
    129          
    130         bool mShutdownRequested; 
    131         int mCurrentAlgorithm; 
    132         int mVisibilityThreshold; 
    133          
    134         OverlayElement *mAlgorithmInfo; 
    135         OverlayElement *mThresholdInfo; 
    136         OverlayElement *mFrustumCulledNodesInfo; 
    137         OverlayElement *mQueryCulledNodesInfo; 
    138     OverlayElement *mTraversedNodesInfo; 
    139         OverlayElement *mHierarchyNodesInfo; 
    140         OverlayElement *mUseOptimizationInfo; 
    141         OverlayElement *mRenderedNodesInfo; 
    142         OverlayElement *mObjectsInfo; 
    143         OverlayElement *mQueriesIssuedInfo; 
    144  
    145         SceneNode *mCurrentObject;    // the newly created object 
    146         int mObjectCount;             // The number of objects on the screen 
    147  
    148         RayQueryExecutor *mRayQueryExecutor; 
    149         TerrainContentGenerator *mTerrainContentGenerator; 
    150  
    151         bool mUseOptimization; 
    152         bool mShowOctree; 
    153         bool mUseVisibilityCulling; 
    154         bool mShowVisualization; 
    155         int mNodeVizMode; 
    156         bool mCullCamera; 
    157  
    158         Real mVizCameraHeight; 
    159  
    160         Camera *mVizCamera; 
    161         SceneNode *mCamNode; 
    162          
    163         //std::deque<Vector3> mWalkList;   // The list of points we are walking to 
    164         std::vector<frame_info> mFrameInfo; 
    165                  
    166         int mCurrentFrame; 
    167         // the current application state 
    168         int mAppState; 
    169         bool mRecord; 
    170         Real mTimeElapsed; 
    171         bool mUseShadows; 
    172  
    173         bool mVisualizeCulledNodes; 
    17421}; 
    17522 
     
    20956        VisualizationRenderTargetListener *mRenderTargetListener; 
    21057 
     58        TerrainMouseQueryListener *mTerrainFrameListener; 
     59 
    21160private: 
    21261        void chooseSceneManager(void); 
    21362}; 
     63 
     64#endif // TestCullingTerrainApplication 
Note: See TracChangeset for help on using the changeset viewer.