Show
Ignore:
Timestamp:
07/09/08 21:28:00 (6 years ago)
Author:
robert
Message:

Added range of camera manipulators and a center of screen test intersection that
is insticated by pressing 'c' key

Files:
1 modified

Legend:

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

    r7909 r8551  
    2727#include <osgViewer/CompositeViewer> 
    2828 
     29#include <osgGA/TerrainManipulator> 
     30#include <osgGA/StateSetManipulator> 
     31#include <osgGA/AnimationPathManipulator> 
     32#include <osgGA/TrackballManipulator> 
     33#include <osgGA/FlightManipulator> 
     34#include <osgGA/DriveManipulator> 
     35#include <osgGA/KeySwitchMatrixManipulator> 
     36#include <osgGA/StateSetManipulator> 
     37#include <osgGA/AnimationPathManipulator> 
     38#include <osgGA/TerrainManipulator> 
     39 
    2940#include <osg/Material> 
    3041#include <osg/Geode> 
     
    7182            osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa); 
    7283            if (view) pick(view,ea); 
     84            return false; 
     85        }     
     86        case(osgGA::GUIEventAdapter::KEYDOWN): 
     87        { 
     88            if (ea.getKey()=='c') 
     89            {         
     90                osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa); 
     91                osg::ref_ptr<osgGA::GUIEventAdapter> event = new osgGA::GUIEventAdapter(ea); 
     92                event->setX((ea.getXmin()+ea.getXmax())*0.5); 
     93                event->setY((ea.getYmin()+ea.getYmax())*0.5); 
     94                if (view) pick(view,*event); 
     95            } 
    7396            return false; 
    7497        }     
     
    256279        osgViewer::Viewer viewer; 
    257280 
     281 
     282        // add all the camera manipulators 
     283        { 
     284            osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; 
     285 
     286            keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); 
     287            keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); 
     288            keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); 
     289 
     290            unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); 
     291            keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); 
     292 
     293            std::string pathfile; 
     294            char keyForAnimationPath = '5'; 
     295            while (arguments.read("-p",pathfile)) 
     296            { 
     297                osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); 
     298                if (apm || !apm->valid())  
     299                { 
     300                    num = keyswitchManipulator->getNumMatrixManipulators(); 
     301                    keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); 
     302                    ++keyForAnimationPath; 
     303                } 
     304            } 
     305 
     306            keyswitchManipulator->selectMatrixManipulator(num); 
     307 
     308            viewer.setCameraManipulator( keyswitchManipulator.get() ); 
     309        } 
     310 
    258311        // add the handler for doing the picking 
    259312        viewer.addEventHandler(new PickHandler(updateText.get()));