[307] | 1 | /* osgVisual test. distortionNG, experimental. |
---|
| 2 | * |
---|
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 4 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 5 | * in the Software without restriction, including without limitation the rights |
---|
| 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 7 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 8 | * furnished to do so, subject to the following conditions: |
---|
| 9 | * |
---|
| 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 11 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 13 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 14 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 16 | * THE SOFTWARE. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include <osg/ArgumentParser> |
---|
| 20 | #include <osgDB/ReadFile> |
---|
| 21 | |
---|
| 22 | #include <osgViewer/Viewer> |
---|
| 23 | #include <osgViewer/ViewerEventHandlers> |
---|
| 24 | |
---|
| 25 | #include <osgGA/TrackballManipulator> |
---|
| 26 | #include <osgGA/FlightManipulator> |
---|
| 27 | #include <osgGA/DriveManipulator> |
---|
| 28 | #include <osgGA/KeySwitchMatrixManipulator> |
---|
| 29 | #include <osgGA/StateSetManipulator> |
---|
| 30 | #include <osgGA/AnimationPathManipulator> |
---|
| 31 | #include <osgGA/TerrainManipulator> |
---|
| 32 | int main(int argc, char** argv) |
---|
| 33 | { |
---|
| 34 | osg::ArgumentParser arguments(&argc, argv); |
---|
| 35 | |
---|
| 36 | // construct the viewer. |
---|
| 37 | osgViewer::Viewer viewer(arguments); |
---|
| 38 | |
---|
| 39 | // set up the camera manipulators. |
---|
| 40 | { |
---|
| 41 | osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; |
---|
| 42 | |
---|
| 43 | keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); |
---|
| 44 | keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); |
---|
| 45 | keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); |
---|
| 46 | keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); |
---|
| 47 | |
---|
| 48 | std::string pathfile; |
---|
| 49 | char keyForAnimationPath = '5'; |
---|
| 50 | while (arguments.read("-p",pathfile)) |
---|
| 51 | { |
---|
| 52 | osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); |
---|
| 53 | if (apm || !apm->valid()) |
---|
| 54 | { |
---|
| 55 | unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); |
---|
| 56 | keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); |
---|
| 57 | keyswitchManipulator->selectMatrixManipulator(num); |
---|
| 58 | ++keyForAnimationPath; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | viewer.setCameraManipulator( keyswitchManipulator.get() ); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | // add the state manipulator |
---|
| 67 | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
---|
| 68 | |
---|
| 69 | // add the stats handler |
---|
| 70 | viewer.addEventHandler(new osgViewer::StatsHandler); |
---|
| 71 | |
---|
| 72 | // add the record camera path handler |
---|
| 73 | viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); |
---|
| 74 | |
---|
| 75 | // add the window size toggle handler |
---|
| 76 | viewer.addEventHandler(new osgViewer::WindowSizeHandler); |
---|
| 77 | |
---|
| 78 | // add the thread model handler |
---|
| 79 | viewer.addEventHandler(new osgViewer::ThreadingHandler); |
---|
| 80 | |
---|
| 81 | // add the help handler |
---|
| 82 | viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); |
---|
| 83 | |
---|
| 84 | // add the LOD Scale handler |
---|
| 85 | viewer.addEventHandler(new osgViewer::LODScaleHandler); |
---|
| 86 | |
---|
| 87 | // add the screen capture handler |
---|
| 88 | viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); |
---|
| 89 | |
---|
| 90 | // load the nodes from the commandline arguments. |
---|
| 91 | osg::Node* rootnode = osgDB::readNodeFiles(arguments); |
---|
| 92 | |
---|
| 93 | if (!rootnode) |
---|
| 94 | { |
---|
[308] | 95 | osg::notify(osg::WARN)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl; |
---|
[307] | 96 | return 1; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | // add a viewport to the viewer and attach the scene graph. |
---|
| 101 | viewer.setSceneData( rootnode ); |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | // run the viewers main loop |
---|
| 105 | return viewer.run(); |
---|
| 106 | |
---|
| 107 | } |
---|