Show
Ignore:
Timestamp:
01/10/07 14:52:22 (7 years ago)
Author:
robert
Message:

Ported following examples to osgViewer:

osgparticleeffects
osgphotoalbum
osgpick
osgpoints
osgpointsprite
osgprecipitation
osgprerender
osgprerendercubemap
osgreflect
osgscalarbar
osgscribe
osgsequence
osgplanets

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgparticleeffects/osgparticleeffects.cpp

    r5381 r5954  
    1 #include <osgProducer/Viewer> 
     1#include <osgViewer/Viewer> 
    22 
    33#include <osg/Group> 
     
    1010 
    1111#include <osgUtil/Optimizer> 
     12#include <osgUtil/IntersectVisitor> 
    1213 
    1314#include <osgDB/ReadFile> 
     
    240241            case(osgGA::GUIEventAdapter::PUSH): 
    241242            { 
    242                 osgProducer::Viewer* viewer = dynamic_cast<osgProducer::Viewer*>(&aa); 
     243                osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa); 
    243244                pick(viewer,ea); 
    244245            } 
     
    250251    } 
    251252 
    252     void pick(osgProducer::Viewer* viewer, const osgGA::GUIEventAdapter& ea) 
     253    void pick(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter& ea) 
    253254    { 
    254255        osg::Group* root = dynamic_cast<osg::Group*>(viewer->getSceneData());        
    255256        if (!root) return; 
    256257 
    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)) 
    259260        { 
    260             osgUtil::Hit& hit = hlist.front(); 
     261            const osgUtil::LineSegmentIntersector::Intersection& hit = *intersections.begin(); 
    261262 
    262263            bool handleMovingModels = false; 
    263             const osg::NodePath& nodePath = hit.getNodePath(); 
     264            const osg::NodePath& nodePath = hit.nodePath; 
    264265            for(osg::NodePath::const_iterator nitr=nodePath.begin(); 
    265266                nitr!=nodePath.end(); 
     
    318319                // is found then this needs to be inserted above the hit node, and then the 
    319320                // particle effect can be inserted into this. 
    320                 osg::ref_ptr<osg::Geode> hitGeode = hit.getGeode(); 
    321                 osg::Node::ParentList parents = hitGeode->getParents();                 
     321                osg::ref_ptr<osg::Node> hitNode = hit.nodePath.back(); 
     322                osg::Node::ParentList parents = hitNode->getParents();                 
    322323                osg::Group* insertGroup = 0; 
    323324                unsigned int numGroupsFound = 0; 
     
    347348                        ++itr) 
    348349                    { 
    349                         (*itr)->replaceChild(hit.getGeode(),insertGroup); 
     350                        (*itr)->replaceChild(hit.nodePath.back(),insertGroup); 
    350351                    } 
    351                     insertGroup->addChild(hitGeode.get()); 
     352                    insertGroup->addChild(hitNode.get()); 
    352353                    insertGroup->addChild(effectsGroup); 
    353354                } 
     
    424425////////////////////////////////////////////////////////////////////////////// 
    425426 
    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  
     427int main(int, char **) 
     428{ 
    437429    // 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 
    446432    // 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()); 
    465434     
    466435    osg::Group *root = new osg::Group; 
    467436    build_world(root); 
    468  
    469437 
    470438    osgUtil::Optimizer optimizer; 
     
    474442    viewer.setSceneData(root); 
    475443         
    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}