Changeset 1187 for GTP/trunk/App/Demos
- Timestamp:
- 08/08/06 18:25:06 (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
r1163 r1187 2 2 #define __KdTreeApp_H__ 3 3 4 #include "ExampleApplication.h" 4 #include <OgreRenderTargetListener.h> 5 #include <ExampleApplication.h> 6 #include <ivreader.h> 5 7 #include "TestKdTreeAppListener.h" 6 7 #include <ivreader.h>8 8 9 9 class KdTreeApp : public ExampleApplication … … 19 19 20 20 protected: 21 SceneNode *mCamNode; 21 22 SceneNode *mDeathNode; 22 23 Camera *mTopCam; … … 68 69 }; 69 70 71 class KdTreeAppRenderTargetListener : public RenderTargetListener 72 { 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 70 86 #endif -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h
r1183 r1187 42 42 #include "OgreException.h" 43 43 44 #define VIZ_VIEWPORT_Z_ORDER 10 45 44 46 using namespace Ogre; 45 47 … … 78 80 OverlayElement *mQueriesIssuedInfo; 79 81 80 void updateStats(void) 81 { 82 static unsigned int opt = 0; 83 static char str[100]; 82 EventProcessor* mEventProcessor; 83 InputReader* mInputDevice; 84 SceneNode *mCamNode; 85 Camera* mCamera; 86 Camera* mTopCam; 87 SceneManager *mSceneMgr; 88 Radian mDeathAngle; 84 89 85 static String currFps = "Current FPS: "; 86 static String avgFps = "Average FPS: "; 87 static String bestFps = "Best FPS: "; 88 static String worstFps = "Worst FPS: "; 89 static String tris = "Triangle Count: "; 90 Vector3 mTranslateVector; 91 RenderWindow* mWindow; 92 bool mStatsOn; 93 bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn; 94 unsigned int mNumScreenShots; 95 float mMoveScale; 96 Degree mRotScale; 97 // just to stop toggles flipping too fast 98 Real mTimeUntilNextToggle ; 99 Radian mRotX, mRotY; 100 TextureFilterOptions mFiltering; 101 int mAniso; 90 102 91 // update stats when necessary 92 try { 93 OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Core/AverageFps"); 94 OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Core/CurrFps"); 95 OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("Core/BestFps"); 96 OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Core/WorstFps"); 103 // stuff for the viz camera 104 bool mVizCamera; 105 Vector3 mVizCamTransVect; 97 106 98 const RenderTarget::FrameStats& stats = mWindow->getStatistics(); 99 100 guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); 101 guiCurr->setCaption(currFps + StringConverter::toString((int)stats.lastFPS)); 102 guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS) 103 +" "+StringConverter::toString(stats.bestFrameTime)+" ms"); 104 guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS) 105 +" "+StringConverter::toString(stats.worstFrameTime)+" ms"); 106 107 OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Core/NumTris"); 108 guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount)); 109 110 OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText"); 111 guiDbg->setCaption(mWindow->getDebugText()); 112 113 114 //-- culling stats 115 mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,": %d", opt); 116 mFrustumCulledNodesInfo->setCaption(str); 117 118 mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,": %d", opt); 119 mQueryCulledNodesInfo->setCaption(str); 120 121 mSceneMgr->getOption("NumHierarchyNodes", &opt); sprintf(str,": %d", opt); 122 mHierarchyNodesInfo->setCaption(str); 123 124 mSceneMgr->getOption("NumRenderedNodes", &opt); sprintf(str,": %d", opt); 125 mRenderedNodesInfo->setCaption(str); 126 127 // take old value into account in order to create no sudden changes 128 mSceneMgr->getOption("NumQueriesIssued", &opt); 129 mDelayedQueriesIssued = mDelayedQueriesIssued * 0.8 + (float)opt * 0.2f; 130 sprintf(str,": %d", (int)mDelayedQueriesIssued); 131 mQueriesIssuedInfo->setCaption(str); 132 133 mSceneMgr->getOption("NumTraversedNodes", &opt); 134 mDelayedTraversedNodes = mDelayedTraversedNodes * 0.8 + (float)opt * 0.2f; 135 sprintf(str,": %d", (int)mDelayedTraversedNodes); 136 mTraversedNodesInfo->setCaption(str); 137 } 138 catch(...) 139 { 140 // ignore 141 } 142 } 107 void updateStats(void); 143 108 144 109 public: … … 155 120 // Constructor takes a RenderWindow because it uses that to determine input context 156 121 KdTreeAppListener(RenderWindow* win, SceneManager* sm, Real rs, Real ms, Real rp, 157 bool useBufferedInputKeys = false, bool useBufferedInputMouse = false) 158 { 159 mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); 160 mKdTreeOverlay = OverlayManager::getSingleton().getByName("KdTree/DebugOverlay"); 122 bool useBufferedInputKeys = false, bool useBufferedInputMouse = false); 161 123 124 virtual ~KdTreeAppListener(); 162 125 163 mUseBufferedInputKeys = useBufferedInputKeys; 164 mUseBufferedInputMouse = useBufferedInputMouse; 165 mInputTypeSwitchingOn = mUseBufferedInputKeys || mUseBufferedInputMouse; 126 void initOverlayElement(OverlayElement **elInfo, String ext, 127 String name, int top, String caption); 166 128 167 if (mInputTypeSwitchingOn) 168 { 169 mEventProcessor = new EventProcessor(); 170 mEventProcessor->initialise(win); 171 mEventProcessor->startProcessingEvents(); 172 mEventProcessor->addKeyListener(this); 173 mInputDevice = mEventProcessor->getInputReader(); 129 void initStatsOverlay(); 174 130 175 } 176 else 177 { 178 mInputDevice = PlatformManager::getSingleton().createInputReader(); 179 mInputDevice->initialise(win,true, true); 180 } 131 void initKdTreeOverlay(); 181 132 182 mFreeMove = false; 183 mShowTree = false; 184 mCullCamera = false; 185 mCullTransVec = Vector3::ZERO; 186 mSeqNum = 0; 133 void showDebugOverlay(bool show); 187 134 188 mDelayedQueriesIssued = 0.0; 189 mDelayedTraversedNodes = 0.0; 135 void toggleVizCamera(); 190 136 191 mCamera = sm->getCamera("PlayerCam"); 192 mTopCam = sm->getCamera("TopCam"); 193 mSceneMgr = sm; 194 mWindow = win; 195 mRotateSpeed = rs; 196 mMoveSpeed = ms; 197 mRotationPeriod = rp; 198 mDeathAngle = 0; 199 mStatsOn = true; 200 mNumScreenShots = 0; 201 mTimeUntilNextToggle = 0; 202 mSceneDetailIndex = 0; 203 mMoveScale = 0.0f; 204 mRotScale = 0.0f; 205 mTranslateVector = Vector3::ZERO; 206 mAniso = 8; 207 mFiltering = TFO_ANISOTROPIC; 137 virtual bool processUnbufferedKeyInput(const FrameEvent& evt); 208 138 209 MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering); 210 MaterialManager::getSingleton().setDefaultAnisotropy(mAniso); 139 bool processUnbufferedMouseInput(const FrameEvent& evt); 211 140 212 initKdTreeOverlay(); 213 initStatsOverlay(); 214 215 showDebugOverlay(true); 216 } 217 virtual ~KdTreeAppListener() 218 { 219 if (mInputTypeSwitchingOn) 220 { 221 delete mEventProcessor; 222 } 223 else 224 { 225 PlatformManager::getSingleton().destroyInputReader( mInputDevice ); 226 } 227 } 228 229 //----------------------------------------------------------------------- 230 void initOverlayElement(OverlayElement **elInfo, String ext, 231 String name, int top, String caption) 232 { 233 OverlayElement *el = 234 OverlayManager::getSingleton().getOverlayElement(ext + name); 235 236 (*elInfo) = OverlayManager::getSingleton().getOverlayElement(ext + name + "Info"); 237 (*elInfo)->setCaption(caption); 238 239 el->setTop(top); 240 (*elInfo)->setTop(top); 241 } 242 //----------------------------------------------------------------------- 243 void initStatsOverlay() 244 { 245 const int border_height = 10; 246 const int vert_space = 15; 247 248 //-- visibility culling stats overlay 249 int top = border_height; 250 251 String ext = "KdTree/Visibility/"; 252 253 initOverlayElement(&mFrustumCulledNodesInfo, ext, "FrustumCulledNodes", top, ": 0"); top += vert_space; 254 initOverlayElement(&mQueryCulledNodesInfo, ext, "QueryCulledNodes", top, ": 0"); top += vert_space; 255 initOverlayElement(&mTraversedNodesInfo, ext, "TraversedNodes", top, ": 0"); top += vert_space; 256 initOverlayElement(&mHierarchyNodesInfo, ext, "HierarchyNodes", top, ": 0"); top += vert_space; 257 initOverlayElement(&mRenderedNodesInfo, ext, "RenderedNodes", top, ": 0"); top += vert_space; 258 initOverlayElement(&mObjectsCountInfo, ext, "ObjectsCount", top, ": 0"); top += vert_space; 259 initOverlayElement(&mQueriesIssuedInfo, ext, "QueriesIssued", top, ": 0"); top += vert_space; 260 261 OverlayElement *visPanel = OverlayManager::getSingleton(). 262 getOverlayElement("KdTree/VisibilityStatsPanel"); 263 264 visPanel->setHeight(top + border_height); 265 } 266 //----------------------------------------------------------------------- 267 void initKdTreeOverlay() 268 { 269 const int border_height = 10; 270 const int vert_space = 15; 271 const String na = ": N/A"; 272 String sMD, sKT, sKI, sHL, sBM, sRM, sFM; 273 274 int top = border_height; 275 276 String ext = "KdTree/"; 277 278 int maxd; 279 if (mSceneMgr->getOption("KdTreeMaxDepth", &maxd)) 280 sMD = ": " + StringConverter::toString(maxd); 281 else 282 sMD = na; 283 284 Real kt; 285 if (mSceneMgr->getOption("KT", &kt)) 286 sKT = ": " + StringConverter::toString(kt); 287 else 288 sKT = na; 289 290 Real ki; 291 if (mSceneMgr->getOption("KI", &ki)) 292 sKI = ": " + StringConverter::toString(ki); 293 else 294 sKI = na; 295 296 int hl; 297 if (mSceneMgr->getOption("HighlightLevel", &hl)) 298 sHL = ": " + StringConverter::toString(hl); 299 else 300 sHL = na; 301 if (!mShowTree) 302 sHL = ": off"; 303 304 String bm; 305 if (mSceneMgr->getOption("BuildMethod", &bm)) 306 sBM = ": " + bm; 307 else 308 sBM = na; 309 310 String rm; 311 if (mSceneMgr->getOption("RenderMethod", &rm)) 312 { 313 if (rm == "INT") 314 sRM = ": Internal Frustum Culling"; 315 else if (rm == "VFC") 316 sRM = ": View Frustum Culling"; 317 else if (rm == "SWC") 318 sRM = ": Stop and Wait Culling"; 319 else if (rm == "CHC") 320 sRM = ": Coherent Hierarchical Culling"; 321 else 322 sRM = na; 323 } 324 else 325 sRM = na; 326 327 sFM = na; 328 if (mFreeMove) 329 sFM = ": Free"; 330 else 331 sFM = ": Ground"; 332 333 initOverlayElement(&mRenderMethodInfo, ext, "RenderMethod", top, sRM); top += vert_space; 334 initOverlayElement(&mBuildMethodInfo, ext, "BuildMethod", top, sBM); top += vert_space; 335 initOverlayElement(&mKdTreeMaxDepthInfo, ext, "KdTreeMaxDepth", top, sMD); top += vert_space; 336 initOverlayElement(&mHighlightLevelInfo, ext, "HighlightLevel", top, sHL); top += vert_space; 337 initOverlayElement(&mKTInfo, ext, "KT", top, sKT); top += vert_space; 338 initOverlayElement(&mKIInfo, ext, "KI", top, sKI); top += vert_space; 339 initOverlayElement(&mMovementInfo, ext, "Movement", top, sFM); top += vert_space; 340 341 OverlayElement *visPanel = OverlayManager::getSingleton(). 342 getOverlayElement("KdTree/OptionsPanel"); 343 344 visPanel->setHeight(top + border_height); 345 } 346 347 void showDebugOverlay(bool show) 348 { 349 if (mDebugOverlay) 350 { 351 if (show) 352 { 353 mDebugOverlay->show(); 354 mKdTreeOverlay->show(); 355 } 356 else 357 { 358 mDebugOverlay->hide(); 359 mKdTreeOverlay->hide(); 360 } 361 } 362 } 363 364 void toggleVizCamera() 365 { 366 static const int zorder = 10; 367 static nodeVizMode = 0; 368 369 nodeVizMode = (nodeVizMode + 1) % NODEVIZ_MODES_NUM; 370 371 if (nodeVizMode != 0) 372 { 373 if (!mCullCamera) 374 { 375 Viewport* tvp = mWindow->addViewport(mTopCam,zorder,0.66,0.66,0.34,0.34); 376 tvp->setBackgroundColour(ColourValue(1.0, 0.0, 0.0)); 377 tvp->setOverlaysEnabled(false); 378 379 mTopCam->setAspectRatio( 380 Real(tvp->getActualWidth())/Real(tvp->getActualHeight())); 381 mCullCamera = true; 382 mSceneMgr->setOption("VisualizeCulledNodes", &mCullCamera); 383 } 384 385 bool renderNodesForViz = (nodeVizMode == NODEVIZ_RENDER_NODES) || 386 (nodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT); 387 bool renderNodesContentForViz = (nodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT); 388 389 mSceneMgr->setOption("RenderNodesForViz", &renderNodesForViz); 390 mSceneMgr->setOption("RenderNodesContentForViz", &renderNodesContentForViz); 391 } 392 else 393 { 394 mWindow->removeViewport(zorder); 395 mCullCamera = false; 396 mSceneMgr->setOption("VisualizeCulledNodes", &mCullCamera); 397 } 398 } 399 400 virtual bool processUnbufferedKeyInput(const FrameEvent& evt) 401 { 402 // moving the cull camera 403 if (mInputDevice->isKeyDown(KC_NUMPAD2)) 404 { 405 mCullTransVec.y = -mMoveScale; 406 } 407 if (mInputDevice->isKeyDown(KC_NUMPAD8)) 408 { 409 mCullTransVec.y = mMoveScale; 410 } 411 if (mInputDevice->isKeyDown(KC_NUMPAD4)) 412 { 413 mCullTransVec.x = mMoveScale; 414 } 415 if (mInputDevice->isKeyDown(KC_NUMPAD6)) 416 { 417 mCullTransVec.x = -mMoveScale; 418 } 419 if (mInputDevice->isKeyDown(KC_SUBTRACT)) 420 { 421 mCullTransVec.z = mMoveScale; 422 } 423 if (mInputDevice->isKeyDown(KC_ADD)) 424 { 425 mCullTransVec.z = -mMoveScale; 426 } 427 428 // stuff for the overlay 429 static String sNA = ": N/A"; 430 431 static String bmOptions[] = { "Recursive", "PriorityQueue" }; 432 static String bmOptionCaptions[] = { ": Recursive", ": PriorityQueue" }; 433 static int bmOptionsSize = sizeof(bmOptions) / sizeof(String); 434 static int bmCurrent = 0; 435 436 //static String rmOptions[] = { "Recursive", "Stack", "StopAndWait", "CHC" }; 437 static String rmOptions[] = { "INT", "VFC", "SWC", "CHC" }; 438 static String rmOptionCaptions[] = 439 { 440 ": Internal Frustum Culling", 441 ": View Frustum Culling", 442 ": Stop and Wait Culling", 443 ": Coherent Hierarchical Culling" 444 }; 445 static int rmOptionsSize = sizeof(rmOptions) / sizeof (String); 446 static int rmCurrent = 0; 447 448 if ((mInputDevice->isKeyDown(KC_1) || mInputDevice->isKeyDown(KC_2)) && mTimeUntilNextToggle <= 0) 449 { 450 int currdepth; 451 if (mSceneMgr->getOption("KdTreeMaxDepth", &currdepth)) 452 { 453 if (mInputDevice->isKeyDown(KC_1)) 454 currdepth--; 455 else if (mInputDevice->isKeyDown(KC_2)) 456 currdepth++; 457 458 if (mSceneMgr->setOption("KdTreeMaxDepth", &currdepth)) 459 { 460 mKdTreeMaxDepthInfo->setCaption(": " + StringConverter::toString(currdepth)); 461 int hl; 462 if (mSceneMgr->getOption("HighlightLevel", &hl)) 463 mHighlightLevelInfo->setCaption(": " + StringConverter::toString(hl)); 464 else 465 mHighlightLevelInfo->setCaption(sNA); 466 } 467 } 468 else 469 { 470 mKdTreeMaxDepthInfo->setCaption(sNA); 471 mHighlightLevelInfo->setCaption(sNA); 472 } 473 474 if (!mShowTree) 475 mHighlightLevelInfo->setCaption(": off"); 476 477 mTimeUntilNextToggle = 0.2; 478 } 479 480 if ((mInputDevice->isKeyDown(KC_3) || mInputDevice->isKeyDown(KC_4)) && mTimeUntilNextToggle <= 0) 481 { 482 int hl; 483 if (mSceneMgr->getOption("HighlightLevel", &hl)) 484 { 485 if (mInputDevice->isKeyDown(KC_3)) 486 hl--; 487 else if (mInputDevice->isKeyDown(KC_4)) 488 hl++; 489 490 if (mSceneMgr->setOption("HighlightLevel", &hl)) 491 mHighlightLevelInfo->setCaption(": " + StringConverter::toString(hl)); 492 } 493 else 494 { 495 mHighlightLevelInfo->setCaption(sNA); 496 } 497 498 if (!mShowTree) 499 mHighlightLevelInfo->setCaption(": off"); 500 501 mTimeUntilNextToggle = 0.2; 502 } 503 504 505 if ((mInputDevice->isKeyDown(KC_5) ||mInputDevice->isKeyDown(KC_6)) && mTimeUntilNextToggle <= 0) 506 { 507 Real kt; 508 if (mSceneMgr->getOption("KT", &kt)) 509 { 510 if (mInputDevice->isKeyDown(KC_5)) 511 kt -= 0.1; 512 else if (mInputDevice->isKeyDown(KC_6)) 513 kt += 0.1; 514 515 if (kt < 0.1) 516 kt = 0.1; 517 518 if (mSceneMgr->setOption("KT", &kt)) 519 mKTInfo->setCaption(": " + StringConverter::toString(kt)); 520 } 521 else 522 { 523 mKTInfo->setCaption(sNA); 524 } 525 526 mTimeUntilNextToggle = 0.2; 527 } 528 529 if ((mInputDevice->isKeyDown(KC_7) || mInputDevice->isKeyDown(KC_8)) && mTimeUntilNextToggle <= 0) 530 { 531 Real ki; 532 if (mSceneMgr->getOption("KI", &ki)) 533 { 534 if (mInputDevice->isKeyDown(KC_7)) 535 ki -= 0.1; 536 else if (mInputDevice->isKeyDown(KC_8)) 537 ki += 0.1; 538 539 if (ki < 0.1) 540 ki = 0.1; 541 542 if (mSceneMgr->setOption("KI", &ki)) 543 mKIInfo->setCaption(": " + StringConverter::toString(ki)); 544 } 545 else 546 { 547 mKIInfo->setCaption(sNA); 548 } 549 550 mTimeUntilNextToggle = 0.2; 551 } 552 553 if (mInputDevice->isKeyDown(KC_X) && mTimeUntilNextToggle <= 0) 554 { 555 String bm; 556 if (mSceneMgr->getOption("BuildMethod", &bm)) 557 { 558 for (int idx = 0; idx < bmOptionsSize; idx++) 559 if (bmOptions[idx] == bm) 560 bmCurrent = idx; 561 bmCurrent = (bmCurrent + 1) % bmOptionsSize; 562 if (mSceneMgr->setOption("BuildMethod", &bmOptions[bmCurrent])) 563 mBuildMethodInfo->setCaption(bmOptionCaptions[bmCurrent]); 564 } 565 else 566 { 567 mBuildMethodInfo->setCaption(sNA); 568 } 569 570 mTimeUntilNextToggle = 0.5; 571 } 572 573 if (mInputDevice->isKeyDown(KC_SPACE) && mTimeUntilNextToggle <= 0) 574 { 575 String rm; 576 if (mSceneMgr->getOption("RenderMethod", &rm)) 577 { 578 for (int idx = 0; idx < rmOptionsSize; idx++) 579 if (rmOptions[idx] == rm) 580 rmCurrent = idx; 581 rmCurrent = (rmCurrent + 1) % rmOptionsSize; 582 if (mSceneMgr->setOption("RenderMethod", &rmOptions[rmCurrent])) 583 mRenderMethodInfo->setCaption(rmOptionCaptions[rmCurrent]); 584 } 585 else 586 { 587 mRenderMethodInfo->setCaption(sNA); 588 } 589 590 mTimeUntilNextToggle = 0.5; 591 } 592 593 if (mInputDevice->isKeyDown(KC_Q) && mTimeUntilNextToggle <= 0) 594 { 595 mFreeMove = !mFreeMove; 596 String move = "N/A"; 597 if (mFreeMove) 598 move = ": Free"; 599 else 600 move = ": Ground"; 601 602 mMovementInfo->setCaption(move); 603 604 mTimeUntilNextToggle = 0.5; 605 } 606 607 608 if (mInputDevice->isKeyDown(KC_BACK) && mTimeUntilNextToggle <= 0) 609 { 610 mSceneMgr->setOption("RebuildKdTree", 0); 611 mTimeUntilNextToggle = 1; 612 } 613 614 if (mInputDevice->isKeyDown(KC_N) && mTimeUntilNextToggle <= 0) 615 { 616 //Entity * ent = mSceneMgr->createEntity("randominsert" + StringConverter::toString(mSeqNum), "robot.mesh"); 617 Entity * ent = mSceneMgr->createEntity("randominsert" + StringConverter::toString(mSeqNum), "razor.mesh"); 618 //Vector3 position(Math::RangeRandom(100, 1125), -0, Math::RangeRandom(-1125, 1125)); 619 Vector3 position(Math::RangeRandom(-5000, 5000), Math::RangeRandom(-5000, 5000), Math::RangeRandom(-5000, 5000)); 620 //Quaternion orientation(Radian(Math::RangeRandom(-Math::PI, Math::PI)), Vector3::UNIT_Y); 621 Vector3 axis(Math::RangeRandom(-1,1),Math::RangeRandom(-1,1),Math::RangeRandom(-1,1)); 622 axis.normalise(); 623 Quaternion orientation(Radian(Math::RangeRandom(-Math::PI, Math::PI)), axis); 624 Vector3 scale(Math::RangeRandom(0.5, 5),Math::RangeRandom(0.5, 5),Math::RangeRandom(0.5, 5)); 625 SceneNode * anchor = mSceneMgr->getSceneNode("AnchorNode"); 626 SceneNode *sn = anchor->createChildSceneNode("RandomInsertNode" + StringConverter::toString(mSeqNum), position, orientation); 627 sn->attachObject(ent); 628 sn->setScale(scale); 629 mTimeUntilNextToggle = 0.5; 630 mSeqNum++; 631 } 632 633 if (mInputDevice->isKeyDown(KC_J) && mTimeUntilNextToggle <= 0) 634 { 635 if (mSeqNum > 0) 636 { 637 mSeqNum--; 638 mSceneMgr->destroySceneNode("RandomInsertNode" + StringConverter::toString(mSeqNum)); 639 mSceneMgr->destroyEntity("randominsert" + StringConverter::toString(mSeqNum)); 640 mTimeUntilNextToggle = 0.5; 641 } 642 } 643 644 if (mInputDevice->isKeyDown(KC_O) && mTimeUntilNextToggle <= 0) 645 { 646 LogManager::getSingleton().logMessage("############## Camera Position:"); 647 LogManager::getSingleton().logMessage("############## " + StringConverter::toString(mCamera->getPosition())); 648 LogManager::getSingleton().logMessage("############## " + StringConverter::toString(mCamera->getOrientation())); 649 LogManager::getSingleton().logMessage("############## Cull Camera Position:"); 650 LogManager::getSingleton().logMessage("############## " + StringConverter::toString(mTopCam->getPosition())); 651 LogManager::getSingleton().logMessage("############## " + StringConverter::toString(mTopCam->getOrientation())); 652 mTimeUntilNextToggle = 1.0; 653 } 654 655 if (mInputDevice->isKeyDown(KC_B) && mTimeUntilNextToggle <= 0) 656 { 657 mSceneMgr->showBoundingBoxes( ! mSceneMgr->getShowBoundingBoxes() ); 658 mTimeUntilNextToggle = 0.5; 659 } 660 661 if (mInputDevice->isKeyDown(KC_C) && mTimeUntilNextToggle <= 0) 662 { 663 toggleVizCamera(); 664 mTimeUntilNextToggle = 0.5; 665 } 666 667 if (mInputDevice->isKeyDown(KC_V) && mTimeUntilNextToggle <= 0) 668 { 669 mShowTree = !mShowTree; 670 671 if (mSceneMgr->getTypeName() == "OctreeSceneManager") 672 { 673 //(static_cast<OctreeSceneManager *>(mSceneMgr))->setShowBoxes(mShowTree); 674 mSceneMgr->setOption("ShowOctree", &mShowTree); 675 } 676 else if (mSceneMgr->getTypeName() == "KdTreeSceneManager") 677 { 678 mSceneMgr->setOption("ShowKdTree", &mShowTree); 679 //KdTreeSceneManager *sm = static_cast<KdTreeSceneManager *>(mSceneMgr); 680 //sm->setShowBoxes(!sm->getShowBoxes()); 681 //(static_cast<KdTreeSceneManager *>(mSceneMgr))->setShowBoxes(mShowTree); 682 } 683 684 if (!mShowTree) 685 mHighlightLevelInfo->setCaption(": off"); 686 else 687 { 688 int hl; 689 if (mSceneMgr->getOption("HighlightLevel", &hl)) 690 mHighlightLevelInfo->setCaption(": " + StringConverter::toString(hl)); 691 else 692 mHighlightLevelInfo->setCaption(sNA); 693 } 694 695 mTimeUntilNextToggle = 0.5; 696 } 697 698 if (mInputDevice->isKeyDown(KC_G) && mTimeUntilNextToggle <= 0) 699 { 700 bool toggleShowAllBoxes; 701 mSceneMgr->getOption("ShowAllBoxes", &toggleShowAllBoxes); 702 toggleShowAllBoxes = !toggleShowAllBoxes; 703 mSceneMgr->setOption("ShowAllBoxes", &toggleShowAllBoxes); 704 mTimeUntilNextToggle = 0.2; 705 } 706 707 if (mInputDevice->isKeyDown(KC_H) && mTimeUntilNextToggle <= 0) 708 { 709 bool toggleShow; 710 mSceneMgr->getOption("ShowNodeAABB", &toggleShow); 711 toggleShow = !toggleShow; 712 mSceneMgr->setOption("ShowNodeAABB", &toggleShow); 713 mTimeUntilNextToggle = 0.2; 714 } 715 716 if (mInputDevice->isKeyDown(KC_P)) 717 { 718 mWindow->writeContentsToTimestampedFile("Screenshot",".jpg"); 719 } 720 721 if (mInputDevice->isKeyDown(KC_A)) 722 { 723 // Move camera left 724 mTranslateVector.x = -mMoveScale; 725 } 726 727 if (mInputDevice->isKeyDown(KC_D)) 728 { 729 // Move camera RIGHT 730 mTranslateVector.x = mMoveScale; 731 } 732 733 /* Move camera forward by keypress. */ 734 if (mInputDevice->isKeyDown(KC_UP) || mInputDevice->isKeyDown(KC_W) ) 735 { 736 mTranslateVector.z = -mMoveScale; 737 } 738 739 /* Move camera backward by keypress. */ 740 if (mInputDevice->isKeyDown(KC_DOWN) || mInputDevice->isKeyDown(KC_S) ) 741 { 742 mTranslateVector.z = mMoveScale; 743 } 744 745 if (mInputDevice->isKeyDown(KC_PGUP)) 746 { 747 // Move camera up 748 mTranslateVector.y = mMoveScale; 749 } 750 751 if (mInputDevice->isKeyDown(KC_PGDOWN)) 752 { 753 // Move camera down 754 mTranslateVector.y = -mMoveScale; 755 } 756 757 if (mInputDevice->isKeyDown(KC_RIGHT)) 758 { 759 mCamera->yaw(-mRotScale); 760 } 761 762 if (mInputDevice->isKeyDown(KC_LEFT)) 763 { 764 mCamera->yaw(mRotScale); 765 } 766 767 if( mInputDevice->isKeyDown( KC_ESCAPE) ) 768 { 769 return false; 770 } 771 772 // see if switching is on, and you want to toggle 773 if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_M) && mTimeUntilNextToggle <= 0) 774 { 775 switchMouseMode(); 776 mTimeUntilNextToggle = 1; 777 } 778 779 if (mInputTypeSwitchingOn && mInputDevice->isKeyDown(KC_K) && mTimeUntilNextToggle <= 0) 780 { 781 // must be going from immediate keyboard to buffered keyboard 782 switchKeyMode(); 783 mTimeUntilNextToggle = 1; 784 } 785 if (mInputDevice->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0) 786 { 787 mStatsOn = !mStatsOn; 788 showDebugOverlay(mStatsOn); 789 790 mTimeUntilNextToggle = 1; 791 } 792 if (mInputDevice->isKeyDown(KC_T) && mTimeUntilNextToggle <= 0) 793 { 794 switch(mFiltering) 795 { 796 case TFO_BILINEAR: 797 mFiltering = TFO_TRILINEAR; 798 mAniso = 1; 799 break; 800 case TFO_TRILINEAR: 801 mFiltering = TFO_ANISOTROPIC; 802 mAniso = 8; 803 break; 804 case TFO_ANISOTROPIC: 805 mFiltering = TFO_BILINEAR; 806 mAniso = 1; 807 break; 808 default: 809 break; 810 } 811 MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering); 812 MaterialManager::getSingleton().setDefaultAnisotropy(mAniso); 813 814 815 showDebugOverlay(mStatsOn); 816 817 mTimeUntilNextToggle = 1; 818 } 819 820 if (mInputDevice->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0) 821 { 822 char tmp[20]; 823 sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots); 824 mWindow->writeContentsToFile(tmp); 825 mTimeUntilNextToggle = 0.5; 826 mWindow->setDebugText(String("Wrote ") + tmp); 827 } 828 829 if (mInputDevice->isKeyDown(KC_R) && mTimeUntilNextToggle <=0) 830 { 831 mSceneDetailIndex = (mSceneDetailIndex+1)%3 ; 832 switch(mSceneDetailIndex) { 833 case 0 : mCamera->setPolygonMode(PM_SOLID) ; break ; 834 case 1 : mCamera->setPolygonMode(PM_WIREFRAME) ; break ; 835 case 2 : mCamera->setPolygonMode(PM_POINTS) ; break ; 836 } 837 mTimeUntilNextToggle = 0.5; 838 } 839 840 static bool displayCameraDetails = false; 841 if (mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0) 842 { 843 displayCameraDetails = !displayCameraDetails; 844 mTimeUntilNextToggle = 0.5; 845 if (!displayCameraDetails) 846 mWindow->setDebugText(""); 847 } 848 if (displayCameraDetails) 849 { 850 // Print camera details 851 mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " + 852 "O: " + StringConverter::toString(mCamera->getDerivedOrientation())); 853 } 854 855 // Return true to continue rendering 856 return true; 857 } 858 859 bool processUnbufferedMouseInput(const FrameEvent& evt) 860 { 861 /* Rotation factors, may not be used if the second mouse button is pressed. */ 862 863 /* If the second mouse button is pressed, then the mouse movement results in 864 sliding the camera, otherwise we rotate. */ 865 if( mInputDevice->getMouseButton( 1 ) ) 866 { 867 mTranslateVector.x += mInputDevice->getMouseRelativeX() * 0.13; 868 mTranslateVector.y -= mInputDevice->getMouseRelativeY() * 0.13; 869 } 870 else 871 { 872 mRotX = Degree(-mInputDevice->getMouseRelativeX() * 0.13); 873 mRotY = Degree(-mInputDevice->getMouseRelativeY() * 0.13); 874 } 875 876 877 return true; 878 } 879 880 void moveCamera() 881 { 882 883 // Make all the changes to the camera 884 // Note that YAW direction is around a fixed axis (freelook style) rather than a natural YAW (e.g. airplane) 885 mCamera->yaw(mRotX); 886 mCamera->pitch(mRotY); 887 mCamera->moveRelative(mTranslateVector); 888 mTopCam->moveRelative(mCullTransVec); 889 890 if (!mFreeMove) 891 { 892 Vector3 pos = mCamera->getPosition(); 893 RaySceneQuery * rsquery = mSceneMgr->createRayQuery(Ray(pos, Vector3::NEGATIVE_UNIT_Y)); 894 RaySceneQueryResult& rsresult = rsquery->execute(); 895 896 RaySceneQueryResult::iterator it = rsresult.begin(); 897 RaySceneQueryResult::iterator end = rsresult.end(); 898 899 while (it != end && it->movable) 900 { 901 if (it->movable->getName() != "PlayerCam") 902 { 903 mCamera->setPosition(pos.x, it->movable->getWorldBoundingBox().getCenter().y + 3, pos.z); 904 break; 905 } 906 it++; 907 } 908 OGRE_DELETE(rsquery); 909 } 910 } 141 void moveCamera(); 911 142 912 143 // Override frameStarted event to process that (don't care about frameEnded) 913 bool frameStarted(const FrameEvent& evt) 914 { 915 if(mWindow->isClosed()) 916 return false; 144 bool frameStarted(const FrameEvent& evt); 917 145 918 if (!mInputTypeSwitchingOn) 919 { 920 mInputDevice->capture(); 921 } 146 bool frameEnded(const FrameEvent& evt); 922 147 148 void switchMouseMode(); 923 149 924 if ( !mUseBufferedInputMouse || !mUseBufferedInputKeys) 925 { 926 // one of the input modes is immediate, so setup what is needed for immediate mouse/key movement 927 if (mTimeUntilNextToggle >= 0) 928 mTimeUntilNextToggle -= evt.timeSinceLastFrame; 150 void switchKeyMode(); 929 151 930 // If this is the first frame, pick a speed 931 if (evt.timeSinceLastFrame == 0) 932 { 933 mMoveScale = 1; 934 mRotScale = 0.1; 935 } 936 // Otherwise scale movement units by time passed since last frame 937 else 938 { 939 // Move about 100 units per second, 940 mMoveScale = mMoveSpeed * evt.timeSinceLastFrame; 941 // Take about 10 seconds for full rotation 942 mRotScale = mRotateSpeed * evt.timeSinceLastFrame; 943 } 944 mRotX = 0; 945 mRotY = 0; 946 mTranslateVector = Vector3::ZERO; 947 mCullTransVec = Vector3::ZERO; 948 } 152 void keyClicked(KeyEvent* e); 949 153 950 if (mUseBufferedInputKeys) 951 { 952 // no need to do any processing here, it is handled by event processor and 953 // you get the results as KeyEvents 954 } 955 else 956 { 957 if (processUnbufferedKeyInput(evt) == false) 958 { 959 return false; 960 } 961 } 962 if (mUseBufferedInputMouse) 963 { 964 // no need to do any processing here, it is handled by event processor and 965 // you get the results as MouseEvents 966 } 967 else 968 { 969 if (processUnbufferedMouseInput(evt) == false) 970 { 971 return false; 972 } 973 } 974 975 if ( !mUseBufferedInputMouse || !mUseBufferedInputKeys) 976 { 977 // one of the input modes is immediate, so update the movement vector 978 979 moveCamera(); 980 981 } 982 983 Camera *followCam = mSceneMgr->getCamera("FollowCam"); 984 if (followCam->getAutoTrackTarget() != 0) 985 { 986 // Move the death thingy & update lookat camera FOV 987 SceneNode *deathPivotNode = mSceneMgr->getSceneNode("deathPivotNode"); 988 SceneNode *deathNode = mSceneMgr->getSceneNode("movingNode"); 989 SceneNode *pivotNode = mSceneMgr->getSceneNode("pivotNode"); 990 991 Vector3 fcpos = followCam->getPosition(); 992 Vector3 oldpos = deathNode->getWorldPosition(); 993 994 Radian deltaAngle = Radian(evt.timeSinceLastFrame / mRotationPeriod * Math::TWO_PI); 995 deathPivotNode->rotate(Vector3::UNIT_Y, deltaAngle); 996 pivotNode->rotate(Vector3::UNIT_Y, deltaAngle * 4); 997 998 Vector3 pos = deathNode->getWorldPosition(); 999 1000 Real olddist = (oldpos - fcpos).length(); 1001 Real dist = (pos - fcpos).length(); 1002 1003 Radian oldfov = followCam->getFOVy(); 1004 Radian fov = Radian(olddist / dist) * oldfov; 1005 1006 followCam->setFOVy(fov); 1007 } 1008 1009 return true; 1010 } 1011 1012 bool frameEnded(const FrameEvent& evt) 1013 { 1014 updateStats(); 1015 return true; 1016 } 1017 1018 void switchMouseMode() 1019 { 1020 mUseBufferedInputMouse = !mUseBufferedInputMouse; 1021 mInputDevice->setBufferedInput(mUseBufferedInputKeys, mUseBufferedInputMouse); 1022 } 1023 void switchKeyMode() 1024 { 1025 mUseBufferedInputKeys = !mUseBufferedInputKeys; 1026 mInputDevice->setBufferedInput(mUseBufferedInputKeys, mUseBufferedInputMouse); 1027 } 1028 1029 void keyClicked(KeyEvent* e) 1030 { 1031 if (e->getKeyChar() == 'm') 1032 { 1033 switchMouseMode(); 1034 } 1035 else if (e->getKeyChar() == 'k') 1036 { 1037 1038 switchKeyMode(); 1039 } 1040 1041 } 1042 void keyPressed(KeyEvent* e) {} 1043 void keyReleased(KeyEvent* e) {} 1044 1045 protected: 1046 EventProcessor* mEventProcessor; 1047 InputReader* mInputDevice; 1048 Camera* mCamera; 1049 Camera* mTopCam; 1050 SceneManager *mSceneMgr; 1051 Radian mDeathAngle; 1052 1053 Vector3 mTranslateVector; 1054 RenderWindow* mWindow; 1055 bool mStatsOn; 1056 bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn; 1057 unsigned int mNumScreenShots; 1058 float mMoveScale; 1059 Degree mRotScale; 1060 // just to stop toggles flipping too fast 1061 Real mTimeUntilNextToggle ; 1062 Radian mRotX, mRotY; 1063 TextureFilterOptions mFiltering; 1064 int mAniso; 1065 1066 // stuff for the culling camera 1067 bool mCullCamera; 1068 Vector3 mCullTransVec; 154 void keyPressed(KeyEvent* e) {}; 155 void keyReleased(KeyEvent* e) {}; 1069 156 }; 1070 157 -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/scripts/TestKdTree.vcproj
r1177 r1187 141 141 RelativePath="..\src\TestKdTree.cpp"> 142 142 </File> 143 <File 144 RelativePath="..\src\TestKdTreeAppListener.cpp"> 145 </File> 143 146 </Filter> 144 147 <Filter -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp
r1165 r1187 122 122 mTopCam->setPosition(Vector3(1232, 3990, -1477)); 123 123 // walkthrough view 124 mCamera->setPosition(Vector3(1102.56, 181.845, -350.305)); 125 mCamera->setOrientation(Quaternion(-0.977321, -0.117497, -0.174903, 0.0210273)); 124 mCamNode->setPosition(Vector3(1102.56, 181.845, -350.305)); 125 //mCamNode->setOrientation(Quaternion(-0.977321, -0.117497, -0.174903, 0.0210273)); 126 127 mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, true); 126 128 } 127 129 else 128 130 { 131 mCamNode->setPosition(Vector3(1280,600,1666)); 132 mCamNode->setOrientation(Quaternion(0.936893, -0.124586, 0.323813, 0.04306)); 133 //mCamera->lookAt(Vector3(-20,30,10)); 134 129 135 SceneNode *anchor = mSceneMgr->getRootSceneNode()->createChildSceneNode("AnchorNode"); 130 136 //SceneNode *grndan = anchor->createChildSceneNode("GroundAnchor"); … … 244 250 245 251 // Skybox 246 // mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", mPlaneDim * 2); 247 252 mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", mPlaneDim * 2); 248 253 } 249 254 … … 271 276 mFrameListener->showDebugOverlay( true ); 272 277 mRoot->addFrameListener(mFrameListener); 278 mWindow->addListener(new KdTreeAppRenderTargetListener(mSceneMgr)); 273 279 } 274 280 … … 283 289 // Create the camera 284 290 mCamera = mSceneMgr->createCamera("PlayerCam"); 291 mCamera->setNearClipDistance(1); 292 293 mCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("PlayerCamNode", Vector3(0,0,0)); 294 mCamNode->attachObject(mCamera); 295 285 296 286 297 // Position it at 500 in Z direction 287 298 //mCamera->setPosition(Vector3(0,50,500)); 288 299 //mCamera->setPosition(Vector3(500,256,666)); 289 mCamera->setPosition(Vector3(1280,600,1666));300 //mCamera->setPosition(Vector3(1280,600,1666)); 290 301 // Look back along -Z 291 302 //mCamera->lookAt(Vector3(0,50,-300)); 292 mCamera->lookAt(Vector3(-20,30,10)); 293 mCamera->setNearClipDistance(5); 294 295 mFollowCam = mSceneMgr->createCamera("FollowCam"); 296 mFollowCam->setPosition(Vector3(800,150,800)); 297 mFollowCam->setNearClipDistance(5); 298 mFollowCam->setFOVy(Angle(15)); 303 //mCamera->lookAt(Vector3(-20,30,10)); 304 305 //mFollowCam = mSceneMgr->createCamera("FollowCam"); 306 //mFollowCam->setPosition(Vector3(800,150,800)); 307 //mFollowCam->setNearClipDistance(5); 308 //mFollowCam->setFOVy(Angle(15)); 299 309 300 310 mTopCam = mSceneMgr->createCamera("TopCam"); … … 303 313 mTopCam->pitch(Radian(-Math::HALF_PI)); 304 314 mTopCam->setCullingFrustum(mCamera); 305 //mTopCam->setProjectionType(PT_ORTHOGRAPHIC); 306 //mTopCam->lookAt(Vector3(0,0,0)); 315 mTopCam->setNearClipDistance(1); 316 317 // infinite far plane? 318 if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE)) 319 { 320 mTopCam->setFarClipDistance(0); 321 mCamera->setFarClipDistance(0); 322 } 323 else 324 { 325 mTopCam->setFarClipDistance(20000); 326 mCamera->setFarClipDistance(20000); 327 } 307 328 } 308 329 … … 445 466 return false; 446 467 } 468 469 /**********************************************************************/ 470 /* VisualizationRenderTargetListener implementation */ 471 /**********************************************************************/ 472 473 474 //----------------------------------------------------------------------- 475 KdTreeAppRenderTargetListener::KdTreeAppRenderTargetListener(SceneManager *sceneMgr) 476 :RenderTargetListener(), mSceneMgr(sceneMgr) 477 { 478 } 479 //----------------------------------------------------------------------- 480 void KdTreeAppRenderTargetListener::preViewportUpdate(const RenderTargetViewportEvent &evt) 481 { 482 // visualization viewport 483 const bool showViz = evt.source->getZOrder() == VIZ_VIEWPORT_Z_ORDER; 484 const bool nShowViz = !showViz; 485 486 mSavedShadowTechnique = mSceneMgr->getShadowTechnique(); 487 mSavedAmbientLight = mSceneMgr->getAmbientLight(); 488 489 // -- ambient light must be full for visualization, shadows disabled 490 if (showViz) 491 { 492 mSceneMgr->setAmbientLight(ColourValue(1, 1, 1)); 493 mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); 494 } 495 496 mSceneMgr->setOption("PrepareVisualization", &showViz); 497 mSceneMgr->setOption("SkyBoxEnabled", &nShowViz); 498 //mSceneMgr->setOption("SkyPlaneEnabled", &showViz); 499 500 RenderTargetListener::preViewportUpdate(evt); 501 } 502 //----------------------------------------------------------------------- 503 void KdTreeAppRenderTargetListener::postRenderTargetUpdate(const RenderTargetEvent &evt) 504 { 505 // reset values 506 mSceneMgr->setShadowTechnique(mSavedShadowTechnique); 507 mSceneMgr->setAmbientLight(mSavedAmbientLight); 508 509 RenderTargetListener::postRenderTargetUpdate(evt); 510 }
Note: See TracChangeset
for help on using the changeset viewer.