Changeset 120 for trunk/VUT/work
- Timestamp:
- 06/06/05 18:55:02 (20 years ago)
- Location:
- trunk/VUT/work/TestCullingTerrain
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp
r115 r120 13 13 14 14 15 Real timeDelay = 0; 16 #define KEY_PRESSED(_key,_timeDelay, _macro) \ 15 #define KEY_PRESSED(_key, _timeDelay, _macro) \ 17 16 { \ 18 if (mInputDevice->isKeyDown(_key) && timeDelay <= 0) \17 if (mInputDevice->isKeyDown(_key) && mTimeDelay <= 0) \ 19 18 { \ 20 timeDelay = _timeDelay; \19 mTimeDelay = _timeDelay; \ 21 20 _macro ; \ 22 21 } \ … … 41 40 mCamera(cam), 42 41 mWindow(win), 43 mStatsOn(true),44 42 mNumScreenShots(0), 45 mTime UntilNextToggle(0),43 mTimeDelay(0), 46 44 mSceneDetailIndex(0), 47 45 mMoveScale(0.0f), … … 51 49 mFiltering(TFO_BILINEAR), 52 50 mGUIRenderer(renderer), 53 mShutdownRequested(false),54 mLMouseDown(false),55 mRMouseDown(false),56 51 mSceneMgr(sceneManager), 57 52 mCurrentObject(NULL), … … 60 55 mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING), 61 56 //mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::FRUSTUM_CULLING), 57 mNodeVizMode(NODEVIZ_NONE), 58 mVizCameraHeight(Real(2500.0)), 59 mCamNode(camNode), 60 mAppState(WALKTHROUGH), 61 mCurrentFrame(0), 62 mTimeElapsed(0), 63 mRotateSpeed(72), 64 mMoveSpeed(50), 65 mVizCamera(vizCamera), 66 mStatsOn(true), 67 mShutdownRequested(false), 68 mLMouseDown(false), 69 mRMouseDown(false), 62 70 mShowOctree(false), 63 71 mUseDepthPass(false), 64 72 mUseOptimization(true), 65 mVizCamera(vizCamera),66 73 mShowVisualization(false), 67 mNodeVizMode(NODEVIZ_NONE),68 mVizCameraHeight(Real(2500.0)),69 mCamNode(camNode),70 74 mCullCamera(false), 71 mAppState(WALKTHROUGH),72 mCurrentFrame(0),73 75 mRecord(false), 74 mTimeElapsed(0),75 76 mUseShadows(false), 76 mVisualizeCulledNodes(false), 77 mRotateSpeed(72), 78 mMoveSpeed(50) 79 { 80 mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); 81 82 mInputDevice = PlatformManager::getSingleton().createInputReader(); 77 mShowHelp(false), 78 mDisplayCameraDetails(false), 79 mVisualizeCulledNodes(false) 80 { 81 mInputDevice = PlatformManager::getSingleton().createInputReader(); 83 82 mInputDevice->initialise(win, true, true); 84 83 85 showDebugOverlay(true); 86 87 // Register this so that we get mouse events. 88 /*mEventProcessor->addMouseListener(this); 84 /* 85 mEventProcessor->addMouseListener(this); 89 86 mEventProcessor->addMouseMotionListener(this); 90 87 mEventProcessor->addKeyListener(this); … … 94 91 mRayQueryExecutor = new RayQueryExecutor(mSceneMgr); 95 92 96 //-- show visibility overlay 97 Overlay* pOver = OverlayManager::getSingleton().getByName("Example/VisibilityDemoOverlay"); 98 93 mHelpOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/HelpOverlay"); 94 mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); 95 96 97 //-- visibility culling stats overlay 98 mCullStatsOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/DemoOverlay"); 99 99 100 mAlgorithmInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/AlgorithmInfo"); 100 101 mThresholdInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ThresholdInfo"); … … 121 122 mUseDepthPassInfo->setCaption(": false"); 122 123 mQueriesIssuedInfo->setCaption(": 0"); 123 124 pOver->show(); 125 124 125 // show stats overlays 126 showStats(true); 127 //mHelpOverlay->show(); 126 128 127 129 // set culling algorithm type 128 130 setAlgorithm(mCurrentAlgorithm); 129 131 130 131 132 // set scene manager options 132 133 mSceneMgr->setOption("UseOptimization", &mUseOptimization); 133 bool delayedRendering = !mUseOptimization; 134 mSceneMgr->setOption("DelayRenderTransparents", &delayedRendering); 134 135 // apply delayed rendering (i.e., transparents after hierarchical culling pass) 136 // only if optimization is not used 137 bool delayRenderTransparents = !mUseOptimization; 138 139 mSceneMgr->setOption("DelayRenderTransparents", &delayRenderTransparents); 135 140 mSceneMgr->setOption("UseDepthPass", &mUseDepthPass); 141 136 142 mSceneMgr->setOption("ShowOctree", &mShowOctree); 137 143 mSceneMgr->setOption("CullCamera", &mCullCamera); … … 229 235 230 236 //-- setup what is needed for immediate mouse/key movement 231 if (mTime UntilNextToggle>= 0)232 mTime UntilNextToggle-= evt.timeSinceLastFrame;237 if (mTimeDelay >= 0) 238 mTimeDelay -= evt.timeSinceLastFrame; 233 239 234 240 // If this is the first frame, pick a speed … … 329 335 return false; 330 336 331 if (timeDelay >= 0) 332 timeDelay -= evt.timeSinceLastFrame; 333 334 KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm()); 335 336 KEY_PRESSED(KC_O, 0.3, toggleUseOptimization()); 337 KEY_PRESSED(KC_T, 0.3, toggleShowOctree()); 338 KEY_PRESSED(KC_X, 0.3, toggleUseDepthPass()); 339 KEY_PRESSED(KC_1, 0.3, toggleShowViz()); 340 KEY_PRESSED(KC_2, 0.3, nextNodeVizMode()); 341 342 KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10)); 343 KEY_PRESSED(KC_ADD, 0, changeThreshold(10)); 344 345 KEY_PRESSED(KC_4, 0, zoomVizCamera(50)); 346 KEY_PRESSED(KC_5, 0, zoomVizCamera(-50)); 347 348 KEY_PRESSED(KC_F1, 0.3, nextAppState()); 349 KEY_PRESSED(KC_F2, 0.3, toggleRecord()); 350 KEY_PRESSED(KC_F3, 0.3, mTerrainContentGenerator->WriteObjects(objects_out_filename)); 351 KEY_PRESSED(KC_F4, 0.3, toggleUseShadows()); 352 //KEY_PRESSED(KC_F3, 0.3, writeFrames()); 353 //KEY_PRESSED(KC_F4, 0.3, loadFrames()); 354 355 updateStats(); 337 updateStats(); 356 338 357 339 return true; … … 408 390 } 409 391 ifstr.close(); 410 }411 //-----------------------------------------------------------------------412 void TerrainMouseQueryListener::setAppState(int state)413 {414 mAppState = state;415 392 } 416 393 //----------------------------------------------------------------------- … … 608 585 609 586 if (mUseDepthPass) 587 { 610 588 mUseDepthPassInfo->setCaption(": true"); 589 } 611 590 else 591 { 612 592 mUseDepthPassInfo->setCaption(": false"); 593 } 613 594 } 614 595 //----------------------------------------------------------------------- … … 673 654 mNodeVizMode = (mNodeVizMode + 1) % NODEVIZ_MODES_NUM; 674 655 675 bool renderNodesForViz = (mNodeVizMode == NODEVIZ_RENDER_NODES) || (mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT); 656 bool renderNodesForViz = (mNodeVizMode == NODEVIZ_RENDER_NODES) || 657 (mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT); 676 658 bool renderNodesContentForViz = (mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT); 677 659 //bool renderNodesContentForViz = mNodeVizMode == NODEVIZ_RENDER_GEOMETRY; … … 752 734 bool TerrainMouseQueryListener::processUnbufferedKeyInput(const FrameEvent& evt) 753 735 { 754 if (mInputDevice->isKeyDown(KC_A)) 736 if (mInputDevice->isKeyDown(KC_ESCAPE)) 737 { 738 return false; 739 } 740 741 /* Move camera forward by keypress. */ 742 if (mInputDevice->isKeyDown(KC_UP)) 743 { 744 mTranslateVector.z = -mMoveScale; 745 } 746 747 /* Move camera backward by keypress. */ 748 if (mInputDevice->isKeyDown(KC_DOWN)) 755 749 { 756 // Move camera left 757 mTranslateVector.x = -mMoveScale; 758 } 759 760 if (mInputDevice->isKeyDown(KC_D)) 761 { 762 // Move camera RIGHT 763 mTranslateVector.x = mMoveScale; 764 } 765 766 /* Move camera forward by keypress. */ 767 if (mInputDevice->isKeyDown(KC_UP) || mInputDevice->isKeyDown(KC_W) ) 768 { 769 mTranslateVector.z = -mMoveScale; 770 } 771 772 /* Move camera backward by keypress. */ 773 if (mInputDevice->isKeyDown(KC_DOWN) || mInputDevice->isKeyDown(KC_S) ) 774 { 775 mTranslateVector.z = mMoveScale; 776 } 777 778 if (mInputDevice->isKeyDown(KC_PGUP)) 779 { 780 // Move camera up 781 mTranslateVector.y = mMoveScale; 782 } 783 784 if (mInputDevice->isKeyDown(KC_PGDOWN)) 785 { 786 // Move camera down 787 mTranslateVector.y = -mMoveScale; 750 mTranslateVector.z = mMoveScale; 788 751 } 789 752 … … 798 761 } 799 762 800 if( mInputDevice->isKeyDown( KC_ESCAPE) ) 801 { 802 return false; 803 } 804 805 if (mInputDevice->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0) 806 { 807 mStatsOn = !mStatsOn; 808 showDebugOverlay(mStatsOn); 809 810 mTimeUntilNextToggle = 1; 811 } 812 if (mInputDevice->isKeyDown(KC_T) && mTimeUntilNextToggle <= 0) 813 { 814 switch(mFiltering) 815 { 816 case TFO_BILINEAR: 817 mFiltering = TFO_TRILINEAR; 818 mAniso = 1; 819 break; 820 case TFO_TRILINEAR: 821 mFiltering = TFO_ANISOTROPIC; 822 mAniso = 8; 823 break; 824 case TFO_ANISOTROPIC: 825 mFiltering = TFO_BILINEAR; 826 mAniso = 1; 827 break; 828 default: 829 break; 830 } 831 MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering); 832 MaterialManager::getSingleton().setDefaultAnisotropy(mAniso); 833 834 835 showDebugOverlay(mStatsOn); 836 837 mTimeUntilNextToggle = 1; 838 } 839 840 if (mInputDevice->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0) 841 { 842 char tmp[20]; 843 sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots); 844 mWindow->writeContentsToFile(tmp); 845 mTimeUntilNextToggle = 0.5; 846 mWindow->setDebugText(String("Wrote ") + tmp); 847 } 848 849 if (mInputDevice->isKeyDown(KC_R) && mTimeUntilNextToggle <=0) 850 { 851 mSceneDetailIndex = (mSceneDetailIndex+1)%3 ; 852 switch(mSceneDetailIndex) { 853 case 0 : mCamera->setDetailLevel(SDL_SOLID) ; break ; 854 case 1 : mCamera->setDetailLevel(SDL_WIREFRAME) ; break ; 855 case 2 : mCamera->setDetailLevel(SDL_POINTS) ; break ; 856 } 857 mTimeUntilNextToggle = 0.5; 858 } 859 860 static bool displayCameraDetails = false; 861 if (mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0) 862 { 863 displayCameraDetails = !displayCameraDetails; 864 mTimeUntilNextToggle = 0.5; 865 if (!displayCameraDetails) 866 mWindow->setDebugText(""); 867 } 868 if (displayCameraDetails) 763 KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm()); 764 KEY_PRESSED(KC_F, 0.3, nextFilter()); 765 KEY_PRESSED(KC_R, 0.3, nextSceneDetailLevel()); 766 767 KEY_PRESSED(KC_P, 0.3, toggleDisplayCameraDetails()); 768 KEY_PRESSED(KC_O, 0.3, toggleUseOptimization()); 769 KEY_PRESSED(KC_T, 0.3, toggleShowOctree()); 770 KEY_PRESSED(KC_X, 0.3, toggleUseDepthPass()); 771 KEY_PRESSED(KC_S, 0.3, toggleUseShadows()); 772 773 KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10)); 774 KEY_PRESSED(KC_ADD, 0, changeThreshold(10)); 775 776 //-- visualization 777 KEY_PRESSED(KC_1, 0.3, toggleShowViz()); 778 KEY_PRESSED(KC_2, 0.3, nextNodeVizMode()); 779 KEY_PRESSED(KC_3, 0, zoomVizCamera(50)); 780 KEY_PRESSED(KC_4, 0, zoomVizCamera(-50)); 781 782 KEY_PRESSED(KC_F1, 0.3, toggleShowHelp()); 783 KEY_PRESSED(KC_F2, 0.3, toggleShowStats()); 784 KEY_PRESSED(KC_F3, 0.3, nextAppState()); 785 786 KEY_PRESSED(KC_F10, 0.3, toggleRecord()); 787 KEY_PRESSED(KC_F11, 0.3, takeScreenShot()); 788 KEY_PRESSED(KC_F12, 0.3, mTerrainContentGenerator->WriteObjects(objects_out_filename)); 789 //KEY_PRESSED(KC_F3, 0.3, writeFrames()); 790 //KEY_PRESSED(KC_F4, 0.3, loadFrames()); 791 792 if (mDisplayCameraDetails) 869 793 { 870 794 // Print camera details … … 877 801 } 878 802 //----------------------------------------------------------------------- 803 void TerrainMouseQueryListener::nextFilter() 804 { 805 switch(mFiltering) 806 { 807 case TFO_BILINEAR: 808 mFiltering = TFO_TRILINEAR; 809 mAniso = 1; 810 break; 811 case TFO_TRILINEAR: 812 mFiltering = TFO_ANISOTROPIC; 813 mAniso = 8; 814 break; 815 case TFO_ANISOTROPIC: 816 mFiltering = TFO_BILINEAR; 817 mAniso = 1; 818 break; 819 default: 820 break; 821 } 822 823 MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering); 824 MaterialManager::getSingleton().setDefaultAnisotropy(mAniso); 825 826 showStats(mStatsOn); 827 } 828 //----------------------------------------------------------------------- 829 void TerrainMouseQueryListener::nextSceneDetailLevel() 830 { 831 mSceneDetailIndex = (mSceneDetailIndex+1)%3 ; 832 switch(mSceneDetailIndex) 833 { 834 case 0 : mCamera->setDetailLevel(SDL_SOLID) ; break ; 835 case 1 : mCamera->setDetailLevel(SDL_WIREFRAME) ; break ; 836 case 2 : mCamera->setDetailLevel(SDL_POINTS) ; break ; 837 } 838 } 839 //----------------------------------------------------------------------- 840 void TerrainMouseQueryListener::takeScreenShot() 841 { 842 char tmp[20]; 843 sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots); 844 mWindow->writeContentsToFile(tmp); 845 mWindow->setDebugText(String("Wrote ") + tmp); 846 } 847 //----------------------------------------------------------------------- 848 void TerrainMouseQueryListener::toggleDisplayCameraDetails() 849 { 850 mDisplayCameraDetails = !mDisplayCameraDetails; 851 852 if (!mDisplayCameraDetails) 853 mWindow->setDebugText(""); 854 } 855 //----------------------------------------------------------------------- 879 856 bool TerrainMouseQueryListener::processUnbufferedMouseInput(const FrameEvent& evt) 880 857 { … … 897 874 return true; 898 875 } 899 900 void TerrainMouseQueryListener::show DebugOverlay(bool show)901 { 902 if (mDebugOverlay )876 //----------------------------------------------------------------------- 877 void TerrainMouseQueryListener::showStats(bool show) 878 { 879 if (mDebugOverlay && mCullStatsOverlay) 903 880 { 904 881 if (show) 905 882 { 906 883 mDebugOverlay->show(); 884 mCullStatsOverlay->show(); 907 885 } 908 886 else 909 887 { 910 888 mDebugOverlay->hide(); 889 mCullStatsOverlay->hide(); 911 890 } 912 891 } 913 892 } 914 915 916 917 893 //----------------------------------------------------------------------- 894 void TerrainMouseQueryListener::toggleShowStats() 895 { 896 mStatsOn = !mStatsOn; 897 898 showStats(mStatsOn); 899 } 900 //----------------------------------------------------------------------- 901 void TerrainMouseQueryListener::toggleShowHelp() 902 { 903 mShowHelp = !mShowHelp; 904 905 if (mShowHelp) 906 { 907 mHelpOverlay->show(); 908 } 909 else 910 { 911 mHelpOverlay->hide(); 912 } 913 } 914 915 -
trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h
r115 r120 71 71 //enum {NODEVIZ_NONE, NODEVIZ_RENDER_GEOMETRY, NODEVIZ_MODES_NUM}; 72 72 73 void nextAlgorithm(); 74 void changeThreshold(int incr); 75 void updateStats(); 76 77 void toggleUseOptimization(); 78 void toggleShowOctree(); 79 void toggleUseDepthPass(); 80 void toggleShowViz(); 81 void nextNodeVizMode(); 82 void toggleRecord(); 83 84 void zoomVizCamera(int zoom); 73 void zoomVizCamera(int zoom); 85 74 86 75 void addFrameInfo(SceneNode *camNode, Real timeElapsed); 87 76 void setCurrentFrameInfo(Real timeElapsed); 88 77 89 void setAppState(int state);90 void nextAppState();91 92 78 void setAlgorithm(int algorithm); 93 79 … … 97 83 void loadFrames(); 98 84 99 void toggleUseShadows();100 85 101 86 … … 106 91 bool processUnbufferedMouseInput(const FrameEvent& evt); 107 92 108 void showDebugOverlay(bool show); 93 void showStats(bool show); 94 95 void updateStats(); 96 97 void toggleShowHelp(); 98 void toggleShowStats(); 99 100 void toggleUseShadows(); 101 void toggleDisplayCameraDetails(); 102 void takeScreenShot(); 103 void nextSceneDetailLevel(); 104 void nextFilter(); 105 void nextAlgorithm(); 106 void nextNodeVizMode(); 107 void nextAppState(); 108 void changeThreshold(int incr); 109 110 void toggleUseOptimization(); 111 void toggleShowOctree(); 112 void toggleUseDepthPass(); 113 void toggleShowViz(); 114 void toggleRecord(); 109 115 110 116 protected: … … 114 120 void Clamp2Terrain(); 115 121 116 bool mLMouseDown, mRMouseDown; // True if the mouse buttons are down 117 SceneManager *mSceneMgr; // A pointer to the scene manager 122 SceneManager *mSceneMgr; // A pointer to the scene manager 118 123 119 124 CEGUI::Renderer *mGUIRenderer; // cegui renderer 120 125 121 bool mShutdownRequested;122 126 int mCurrentAlgorithm; 123 127 int mVisibilityThreshold; 124 128 // the current frame number 129 int mCurrentFrame; 130 // the current application state 131 int mAppState; 132 // The number of objects on the screen 133 int mObjectCount; 134 // visualization mode 135 int mNodeVizMode; 136 137 SceneNode *mCurrentObject; // the newly created object 138 125 139 OverlayElement *mAlgorithmInfo; 126 140 OverlayElement *mThresholdInfo; … … 135 149 OverlayElement *mQueriesIssuedInfo; 136 150 137 SceneNode *mCurrentObject; // the newly created object138 int mObjectCount; // The number of objects on the screen139 140 151 RayQueryExecutor *mRayQueryExecutor; 141 152 TerrainContentGenerator *mTerrainContentGenerator; … … 145 156 bool mUseDepthPass; 146 157 bool mShowVisualization; 147 int mNodeVizMode;148 158 bool mCullCamera; 159 bool mRecord; 160 bool mUseShadows; 161 bool mVisualizeCulledNodes; 162 bool mShowHelp; 163 bool mStatsOn; 164 bool mLMouseDown, mRMouseDown; // True if the mouse buttons are down 165 bool mShutdownRequested; 166 bool mDisplayCameraDetails; 149 167 150 168 Real mVizCameraHeight; … … 156 174 std::vector<frame_info> mFrameInfo; 157 175 158 int mCurrentFrame;159 // the current application state160 int mAppState;161 bool mRecord;162 176 Real mTimeElapsed; 163 bool mUseShadows;164 165 bool mVisualizeCulledNodes;166 167 168 177 //EventProcessor* mEventProcessor; 169 178 InputReader* mInputDevice; … … 172 181 Vector3 mTranslateVector; 173 182 RenderWindow* mWindow; 174 bool mStatsOn;175 bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;183 184 //bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn; 176 185 unsigned int mNumScreenShots; 177 float mMoveScale; 186 int mSceneDetailIndex; 187 int mAniso; 188 189 float mMoveScale; 178 190 Degree mRotScale; 179 191 // just to stop toggles flipping too fast 180 Real mTime UntilNextToggle;192 Real mTimeDelay; 181 193 Radian mRotX, mRotY; 182 194 TextureFilterOptions mFiltering; 183 int mAniso; 184 185 int mSceneDetailIndex; 186 Real mMoveSpeed; 195 196 Real mMoveSpeed; 187 197 Degree mRotateSpeed; 188 Overlay* mDebugOverlay; 198 199 Overlay* mDebugOverlay; 200 Overlay* mHelpOverlay; 201 Overlay* mCullStatsOverlay; 189 202 }; 190 203 -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
r115 r120 163 163 164 164 // the objects are generated on the whole terrain 165 mTerrainContentGenerator->GenerateScene(1500, "robot"); 165 166 //mTerrainContentGenerator->GenerateScene(1500, "athene"); 166 mTerrainContentGenerator->GenerateScene(1500, "robot"); 167 // mTerrainContentGenerator->GenerateScene(500, "ninja"); 167 //mTerrainContentGenerator->GenerateScene(500, "ninja"); 168 168 } 169 169 … … 192 192 mTerrainFrameListener = new TerrainMouseQueryListener(mWindow, mCamera, mSceneMgr, 193 193 mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode); 194 mTerrainFrameListener->showDebugOverlay(true);194 195 195 mRoot->addFrameListener(mTerrainFrameListener); 196 196 }
Note: See TracChangeset
for help on using the changeset viewer.