[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 | |
---|
| 91 | // obtain the vertical scale |
---|
| 92 | float verticalScale = 1.0f; |
---|
| 93 | while(arguments.read("-v",verticalScale)) {} |
---|
| 94 | |
---|
| 95 | // obtain the sample ratio |
---|
| 96 | float sampleRatio = 1.0f; |
---|
| 97 | while(arguments.read("-r",sampleRatio)) {} |
---|
| 98 | |
---|
| 99 | // load the nodes from the commandline arguments. |
---|
| 100 | osg::Node* rootnode = osgDB::readNodeFiles(arguments); |
---|
| 101 | |
---|
| 102 | if (!rootnode) |
---|
| 103 | { |
---|
| 104 | osg::notify(osg::NOTICE)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl; |
---|
| 105 | return 1; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | terrain->setSampleRatio(sampleRatio); |
---|
| 109 | terrain->setVerticalScale(verticalScale); |
---|
| 110 | terrain->setBlendingPolicy(blendingPolicy); |
---|
| 111 | //osg::ref_ptr<osgTerrain::TerrainTechnique> myT = new osgTerrain::myTerrainTechnique(); |
---|
| 112 | //terrain->setTerrainTechniquePrototype( myT ); |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | // Use Tile load Callback |
---|
| 116 | osg::ref_ptr<osgTerrain::GeometryTechniquePrototypeWorkaroundTLC<osgTerrain::myTerrainTechnique> > tlcb = new osgTerrain::GeometryTechniquePrototypeWorkaroundTLC<osgTerrain::myTerrainTechnique>(); |
---|
| 117 | osgTerrain::TerrainTile::setTileLoadedCallback(tlcb); |
---|
| 118 | |
---|
| 119 | // register our custom handler for adjust Terrain settings |
---|
| 120 | viewer.addEventHandler(new TerrainHandler(terrain)); |
---|
| 121 | |
---|
| 122 | // add a viewport to the viewer and attach the scene graph. |
---|
| 123 | viewer.setSceneData( rootnode ); |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | // run the viewers main loop |
---|
| 127 | return viewer.run(); |
---|
| 128 | |
---|
| 129 | } |
---|