Changeset 1296 for GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src
- Timestamp:
- 08/29/06 18:28:00 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp
r1285 r1296 39 39 .addOpt("","comment", ARGUMENT_REQUIRED) 40 40 .addOpt("e","enhancevis", ARGUMENT_NONE) 41 .addOpt("","savesceneto", ARGUMENT_REQUIRED); 41 .addOpt("","savesceneto", ARGUMENT_REQUIRED) 42 .addOpt("f","faststart", ARGUMENT_NONE) 43 .addOpt("b","burnin", ARGUMENT_NONE); 42 44 43 45 … … 46 48 cmdparser.getOpt("l", options.mDemoLogfileName); 47 49 cmdparser.getOpt("comment", options.mComment); 50 options.mFastStart = cmdparser.getOpt("f"); 51 options.mBurnIn = cmdparser.getOpt("b"); 48 52 options.mDemoMode = cmdparser.getOpt("d"); 49 53 options.mEnhancedVisibility = cmdparser.getOpt("e"); … … 184 188 cfDeath.load("testKdTree.cfg"); 185 189 186 mOptions.mSceneFiles = cfDeath.getSetting("scene"); 190 mSceneFiles = cfDeath.getSetting("scene"); 191 mViewCells = cfDeath.getSetting("viewcells"); 187 192 188 193 tmp = cfDeath.getSetting("shadows"); … … 240 245 241 246 // load simple scene (planes & robots) 242 if (m Options.mSceneFiles == "")247 if (mSceneFiles == "") 243 248 { 244 249 createSimpleScene(); 250 mOptions.mSceneType = KdTreeAppListener::ST_SIMPLE; 245 251 mCamNode->setPosition(Vector3(1280,600,1666)); 246 252 mCamNode->setOrientation(Quaternion(0.936893, -0.124586, 0.323813, 0.04306)); 247 253 } 248 // load terrain, but only if terrainscenemanager selected249 else if (mOptions.mSceneFiles == TERRAIN_SCENE)250 {251 Plane waterPlane;252 253 // Set ambient light254 mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));255 256 // Create a light257 Light* l = mSceneMgr->createLight("MainLight");258 // Accept default settings: point light, white diffuse, just set position259 // NB I could attach the light to a SceneNode if I wanted it to move automatically with260 // other objects, but I don't261 l->setPosition(20,80,50);262 263 // Fog264 // NB it's VERY important to set this before calling setWorldGeometry265 // because the vertex program picked will be different266 //ColourValue fadeColour(0.93, 0.86, 0.76);267 //mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);268 //mWindow->getViewport(0)->setBackgroundColour(fadeColour);269 mWindow->getViewport(0)->setBackgroundColour(ColourValue::Blue);270 271 std::string terrain_cfg("terrain.cfg");272 273 mSceneMgr -> setWorldGeometry( terrain_cfg );274 275 // Define the required skyplane276 Plane plane;277 // 5000 world units from the camera278 plane.d = 5000;279 // Above the camera, facing down280 plane.normal = -Vector3::UNIT_Y;281 282 // read interesting params from config file283 ConfigFile terrainconf;284 std::stringstream s;285 Real x,y,z;286 287 terrainconf.load(terrain_cfg);288 289 s << terrainconf.getSetting("PageWorldX");290 s >> x;291 s.clear();292 293 s << terrainconf.getSetting("MaxHeight");294 s >> y;295 s.clear();296 297 s << terrainconf.getSetting("PageWorldZ");298 s >> z;299 s.clear();300 301 // add stuff minus gound plane302 createTerrainScene(x, y + 1500, z);303 304 // Set a nice viewpoint305 mCamNode->setPosition(707,2500,528);306 mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));307 //mCamNode->setPosition(1056.59, 467.412, 783.502);308 //mCamNode->setOrientation(Quaternion(-0.281354, 0.0204027, 0.956747, 0.0695345));309 }254 //// load terrain, but only if terrainscenemanager selected 255 //else if (mSceneFiles == TERRAIN_SCENE) 256 //{ 257 // Plane waterPlane; 258 259 // // Set ambient light 260 // mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); 261 262 // // Create a light 263 // Light* l = mSceneMgr->createLight("MainLight"); 264 // // Accept default settings: point light, white diffuse, just set position 265 // // NB I could attach the light to a SceneNode if I wanted it to move automatically with 266 // // other objects, but I don't 267 // l->setPosition(20,80,50); 268 269 // // Fog 270 // // NB it's VERY important to set this before calling setWorldGeometry 271 // // because the vertex program picked will be different 272 // //ColourValue fadeColour(0.93, 0.86, 0.76); 273 // //mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000); 274 // //mWindow->getViewport(0)->setBackgroundColour(fadeColour); 275 // mWindow->getViewport(0)->setBackgroundColour(ColourValue::Blue); 276 277 // std::string terrain_cfg("terrain.cfg"); 278 279 // mSceneMgr -> setWorldGeometry( terrain_cfg ); 280 281 // // Define the required skyplane 282 // Plane plane; 283 // // 5000 world units from the camera 284 // plane.d = 5000; 285 // // Above the camera, facing down 286 // plane.normal = -Vector3::UNIT_Y; 287 288 // // read interesting params from config file 289 // ConfigFile terrainconf; 290 // std::stringstream s; 291 // Real x,y,z; 292 // 293 // terrainconf.load(terrain_cfg); 294 295 // s << terrainconf.getSetting("PageWorldX"); 296 // s >> x; 297 // s.clear(); 298 299 // s << terrainconf.getSetting("MaxHeight"); 300 // s >> y; 301 // s.clear(); 302 303 // s << terrainconf.getSetting("PageWorldZ"); 304 // s >> z; 305 // s.clear(); 306 307 // // add stuff minus gound plane 308 // createTerrainScene(x, y + 1500, z); 309 310 // // Set a nice viewpoint 311 // mCamNode->setPosition(707,2500,528); 312 // mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 313 // //mCamNode->setPosition(1056.59, 467.412, 783.502); 314 // //mCamNode->setOrientation(Quaternion(-0.281354, 0.0204027, 0.956747, 0.0695345)); 315 //} 310 316 // load scene from file 311 317 else 312 318 { 313 319 // don't load the other stuff 314 loadScene(mOptions.mSceneFiles); 315 316 // top view 317 mTopCam->setPosition(Vector3(1232, 3990, -1477)); 318 // walkthrough view 319 mCamNode->setPosition(Vector3(827.885, 184.435, -524.984)); 320 mCamNode->setOrientation(Quaternion(0.98935, 0.0348082, -0.141246, 0.00496945)); 321 322 mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, true); 320 loadScene(mSceneFiles); 321 322 if (mOptions.mSceneType == KdTreeAppListener::ST_GEOMETRY) 323 { 324 // initial position 325 mCamNode->setPosition(Vector3(827.885, 184.435, -524.984)); 326 mCamNode->setOrientation(Quaternion(0.98935, 0.0348082, -0.141246, 0.00496945)); 327 // initial position for vis camera 328 mTopCam->setPosition(Vector3(1232, 3990, -1477)); 329 330 // try loading view cells if specified and if scene manager supports it 331 if (!mViewCells.empty()) 332 mSceneMgr->setOption("LoadViewCells", mViewCells.c_str()); 333 334 // sky box 335 mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, true); 336 } 337 else if (mOptions.mSceneType == KdTreeAppListener::ST_TERRAIN) 338 { 339 // initial position 340 mCamNode->setPosition(707,2500,528); 341 mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 342 343 // sky box 344 mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", mPlaneDim * 2); 345 } 323 346 } 324 347 } … … 329 352 Vector3 scale(0.3, 0.3, 0.3); 330 353 Entity *deaths; 331 SceneNode *nodes ;354 SceneNode *nodes, *anchor; 332 355 std::string entName; 333 356 std::string nodeName; … … 336 359 max_x -= 100; max_z -= 100; 337 360 338 SceneNode *anchor = mSceneMgr->getRootSceneNode()->createChildSceneNode("AnchorNode"); 361 try 362 { 363 anchor = mSceneMgr->getSceneNode("AnchorNode"); 364 } 365 catch (Exception) 366 { 367 anchor = mSceneMgr->getRootSceneNode()->createChildSceneNode("AnchorNode"); 368 } 339 369 340 370 if (mSelectEntities & ENT_RND) … … 348 378 max_y, 349 379 Math::RangeRandom(min_z, max_z)), 0, max_y); 380 381 // hack to fill valleys 382 if (pos == Vector3::ZERO) 383 { 384 -- i; 385 continue; 386 } 387 350 388 deaths = mSceneMgr->createEntity(cat(entName,666,i),"robot.mesh"); 351 389 if (mShadowsEnabled) … … 369 407 Math::RangeRandom(min_z, max_z)), 370 408 Math::RangeRandom(20, 500), max_y); 409 410 // hack to fill valleys 411 if (pos == Vector3::ZERO) 412 { 413 -- i; 414 continue; 415 } 416 371 417 deaths = mSceneMgr->createEntity(cat(entName,666,i),"razor.mesh"); 372 418 if (mShadowsEnabled) … … 398 444 node_ball->setScale(scale/10); 399 445 } 400 401 mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", mPlaneDim * 2);402 446 } 403 447 … … 644 688 // You can skip this and use root.restoreConfig() to load configuration 645 689 // settings if you were sure there are valid ones saved in ogre.cfg 646 #ifdef KDTREE_FASTSTART 647 if(mRoot->restoreConfig()) 648 #else 649 if(mRoot->showConfigDialog()) 650 #endif 690 bool cont = false; 691 692 if (mOptions.mFastStart) 693 cont = mRoot->restoreConfig(); 694 else 695 cont = mRoot->showConfigDialog(); 696 697 if (cont) 651 698 { 652 699 // If returned true, user clicked OK so initialise … … 700 747 result = vect; 701 748 702 if (mOptions.mScene Files == TERRAIN_SCENE)749 if (mOptions.mSceneType == KdTreeAppListener::ST_TERRAIN) 703 750 { 704 751 updateRay.setOrigin(vect); … … 732 779 } 733 780 781 // hack to fill the valleys only - make cap lower than max height 782 if (result.y >= cap) 783 return Vector3::ZERO; 784 734 785 result.y = result.y + offset > cap ? cap : result.y + offset; 735 786 … … 780 831 { 781 832 // load iv files 782 loadres = loadSceneIV(fn, mSceneMgr->getRootSceneNode(), i); 833 loadres = loadSceneIV(fn, mSceneMgr->getRootSceneNode(), i); 834 mOptions.mSceneType = KdTreeAppListener::ST_GEOMETRY; 783 835 } 784 836 else if (strstr(fn.c_str(), ".cfg")) … … 786 838 // load terrain from cfg 787 839 loadres = loadSceneCfg(fn, mSceneMgr->getRootSceneNode(), i); 840 mOptions.mSceneType = KdTreeAppListener::ST_TERRAIN; 788 841 } 789 842 else if (strstr(fn.c_str(), ".txt")) … … 899 952 s.clear(); 900 953 s << line[2]; 901 s >> or. x >> or.y >> or.z >> or.w;954 s >> or.w >> or.x >> or.y >> or.z; 902 955 s.clear(); 903 956 s << line[3]; … … 912 965 } 913 966 // build node 914 SceneNode *newnode = anchor->createChildSceneNode(node, pos, or);915 newnode->setScale(scale);967 //SceneNode *newnode = anchor->createChildSceneNode(node, pos, or); 968 SceneNode *newnode = anchor->createChildSceneNode(node); 916 969 for (EntMeshMap::iterator emmit = emm.begin(); emmit != emm.end(); emmit ++) 917 970 { … … 919 972 newnode->attachObject(entity); 920 973 } 974 newnode->setPosition(pos); 975 newnode->setOrientation(or); 976 newnode->setScale(scale); 921 977 emm.clear(); 922 978 } -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp
r1285 r1296 113 113 mTopCamFollow(true), 114 114 mShowTree(SHOWTREE_OFF), 115 // view cells 116 mUseViewCells(false), 117 mUseVisibilityFilter(false), 115 118 //counters 116 119 mSeqNum(0), … … 164 167 mCamNode = sm->getSceneNode("PlayerCamNode"); 165 168 169 sm->getOption("UseViewCells", &mUseViewCells); 170 sm->getOption("UseVisibilityFilter", &mUseVisibilityFilter); 171 166 172 mRaySceneQuery = mSceneMgr->createRayQuery(Ray(mCamNode->getPosition(), Vector3::NEGATIVE_UNIT_Y)); 167 173 … … 248 254 249 255 String ext = "KdTree/"; 250 String sMD, sKT, sKI, sHL, sBM, sRM, sFM, sTC, sEV ;256 String sMD, sKT, sKI, sHL, sBM, sRM, sFM, sTC, sEV, sVC, sVF; 251 257 252 258 int maxd; … … 319 325 else 320 326 sTC = ": Free"; 327 328 if (mSceneMgr->getOption("UseViewCells", &mUseViewCells)) 329 { 330 if (mUseViewCells) 331 sVC = ": on"; 332 else 333 sVC = ": off"; 334 } 335 else 336 { 337 sVC = NA; 338 } 339 340 if (mSceneMgr->getOption("UseVisibilityFilter", &mUseVisibilityFilter)) 341 { 342 if (mUseVisibilityFilter) 343 sVF = ": on"; 344 else 345 sVF = ": off"; 346 } 347 else 348 { 349 sVF = NA; 350 } 321 351 322 352 initOverlayElement(&mRenderMethodInfo, ext, "RenderMethod", top, sRM); top += vert_space; … … 329 359 initOverlayElement(&mMovementInfo, ext, "Movement", top, sFM); top += vert_space; 330 360 initOverlayElement(&mTopCamInfo, ext, "TopCam", top, sTC); top += vert_space; 361 initOverlayElement(&mViewCellsInfo, ext, "ViewCells", top, sVC); top += vert_space; 362 initOverlayElement(&mViewFilterInfo, ext, "ViewFilter", top, sVF); top += vert_space; 331 363 332 364 OverlayElement *visPanel = OverlayManager::getSingleton(). … … 350 382 mKdTreeOverlay->hide(); 351 383 } 384 } 385 } 386 387 void KdTreeAppListener::toggleUseViewCells() 388 { 389 mUseViewCells = !mUseViewCells; 390 if (mSceneMgr->setOption("UseViewCells", &mUseViewCells)) 391 { 392 if (mUseViewCells) 393 mViewCellsInfo->setCaption(": on"); 394 else 395 mViewCellsInfo->setCaption(": off"); 396 } 397 else 398 { 399 mViewCellsInfo->setCaption(NA); 400 } 401 } 402 403 void KdTreeAppListener::toggleUseVisibilityFilter() 404 { 405 mUseVisibilityFilter = !mUseVisibilityFilter; 406 if (mSceneMgr->setOption("UseVisibilityFilter", &mUseVisibilityFilter)) 407 { 408 if (mUseVisibilityFilter) 409 mViewFilterInfo->setCaption(": on"); 410 else 411 mViewFilterInfo->setCaption(": off"); 412 } 413 else 414 { 415 mViewFilterInfo->setCaption(NA); 352 416 } 353 417 } … … 442 506 else 443 507 mEnhancedVisInfo->setCaption(": Simple"); 508 509 mOptions.mEnhancedVisibility = mode; 444 510 } 445 511 } … … 458 524 bm = (bm + 1) % KdTree::KDBM_SIZE; 459 525 if (mSceneMgr->setOption("BuildMethod", &bm)) 526 { 460 527 mBuildMethodInfo->setCaption(": " + BUILDMETHODCAPTION[bm]); 528 mOptions.mBuildMethod = bm; 529 } 461 530 } 462 531 else … … 474 543 rm = (rm + 1) % KdTree::KDRM_SIZE; 475 544 if (mSceneMgr->setOption("RenderMethod", &rm)) 545 { 476 546 mRenderMethodInfo->setCaption(": " + RENDERMETHODCAPTION[rm]); 547 mOptions.mRenderMethod = rm; 548 } 477 549 } 478 550 else … … 553 625 } 554 626 627 if (mInputDevice->isKeyDown(KC_F8) && mTimeUntilNextToggle <= 0) 628 { 629 // fill scene only once (for now), stop if anchor node exists 630 try 631 { 632 SceneNode *entnode = mSceneMgr->getSceneNode("AnchorNode"); 633 } 634 catch (Exception) 635 { 636 // read interesting params from config file 637 ConfigFile terrainconf; 638 std::stringstream s; 639 Real x,y,z; 640 641 terrainconf.load("terrain.cfg"); 642 643 s << terrainconf.getSetting("PageWorldX"); 644 s >> x; 645 s.clear(); 646 647 s << terrainconf.getSetting("MaxHeight"); 648 s >> y; 649 s.clear(); 650 651 s << terrainconf.getSetting("PageWorldZ"); 652 s >> z; 653 s.clear(); 654 655 mOptions.myApp->createTerrainScene(x, y * 0.3, z); 656 657 // rebuild tree 658 mSceneMgr->setOption("RebuildKdTree", 0); 659 } 660 661 mTimeUntilNextToggle = 0.5; 662 } 663 664 555 665 if (mInputDevice->isKeyDown(KC_F9) && mTimeUntilNextToggle <= 0) 556 666 { … … 571 681 } 572 682 573 if (mInputDevice->isKeyDown(KC_V) && mTimeUntilNextToggle <= 0) 574 { 575 toggleEnhancedVisibility(); 683 if (mInputDevice->isKeyDown(KC_C) && mTimeUntilNextToggle <= 0) 684 { 685 toggleUseViewCells(); 686 mTimeUntilNextToggle = 0.5; 687 } 688 689 if (mInputDevice->isKeyDown(KC_X) && mTimeUntilNextToggle <= 0) 690 { 691 toggleUseVisibilityFilter(); 576 692 mTimeUntilNextToggle = 0.5; 577 693 } … … 982 1098 if (!mFreeMove) 983 1099 { 984 if (mOptions.mScene Files == TERRAIN_SCENE)1100 if (mOptions.mSceneType == ST_TERRAIN) 985 1101 { 986 1102 static Vector3 pos; … … 1155 1271 { 1156 1272 saveLog(); 1157 return false; 1273 if (mOptions.mBurnIn) 1274 togglePlayback(); 1275 else 1276 return false; 1158 1277 } 1159 1278 } … … 1344 1463 mDemoStats.mEllapsedTime = 0.0f; 1345 1464 mDemoStats.mTotalEllapsedTime = 0.0f; 1465 mDemoFPS.clear(); 1346 1466 } 1347 1467 // stop playback … … 1597 1717 if (mOptions.mSceneManager == SM_KDT || mOptions.mSceneManager == SM_KTE) 1598 1718 { 1599 logwrite << ds << RENDERMETHOD[mOptions.mRenderMethod] << ds << mOptions.mMaxDepth << ds 1600 << mOptions.mKT << ds << mOptions.mKI; 1719 // info about enhanced visibility if internal rendering 1720 String senhvis; 1721 if (mOptions.mRenderMethod == KdTree::KDRM_INTERNAL) 1722 { 1723 if (mOptions.mEnhancedVisibility) 1724 senhvis = "E" + ds; 1725 else 1726 senhvis = "S" + ds; 1727 } 1728 1729 logwrite << ds << RENDERMETHOD[mOptions.mRenderMethod] << ds << senhvis << 1730 mOptions.mMaxDepth << ds << mOptions.mKT << ds << mOptions.mKI << ds << 1731 BUILDMETHOD[mOptions.mBuildMethod]; 1601 1732 } 1602 1733 else if (mOptions.mSceneManager == SM_OCM && mOptions.mRenderMethod != KdTree::KDRM_INTERNAL) 1603 1734 { 1604 logwrite << ds << RENDERMETHOD[ (mOptions.mRenderMethod+3)%3];1735 logwrite << ds << RENDERMETHOD[CONV_OCM_TO_KDT_ALG(mOptions.mRenderMethod)]; 1605 1736 } 1606 1737 logwrite << "\"" << fs;
Note: See TracChangeset
for help on using the changeset viewer.