Changeset 1195 for GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE
- Timestamp:
- 08/10/06 17:08:57 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTree.h
r1187 r1195 6 6 #include <ivreader.h> 7 7 #include "TestKdTreeAppListener.h" 8 9 10 class KdTreeAppRenderTargetListener : public RenderTargetListener 11 { 12 public: 13 KdTreeAppRenderTargetListener(SceneManager *sceneMgr); 14 15 protected: 16 void preViewportUpdate (const RenderTargetViewportEvent &evt); 17 void postRenderTargetUpdate (const RenderTargetEvent &evt); 18 19 SceneManager *mSceneMgr; 20 21 ShadowTechnique mSavedShadowTechnique; 22 ColourValue mSavedAmbientLight; 23 }; 8 24 9 25 class KdTreeApp : public ExampleApplication … … 15 31 ~KdTreeApp() 16 32 { 33 delete mRenderTargerListener; 17 34 delete mFrameListener; 18 35 } … … 24 41 Camera *mFollowCam; 25 42 KdTreeAppListener *mFrameListener; 43 KdTreeAppRenderTargetListener *mRenderTargerListener; 26 44 27 45 String mSceneFiles; … … 69 87 }; 70 88 71 class KdTreeAppRenderTargetListener : public RenderTargetListener72 {73 public:74 KdTreeAppRenderTargetListener(SceneManager *sceneMgr);75 76 protected:77 void preViewportUpdate (const RenderTargetViewportEvent &evt);78 void postRenderTargetUpdate (const RenderTargetEvent &evt);79 80 SceneManager *mSceneMgr;81 82 ShadowTechnique mSavedShadowTechnique;83 ColourValue mSavedAmbientLight;84 };85 86 89 #endif -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h
r1187 r1195 55 55 bool mShowTree; 56 56 bool mFreeMove; 57 bool mTopCamFollow; 57 58 58 59 Real mDelayedQueriesIssued; … … 71 72 OverlayElement *mRenderMethodInfo; 72 73 OverlayElement *mMovementInfo; 74 OverlayElement *mTopCamInfo; 73 75 74 76 OverlayElement *mFrustumCulledNodesInfo; … … 107 109 void updateStats(void); 108 110 111 // stuff for walkthrough recording/playback 112 struct FrameInfo 113 { 114 FrameInfo(Vector3 pos, Quaternion or, Real time): 115 mPosition(pos), mOrientation(or), mElapsedTime(time) 116 { } 117 118 Vector3 mPosition; 119 Quaternion mOrientation; 120 Real mElapsedTime; 121 }; 122 123 typedef std::list<FrameInfo> FrameList; 124 125 enum AppState 126 { 127 AS_NORMAL, 128 AS_RECORD, 129 AS_PLAYBACK 130 }; 131 132 FrameList mFrameList; 133 134 AppState mAppState; 135 136 void toggleRecord(); 137 void togglePlayback(); 138 void saveFrameInfo(Real elapsedTime); 139 109 140 public: 141 void loadFrames(const String& filename); 142 void saveFrames(const String& filename); 110 143 111 144 // visualization modes for scene nodes -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp
r1190 r1195 246 246 light->setDirection(-1,-1,-1); 247 247 } 248 light->setDiffuseColour(ColourValue ());248 light->setDiffuseColour(ColourValue::White); 249 249 light->setSpecularColour(ColourValue(1, 1, 0.2)); 250 250 … … 276 276 mFrameListener->showDebugOverlay( true ); 277 277 mRoot->addFrameListener(mFrameListener); 278 mWindow->addListener(new KdTreeAppRenderTargetListener(mSceneMgr)); 278 mRenderTargerListener = new KdTreeAppRenderTargetListener(mSceneMgr); 279 mWindow->addListener(mRenderTargerListener); 279 280 } 280 281 … … 312 313 mTopCam->setDirection(0,0,-1); 313 314 mTopCam->pitch(Radian(-Math::HALF_PI)); 314 mTopCam->setCullingFrustum(mCamera);315 //mTopCam->setCullingFrustum(mCamera); 315 316 mTopCam->setNearClipDistance(1); 316 317 -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp
r1192 r1195 1 #include <fstream> 2 #include <cstdlib> 3 1 4 #include "TestKdTreeAppListener.h" 2 5 … … 92 95 } 93 96 97 mTopCamFollow = true; 94 98 mFreeMove = false; 95 99 mShowTree = false; … … 97 101 mVizCamTransVect = Vector3::ZERO; 98 102 mSeqNum = 0; 103 104 mAppState = AS_NORMAL; 99 105 100 106 mDelayedQueriesIssued = 0.0; … … 127 133 128 134 showDebugOverlay(true); 135 136 loadFrames("demo-in.txt"); 129 137 } 130 138 //----------------------------------------------------------------------- … … 139 147 PlatformManager::getSingleton().destroyInputReader( mInputDevice ); 140 148 } 149 150 // save demo 151 if (!mFrameList.empty()) 152 saveFrames("demo-out.txt"); 141 153 } 142 154 //----------------------------------------------------------------------- … … 183 195 const int vert_space = 15; 184 196 const String na = ": N/A"; 185 String sMD, sKT, sKI, sHL, sBM, sRM, sFM ;197 String sMD, sKT, sKI, sHL, sBM, sRM, sFM, sTC; 186 198 187 199 int top = border_height; … … 244 256 sFM = ": Ground"; 245 257 258 sTC = na; 259 if (mTopCamFollow) 260 sTC = ": Follow"; 261 else 262 sTC = ": Free"; 263 246 264 initOverlayElement(&mRenderMethodInfo, ext, "RenderMethod", top, sRM); top += vert_space; 247 265 initOverlayElement(&mBuildMethodInfo, ext, "BuildMethod", top, sBM); top += vert_space; … … 251 269 initOverlayElement(&mKIInfo, ext, "KI", top, sKI); top += vert_space; 252 270 initOverlayElement(&mMovementInfo, ext, "Movement", top, sFM); top += vert_space; 271 initOverlayElement(&mTopCamInfo, ext, "TopCam", top, sTC); top += vert_space; 253 272 254 273 OverlayElement *visPanel = OverlayManager::getSingleton(). … … 313 332 bool KdTreeAppListener::processUnbufferedKeyInput(const FrameEvent& evt) 314 333 { 334 // demo recording stuff 335 if (mInputDevice->isKeyDown(KC_F5) && mTimeUntilNextToggle <= 0) 336 { 337 toggleRecord(); 338 mTimeUntilNextToggle = 0.5; 339 } 340 341 if (mInputDevice->isKeyDown(KC_F9) && mTimeUntilNextToggle <= 0) 342 { 343 togglePlayback(); 344 mTimeUntilNextToggle = 0.5; 345 } 346 347 const static int vizCamSpeedup = 12; 315 348 // moving the cull camera 316 349 if (mInputDevice->isKeyDown(KC_NUMPAD2)) 317 350 { 318 mVizCamTransVect.y = -mMoveScale ;351 mVizCamTransVect.y = -mMoveScale * vizCamSpeedup; 319 352 } 320 353 if (mInputDevice->isKeyDown(KC_NUMPAD8)) 321 354 { 322 mVizCamTransVect.y = mMoveScale ;355 mVizCamTransVect.y = mMoveScale * vizCamSpeedup; 323 356 } 324 357 if (mInputDevice->isKeyDown(KC_NUMPAD4)) 325 358 { 326 mVizCamTransVect.x = mMoveScale;359 mVizCamTransVect.x = -mMoveScale * vizCamSpeedup; 327 360 } 328 361 if (mInputDevice->isKeyDown(KC_NUMPAD6)) 329 362 { 330 mVizCamTransVect.x = -mMoveScale;363 mVizCamTransVect.x = mMoveScale * vizCamSpeedup; 331 364 } 332 365 if (mInputDevice->isKeyDown(KC_SUBTRACT)) 333 366 { 334 mVizCamTransVect.z = mMoveScale ;367 mVizCamTransVect.z = mMoveScale * vizCamSpeedup; 335 368 } 336 369 if (mInputDevice->isKeyDown(KC_ADD)) 337 370 { 338 mVizCamTransVect.z = -mMoveScale ;371 mVizCamTransVect.z = -mMoveScale * vizCamSpeedup; 339 372 } 340 373 341 374 // stuff for the overlay 342 static String sNA = ": N/A";375 const static String sNA = ": N/A"; 343 376 344 377 static String bmOptions[] = { "Recursive", "PriorityQueue" }; … … 504 537 } 505 538 506 if (mInputDevice->isKeyDown(KC_ Q) && mTimeUntilNextToggle <= 0)539 if (mInputDevice->isKeyDown(KC_U) && mTimeUntilNextToggle <= 0) 507 540 { 508 541 mFreeMove = !mFreeMove; 509 String move = " N/A";542 String move = ": N/A"; 510 543 if (mFreeMove) 511 544 move = ": Free"; … … 518 551 } 519 552 553 if (mInputDevice->isKeyDown(KC_I) && mTimeUntilNextToggle <= 0) 554 { 555 mTopCamFollow = !mTopCamFollow; 556 String move = ": N/A"; 557 if (mTopCamFollow) 558 move = ": Follow"; 559 else 560 move = ": Free"; 561 562 mTopCamInfo->setCaption(move); 563 564 mTimeUntilNextToggle = 0.5; 565 } 520 566 521 567 if (mInputDevice->isKeyDown(KC_BACK) && mTimeUntilNextToggle <= 0) … … 801 847 mCamNode->translate(mCamNode->getLocalAxes(), mTranslateVector); 802 848 mTopCam->moveRelative(mVizCamTransVect); 849 if (mTopCamFollow) 850 { 851 Vector3 toppos = mTopCam->getPosition(); 852 Vector3 campos = mCamNode->getPosition(); 853 mTopCam->setPosition(Vector3::ZERO); 854 mTopCam->setOrientation(Quaternion::IDENTITY); 855 mTopCam->setPosition(campos.x, toppos.y, campos.z); 856 mTopCam->pitch(Radian(-Math::HALF_PI)); 857 } 803 858 804 859 if (!mFreeMove) … … 894 949 895 950 } 951 952 953 //saveFrameInfo(evt.timeSinceLastFrame); 954 if (mAppState == AS_RECORD) 955 { 956 mFrameList.push_back(FrameInfo(mCamNode->getPosition(), mCamNode->getOrientation(), evt.timeSinceLastFrame)); 957 } 958 896 959 897 960 //Camera *followCam = mSceneMgr->getCamera("FollowCam"); … … 953 1016 } 954 1017 } 1018 1019 /************************************************************************/ 1020 /* functions for recording & playback of demos */ 1021 /************************************************************************/ 1022 1023 //----------------------------------------------------------------------------- 1024 void KdTreeAppListener::toggleRecord() 1025 { 1026 // TODO: overlay 1027 if (mAppState == AS_NORMAL) 1028 { 1029 mAppState = AS_RECORD; 1030 } 1031 else if (mAppState == AS_RECORD) 1032 { 1033 mAppState = AS_NORMAL; 1034 } 1035 } 1036 1037 //----------------------------------------------------------------------------- 1038 void KdTreeAppListener::togglePlayback() 1039 { 1040 // TODO: overlay 1041 if (mAppState == AS_NORMAL) 1042 { 1043 mAppState = AS_PLAYBACK; 1044 } 1045 else if (mAppState == AS_PLAYBACK) 1046 { 1047 mAppState = AS_NORMAL; 1048 } 1049 } 1050 1051 //----------------------------------------------------------------------------- 1052 void KdTreeAppListener::saveFrameInfo(Real elapsedTime) 1053 { 1054 mFrameList.push_back(FrameInfo(mCamNode->getPosition(), mCamNode->getOrientation(), elapsedTime)); 1055 } 1056 1057 //----------------------------------------------------------------------------- 1058 void KdTreeAppListener::saveFrames(const String& filename) 1059 { 1060 // open file 1061 std::ofstream dest(filename.c_str()); 1062 if (!dest) 1063 { 1064 LogManager::getSingleton().logMessage("Failed to open file for saving demo: " + filename); 1065 return; 1066 } 1067 1068 FrameList::iterator it = mFrameList.begin(); 1069 FrameList::iterator end = mFrameList.end(); 1070 1071 // dump values 1072 while (it != end) 1073 { 1074 dest << 1075 StringConverter::toString(it->mPosition) << " " << 1076 StringConverter::toString(it->mOrientation) << " " << 1077 StringConverter::toString(it->mElapsedTime) << "\n"; 1078 ++ it; 1079 } 1080 1081 dest.close(); 1082 } 1083 1084 //----------------------------------------------------------------------------- 1085 void KdTreeAppListener::loadFrames(const String& filename) 1086 { 1087 // open file 1088 std::ifstream src(filename.c_str()); 1089 if (!src) 1090 { 1091 LogManager::getSingleton().logMessage("Failed to open file for reading demo: " + filename); 1092 return; 1093 } 1094 1095 // clear the list 1096 mFrameList.clear(); 1097 1098 Vector3 pos; 1099 Quaternion or; 1100 Real time; 1101 1102 while (!src.eof()) 1103 { 1104 src >> pos.x; 1105 src >> pos.y; 1106 src >> pos.z; 1107 1108 src >> or.w; 1109 src >> or.x; 1110 src >> or.y; 1111 src >> or.z; 1112 1113 src >> time; 1114 1115 mFrameList.push_back(FrameInfo(pos, or, time)); 1116 } 1117 1118 // HACK pop last frame, was doubled while reading 1119 mFrameList.pop_back(); 1120 1121 src.close(); 1122 }
Note: See TracChangeset
for help on using the changeset viewer.