- Timestamp:
- 06/05/06 18:25:01 (7 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgspheresegment/osgspheresegment.cpp
r5049 r5157 22 22 #include <osgParticle/FireEffect> 23 23 #include <osgParticle/ParticleSystemUpdater> 24 25 #include <osg/io_utils> 24 26 25 27 // for the grid data.. … … 90 92 if (!lines.empty()) 91 93 { 92 osg::notify(osg::NOTICE)<<"We've found intersections!!!!"<<std::endl;93 94 94 if (intersectionGroup_.valid()) 95 95 { … … 99 99 mt->setMatrix(osg::computeLocalToWorld(nv->getNodePath())); 100 100 intersectionGroup_->addChild(mt); 101 102 // std::cout<<"matrix = "<<mt->getMatrix()<<std::endl; 101 103 102 104 osg::Geode* geode = new osg::Geode; … … 136 138 137 139 138 osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode * terrainGeode, osg::Group * root )140 osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode * terrainGeode, osg::Group * root, bool createMovingRadar = false) 139 141 { 140 142 float animationLength = 10.0f; … … 164 166 model->addChild(xform); 165 167 } 166 if (1) 168 169 if (createMovingRadar) 167 170 { 168 171 // The IntersectionUpdateCallback has to have a safe place to put all its generated geometry into, … … 179 182 osg::DegreesToRadians(135.0f), 180 183 osg::DegreesToRadians(240.0f), 181 osg::DegreesToRadians(- 90.0f),182 osg::DegreesToRadians(- 70.0f),184 osg::DegreesToRadians(-60.0f), 185 osg::DegreesToRadians(-40.0f), 183 186 60); 184 187 … … 428 431 { 429 432 433 osg::Matrix terrainToSS; 434 430 435 switch(testCase) 431 436 { … … 439 444 osg::DegreesToRadians(30.0f), 440 445 60); 446 root->addChild(ss.get()); 441 447 break; 442 448 case(1): … … 449 455 osg::DegreesToRadians(30.0f), 450 456 60); 457 root->addChild(ss.get()); 451 458 break; 452 459 case(2): … … 459 466 osg::DegreesToRadians(30.0f), 460 467 60); 468 root->addChild(ss.get()); 461 469 break; 462 470 case(3): … … 469 477 osg::DegreesToRadians(30.0f), 470 478 60); 479 root->addChild(ss.get()); 471 480 break; 481 case(4): 482 { 483 ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0), 484 700.0f, // radius 485 osg::DegreesToRadians(135.0f), 486 osg::DegreesToRadians(240.0f), 487 osg::DegreesToRadians(-60.0f), 488 osg::DegreesToRadians(-40.0f), 489 60); 490 491 osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform; 492 493 mt->setMatrix(osg::Matrix(-0.851781, 0.156428, -0.5, 0, 494 -0.180627, -0.983552, -6.93889e-18, 0, 495 -0.491776, 0.0903136, 0.866025, 0, 496 598.217, 481.957, 100, 1)); 497 mt->addChild(ss.get()); 498 499 terrainToSS.invert(mt->getMatrix()); 500 501 root->addChild(mt.get()); 502 break; 503 } 504 case(5): 505 { 506 ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0), 507 700.0f, // radius 508 osg::DegreesToRadians(35.0f), 509 osg::DegreesToRadians(135.0f), 510 osg::DegreesToRadians(-60.0f), 511 osg::DegreesToRadians(-40.0f), 512 60); 513 514 osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform; 515 516 mt->setMatrix(osg::Matrix(-0.851781, 0.156428, -0.5, 0, 517 -0.180627, -0.983552, -6.93889e-18, 0, 518 -0.491776, 0.0903136, 0.866025, 0, 519 598.217, 481.957, 100, 1)); 520 mt->addChild(ss.get()); 521 522 terrainToSS.invert(mt->getMatrix()); 523 524 root->addChild(mt.get()); 525 break; 526 } 527 case(6): 528 { 529 ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0), 530 700.0f, // radius 531 osg::DegreesToRadians(-45.0f), 532 osg::DegreesToRadians(45.0f), 533 osg::DegreesToRadians(-60.0f), 534 osg::DegreesToRadians(-40.0f), 535 60); 536 537 osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform; 538 539 mt->setMatrix(osg::Matrix(-0.851781, 0.156428, -0.5, 0, 540 -0.180627, -0.983552, -6.93889e-18, 0, 541 -0.491776, 0.0903136, 0.866025, 0, 542 598.217, 481.957, 100, 1)); 543 mt->addChild(ss.get()); 544 545 terrainToSS.invert(mt->getMatrix()); 546 547 root->addChild(mt.get()); 548 break; 549 } 472 550 }; 473 551 474 ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,0.5f)); 475 ss->setSideColor(osg::Vec4(0.0f,1.0f,1.0f,0.1f)); 476 #if 1 477 root->addChild(ss.get()); 478 #endif 479 } 480 481 #if 1 482 root->addChild(ss->computeIntersectionSubgraph(osg::Matrixd::identity(), terrainGeode.get())); 483 #else 484 osgSim::SphereSegment::LineList lines = ss->computeIntersection(osg::Matrixd::identity(), terrainGeode.get()); 485 if (!lines.empty()) 486 { 487 osg::notify(osg::NOTICE)<<"We've found intersections!!!!"<<std::endl; 488 489 osg::Geode* geode = new osg::Geode; 490 root->addChild(geode); 491 492 geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 493 494 for(osgSim::SphereSegment::LineList::iterator itr=lines.begin(); 495 itr!=lines.end(); 496 ++itr) 552 if (ss.valid()) 497 553 { 498 osg::Geometry* geom = new osg::Geometry; 499 geode->addDrawable(geom); 500 501 osg::Vec3Array* vertices = itr->get(); 502 geom->setVertexArray(vertices); 503 geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, vertices->getNumElements())); 554 ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,0.5f)); 555 ss->setSideColor(osg::Vec4(0.0f,1.0f,1.0f,0.1f)); 556 557 if (!ss->getParents().empty()) 558 { 559 ss->getParent(0)->addChild(ss->computeIntersectionSubgraph(terrainToSS, terrainGeode.get())); 560 } 561 504 562 } 505 563 } 506 else 507 { 508 osg::notify(osg::NOTICE)<<"No intersections found"<<std::endl; 509 } 510 #endif 511 512 #if 0 513 514 515 osgSim::OverlayNode* overlayNode = new osgSim::OverlayNode; 516 517 overlayNode->getOrCreateStateSet()->setTextureAttribute(1, new osg::TexEnv(osg::TexEnv::DECAL)); 518 519 const osg::BoundingSphere& bs = terrainGeode->getBound(); 520 osg::Group* overlaySubgraph = createOverlay(bs.center(), bs.radius()*0.5f); 521 overlaySubgraph->addChild(ss.get()); 522 overlayNode->setOverlaySubgraph(overlaySubgraph); 523 overlayNode->setOverlayTextureSizeHint(2048); 524 overlayNode->addChild(terrainGeode.get()); 525 526 root->addChild(overlayNode); 527 528 #else 564 565 529 566 root->addChild(terrainGeode.get()); 530 #endif531 532 567 533 568 // create particle effects … … 557 592 } 558 593 594 595 bool createMovingRadar = true; 596 559 597 // create the moving models. 560 598 { 561 root->addChild(createMovingModel(osg::Vec3(500.0f,500.0f,500.0f),100.0f, terrainGeode.get(), root ));599 root->addChild(createMovingModel(osg::Vec3(500.0f,500.0f,500.0f),100.0f, terrainGeode.get(), root, createMovingRadar)); 562 600 } 563 601 }
