| 31 | | |
| 32 | | |
| 33 | | void addEventHandlers(osgViewer::View* view) |
| 34 | | { |
| 35 | | // set up the camera manipulators. |
| 36 | | view->setCameraManipulator( new osgGA::TrackballManipulator() ); |
| 37 | | |
| 38 | | // add the state manipulator |
| 39 | | view->addEventHandler( new osgGA::StateSetManipulator(view->getCamera()->getOrCreateStateSet()) ); |
| 40 | | |
| 41 | | // add the thread model handler |
| 42 | | view->addEventHandler(new osgViewer::ThreadingHandler); |
| 43 | | |
| 44 | | // add the window size toggle handler |
| 45 | | view->addEventHandler(new osgViewer::WindowSizeHandler); |
| 46 | | |
| 47 | | // add the stats handler |
| 48 | | view->addEventHandler(new osgViewer::StatsHandler); |
| 49 | | |
| 50 | | // add the record camera path handler |
| 51 | | view->addEventHandler(new osgViewer::RecordCameraPathHandler); |
| 52 | | |
| 53 | | // add the LOD Scale handler |
| 54 | | view->addEventHandler(new osgViewer::LODScaleHandler); |
| 55 | | |
| 56 | | // add the screen capture handler |
| 57 | | view->addEventHandler(new osgViewer::ScreenCaptureHandler); |
| 58 | | } |
| 59 | | |
| 60 | | |
| 61 | | class AddViewHandler : public osgGA::GUIEventHandler |
| 62 | | { |
| 63 | | public: |
| 64 | | AddViewHandler(osgViewer::CompositeViewer* viewer, osg::Node* sceneRoot) |
| 65 | | : _viewer(viewer), _sceneRoot(sceneRoot) {} |
| 66 | | |
| 67 | | bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) |
| 68 | | { |
| 69 | | if (ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN && ea.getKey()== 'a') |
| 70 | | { |
| 71 | | osgViewer::View* view = new osgViewer::View; |
| 72 | | |
| 73 | | view->setUpViewInWindow(50, 50, 800, 600); |
| 74 | | view->getCamera()->getGraphicsContext()->realize(); |
| 75 | | |
| 76 | | view->setSceneData(_sceneRoot.get()); |
| 77 | | addEventHandlers(view); |
| 78 | | |
| 79 | | _viewer->stopThreading(); |
| 80 | | |
| 81 | | _viewer->addView(view); |
| 82 | | |
| 83 | | osg::notify(osg::NOTICE)<<"osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts()="<< osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts()<<std::endl; |
| 84 | | |
| 85 | | view->getSceneData()->setThreadSafeRefUnref(true); |
| 86 | | view->getSceneData()->resizeGLObjectBuffers(osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts()); |
| 87 | | |
| 88 | | _viewer->startThreading(); |
| 89 | | |
| 90 | | return true; |
| 91 | | } |
| 92 | | |
| 93 | | return false; |
| 94 | | } |
| 95 | | |
| 96 | | protected: |
| 97 | | osg::observer_ptr<osgViewer::CompositeViewer> _viewer; |
| 98 | | osg::ref_ptr<osg::Node> _sceneRoot; |
| 99 | | }; |
| 100 | | |
| 149 | | osg::ref_ptr<osgViewer::View> defaultView = new osgViewer::View; |
| 150 | | viewer.addView(defaultView.get()); |
| 151 | | addEventHandlers(defaultView.get()); |
| | 79 | // set up the camera manipulators. |
| | 80 | { |
| | 81 | osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; |
| | 82 | |
| | 83 | keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); |
| | 84 | keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); |
| | 85 | keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); |
| | 86 | keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); |
| | 87 | |
| | 88 | std::string pathfile; |
| | 89 | char keyForAnimationPath = '5'; |
| | 90 | while (arguments.read("-p",pathfile)) |
| | 91 | { |
| | 92 | osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); |
| | 93 | if (apm || !apm->valid()) |
| | 94 | { |
| | 95 | unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); |
| | 96 | keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); |
| | 97 | keyswitchManipulator->selectMatrixManipulator(num); |
| | 98 | ++keyForAnimationPath; |
| | 99 | } |
| | 100 | } |
| | 101 | |
| | 102 | viewer.setCameraManipulator( keyswitchManipulator.get() ); |
| | 103 | } |
| | 104 | |
| | 105 | // add the state manipulator |
| | 106 | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
| | 107 | |
| | 108 | // add the thread model handler |
| | 109 | viewer.addEventHandler(new osgViewer::ThreadingHandler); |
| | 110 | |
| | 111 | // add the window size toggle handler |
| | 112 | viewer.addEventHandler(new osgViewer::WindowSizeHandler); |
| | 113 | |
| | 114 | // add the stats handler |
| | 115 | viewer.addEventHandler(new osgViewer::StatsHandler); |
| | 116 | |
| | 117 | // add the help handler |
| | 118 | viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); |
| | 119 | |
| | 120 | // add the record camera path handler |
| | 121 | viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); |
| | 122 | |
| | 123 | // add the LOD Scale handler |
| | 124 | viewer.addEventHandler(new osgViewer::LODScaleHandler); |
| | 125 | |
| | 126 | // add the screen capture handler |
| | 127 | viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); |