Changeset 1274 for GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE
- Timestamp:
- 08/24/06 17:30:38 (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
r1273 r1274 31 31 mRenderTargerListener(0) 32 32 { 33 34 33 } 35 34 … … 88 87 void createMaterials(void); 89 88 void createSimpleScene(void); 89 void createTerrainScene(Real max_x, Real max_y, Real max_z); 90 Vector3 clampToGround(const Vector3& vect, Real offset, Real cap); 91 92 RaySceneQuery* mRaySceneQuery; 90 93 private: 91 94 std::string cat(std::string name, int x, int z) -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h
r1273 r1274 246 246 OverlayElement *mDemoStatus; 247 247 TextAreaOverlayElement *mDemoTime; 248 TextAreaOverlayElement *mDemoFPSDisp; 248 249 249 250 -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp
r1273 r1274 240 240 { 241 241 createSimpleScene(); 242 mCamNode->setPosition(Vector3(1280,600,1666)); 243 mCamNode->setOrientation(Quaternion(0.936893, -0.124586, 0.323813, 0.04306)); 242 244 } 243 245 // load terrain, but only if terrainscenemanager selected … … 275 277 plane.normal = -Vector3::UNIT_Y; 276 278 277 // add one robot 278 //Entity *robot = mSceneMgr->createEntity("TheRobot","robot.mesh"); 279 //SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("TheRobotNode"); 280 //node->attachObject(robot); 279 // read interesting params from config file 280 ConfigFile terrainconf; 281 std::stringstream s; 282 Real x,y,z; 283 284 terrainconf.load(terrain_cfg); 285 286 s << terrainconf.getSetting("PageWorldX"); 287 s >> x; 288 s.clear(); 289 290 s << terrainconf.getSetting("MaxHeight"); 291 s >> y; 292 s.clear(); 293 294 s << terrainconf.getSetting("PageWorldZ"); 295 s >> z; 296 s.clear(); 297 281 298 // add stuff minus gound plane 282 mSelectEntities &= ~ENT_PLN; 283 createSimpleScene(); 299 createTerrainScene(x, y + 1500, z); 284 300 285 301 // Set a nice viewpoint 286 302 mCamNode->setPosition(707,2500,528); 287 303 mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 304 //mCamNode->setPosition(0,0,0); 305 //mCamNode->setOrientation(Quaternion(Radian(Math::PI),Vector3::UNIT_Y)); 288 306 } 289 307 // load scene from file … … 300 318 mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, true); 301 319 } 320 } 321 322 // fill terrain with robots, spaceships & whatever 323 void KdTreeApp::createTerrainScene(Real max_x, Real max_y, Real max_z) 324 { 325 Vector3 scale(0.3, 0.3, 0.3); 326 Entity *deaths; 327 SceneNode *nodes; 328 std::string entName; 329 std::string nodeName; 330 int i; 331 Real min_x = 100, min_y = 0, min_z = 100; 332 max_x -= 100; max_z -= 100; 333 334 SceneNode *anchor = mSceneMgr->getRootSceneNode()->createChildSceneNode("AnchorNode"); 335 336 if (mSelectEntities & ENT_RND) 337 { 338 entName = "randomdeath"; 339 nodeName = "RandomDeathNode"; 340 for (i = 0; i < mRandomCount; i++) 341 { 342 Vector3 pos = clampToGround(Vector3( 343 Math::RangeRandom(min_x, max_x), 344 max_y, 345 Math::RangeRandom(min_z, max_z)), 0, max_y); 346 deaths = mSceneMgr->createEntity(cat(entName,666,i),"robot.mesh"); 347 if (mShadowsEnabled) 348 deaths->setCastShadows(true); 349 nodes = /*mSceneMgr->getRootSceneNode()*/anchor->createChildSceneNode(cat(nodeName,666,i), pos, 350 Quaternion(Radian(Math::RangeRandom(-Math::PI, Math::PI)), Vector3::UNIT_Y)); 351 nodes->attachObject(deaths); 352 nodes->setScale(scale); 353 } 354 } 355 356 if (mSelectEntities & ENT_SPC) 357 { 358 entName = "randomspaceship"; 359 nodeName = "RandomSpaceshipNode"; 360 for (i = 0; i < mRandomCount; i++) 361 { 362 Vector3 pos = clampToGround(Vector3( 363 Math::RangeRandom(min_x, max_x), 364 max_y, 365 Math::RangeRandom(min_z, max_z)), 366 Math::RangeRandom(20, 500), max_y); 367 deaths = mSceneMgr->createEntity(cat(entName,666,i),"razor.mesh"); 368 if (mShadowsEnabled) 369 deaths->setCastShadows(true); 370 nodes = /*mSceneMgr->getRootSceneNode()*/anchor->createChildSceneNode(cat(nodeName,666,i), pos, 371 Quaternion(Radian(Math::RangeRandom(-Math::PI, Math::PI)), Vector3::UNIT_Y)); 372 nodes->attachObject(deaths); 373 nodes->setScale(scale); 374 } 375 } 376 377 if (mSelectEntities & ENT_MOV) 378 { 379 Entity *movingDeath = mSceneMgr->createEntity("movingDeath","robot.mesh"); 380 if (mShadowsEnabled) 381 movingDeath->setCastShadows( true ); 382 383 SceneNode *deathPivotNode = mSceneMgr->getRootSceneNode()-> 384 createChildSceneNode("deathPivotNode", Vector3((min_x + max_x)/2,0,(min_z + max_z)/2)); 385 mMoveNode = deathPivotNode->createChildSceneNode("movingNode", Vector3(0, 0, mRotationRadius) 386 /*,Quaternion(Radian(Math::HALF_PI), Vector3::UNIT_Y)*/); 387 mMoveNode->attachObject(movingDeath); 388 mMoveNode->setScale(scale); 389 390 Entity *ent_ball = mSceneMgr->createEntity("ball","sphere.mesh"); 391 SceneNode *node_pivot = mMoveNode->createChildSceneNode("pivotNode"); 392 SceneNode *node_ball = node_pivot->createChildSceneNode("orbitNode", Vector3(120, 40, 0)); 393 node_ball->attachObject(ent_ball); 394 node_ball->setScale(scale/10); 395 } 396 397 mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", mPlaneDim * 2); 302 398 } 303 399 … … 312 408 Real planeThreeEights = mPlaneDim * 3 / 8; 313 409 Real planeSixth = mPlaneDim / 6; 314 315 mCamNode->setPosition(Vector3(1280,600,1666));316 mCamNode->setOrientation(Quaternion(0.936893, -0.124586, 0.323813, 0.04306));317 410 318 411 SceneNode *anchor = mSceneMgr->getRootSceneNode()->createChildSceneNode("AnchorNode"); … … 471 564 mSceneMgr->setOption("Algorithm", &alg); 472 565 } 566 567 // create ray query for ground intersection 568 mRaySceneQuery = mSceneMgr->createRayQuery( 569 Ray(Vector3::ZERO, Vector3::NEGATIVE_UNIT_Y)); 473 570 } 474 571 … … 589 686 } 590 687 688 Vector3 KdTreeApp::clampToGround(const Vector3& vect, Real offset, Real cap) 689 { 690 static Ray updateRay; 691 static Vector3 result; 692 693 result = vect; 694 695 if (mOptions.mSceneFiles == TERRAIN_SCENE) 696 { 697 updateRay.setOrigin(vect); 698 updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y); 699 mRaySceneQuery->setRay(updateRay); 700 RaySceneQueryResult& qryResult = mRaySceneQuery->execute(); 701 RaySceneQueryResult::iterator i = qryResult.begin(); 702 if (i != qryResult.end() && i->worldFragment) 703 { 704 SceneQuery::WorldFragment* wf = i->worldFragment; 705 result.y = wf->singleIntersection.y; 706 } 707 } 708 else 709 { 710 updateRay.setOrigin(vect); 711 updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y); 712 mRaySceneQuery->setRay(updateRay); 713 RaySceneQueryResult& qryResult = mRaySceneQuery->execute(); 714 RaySceneQueryResult::iterator i = qryResult.begin(); 715 while (i != qryResult.end() && i->movable) 716 { 717 if (i->movable->getName() != "PlayerCam") 718 { 719 MovableObject *mov = i->movable; 720 result.y = mov->getWorldBoundingBox().getCenter().y; 721 break; 722 } 723 i++; 724 } 725 } 726 727 result.y = result.y + offset > cap ? cap : result.y + offset; 728 729 return result; 730 } 591 731 592 732 //----------------------------------------------------------------------- -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp
r1273 r1274 1105 1105 StringConverter::toString(s, 2, '0')); 1106 1106 1107 // set FPS display 1108 const RenderTarget::FrameStats& stats = mWindow->getStatistics(); 1109 mDemoFPSDisp->setCaption(StringConverter::toString((int)stats.lastFPS)); 1110 1107 1111 // store fps when in demo mode 1108 1112 if (mOptions.mDemoMode) … … 1202 1206 StringConverter::toString(s, 2, '0')); 1203 1207 1208 // set FPS display 1209 const RenderTarget::FrameStats& stats = mWindow->getStatistics(); 1210 mDemoFPSDisp->setCaption(StringConverter::toString((int)stats.lastFPS)); 1211 1212 // store frame 1204 1213 mFrameList.push_back(FrameInfo(mCamNode->getPosition(), mCamNode->getOrientation(), evt.timeSinceLastFrame)); 1205 1214 } … … 1576 1585 // demo settings 1577 1586 logwrite << "\"" << SCENEMANAGER[mOptions.mSceneManager]; 1578 if (mOptions.mSceneManager == SM_KDT )1587 if (mOptions.mSceneManager == SM_KDT || mOptions.mSceneManager == SM_KTE) 1579 1588 { 1580 1589 logwrite << ds << RENDERMETHOD[mOptions.mRenderMethod] << ds << mOptions.mMaxDepth << ds … … 1634 1643 mDemoStatus = OverlayManager::getSingleton().createOverlayElement("Panel", "KdTree/DemoStatus"); 1635 1644 mDemoStatus->setMetricsMode(GMM_PIXELS); 1636 mDemoStatus->setHorizontalAlignment(GHA_CENTER);1637 mDemoStatus->setVerticalAlignment(GVA_TOP);1638 mDemoStatus->setTop(5);1639 mDemoStatus->setLeft(-16);1640 1645 mDemoStatus->setDimensions(32, 32); 1641 1642 //mDemoTime = static_cast<TextAreaOverlayElement *> 1643 // (OverlayManager::getSingleton().createOverlayElementFromTemplate( 1644 // "KdTree/Templates/BasicText", "TextArea", "KdTree/DemoTime")); 1646 mDemoStatus->setLeft(64); 1647 1645 1648 mDemoTime = static_cast<TextAreaOverlayElement *> 1646 1649 (OverlayManager::getSingleton().createOverlayElement("TextArea", "KdTree/DemoTime")); 1647 1650 mDemoTime->setMetricsMode(GMM_PIXELS); 1648 1651 mDemoTime->setTop(6); 1649 mDemoTime->setLeft( 8);1652 mDemoTime->setLeft(104); 1650 1653 mDemoTime->setFontName("TrebuchetMSBold"); 1651 1654 mDemoTime->setCharHeight(24.0); 1652 1655 mDemoTime->setCaption("00:00"); 1653 1656 1654 PanelOverlayElement *timeCont = static_cast<PanelOverlayElement *> 1657 mDemoFPSDisp = static_cast<TextAreaOverlayElement *> 1658 (OverlayManager::getSingleton().createOverlayElement("TextArea", "KdTree/DemoFPS")); 1659 mDemoFPSDisp->setMetricsMode(GMM_PIXELS); 1660 mDemoFPSDisp->setAlignment(TextAreaOverlayElement::Right); 1661 mDemoFPSDisp->setTop(6); 1662 mDemoFPSDisp->setLeft(48); 1663 mDemoFPSDisp->setFontName("TrebuchetMSBold"); 1664 mDemoFPSDisp->setCharHeight(24.0); 1665 mDemoFPSDisp->setCaption("0"); 1666 1667 PanelOverlayElement *demoCont = static_cast<PanelOverlayElement *> 1655 1668 (OverlayManager::getSingleton().createOverlayElement("Panel", "KdTree/DemoTimePanel")); 1656 timeCont->setMetricsMode(GMM_PIXELS); 1657 timeCont->setHorizontalAlignment(GHA_CENTER); 1658 timeCont->setVerticalAlignment(GVA_TOP); 1659 timeCont->setTop(5); 1660 timeCont->setLeft(16); 1661 timeCont->setDimensions(64, 32); 1662 timeCont->addChild(mDemoTime); 1669 demoCont->setMetricsMode(GMM_PIXELS); 1670 demoCont->setHorizontalAlignment(GHA_CENTER); 1671 demoCont->setVerticalAlignment(GVA_TOP); 1672 demoCont->setTop(5); 1673 demoCont->setLeft(-80); 1674 demoCont->setDimensions(160, 32); 1675 demoCont->addChild(mDemoFPSDisp); 1676 demoCont->addChild(mDemoStatus); 1677 demoCont->addChild(mDemoTime); 1678 //demoCont->setMaterialName("Core/StatsBlockCenter"); 1663 1679 1664 1680 mDemoOverlay = OverlayManager::getSingleton().create("KdTree/DemoOverlay"); 1665 1681 mDemoOverlay->setZOrder(500); 1666 mDemoOverlay->add2D(static_cast<PanelOverlayElement *>(mDemoStatus));1667 mDemoOverlay->add2D( timeCont);1682 //mDemoOverlay->add2D(static_cast<PanelOverlayElement *>(mDemoStatus)); 1683 mDemoOverlay->add2D(demoCont); 1668 1684 } 1669 1685 … … 1677 1693 mDemoTime->setColourTop(ColourValue(0.5, 0.7, 0.5)); 1678 1694 mDemoTime->setColourBottom(ColourValue(0.3, 0.5, 0.3)); 1695 mDemoFPSDisp->setColourTop(ColourValue(0.5, 0.7, 0.5)); 1696 mDemoFPSDisp->setColourBottom(ColourValue(0.3, 0.5, 0.3)); 1679 1697 mDemoOverlay->show(); 1680 1698 break; … … 1683 1701 mDemoTime->setColourTop(ColourValue(0.7, 0.5, 0.5)); 1684 1702 mDemoTime->setColourBottom(ColourValue(0.5, 0.3, 0.3)); 1703 mDemoFPSDisp->setColourTop(ColourValue(0.7, 0.5, 0.5)); 1704 mDemoFPSDisp->setColourBottom(ColourValue(0.5, 0.3, 0.3)); 1685 1705 mDemoOverlay->show(); 1686 1706 break;
Note: See TracChangeset
for help on using the changeset viewer.