Changeset 254 for trunk/VUT/work/TestCullingTerrain
- Timestamp:
- 08/26/05 23:24:31 (19 years ago)
- Location:
- trunk/VUT/work/TestCullingTerrain
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
r187 r254 70 70 // output file for object positions / orientations 71 71 const char* objects_out_filename = "objects.out"; 72 72 73 std::ofstream video_out("video.lst"); 73 74 74 75 //----------------------------------------------------------------------- … … 117 118 mShowVisualization(false), 118 119 mCullCamera(false), 119 mRecord (false),120 mRecordFrames(false), 120 121 mShowShadows(false), 121 122 mShowHelp(false), … … 134 135 mDeleteObjects(false), 135 136 mUseItemBuffer(false), 136 mItemBufferMode(GtpVisibility::QueryManager::PATCH_VISIBILITY) 137 mItemBufferMode(GtpVisibility::QueryManager::PATCH_VISIBILITY), 138 mRecordVideo(false), 139 mPureRenderTimeFps(0.0), 140 mNumVideoFrames(0), 141 mDemoFps(0), 142 mUseDemoFps(false) 137 143 { 138 144 //mInputDevice = PlatformManager::getSingleton().createInputReader(); … … 159 165 160 166 initVisStatsOverlay(); // visibility stats overlay 161 initHelpOverlay(); // help overlay162 initQueryOverlay(); // visibility query stats overlay167 initHelpOverlay(); // help overlay 168 initQueryOverlay(); // visibility query stats overlay 163 169 164 170 // show stats overlays … … 179 185 setObjectType(mCurrentObjectType); 180 186 187 // initialise timer 188 mTimer = Root::getSingleton().getTimer(); 189 mTimeFrameEnded = mTimeFrameStarted = mTimer->getMilliseconds(); 190 181 191 // reset statistics 182 192 resetStats(); … … 356 366 { return false; }*/ 357 367 358 // --- set parameters for visualization368 //-- set parameters for visualization 359 369 if (mShowVisualization) 360 370 { … … 362 372 mSceneMgr->setOption("ShowOctree", &mShowVisualization); 363 373 364 // ---- setup visualization camera374 //-- setup visualization camera 365 375 366 376 mVizCamera->setPosition(0, 0, 0); … … 380 390 mVizCamera->moveRelative(Vector3(0, 800, 0)); 381 391 } 392 else 393 { 394 // frame start time 395 mTimeFrameStarted = mTimer->getMilliseconds(); 396 //Ogre::LogManager::getSingleton().logMessage("Frame started"); 397 } 382 398 383 399 //-- set application state … … 385 401 { 386 402 case REPLAY: 403 /// set the current camera data to loaded frame information 387 404 setCurrentFrameInfo(evt.timeSinceLastFrame); 405 // HACK to produce demo 406 addFrameInfo(mSavedFrameInfo, mCamNode, evt.timeSinceLastFrame); 388 407 break; 389 408 case WALKTHROUGH: 390 //-- if we are recording camera status per frame391 if (mRecord )409 //-- recording the camera settings per frame 410 if (mRecordFrames) 392 411 { 393 addFrameInfo(m CamNode, evt.timeSinceLastFrame);412 addFrameInfo(mFrameInfo, mCamNode, evt.timeSinceLastFrame); 394 413 // print recording message 395 414 mWindow->setDebugText("Recording frame " + … … 573 592 return false; 574 593 594 // timer end time 595 if (!mShowVisualization) 596 { 597 mTimeFrameEnded = mTimer->getMilliseconds(); 598 //Ogre::LogManager::getSingleton().logMessage("Frame ended"); 599 } 600 575 601 updateStats(); 576 602 603 if (mRecordVideo) // record current frame 604 { 605 //Ogre::LogManager::getSingleton().logMessage("taking video frame"); 606 takeVideoFrame(video_out); 607 //Ogre::LogManager::getSingleton().logMessage("finished"); 608 } 577 609 //-- IMPORTANT: must be set, otherwise terrain is not rendered correctly 578 610 mSceneMgr->endFrame(); 579 611 580 if (mTimeDelay <= 0) // approx. one second612 if (mTimeDelay <= 0) // simulates approx. one second 581 613 mTimeDelay = 1.0; 582 614 … … 603 635 ofstr << StringConverter::toString((*it).position) << " " 604 636 << StringConverter::toString((*it).orientation) << " " 605 << StringConverter::toString((*it).timeElapsed) << "\n"; 637 << StringConverter::toString((*it).timeElapsed) << " " 638 << StringConverter::toString((*it).fps) << "\n"; 639 } 640 ofstr.close(); 641 } 642 // quick hack 643 void TerrainFrameListener::writeNewFrameInfo() 644 { 645 std::ofstream ofstr("newframe.out"); 646 647 std::vector<frame_info>::const_iterator it, it_end; 648 649 it_end = mSavedFrameInfo.end(); 650 for (it = mSavedFrameInfo.begin(); it < it_end; ++it) 651 { 652 ofstr << StringConverter::toString((*it).position) << " " 653 << StringConverter::toString((*it).orientation) << " " 654 << StringConverter::toString((*it).timeElapsed) << " " 655 << StringConverter::toString((*it).fps) << "\n"; 606 656 } 607 657 ofstr.close(); … … 621 671 { 622 672 ifstr.getline(line, 256); 623 sscanf(line, "%f %f %f %f %f %f %f %f ", &info.position.x, &info.position.y, &info.position.z,673 sscanf(line, "%f %f %f %f %f %f %f %f %f", &info.position.x, &info.position.y, &info.position.z, 624 674 &info.orientation.w, &info.orientation.x, &info.orientation.y, &info.orientation.z, 625 &info.timeElapsed );675 &info.timeElapsed, &info.fps); 626 676 627 677 mFrameInfo.push_back(info); … … 636 686 { 637 687 mCurrentFrame = 0; 688 int lastState = mAppState; 689 690 // transition to the next state 691 mAppState = (mAppState + 1) % STATE_NUM; 638 692 639 693 // if last state was replay state 640 if ( mAppState == REPLAY)641 { 642 // reset debug text and write frame info to file 694 if (lastState == REPLAY) 695 { 696 // reset debug text 643 697 mWindow->setDebugText(""); 644 writeFrames(); 645 698 699 // hack for producing demo 700 writeNewFrameInfo(); 701 mSavedFrameInfo.clear(); 702 646 703 float avgFps = (float)mAvgFps / (float)mFrameCount; 647 704 … … 659 716 } 660 717 661 //-- set the next státe662 mAppState = (mAppState + 1) % STATE_NUM;663 664 718 // replay recorded walkthrough 665 719 if (mAppState == REPLAY) 666 720 { 667 721 // no recording during replay 668 mRecord = false;669 670 // load recorded walkthrough 722 mRecordFrames = false; mWindow->setDebugText(""); 723 724 // load recorded walkthrough from disk 671 725 if (mFrameInfo.size() == 0) 672 726 { 673 727 loadFrames(); 674 728 } 675 729 676 730 // if there are no recorded frames => set next state 677 731 if (mFrameInfo.size() == 0) … … 679 733 nextAppState(); 680 734 } 681 else 735 else // replay 682 736 { 683 737 mWindow->setDebugText("Replay"); … … 699 753 void TerrainFrameListener::toggleRecord() 700 754 { 701 mRecord = !mRecord; 702 703 // clear previous camera path 704 if (mRecord) 755 mRecordFrames = !mRecordFrames; 756 757 if (mRecordFrames) 758 { 759 // starting new recording => clear old frame info 705 760 mFrameInfo.clear(); 761 } 706 762 else 763 { 764 writeFrames(); // write frame info to file 707 765 mWindow->setDebugText(""); 766 } 708 767 } 709 768 //----------------------------------------------------------------------- … … 711 770 { 712 771 mVisibilityThreshold += incr; 713 if(mVisibilityThreshold < 0) mVisibilityThreshold = 0; 714 772 773 if (mVisibilityThreshold < 0) 774 { 775 mVisibilityThreshold = 0; 776 } 777 715 778 char str[100]; sprintf(str,": %d", mVisibilityThreshold); 716 779 … … 722 785 { 723 786 mAssumedVisibility += incr; 724 if(mAssumedVisibility < 0) mAssumedVisibility = 0; 725 787 788 if (mAssumedVisibility < 0) 789 { 790 mAssumedVisibility = 0; 791 } 792 726 793 char str[100]; sprintf(str,": %d", mAssumedVisibility); 727 794 … … 739 806 { 740 807 mCurrentAlgorithm = (mCurrentAlgorithm + 1) % 741 (GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS - 1);808 GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS; 742 809 setAlgorithm(mCurrentAlgorithm); 743 810 } … … 745 812 void TerrainFrameListener::setObjectType(int objectType) 746 813 { 747 if (mCurrentObjectType >= 3) 814 if (mCurrentObjectType >= 3) // TODO: define a constant 748 815 mCurrentObjectType = 0; 749 816 … … 779 846 static String trisString = "Triangle Count: "; 780 847 848 int currentFps = mWindow->getStatistics().lastFPS; 849 850 if (mUseDemoFps) 851 currentFps = mDemoFps; 852 #if 0 853 // HACK: take pure rendering time, only measures the render call 854 long pureRenderTime = mTimeFrameEnded - mTimeFrameStarted; 855 856 if (pureRenderTime) 857 { 858 mPureRenderTimeFps = 1000.0 / (float) pureRenderTime; 859 } 860 currentFps = mPureRenderRenderTimeFps; 861 //std::stringstream d; d << "Pure render time fps: " << mPureRenderTimeFps << "\n"; 862 //Ogre::LogManager::getSingleton().logMessage(d.str()); 863 #endif 864 781 865 // HACK: compute average fps ourselfs, because ogre avg. fps is wrong 782 866 // TODO: update only once per second 783 mAvgFps += mWindow->getStatistics().lastFPS; 784 ++ mFrameCount; 785 786 float avgFps = (float)mAvgFps / (float)mFrameCount; 787 867 mAvgFps += currentFps; 868 float avgFps = (float)mAvgFps / (float)(mFrameCount++); 869 788 870 // update stats when necessary 789 871 try … … 796 878 const RenderTarget::FrameStats& stats = mWindow->getStatistics(); 797 879 798 // guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS));799 if (mTimeDelay < 0) // only update once per second880 // HACK: take newly computed avg. fps instead of Ogre avg fps and update only once per second 881 if (mTimeDelay < 0) 800 882 { 801 883 guiAvg->setCaption(avgFpsString + StringConverter::toString(avgFps) + " ms"); 884 //guiCurr->setCaption(currFpsString + StringConverter::toString(currentFps)); 802 885 } 803 804 guiCurr->setCaption(currFpsString + StringConverter::toString(stats.lastFPS)); 886 //guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); 887 guiCurr->setCaption(currFpsString + StringConverter::toString(currentFps)); 888 889 805 890 guiBest->setCaption(bestFpsString + StringConverter::toString(stats.bestFPS) 806 891 +" "+StringConverter::toString(stats.bestFrameTime) + " ms"); … … 1039 1124 break; 1040 1125 case KC_F2: 1041 toggleShowStats(); 1126 mStatsOn = !mStatsOn; 1127 showStats(mStatsOn); 1042 1128 break; 1043 1129 case KC_F3: … … 1063 1149 mUseAnimation = !mUseAnimation; 1064 1150 break; 1151 1152 case KC_F10: 1153 mRecordVideo = !mRecordVideo; 1154 1065 1155 case KC_F11: 1066 1156 takeScreenshot(); … … 1081 1171 case KC_DELETE: 1082 1172 mDeleteObjects = true; 1173 break; 1174 case KC_M: // hack 1175 mUseDemoFps = !mUseDemoFps; 1083 1176 break; 1084 1177 //KEY_PRESSED(KC_F3, 0.3, writeFrames()); … … 1110 1203 } 1111 1204 //----------------------------------------------------------------------- 1112 void TerrainFrameListener::addFrameInfo( SceneNode *camNode, Real timeElapsed)1205 void TerrainFrameListener::addFrameInfo(FrameInfoContainer &frameInfos, SceneNode *camNode, Real timeElapsed) 1113 1206 { 1114 1207 frame_info info; 1208 1115 1209 info.orientation = mCamNode->getOrientation(); 1116 1210 info.position = mCamNode->getPosition(); 1117 1211 info.timeElapsed = timeElapsed; 1118 1119 mFrameInfo.push_back(info); 1212 info.fps = mWindow->getStatistics().lastFPS; 1213 1214 frameInfos.push_back(info); 1120 1215 } 1121 1216 //----------------------------------------------------------------------- … … 1124 1219 //-- find current frame relative to elapsed frame time 1125 1220 mReplayTimeElapsed -= timeElapsed; 1126 1221 1127 1222 while ((mReplayTimeElapsed <= 0) && (mCurrentFrame < (int)mFrameInfo.size() - 1)) 1128 1223 { … … 1130 1225 } 1131 1226 1132 frame_info new_frame = mFrameInfo[mCurrentFrame]; 1227 1228 // TODO: crashes here if recording / replaying on the same time!! 1229 frame_info new_frame = mFrameInfo[mCurrentFrame]; 1133 1230 frame_info old_frame = mFrameInfo[mCurrentFrame - 1]; 1134 1231 … … 1143 1240 Vector3 camPos = old_frame.position + factor 1144 1241 * (new_frame.position - old_frame.position); 1242 1243 // interpolate the orientation 1145 1244 Quaternion camOrienation = Quaternion::Slerp(factor, old_frame.orientation, 1146 1245 new_frame.orientation, true); 1147 1246 1247 // HACK: interpolate fps 1248 mDemoFps = old_frame.fps + factor * (new_frame.fps -old_frame.fps); 1249 1148 1250 mCamNode->setPosition(camPos); 1149 1251 mCamNode->setOrientation(camOrienation); 1150 1252 1151 // stop replay after afull walkthrough1253 // stop replaying after one full walkthrough 1152 1254 if (mCurrentFrame == (int)mFrameInfo.size() - 1) 1153 1255 { … … 1249 1351 } 1250 1352 //----------------------------------------------------------------------- 1353 void TerrainFrameListener::takeVideoFrame(std::ofstream &ofstr) 1354 { 1355 char name[50]; 1356 1357 sprintf(name, "frame_%05d.tga", ++mNumVideoFrames); 1358 mWindow->writeContentsToFile(name); 1359 //mWindow->setDebugText(String("Wrote ") + name); 1360 1361 ofstr << name << "\n"; 1362 } 1363 //----------------------------------------------------------------------- 1251 1364 void TerrainFrameListener::takeScreenshot() 1252 1365 { 1253 char tmp[20]; 1254 sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots); 1255 mWindow->writeContentsToFile(tmp); 1256 mWindow->setDebugText(String("Wrote ") + tmp); 1366 char name[50]; 1367 1368 sprintf(name, "screenshot_%05d.png", ++mNumScreenShots); 1369 mWindow->writeContentsToFile(name); 1370 //mWindow->setDebugText(String("Wrote ") + name); 1257 1371 } 1258 1372 //----------------------------------------------------------------------- … … 1283 1397 } 1284 1398 } 1285 //----------------------------------------------------------------------- 1286 void TerrainFrameListener::toggleShowStats() 1287 { 1288 mStatsOn = !mStatsOn; 1289 1290 showStats(mStatsOn); 1291 } 1399 1292 1400 //----------------------------------------------------------------------- 1293 1401 void TerrainFrameListener::toggleShowHelp() … … 1336 1444 initHelpOverlayElement("Recorded", top); top += vert_space; 1337 1445 initHelpOverlayElement("Animation", top); top += vert_space; 1446 initHelpOverlayElement("Video", top); top += vert_space; 1338 1447 initHelpOverlayElement("Screenshots", top); top += vert_space; 1339 1448 initHelpOverlayElement("WriteOut", top); top += vert_space; 1449 1340 1450 1341 1451 top +=vert_space; -
trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
r187 r254 20 20 21 21 22 22 23 /** Frame listener specialised for terrains. 23 24 */ … … 75 76 Quaternion orientation; 76 77 Real timeElapsed; 78 Real fps; 77 79 } frame_info; 80 81 typedef std::vector<frame_info> FrameInfoContainer; 78 82 79 83 enum {WALKTHROUGH, REPLAY, STATE_NUM}; … … 85 89 void zoomVizCamera(int zoom); 86 90 87 void addFrameInfo( SceneNode *camNode, Real timeElapsed);91 void addFrameInfo(FrameInfoContainer &frameInfos, SceneNode *camNode, Real timeElapsed); 88 92 void setCurrentFrameInfo(Real timeElapsed); 89 93 … … 95 99 void loadFrames(); 96 100 97 98 // Constructor takes a RenderWindow because it uses that to determine input context 99 //ExampleFrameListener(RenderWindow* win, Camera* cam, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false) 101 // quick hack 102 void writeNewFrameInfo(); 100 103 101 104 bool processUnbufferedKeyInput(const FrameEvent& evt); 102 105 bool processUnbufferedMouseInput(const FrameEvent& evt); 103 106 107 /** Shows the frame / algorithm statistics. 108 */ 104 109 void showStats(bool show); 105 110 111 /** Updates frame statistics and the frame statistics display. 112 */ 106 113 void updateStats(); 107 114 115 /** Toggles wether help screen is shown or not. 116 */ 108 117 void toggleShowHelp(); 109 void toggleShowStats(); 110 118 119 /** Toggles wether shadows are shown or not. 120 */ 111 121 void toggleShowShadows(); 112 122 void toggleDisplayCameraDetails(); 123 /** Takes screenshot of the current scene. 124 */ 113 125 void takeScreenshot(); 126 /** Takes one video frame. 127 */ 128 void takeVideoFrame(std::ofstream &ofstr); 129 114 130 void nextSceneDetailLevel(); 115 131 void nextFilter(); … … 120 136 void changeAssumedVisibility(int incr); 121 137 void setTestGeometryForVisibleLeaves(bool testGeometryForVisibleLeaves); 138 /** Shows octree hierarchy of the scene. 139 */ 122 140 void toggleShowOctree(); 141 /** Toggles wether we use the initial depth pass. 142 */ 123 143 void toggleUseDepthPass(); 144 /** Toggles wether the visualization is shown. 145 */ 124 146 void toggleShowViz(); 147 /** Toggles wether the frames are recorded. 148 */ 125 149 void toggleRecord(); 126 150 … … 134 158 void applyVisibilityQuery(bool fromPoint, bool relativeVisibility, bool useItemBuffer); 135 159 160 /** Shows result from visibility queries. 161 */ 136 162 void toggleShowQueryStats(); 137 163 … … 168 194 int mVisibilityThreshold; 169 195 int mAssumedVisibility; 170 // the current frame number196 /// the current frame number 171 197 int mCurrentFrame; 172 // the current application state198 /// the current application state 173 199 int mAppState; 174 // The number of objects on the screen200 /// The number of objects on the screen 175 201 int mObjectCount; 176 // visualization mode202 /// visualization mode 177 203 int mNodeVizMode; 178 179 SceneNode *mCurrentObject; // the newly created object 180 204 /// number of video frames 205 int mNumVideoFrames; 206 /// the newly created object 207 SceneNode *mCurrentObject; 208 /// HACK 209 float mDemoFps; 210 bool mUseDemoFps; 181 211 OverlayElement *mAlgorithmInfo; 182 212 OverlayElement *mThresholdInfo; … … 214 244 bool mShowVisualization; 215 245 bool mCullCamera; 216 bool mRecord ;246 bool mRecordFrames; 217 247 bool mShowShadows; 218 248 bool mVisualizeCulledNodes; … … 232 262 SceneNode *mCamNode; 233 263 234 //std::deque<Vector3> mWalkList; // The list of points we are walking to 235 std::vector<frame_info> mFrameInfo; 236 264 /// Per frame data stored for a walkthrough 265 FrameInfoContainer mFrameInfo; 266 /// HACK: for demo 267 FrameInfoContainer mSavedFrameInfo; 268 237 269 Real mReplayTimeElapsed; 238 270 //EventProcessor* mEventProcessor; … … 282 314 283 315 bool mDeleteObjects; 284 316 bool mRecordVideo; 317 318 Timer *mTimer; 319 long mTimeFrameEnded; 320 long mTimeFrameStarted; 321 float mPureRenderTimeFps; 285 322 TestCullingTerrainApplication *mApplication; 286 323 }; -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
r187 r254 305 305 { 306 306 // the objects are generated randomly distributed over the terrain 307 generateScene(900, 0); 307 generateScene(900, 0); // create soldiers, trees, ninjas 308 308 generateScene(500, 1); 309 309 generateScene(100, 2); -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
r183 r254 157 157 Vector3 mTerrainMaxPos; 158 158 159 160 159 private: 161 160 void chooseSceneManager(void);
Note: See TracChangeset
for help on using the changeset viewer.