Changeset 1183 for GTP/trunk/App/Demos/Vis
- Timestamp:
- 08/04/06 17:38:52 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h
r1177 r1183 50 50 Real mMoveSpeed; 51 51 Degree mRotateSpeed; 52 Overlay* mDebugOverlay;53 Overlay* mKdTreeOverlay;54 52 Real mRotationPeriod; 55 53 bool mShowTree; 56 54 bool mFreeMove; 57 55 56 Real mDelayedQueriesIssued; 57 Real mDelayedTraversedNodes; 58 58 59 int mSeqNum; 60 61 Overlay* mDebugOverlay; 62 Overlay* mKdTreeOverlay; 63 64 OverlayElement *mKdTreeMaxDepthInfo; 65 OverlayElement *mKTInfo; 66 OverlayElement *mKIInfo; 67 OverlayElement *mHighlightLevelInfo; 68 OverlayElement *mBuildMethodInfo; 69 OverlayElement *mRenderMethodInfo; 70 OverlayElement *mMovementInfo; 71 72 OverlayElement *mFrustumCulledNodesInfo; 73 OverlayElement *mQueryCulledNodesInfo; 74 OverlayElement *mTraversedNodesInfo; 75 OverlayElement *mHierarchyNodesInfo; 76 OverlayElement *mRenderedNodesInfo; 77 OverlayElement *mObjectsCountInfo; 78 OverlayElement *mQueriesIssuedInfo; 59 79 60 80 void updateStats(void) 61 81 { 82 static unsigned int opt = 0; 83 static char str[100]; 84 62 85 static String currFps = "Current FPS: "; 63 86 static String avgFps = "Average FPS: "; … … 76 99 77 100 guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); 78 guiCurr->setCaption(currFps + StringConverter::toString( stats.lastFPS));101 guiCurr->setCaption(currFps + StringConverter::toString((int)stats.lastFPS)); 79 102 guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS) 80 103 +" "+StringConverter::toString(stats.bestFrameTime)+" ms"); … … 87 110 OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText"); 88 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); 89 137 } 90 138 catch(...) … … 95 143 96 144 public: 145 146 // visualization modes for scene nodes 147 enum 148 { 149 NODEVIZ_NONE, 150 NODEVIZ_RENDER_NODES, 151 NODEVIZ_RENDER_NODES_AND_CONTENT, 152 NODEVIZ_MODES_NUM 153 }; 97 154 98 155 // Constructor takes a RenderWindow because it uses that to determine input context … … 128 185 mCullTransVec = Vector3::ZERO; 129 186 mSeqNum = 0; 187 188 mDelayedQueriesIssued = 0.0; 189 mDelayedTraversedNodes = 0.0; 130 190 131 191 mCamera = sm->getCamera("PlayerCam"); … … 151 211 152 212 initKdTreeOverlay(); 213 initStatsOverlay(); 153 214 154 215 showDebugOverlay(true); … … 166 227 } 167 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 //----------------------------------------------------------------------- 168 267 void initKdTreeOverlay() 169 268 { 170 String na = " N/A"; 171 String value; 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/"; 172 277 173 278 int maxd; 174 279 if (mSceneMgr->getOption("KdTreeMaxDepth", &maxd)) 175 value = "" + StringConverter::toString(maxd);280 sMD = ": " + StringConverter::toString(maxd); 176 281 else 177 value = na; 178 String caption = OverlayManager::getSingleton().getOverlayElement("KdTree/Depth")->getCaption(); 179 OverlayManager::getSingleton().getOverlayElement("KdTree/Depth")->setCaption(caption + value); 282 sMD = na; 180 283 181 284 Real kt; 182 285 if (mSceneMgr->getOption("KT", &kt)) 183 value = "" + StringConverter::toString(kt);286 sKT = ": " + StringConverter::toString(kt); 184 287 else 185 value = na; 186 caption = OverlayManager::getSingleton().getOverlayElement("KdTree/KT")->getCaption(); 187 OverlayManager::getSingleton().getOverlayElement("KdTree/KT")->setCaption(caption + value); 288 sKT = na; 188 289 189 290 Real ki; 190 291 if (mSceneMgr->getOption("KI", &ki)) 191 value = "" + StringConverter::toString(ki);292 sKI = ": " + StringConverter::toString(ki); 192 293 else 193 value = na; 194 caption = OverlayManager::getSingleton().getOverlayElement("KdTree/KI")->getCaption(); 195 OverlayManager::getSingleton().getOverlayElement("KdTree/KI")->setCaption(caption + value); 294 sKI = na; 196 295 197 296 int hl; 198 297 if (mSceneMgr->getOption("HighlightLevel", &hl)) 199 value = "" + StringConverter::toString(hl);298 sHL = ": " + StringConverter::toString(hl); 200 299 else 201 value= na;300 sHL = na; 202 301 if (!mShowTree) 203 value = " off"; 204 caption = OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->getCaption(); 205 OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->setCaption(caption + value); 302 sHL = ": off"; 206 303 207 304 String bm; 208 305 if (mSceneMgr->getOption("BuildMethod", &bm)) 209 value = "" + bm;306 sBM = ": " + bm; 210 307 else 211 value = na; 212 caption = OverlayManager::getSingleton().getOverlayElement("KdTree/BuildMethod")->getCaption(); 213 OverlayManager::getSingleton().getOverlayElement("KdTree/BuildMethod")->setCaption(caption + value); 308 sBM = na; 214 309 215 310 String rm; … … 217 312 { 218 313 if (rm == "INT") 219 value = "Internal Frustum Culling";314 sRM = ": Internal Frustum Culling"; 220 315 else if (rm == "VFC") 221 value = "View Frustum Culling";316 sRM = ": View Frustum Culling"; 222 317 else if (rm == "SWC") 223 value = "Stop and Wait Culling";318 sRM = ": Stop and Wait Culling"; 224 319 else if (rm == "CHC") 225 value = "Coherent Hierarchical Culling";320 sRM = ": Coherent Hierarchical Culling"; 226 321 else 227 value= na;322 sRM = na; 228 323 } 229 324 else 230 value = na; 231 caption = OverlayManager::getSingleton().getOverlayElement("KdTree/RenderMethod")->getCaption(); 232 OverlayManager::getSingleton().getOverlayElement("KdTree/RenderMethod")->setCaption(caption + value); 233 234 value = na; 325 sRM = na; 326 327 sFM = na; 235 328 if (mFreeMove) 236 value = "Free";329 sFM = ": Free"; 237 330 else 238 value = " Ground"; 239 caption = OverlayManager::getSingleton().getOverlayElement("KdTree/Movement")->getCaption(); 240 OverlayManager::getSingleton().getOverlayElement("KdTree/Movement")->setCaption(caption + value); 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); 241 345 } 242 346 243 void toggleCullCamera()347 void showDebugOverlay(bool show) 244 348 { 245 mCullCamera = !mCullCamera; 246 int zorder = 2; 247 if (mCullCamera) 248 { 249 Viewport* tvp = mWindow->addViewport(mTopCam,zorder,0.66,0.66,0.34,0.34); 250 tvp->setBackgroundColour(ColourValue(1.0, 0.0, 0.0)); 251 tvp->setOverlaysEnabled(false); 252 253 mTopCam->setAspectRatio( 254 Real(tvp->getActualWidth())/Real(tvp->getActualHeight())); 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); 255 391 } 256 392 else 257 393 { 258 394 mWindow->removeViewport(zorder); 395 mCullCamera = false; 396 mSceneMgr->setOption("VisualizeCulledNodes", &mCullCamera); 259 397 } 260 398 } … … 288 426 } 289 427 290 // stuff for the kdtree overlay 291 static String sRM = "[SPACE] Algorithm: "; 292 static String sBM = "[X] Build Method: "; 293 static String sMaxDepth = "[1][2] Max Tree Depth: "; 294 static String sHL = "[3][4] Highlight: "; 295 static String sKT = "[5][6] KT: "; 296 static String sKI = "[7][8] KI: "; 297 static String sMov = "[Q] Movement: "; 428 // stuff for the overlay 429 static String sNA = ": N/A"; 298 430 299 431 static String bmOptions[] = { "Recursive", "PriorityQueue" }; 432 static String bmOptionCaptions[] = { ": Recursive", ": PriorityQueue" }; 300 433 static int bmOptionsSize = sizeof(bmOptions) / sizeof(String); 301 434 static int bmCurrent = 0; … … 305 438 static String rmOptionCaptions[] = 306 439 { 307 " Internal Frustum Culling",308 " View Frustum Culling",309 " Stop and Wait Culling",310 " Coherent Hierarchical Culling"440 ": Internal Frustum Culling", 441 ": View Frustum Culling", 442 ": Stop and Wait Culling", 443 ": Coherent Hierarchical Culling" 311 444 }; 312 445 static int rmOptionsSize = sizeof(rmOptions) / sizeof (String); … … 325 458 if (mSceneMgr->setOption("KdTreeMaxDepth", &currdepth)) 326 459 { 327 OverlayManager::getSingleton().getOverlayElement("KdTree/Depth")->setCaption(sMaxDepth+ StringConverter::toString(currdepth));460 mKdTreeMaxDepthInfo->setCaption(": " + StringConverter::toString(currdepth)); 328 461 int hl; 329 462 if (mSceneMgr->getOption("HighlightLevel", &hl)) 330 OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->setCaption(sHL+ StringConverter::toString(hl));463 mHighlightLevelInfo->setCaption(": " + StringConverter::toString(hl)); 331 464 else 332 OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->setCaption(sHL + "N/A");465 mHighlightLevelInfo->setCaption(sNA); 333 466 } 334 467 } 335 468 else 336 469 { 337 OverlayManager::getSingleton().getOverlayElement("KdTree/Depth")->setCaption(sMaxDepth + "N/A");338 OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->setCaption(sHL + "N/A");470 mKdTreeMaxDepthInfo->setCaption(sNA); 471 mHighlightLevelInfo->setCaption(sNA); 339 472 } 340 473 341 474 if (!mShowTree) 342 OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->setCaption(sHL + "off");475 mHighlightLevelInfo->setCaption(": off"); 343 476 344 477 mTimeUntilNextToggle = 0.2; … … 356 489 357 490 if (mSceneMgr->setOption("HighlightLevel", &hl)) 358 OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->setCaption(sHL+ StringConverter::toString(hl));491 mHighlightLevelInfo->setCaption(": " + StringConverter::toString(hl)); 359 492 } 360 493 else 361 494 { 362 OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->setCaption(sHL + "N/A");495 mHighlightLevelInfo->setCaption(sNA); 363 496 } 364 497 365 498 if (!mShowTree) 366 OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->setCaption(sHL + "off");499 mHighlightLevelInfo->setCaption(": off"); 367 500 368 501 mTimeUntilNextToggle = 0.2; … … 384 517 385 518 if (mSceneMgr->setOption("KT", &kt)) 386 OverlayManager::getSingleton().getOverlayElement("KdTree/KT")->setCaption(sKT+ StringConverter::toString(kt));519 mKTInfo->setCaption(": " + StringConverter::toString(kt)); 387 520 } 388 521 else 389 522 { 390 OverlayManager::getSingleton().getOverlayElement("KdTree/KT")->setCaption(sKT + "N/A");523 mKTInfo->setCaption(sNA); 391 524 } 392 525 … … 408 541 409 542 if (mSceneMgr->setOption("KI", &ki)) 410 OverlayManager::getSingleton().getOverlayElement("KdTree/KI")->setCaption(sKI+ StringConverter::toString(ki));543 mKIInfo->setCaption(": " + StringConverter::toString(ki)); 411 544 } 412 545 else 413 546 { 414 OverlayManager::getSingleton().getOverlayElement("KdTree/KI")->setCaption(sKI + "N/A");547 mKIInfo->setCaption(sNA); 415 548 } 416 549 … … 423 556 if (mSceneMgr->getOption("BuildMethod", &bm)) 424 557 { 558 for (int idx = 0; idx < bmOptionsSize; idx++) 559 if (bmOptions[idx] == bm) 560 bmCurrent = idx; 425 561 bmCurrent = (bmCurrent + 1) % bmOptionsSize; 426 562 if (mSceneMgr->setOption("BuildMethod", &bmOptions[bmCurrent])) 427 OverlayManager::getSingleton().getOverlayElement("KdTree/BuildMethod")->setCaption(sBM + bmOptions[bmCurrent]);563 mBuildMethodInfo->setCaption(bmOptionCaptions[bmCurrent]); 428 564 } 429 565 else 430 566 { 431 OverlayManager::getSingleton().getOverlayElement("KdTree/BuildMethod")->setCaption(sBM + "N/A");567 mBuildMethodInfo->setCaption(sNA); 432 568 } 433 569 … … 440 576 if (mSceneMgr->getOption("RenderMethod", &rm)) 441 577 { 578 for (int idx = 0; idx < rmOptionsSize; idx++) 579 if (rmOptions[idx] == rm) 580 rmCurrent = idx; 442 581 rmCurrent = (rmCurrent + 1) % rmOptionsSize; 443 582 if (mSceneMgr->setOption("RenderMethod", &rmOptions[rmCurrent])) 444 OverlayManager::getSingleton().getOverlayElement("KdTree/RenderMethod")->setCaption(sRM +rmOptionCaptions[rmCurrent]);583 mRenderMethodInfo->setCaption(rmOptionCaptions[rmCurrent]); 445 584 } 446 585 else 447 586 { 448 OverlayManager::getSingleton().getOverlayElement("KdTree/RenderMethod")->setCaption(sRM + "N/A");587 mRenderMethodInfo->setCaption(sNA); 449 588 } 450 589 … … 457 596 String move = "N/A"; 458 597 if (mFreeMove) 459 move = " Free";598 move = ": Free"; 460 599 else 461 move = " Ground";462 463 OverlayManager::getSingleton().getOverlayElement("KdTree/Movement")->setCaption(sMov +move);600 move = ": Ground"; 601 602 mMovementInfo->setCaption(move); 464 603 465 604 mTimeUntilNextToggle = 0.5; … … 503 642 } 504 643 505 if (mInputDevice->isKeyDown(KC_ Y) && mTimeUntilNextToggle <= 0)644 if (mInputDevice->isKeyDown(KC_O) && mTimeUntilNextToggle <= 0) 506 645 { 507 646 LogManager::getSingleton().logMessage("############## Camera Position:"); … … 522 661 if (mInputDevice->isKeyDown(KC_C) && mTimeUntilNextToggle <= 0) 523 662 { 524 toggle CullCamera();663 toggleVizCamera(); 525 664 mTimeUntilNextToggle = 0.5; 526 665 } … … 544 683 545 684 if (!mShowTree) 546 OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->setCaption(sHL + "off");685 mHighlightLevelInfo->setCaption(": off"); 547 686 else 548 687 { 549 688 int hl; 550 689 if (mSceneMgr->getOption("HighlightLevel", &hl)) 551 OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->setCaption(sHL+ StringConverter::toString(hl));690 mHighlightLevelInfo->setCaption(": " + StringConverter::toString(hl)); 552 691 else 553 OverlayManager::getSingleton().getOverlayElement("KdTree/Highlight")->setCaption(sHL + "N/A");692 mHighlightLevelInfo->setCaption(sNA); 554 693 } 555 694 … … 563 702 toggleShowAllBoxes = !toggleShowAllBoxes; 564 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); 565 713 mTimeUntilNextToggle = 0.2; 566 714 } … … 762 910 } 763 911 764 void showDebugOverlay(bool show)765 {766 if (mDebugOverlay)767 {768 if (show)769 {770 mDebugOverlay->show();771 mKdTreeOverlay->show();772 }773 else774 {775 mDebugOverlay->hide();776 mKdTreeOverlay->hide();777 }778 }779 }780 781 912 // Override frameStarted event to process that (don't care about frameEnded) 782 913 bool frameStarted(const FrameEvent& evt)
Note: See TracChangeset
for help on using the changeset viewer.