diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index 4a19d8052..56955dcc7 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -13,6 +13,10 @@ #include #include +/////////////////////////////////////////////////////////////////////////// +// +// osgProducer version (see osgViewer version in next section below) + #include int main_osgProducer(osg::ArgumentParser& arguments) { @@ -124,12 +128,42 @@ int main_osgProducer(osg::ArgumentParser& arguments) return 0; } +/////////////////////////////////////////////////////////////////////////// +// +// osgViewer version + #include +#include +#include +#include +#include +#include + + int main_osgViewer(osg::ArgumentParser& arguments) { osgViewer::Viewer viewer; - viewer.setSceneData( osgDB::readNodeFiles(arguments)); + // set up the camera manipulators. + { + osg::ref_ptr keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; + + keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); + keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); + keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); + + viewer.setCameraManipulator( keyswitchManipulator.get() ); + } + + // add the state manipulator + { + osg::ref_ptr statesetManipulator = new osgGA::StateSetManipulator; + statesetManipulator->setStateSet(viewer.getCamera()->getOrCreateStateSet()); + + viewer.addEventHandler( statesetManipulator.get() ); + } + + viewer.setSceneData( osgDB::readNodeFiles(arguments) ); return viewer.run(); }