Show
Ignore:
Timestamp:
03/04/08 15:19:03 (6 years ago)
Author:
robert
Message:

From Jean-Sebastien Guay and Robert Osfield, added optional --CompositeViewer? path into osgpick to illustrate how to do picking in both viewers and as unit test for picking.

Files:
1 modified

Legend:

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

    r6941 r7909  
    2525#include <osgDB/ReadFile> 
    2626#include <osgViewer/Viewer> 
     27#include <osgViewer/CompositeViewer> 
    2728 
    2829#include <osg/Material> 
     
    5051    bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa); 
    5152 
    52     virtual void pick(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter& ea); 
     53    virtual void pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea); 
    5354 
    5455    void setLabel(const std::string& name) 
     
    6667    switch(ea.getEventType()) 
    6768    { 
    68         case(osgGA::GUIEventAdapter::FRAME): 
     69        case(osgGA::GUIEventAdapter::PUSH): 
    6970        { 
    70             osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa); 
    71             if (viewer) pick(viewer,ea); 
     71            osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa); 
     72            if (view) pick(view,ea); 
    7273            return false; 
    7374        }     
     
    7778} 
    7879 
    79 void PickHandler::pick(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter& ea) 
     80void PickHandler::pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea) 
    8081{ 
    8182    osgUtil::LineSegmentIntersector::Intersections intersections; 
    8283 
    8384    std::string gdlist=""; 
    84     if (viewer->computeIntersections(ea.getX(),ea.getY(),intersections)) 
     85    float x = ea.getX(); 
     86    float y = ea.getY(); 
     87    if (view->computeIntersections(x,y,intersections)) 
    8588    { 
    8689        for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin(); 
     
    211214int main( int argc, char **argv ) 
    212215{ 
    213  
    214216    // use an ArgumentParser object to manage the program arguments. 
    215217    osg::ArgumentParser arguments(&argc,argv); 
    216  
    217     // construct the viewer. 
    218     osgViewer::Viewer viewer; 
    219218 
    220219    // read the scene from the list of file specified commandline args. 
     
    236235    group->addChild(createHUD(updateText.get())); 
    237236 
    238     // add the handler for doing the picking 
    239     viewer.addEventHandler(new PickHandler(updateText.get())); 
    240  
    241     // set the scene to render 
    242     viewer.setSceneData(group.get()); 
    243  
    244     return viewer.run(); 
    245 } 
     237    if (arguments.read("--CompositeViewer")) 
     238    { 
     239        osg::ref_ptr<osgViewer::View> view = new osgViewer::View; 
     240        // add the handler for doing the picking 
     241        view->addEventHandler(new PickHandler(updateText.get())); 
     242 
     243        // set the scene to render 
     244        view->setSceneData(group.get()); 
     245 
     246        view->setUpViewAcrossAllScreens(); 
     247 
     248        osgViewer::CompositeViewer viewer; 
     249        viewer.addView(view.get()); 
     250 
     251        return viewer.run(); 
     252 
     253    } 
     254    else 
     255    { 
     256        osgViewer::Viewer viewer; 
     257 
     258        // add the handler for doing the picking 
     259        viewer.addEventHandler(new PickHandler(updateText.get())); 
     260 
     261        // set the scene to render 
     262        viewer.setSceneData(group.get()); 
     263 
     264        return viewer.run(); 
     265    } 
     266 
     267}