Changeset 1211 for GTP/trunk/App/Demos
- Timestamp:
- 08/17/06 18:04:15 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h
r1205 r1211 72 72 }; 73 73 74 enum ShowTree 75 { 76 SHOWTREE_OFF, 77 SHOWTREE_HILITE, 78 SHOWTREE_ALL, 79 SHOWTREE_MODES_NUM 80 }; 81 74 82 enum AppState 75 83 { … … 113 121 bool useBufferedInputKeys = false, bool useBufferedInputMouse = false); 114 122 115 virtual ~KdTreeAppListener( );123 virtual ~KdTreeAppListener(void); 116 124 117 125 void initOverlayElement(OverlayElement **elInfo, String ext, 118 126 String name, int top, String caption); 119 127 120 void initStatsOverlay( );121 122 void initKdTreeOverlay( );128 void initStatsOverlay(void); 129 130 void initKdTreeOverlay(void); 123 131 124 132 void showDebugOverlay(bool show); 125 133 126 void toggleVizCamera(); 134 void toggleVizCamera(void); 135 136 void toggleShowBoxes(void); 137 138 void toggleEnhancedVisibility(void); 139 140 void toggleBuildMethod(void); 141 142 void toggleRenderMethod(void); 127 143 128 144 virtual bool processUnbufferedKeyInput(const FrameEvent& evt); … … 130 146 bool processUnbufferedMouseInput(const FrameEvent& evt); 131 147 132 void moveCamera( );148 void moveCamera(void); 133 149 134 150 // Override frameStarted event to process that (don't care about frameEnded) … … 137 153 bool frameEnded(const FrameEvent& evt); 138 154 139 void switchMouseMode( );140 141 void switchKeyMode( );155 void switchMouseMode(void); 156 157 void switchKeyMode(void); 142 158 143 159 void keyClicked(KeyEvent* e); … … 146 162 void keyReleased(KeyEvent* e) {}; 147 163 148 164 const static String NA; 149 165 protected: 150 166 // basic … … 163 179 164 180 bool mVizCamera; 165 bool mShowTree;166 181 bool mFreeMove; 167 182 bool mTopCamFollow; 183 184 int mShowTree; 168 185 169 186 // counters … … 187 204 OverlayElement *mDemoStatus; 188 205 206 207 OverlayElement *mRenderMethodInfo; 208 OverlayElement *mEnhancedVisInfo; 209 OverlayElement *mBuildMethodInfo; 189 210 OverlayElement *mKdTreeMaxDepthInfo; 211 OverlayElement *mHighlightLevelInfo; 190 212 OverlayElement *mKTInfo; 191 213 OverlayElement *mKIInfo; 192 OverlayElement *mHighlightLevelInfo;193 OverlayElement *mBuildMethodInfo;194 OverlayElement *mRenderMethodInfo;195 214 OverlayElement *mMovementInfo; 196 215 OverlayElement *mTopCamInfo; -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp
r1205 r1211 5 5 #include "TestKdTreeAppListener.h" 6 6 #include <windows.h> 7 8 const String KdTreeAppListener::NA = ": N/A"; 7 9 8 10 void KdTreeAppListener::updateStats(void) … … 86 88 mStatsOn(true), 87 89 mVizCamera(false), 88 mShowTree(false),89 90 mFreeMove(false), 90 91 mTopCamFollow(true), 92 mShowTree(SHOWTREE_OFF), 91 93 //counters 92 94 mSeqNum(0), … … 217 219 const int border_height = 10; 218 220 const int vert_space = 15; 219 const String na = ": N/A"; 220 String sMD, sKT, sKI, sHL, sBM, sRM, sFM, sTC; 221 String sMD, sKT, sKI, sHL, sBM, sRM, sFM, sTC, sEV; 221 222 222 223 int top = border_height; … … 228 229 sMD = ": " + StringConverter::toString(maxd); 229 230 else 230 sMD = na;231 sMD = NA; 231 232 232 233 Real kt; … … 234 235 sKT = ": " + StringConverter::toString(kt); 235 236 else 236 sKT = na;237 sKT = NA; 237 238 238 239 Real ki; … … 240 241 sKI = ": " + StringConverter::toString(ki); 241 242 else 242 sKI = na;243 sKI = NA; 243 244 244 245 int hl; … … 246 247 sHL = ": " + StringConverter::toString(hl); 247 248 else 248 sHL = na;249 if ( !mShowTree)249 sHL = NA; 250 if (mShowTree == SHOWTREE_OFF) 250 251 sHL = ": off"; 251 252 … … 254 255 sBM = ": " + bm; 255 256 else 256 sBM = na;257 sBM = NA; 257 258 258 259 String rm; … … 268 269 sRM = ": Coherent Hierarchical Culling"; 269 270 else 270 sRM = na; 271 } 272 else 273 sRM = na; 274 275 sFM = na; 271 sRM = NA; 272 } 273 else 274 sRM = NA; 275 276 bool enh; 277 if (mSceneMgr->getOption("EnhancedVisibility", &enh)) 278 { 279 if (enh) 280 sEV = ": Enhanced"; 281 else 282 sEV = ": Simple"; 283 } 284 else 285 { 286 sEV = NA; 287 } 288 289 sFM = NA; 276 290 if (mFreeMove) 277 291 sFM = ": Free"; … … 279 293 sFM = ": Ground"; 280 294 281 sTC = na;295 sTC = NA; 282 296 if (mTopCamFollow) 283 297 sTC = ": Follow"; … … 286 300 287 301 initOverlayElement(&mRenderMethodInfo, ext, "RenderMethod", top, sRM); top += vert_space; 302 initOverlayElement(&mEnhancedVisInfo, ext, "EnhancedVis", top, sEV); top += vert_space; 288 303 initOverlayElement(&mBuildMethodInfo, ext, "BuildMethod", top, sBM); top += vert_space; 289 304 initOverlayElement(&mKdTreeMaxDepthInfo, ext, "KdTreeMaxDepth", top, sMD); top += vert_space; … … 353 368 } 354 369 370 void KdTreeAppListener::toggleShowBoxes() 371 { 372 mShowTree = (mShowTree + 1) % SHOWTREE_MODES_NUM; 373 bool show = false, all = false; 374 375 switch (mShowTree) 376 { 377 case SHOWTREE_OFF: 378 break; 379 case SHOWTREE_HILITE: 380 show = true; 381 break; 382 case SHOWTREE_ALL: 383 show = all = true; 384 break; 385 } 386 387 // set display 388 389 if (mSceneMgr->getTypeName() == "OctreeSceneManager") 390 mSceneMgr->setOption("ShowOctree", &show); 391 else if (mSceneMgr->getTypeName() == "KdTreeSceneManager") 392 mSceneMgr->setOption("ShowKdTree", &show); 393 394 // set showall 395 mSceneMgr->setOption("ShowAllBoxes", &all); 396 397 if (!show) 398 mHighlightLevelInfo->setCaption(": off"); 399 else 400 { 401 int hl; 402 if (mSceneMgr->getOption("HiLiteLevel", &hl)) 403 mHighlightLevelInfo->setCaption(": " + StringConverter::toString(hl)); 404 else 405 mHighlightLevelInfo->setCaption(NA); 406 } 407 } 408 409 void KdTreeAppListener::toggleEnhancedVisibility() 410 { 411 bool mode; 412 if (mSceneMgr->getOption("EnhancedVisibility", &mode)) 413 { 414 mode = !mode; 415 if (mSceneMgr->setOption("EnhancedVisibility", &mode)) 416 { 417 if (mode) 418 mEnhancedVisInfo->setCaption(": Enhanced"); 419 else 420 mEnhancedVisInfo->setCaption(": Simple"); 421 } 422 } 423 else 424 { 425 mEnhancedVisInfo->setCaption(NA); 426 } 427 } 428 429 void KdTreeAppListener::toggleBuildMethod() 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 String bm; 437 if (mSceneMgr->getOption("BuildMethod", &bm)) 438 { 439 for (int idx = 0; idx < bmOptionsSize; idx++) 440 if (bmOptions[idx] == bm) 441 bmCurrent = idx; 442 bmCurrent = (bmCurrent + 1) % bmOptionsSize; 443 if (mSceneMgr->setOption("BuildMethod", &bmOptions[bmCurrent])) 444 mBuildMethodInfo->setCaption(bmOptionCaptions[bmCurrent]); 445 } 446 else 447 { 448 mBuildMethodInfo->setCaption(NA); 449 } 450 } 451 452 void KdTreeAppListener::toggleRenderMethod() 453 { 454 static String rmOptions[] = { "INT", "VFC", "SWC", "CHC" }; 455 static String rmOptionCaptions[] = 456 { 457 ": Internal Frustum Culling", 458 ": View Frustum Culling", 459 ": Stop and Wait Culling", 460 ": Coherent Hierarchical Culling" 461 }; 462 static int rmOptionsSize = sizeof(rmOptions) / sizeof (String); 463 static int rmCurrent = 0; 464 465 String rm; 466 if (mSceneMgr->getOption("RenderMethod", &rm)) 467 { 468 for (int idx = 0; idx < rmOptionsSize; idx++) 469 if (rmOptions[idx] == rm) 470 rmCurrent = idx; 471 rmCurrent = (rmCurrent + 1) % rmOptionsSize; 472 if (mSceneMgr->setOption("RenderMethod", &rmOptions[rmCurrent])) 473 mRenderMethodInfo->setCaption(rmOptionCaptions[rmCurrent]); 474 } 475 else 476 { 477 mRenderMethodInfo->setCaption(NA); 478 } 479 } 480 355 481 bool KdTreeAppListener::processUnbufferedKeyInput(const FrameEvent& evt) 356 482 { … … 364 490 } 365 491 492 if (mInputDevice->isKeyDown(KC_F1) && mTimeUntilNextToggle <= 0) 493 { 494 // TODO show help overlay 495 } 496 497 // show/hide vis viewport 498 if (mInputDevice->isKeyDown(KC_F2) && mTimeUntilNextToggle <= 0) 499 { 500 toggleVizCamera(); 501 mTimeUntilNextToggle = 0.5; 502 } 503 504 // show/hide kdtree boxes 505 if (mInputDevice->isKeyDown(KC_F3) && mTimeUntilNextToggle <= 0) 506 { 507 toggleShowBoxes(); 508 mTimeUntilNextToggle = 0.5; 509 } 510 511 if (mInputDevice->isKeyDown(KC_F4) && mTimeUntilNextToggle <= 0) 512 { 513 bool toggleShow; 514 mSceneMgr->getOption("ShowNodes", &toggleShow); 515 toggleShow = !toggleShow; 516 mSceneMgr->setOption("ShowNodes", &toggleShow); 517 mTimeUntilNextToggle = 0.5; 518 } 519 366 520 // demo recording stuff 367 521 if (mInputDevice->isKeyDown(KC_F5) && mTimeUntilNextToggle <= 0) … … 384 538 } 385 539 540 if (mInputDevice->isKeyDown(KC_F11) && mTimeUntilNextToggle <= 0) 541 { 542 toggleBuildMethod(); 543 mTimeUntilNextToggle = 0.5; 544 } 545 546 if (mInputDevice->isKeyDown(KC_SPACE) && mTimeUntilNextToggle <= 0) 547 { 548 toggleRenderMethod(); 549 mTimeUntilNextToggle = 0.5; 550 } 551 552 if (mInputDevice->isKeyDown(KC_V) && mTimeUntilNextToggle <= 0) 553 { 554 toggleEnhancedVisibility(); 555 mTimeUntilNextToggle = 0.5; 556 } 557 558 if (mInputDevice->isKeyDown(KC_B) && mTimeUntilNextToggle <= 0) 559 { 560 mSceneMgr->showBoundingBoxes( ! mSceneMgr->getShowBoundingBoxes() ); 561 mTimeUntilNextToggle = 0.5; 562 } 563 386 564 const static int vizCamSpeedup = 12; 387 565 // moving the cull camera … … 410 588 mVizCamTransVect.z = -mMoveScale * vizCamSpeedup; 411 589 } 412 413 // stuff for the overlay414 const static String sNA = ": N/A";415 416 static String bmOptions[] = { "Recursive", "PriorityQueue" };417 static String bmOptionCaptions[] = { ": Recursive", ": PriorityQueue" };418 static int bmOptionsSize = sizeof(bmOptions) / sizeof(String);419 static int bmCurrent = 0;420 421 //static String rmOptions[] = { "Recursive", "Stack", "StopAndWait", "CHC" };422 static String rmOptions[] = { "INT", "VFC", "SWC", "CHC" };423 static String rmOptionCaptions[] =424 {425 ": Internal Frustum Culling",426 ": View Frustum Culling",427 ": Stop and Wait Culling",428 ": Coherent Hierarchical Culling"429 };430 static int rmOptionsSize = sizeof(rmOptions) / sizeof (String);431 static int rmCurrent = 0;432 590 433 591 if ((mInputDevice->isKeyDown(KC_1) || mInputDevice->isKeyDown(KC_2)) && mTimeUntilNextToggle <= 0) … … 448 606 mHighlightLevelInfo->setCaption(": " + StringConverter::toString(hl)); 449 607 else 450 mHighlightLevelInfo->setCaption( sNA);608 mHighlightLevelInfo->setCaption(NA); 451 609 } 452 610 } 453 611 else 454 612 { 455 mKdTreeMaxDepthInfo->setCaption( sNA);456 mHighlightLevelInfo->setCaption( sNA);457 } 458 459 if ( !mShowTree)613 mKdTreeMaxDepthInfo->setCaption(NA); 614 mHighlightLevelInfo->setCaption(NA); 615 } 616 617 if (mShowTree == SHOWTREE_OFF) 460 618 mHighlightLevelInfo->setCaption(": off"); 461 619 … … 478 636 else 479 637 { 480 mHighlightLevelInfo->setCaption( sNA);481 } 482 483 if ( !mShowTree)638 mHighlightLevelInfo->setCaption(NA); 639 } 640 641 if (mShowTree == SHOWTREE_OFF) 484 642 mHighlightLevelInfo->setCaption(": off"); 485 643 … … 506 664 else 507 665 { 508 mKTInfo->setCaption( sNA);666 mKTInfo->setCaption(NA); 509 667 } 510 668 … … 530 688 else 531 689 { 532 mKIInfo->setCaption( sNA);690 mKIInfo->setCaption(NA); 533 691 } 534 692 535 693 mTimeUntilNextToggle = 0.2; 536 }537 538 if (mInputDevice->isKeyDown(KC_X) && mTimeUntilNextToggle <= 0)539 {540 String bm;541 if (mSceneMgr->getOption("BuildMethod", &bm))542 {543 for (int idx = 0; idx < bmOptionsSize; idx++)544 if (bmOptions[idx] == bm)545 bmCurrent = idx;546 bmCurrent = (bmCurrent + 1) % bmOptionsSize;547 if (mSceneMgr->setOption("BuildMethod", &bmOptions[bmCurrent]))548 mBuildMethodInfo->setCaption(bmOptionCaptions[bmCurrent]);549 }550 else551 {552 mBuildMethodInfo->setCaption(sNA);553 }554 555 mTimeUntilNextToggle = 0.5;556 }557 558 if (mInputDevice->isKeyDown(KC_SPACE) && mTimeUntilNextToggle <= 0)559 {560 String rm;561 if (mSceneMgr->getOption("RenderMethod", &rm))562 {563 for (int idx = 0; idx < rmOptionsSize; idx++)564 if (rmOptions[idx] == rm)565 rmCurrent = idx;566 rmCurrent = (rmCurrent + 1) % rmOptionsSize;567 if (mSceneMgr->setOption("RenderMethod", &rmOptions[rmCurrent]))568 mRenderMethodInfo->setCaption(rmOptionCaptions[rmCurrent]);569 }570 else571 {572 mRenderMethodInfo->setCaption(sNA);573 }574 575 mTimeUntilNextToggle = 0.5;576 694 } 577 695 … … 610 728 } 611 729 612 if (mInputDevice->isKeyDown(KC_N) && mTimeUntilNextToggle <= 0)613 {614 //Entity * ent = mSceneMgr->createEntity("randominsert" + StringConverter::toString(mSeqNum), "robot.mesh");615 Entity * ent = mSceneMgr->createEntity("randominsert" + StringConverter::toString(mSeqNum), "razor.mesh");616 //Vector3 position(Math::RangeRandom(100, 1125), -0, Math::RangeRandom(-1125, 1125));617 Vector3 position(Math::RangeRandom(-5000, 5000), Math::RangeRandom(-5000, 5000), Math::RangeRandom(-5000, 5000));618 //Quaternion orientation(Radian(Math::RangeRandom(-Math::PI, Math::PI)), Vector3::UNIT_Y);619 Vector3 axis(Math::RangeRandom(-1,1),Math::RangeRandom(-1,1),Math::RangeRandom(-1,1));620 axis.normalise();621 Quaternion orientation(Radian(Math::RangeRandom(-Math::PI, Math::PI)), axis);622 Vector3 scale(Math::RangeRandom(0.5, 5),Math::RangeRandom(0.5, 5),Math::RangeRandom(0.5, 5));623 SceneNode * anchor = mSceneMgr->getSceneNode("AnchorNode");624 SceneNode *sn = anchor->createChildSceneNode("RandomInsertNode" + StringConverter::toString(mSeqNum), position, orientation);625 sn->attachObject(ent);626 sn->setScale(scale);627 mTimeUntilNextToggle = 0.5;628 mSeqNum++;629 }630 631 if (mInputDevice->isKeyDown(KC_J) && mTimeUntilNextToggle <= 0)632 {633 if (mSeqNum > 0)634 {635 mSeqNum--;636 mSceneMgr->destroySceneNode("RandomInsertNode" + StringConverter::toString(mSeqNum));637 mSceneMgr->destroyEntity("randominsert" + StringConverter::toString(mSeqNum));638 mTimeUntilNextToggle = 0.5;639 }640 }730 //if (mInputDevice->isKeyDown(KC_N) && mTimeUntilNextToggle <= 0) 731 //{ 732 // //Entity * ent = mSceneMgr->createEntity("randominsert" + StringConverter::toString(mSeqNum), "robot.mesh"); 733 // Entity * ent = mSceneMgr->createEntity("randominsert" + StringConverter::toString(mSeqNum), "razor.mesh"); 734 // //Vector3 position(Math::RangeRandom(100, 1125), -0, Math::RangeRandom(-1125, 1125)); 735 // Vector3 position(Math::RangeRandom(-5000, 5000), Math::RangeRandom(-5000, 5000), Math::RangeRandom(-5000, 5000)); 736 // //Quaternion orientation(Radian(Math::RangeRandom(-Math::PI, Math::PI)), Vector3::UNIT_Y); 737 // Vector3 axis(Math::RangeRandom(-1,1),Math::RangeRandom(-1,1),Math::RangeRandom(-1,1)); 738 // axis.normalise(); 739 // Quaternion orientation(Radian(Math::RangeRandom(-Math::PI, Math::PI)), axis); 740 // Vector3 scale(Math::RangeRandom(0.5, 5),Math::RangeRandom(0.5, 5),Math::RangeRandom(0.5, 5)); 741 // SceneNode * anchor = mSceneMgr->getSceneNode("AnchorNode"); 742 // SceneNode *sn = anchor->createChildSceneNode("RandomInsertNode" + StringConverter::toString(mSeqNum), position, orientation); 743 // sn->attachObject(ent); 744 // sn->setScale(scale); 745 // mTimeUntilNextToggle = 0.5; 746 // mSeqNum++; 747 //} 748 749 //if (mInputDevice->isKeyDown(KC_J) && mTimeUntilNextToggle <= 0) 750 //{ 751 // if (mSeqNum > 0) 752 // { 753 // mSeqNum--; 754 // mSceneMgr->destroySceneNode("RandomInsertNode" + StringConverter::toString(mSeqNum)); 755 // mSceneMgr->destroyEntity("randominsert" + StringConverter::toString(mSeqNum)); 756 // mTimeUntilNextToggle = 0.5; 757 // } 758 //} 641 759 642 760 //if (mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0) … … 650 768 // mTimeUntilNextToggle = 1.0; 651 769 //} 652 653 if (mInputDevice->isKeyDown(KC_B) && mTimeUntilNextToggle <= 0)654 {655 mSceneMgr->showBoundingBoxes( ! mSceneMgr->getShowBoundingBoxes() );656 mTimeUntilNextToggle = 0.5;657 }658 659 if (mInputDevice->isKeyDown(KC_C) && mTimeUntilNextToggle <= 0)660 {661 toggleVizCamera();662 mTimeUntilNextToggle = 0.5;663 }664 665 if (mInputDevice->isKeyDown(KC_V) && mTimeUntilNextToggle <= 0)666 {667 mShowTree = !mShowTree;668 669 if (mSceneMgr->getTypeName() == "OctreeSceneManager")670 {671 //(static_cast<OctreeSceneManager *>(mSceneMgr))->setShowBoxes(mShowTree);672 mSceneMgr->setOption("ShowOctree", &mShowTree);673 }674 else if (mSceneMgr->getTypeName() == "KdTreeSceneManager")675 {676 mSceneMgr->setOption("ShowKdTree", &mShowTree);677 //KdTreeSceneManager *sm = static_cast<KdTreeSceneManager *>(mSceneMgr);678 //sm->setShowBoxes(!sm->getShowBoxes());679 //(static_cast<KdTreeSceneManager *>(mSceneMgr))->setShowBoxes(mShowTree);680 }681 682 if (!mShowTree)683 mHighlightLevelInfo->setCaption(": off");684 else685 {686 int hl;687 if (mSceneMgr->getOption("HiLiteLevel", &hl))688 mHighlightLevelInfo->setCaption(": " + StringConverter::toString(hl));689 else690 mHighlightLevelInfo->setCaption(sNA);691 }692 693 mTimeUntilNextToggle = 0.5;694 }695 696 if (mInputDevice->isKeyDown(KC_G) && mTimeUntilNextToggle <= 0)697 {698 bool toggleShowAllBoxes;699 mSceneMgr->getOption("ShowAllBoxes", &toggleShowAllBoxes);700 toggleShowAllBoxes = !toggleShowAllBoxes;701 mSceneMgr->setOption("ShowAllBoxes", &toggleShowAllBoxes);702 mTimeUntilNextToggle = 0.2;703 }704 705 if (mInputDevice->isKeyDown(KC_H) && mTimeUntilNextToggle <= 0)706 {707 bool toggleShow;708 mSceneMgr->getOption("ShowNodes", &toggleShow);709 toggleShow = !toggleShow;710 mSceneMgr->setOption("ShowNodes", &toggleShow);711 mTimeUntilNextToggle = 0.2;712 }713 714 if (mInputDevice->isKeyDown(KC_O))715 {716 mWindow->writeContentsToTimestampedFile("Screenshot",".jpg");717 }718 770 719 771 if (mInputDevice->isKeyDown(KC_A))
Note: See TracChangeset
for help on using the changeset viewer.