- Timestamp:
- 01/10/07 14:52:22 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgparticleeffects/osgparticleeffects.cpp
r5381 r5954 1 #include <osg Producer/Viewer>1 #include <osgViewer/Viewer> 2 2 3 3 #include <osg/Group> … … 10 10 11 11 #include <osgUtil/Optimizer> 12 #include <osgUtil/IntersectVisitor> 12 13 13 14 #include <osgDB/ReadFile> … … 240 241 case(osgGA::GUIEventAdapter::PUSH): 241 242 { 242 osg Producer::Viewer* viewer = dynamic_cast<osgProducer::Viewer*>(&aa);243 osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa); 243 244 pick(viewer,ea); 244 245 } … … 250 251 } 251 252 252 void pick(osg Producer::Viewer* viewer, const osgGA::GUIEventAdapter& ea)253 void pick(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter& ea) 253 254 { 254 255 osg::Group* root = dynamic_cast<osg::Group*>(viewer->getSceneData()); 255 256 if (!root) return; 256 257 257 osgUtil:: IntersectVisitor::HitList hlist;258 if (viewer->computeIntersections(ea.getX(),ea.getY(), hlist))258 osgUtil::LineSegmentIntersector::Intersections intersections; 259 if (viewer->computeIntersections(ea.getX(),ea.getY(),intersections)) 259 260 { 260 osgUtil::Hit& hit = hlist.front();261 const osgUtil::LineSegmentIntersector::Intersection& hit = *intersections.begin(); 261 262 262 263 bool handleMovingModels = false; 263 const osg::NodePath& nodePath = hit. getNodePath();264 const osg::NodePath& nodePath = hit.nodePath; 264 265 for(osg::NodePath::const_iterator nitr=nodePath.begin(); 265 266 nitr!=nodePath.end(); … … 318 319 // is found then this needs to be inserted above the hit node, and then the 319 320 // particle effect can be inserted into this. 320 osg::ref_ptr<osg:: Geode> hitGeode = hit.getGeode();321 osg::Node::ParentList parents = hit Geode->getParents();321 osg::ref_ptr<osg::Node> hitNode = hit.nodePath.back(); 322 osg::Node::ParentList parents = hitNode->getParents(); 322 323 osg::Group* insertGroup = 0; 323 324 unsigned int numGroupsFound = 0; … … 347 348 ++itr) 348 349 { 349 (*itr)->replaceChild(hit. getGeode(),insertGroup);350 (*itr)->replaceChild(hit.nodePath.back(),insertGroup); 350 351 } 351 insertGroup->addChild(hit Geode.get());352 insertGroup->addChild(hitNode.get()); 352 353 insertGroup->addChild(effectsGroup); 353 354 } … … 424 425 ////////////////////////////////////////////////////////////////////////////// 425 426 426 int main(int argc, char **argv) 427 { 428 // use an ArgumentParser object to manage the program arguments. 429 osg::ArgumentParser arguments(&argc,argv); 430 431 // set up the usage document, in case we need to print out how to use this program. 432 arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of particle systems."); 433 arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye"); 434 arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 435 436 427 int main(int, char **) 428 { 437 429 // construct the viewer. 438 osgProducer::Viewer viewer(arguments); 439 440 // set up the value with sensible default event handlers. 441 viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 442 443 // get details on keyboard and mouse bindings used by the viewer. 444 viewer.getUsage(*arguments.getApplicationUsage()); 445 430 osgViewer::Viewer viewer; 431 446 432 // register the pick handler 447 viewer.getEventHandlerList().push_front(new PickHandler()); 448 449 // if user request help write it out to cout. 450 if (arguments.read("-h") || arguments.read("--help")) 451 { 452 arguments.getApplicationUsage()->write(std::cout); 453 return 1; 454 } 455 456 // any option left unread are converted into errors to write out later. 457 arguments.reportRemainingOptionsAsUnrecognized(); 458 459 // report any errors if they have occured when parsing the program aguments. 460 if (arguments.errors()) 461 { 462 arguments.writeErrorMessages(std::cout); 463 return 1; 464 } 433 viewer.addEventHandler(new PickHandler()); 465 434 466 435 osg::Group *root = new osg::Group; 467 436 build_world(root); 468 469 437 470 438 osgUtil::Optimizer optimizer; … … 474 442 viewer.setSceneData(root); 475 443 476 // create the windows and run the threads. 477 viewer.realize(); 478 479 // osg::Vec3 center = root->getBound().center(); 480 // float radius = root->getBound().radius(); 481 482 while( !viewer.done() ) 483 { 484 // wait for all cull and draw threads to complete. 485 viewer.sync(); 486 487 // insertParticle(root, center, radius); 488 489 // update the scene by traversing it with the the update visitor which will 490 // call all node update callbacks and animations. 491 viewer.update(); 492 493 // fire off the cull and draw traversals of the scene. 494 viewer.frame(); 495 496 } 497 498 // wait for all cull and draw threads to complete. 499 viewer.sync(); 500 501 // run a clean up frame to delete all OpenGL objects. 502 viewer.cleanup_frame(); 503 504 // wait for all the clean up frame to complete. 505 viewer.sync(); 506 507 return 0; 508 } 444 return viewer.run(); 445 }
