Show
Ignore:
Timestamp:
01/10/07 14:52:22 (8 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/osgpick/osgpick.cpp

    r5757 r5954  
    1818#include <osgUtil/Optimizer> 
    1919#include <osgDB/ReadFile> 
    20 #include <osgProducer/Viewer> 
     20#include <osgViewer/Viewer> 
    2121 
    2222#include <osg/Material> 
     
    3737public:  
    3838 
    39     PickHandler(osgProducer::Viewer* viewer,osgText::Text* updateText): 
    40         _viewer(viewer), 
     39    PickHandler(osgText::Text* updateText): 
    4140        _updateText(updateText) {} 
    4241         
    4342    ~PickHandler() {} 
    4443     
    45     bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us); 
    46  
    47     virtual void pick(const osgGA::GUIEventAdapter& ea); 
     44    bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa); 
     45 
     46    virtual void pick(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter& ea); 
    4847 
    4948    void setLabel(const std::string& name) 
     
    5453protected: 
    5554 
    56     osgProducer::Viewer* _viewer; 
    5755    osg::ref_ptr<osgText::Text>  _updateText; 
    5856}; 
    5957 
    60 bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) 
     58bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) 
    6159{ 
    6260    switch(ea.getEventType()) 
    6361    { 
    64     case(osgGA::GUIEventAdapter::FRAME): 
     62        case(osgGA::GUIEventAdapter::FRAME): 
    6563        { 
    66             pick(ea); 
    67         } 
    68         return false; 
    69          
    70     default: 
    71         return false; 
    72     } 
    73 } 
    74  
    75 void PickHandler::pick(const osgGA::GUIEventAdapter& ea) 
    76 { 
    77     osgUtil::IntersectVisitor::HitList hlist; 
    78      
     64            osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa); 
     65            if (viewer) pick(viewer,ea); 
     66            return false; 
     67        }     
     68        default: 
     69            return false; 
     70    } 
     71} 
     72 
     73void PickHandler::pick(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter& ea) 
     74{ 
     75    osgUtil::LineSegmentIntersector::Intersections intersections; 
     76 
    7977    std::string gdlist=""; 
    80     if (_viewer->computeIntersections(ea.getX(),ea.getY(),hlist)) 
    81     { 
    82         for(osgUtil::IntersectVisitor::HitList::iterator hitr=hlist.begin(); 
    83             hitr!=hlist.end(); 
     78    if (viewer->computeIntersections(ea.getX(),ea.getY(),intersections)) 
     79    { 
     80        for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin(); 
     81            hitr != intersections.end(); 
    8482            ++hitr) 
    8583        { 
    8684            std::ostringstream os; 
    87             if (hitr->_geode.valid() && !hitr->_geode->getName().empty()) 
     85            if (!hitr->nodePath.empty() && !(hitr->nodePath.back()->getName().empty())) 
    8886            { 
    8987                // the geodes are identified by name. 
    90                 os<<"Object \""<<hitr->_geode->getName()<<"\""<<std::endl; 
     88                os<<"Object \""<<hitr->nodePath.back()->getName()<<"\""<<std::endl; 
    9189            } 
    92             else if (hitr->_drawable.valid()) 
     90            else if (hitr->drawable.valid()) 
    9391            { 
    94                 os<<"Object \""<<hitr->_drawable->className()<<"\""<<std::endl; 
     92                os<<"Object \""<<hitr->drawable->className()<<"\""<<std::endl; 
    9593            } 
    9694 
    9795            os<<"        local coords vertex("<< hitr->getLocalIntersectPoint()<<")"<<"  normal("<<hitr->getLocalIntersectNormal()<<")"<<std::endl; 
    9896            os<<"        world coords vertex("<< hitr->getWorldIntersectPoint()<<")"<<"  normal("<<hitr->getWorldIntersectNormal()<<")"<<std::endl; 
    99             osgUtil::Hit::VecIndexList& vil = hitr->_vecIndexList; 
     97            const osgUtil::LineSegmentIntersector::Intersection::IndexList& vil = hitr->indexList; 
    10098            for(unsigned int i=0;i<vil.size();++i) 
    10199            { 
     
    209207    // use an ArgumentParser object to manage the program arguments. 
    210208    osg::ArgumentParser arguments(&argc,argv); 
    211      
    212     // set up the usage document, in case we need to print out how to use this program. 
    213     arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates how to do Head Up Displays."); 
    214     arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] [filename] ..."); 
    215     arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    216      
    217209 
    218210    // construct the viewer. 
    219     osgProducer::Viewer viewer(arguments); 
    220  
    221     // set up the value with sensible default event handlers. 
    222     viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 
    223  
    224     // get details on keyboard and mouse bindings used by the viewer. 
    225     viewer.getUsage(*arguments.getApplicationUsage()); 
    226  
    227     // if user request help write it out to cout. 
    228     if (arguments.read("-h") || arguments.read("--help")) 
    229     { 
    230         arguments.getApplicationUsage()->write(std::cout); 
    231         return 1; 
    232     } 
    233  
    234     // any option left unread are converted into errors to write out later. 
    235     arguments.reportRemainingOptionsAsUnrecognized(); 
    236  
    237     // report any errors if they have occured when parsing the program aguments. 
    238     if (arguments.errors()) 
    239     { 
    240         arguments.writeErrorMessages(std::cout); 
    241         return 1; 
    242     } 
    243      
     211    osgViewer::Viewer viewer; 
     212 
    244213    // read the scene from the list of file specified commandline args. 
    245214    osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments); 
     
    258227 
    259228    // add the handler for doing the picking 
    260     viewer.getEventHandlerList().push_front(new PickHandler(&viewer,updateText.get())); 
     229    viewer.addEventHandler(new PickHandler(updateText.get())); 
    261230 
    262231    // set the scene to render 
    263232    viewer.setSceneData(group.get()); 
    264233 
    265     // create the windows and run the threads. 
    266     viewer.realize(); 
    267  
    268     while( !viewer.done() ) 
    269     { 
    270         // wait for all cull and draw threads to complete. 
    271         viewer.sync(); 
    272  
    273         // update the scene by traversing it with the the update visitor which will 
    274         // call all node update callbacks and animations. 
    275         viewer.update(); 
    276           
    277         // fire off the cull and draw traversals of the scene. 
    278         viewer.frame(); 
    279          
    280     } 
    281      
    282     // wait for all cull and draw threads to complete. 
    283     viewer.sync(); 
    284  
    285     // run a clean up frame to delete all OpenGL objects. 
    286     viewer.cleanup_frame(); 
    287  
    288     // wait for all the clean up frame to complete. 
    289     viewer.sync(); 
    290      
    291     return 0; 
    292 } 
     234    return viewer.run(); 
     235}