[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 | |
---|
[310] | 19 | #include "extViewer.h" |
---|
[309] | 20 | #include "distortionNG.h" |
---|
| 21 | |
---|
[307] | 22 | #include <osg/ArgumentParser> |
---|
[309] | 23 | #include <osg/PolygonOffset> |
---|
| 24 | |
---|
[307] | 25 | #include <osgDB/ReadFile> |
---|
| 26 | |
---|
| 27 | #include <osgViewer/Viewer> |
---|
| 28 | #include <osgViewer/ViewerEventHandlers> |
---|
| 29 | |
---|
| 30 | #include <osgGA/TrackballManipulator> |
---|
| 31 | #include <osgGA/FlightManipulator> |
---|
| 32 | #include <osgGA/DriveManipulator> |
---|
| 33 | #include <osgGA/KeySwitchMatrixManipulator> |
---|
| 34 | #include <osgGA/StateSetManipulator> |
---|
| 35 | #include <osgGA/AnimationPathManipulator> |
---|
| 36 | #include <osgGA/TerrainManipulator> |
---|
| 37 | int main(int argc, char** argv) |
---|
| 38 | { |
---|
| 39 | osg::ArgumentParser arguments(&argc, argv); |
---|
| 40 | |
---|
| 41 | // construct the viewer. |
---|
[311] | 42 | extViewer viewer(arguments); |
---|
[307] | 43 | |
---|
[331] | 44 | osg::Image* intMap = osgDB::readImageFile("intensitymap.png"); |
---|
| 45 | if (!intMap) |
---|
| 46 | { |
---|
| 47 | osg::notify(osg::WARN) << "Couldn't find intensity map, quiting." << std::endl; |
---|
| 48 | return -1; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | viewer.setUpViewForManualDistortion(0, intMap); |
---|
| 52 | //viewer.setUpViewForPanoramicSphericalDisplay(1, 0, 0, intMap); |
---|
| 53 | |
---|
| 54 | // set up the camera manipulators. |
---|
[307] | 55 | { |
---|
| 56 | osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; |
---|
| 57 | |
---|
| 58 | keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); |
---|
| 59 | keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); |
---|
| 60 | keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); |
---|
| 61 | keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); |
---|
| 62 | |
---|
| 63 | std::string pathfile; |
---|
| 64 | char keyForAnimationPath = '5'; |
---|
| 65 | while (arguments.read("-p",pathfile)) |
---|
| 66 | { |
---|
| 67 | osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); |
---|
| 68 | if (apm || !apm->valid()) |
---|
| 69 | { |
---|
| 70 | unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); |
---|
| 71 | keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); |
---|
| 72 | keyswitchManipulator->selectMatrixManipulator(num); |
---|
| 73 | ++keyForAnimationPath; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | viewer.setCameraManipulator( keyswitchManipulator.get() ); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | // add the state manipulator |
---|
| 82 | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
---|
| 83 | |
---|
| 84 | // add the stats handler |
---|
| 85 | viewer.addEventHandler(new osgViewer::StatsHandler); |
---|
| 86 | |
---|
| 87 | // add the record camera path handler |
---|
| 88 | viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); |
---|
| 89 | |
---|
| 90 | // add the window size toggle handler |
---|
| 91 | viewer.addEventHandler(new osgViewer::WindowSizeHandler); |
---|
| 92 | |
---|
| 93 | // add the thread model handler |
---|
| 94 | viewer.addEventHandler(new osgViewer::ThreadingHandler); |
---|
| 95 | |
---|
| 96 | // add the help handler |
---|
| 97 | viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); |
---|
| 98 | |
---|
| 99 | // add the LOD Scale handler |
---|
| 100 | viewer.addEventHandler(new osgViewer::LODScaleHandler); |
---|
| 101 | |
---|
| 102 | // add the screen capture handler |
---|
| 103 | viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); |
---|
| 104 | |
---|
| 105 | // load the nodes from the commandline arguments. |
---|
| 106 | osg::Node* rootnode = osgDB::readNodeFiles(arguments); |
---|
| 107 | |
---|
| 108 | if (!rootnode) |
---|
| 109 | { |
---|
[309] | 110 | rootnode = osgDB::readNodeFile("cow.osgt"); |
---|
| 111 | if(!rootnode) |
---|
| 112 | { |
---|
| 113 | osg::notify(osg::WARN)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl; |
---|
| 114 | return 1; |
---|
| 115 | } |
---|
[325] | 116 | } |
---|
[327] | 117 | viewer.setSceneData( rootnode ); |
---|
[307] | 118 | |
---|
[315] | 119 | //osg::ref_ptr<osg::Geode> geode = new osg::Geode; |
---|
| 120 | //geode->addDrawable( extViewer::createMesh(16, 9) ); |
---|
| 121 | //geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); |
---|
| 122 | //geode->getOrCreateStateSet()->setAttributeAndModes( new osg::PolygonOffset(1.0f, 1.0f) ); |
---|
[307] | 123 | |
---|
[315] | 124 | //osg::ref_ptr<distortionHandler> selector = new distortionHandler( viewer.getCamera() ); |
---|
[307] | 125 | |
---|
[315] | 126 | //osg::ref_ptr<osg::Group> root = new osg::Group; |
---|
| 127 | //root->addChild( geode.get() ); |
---|
| 128 | //root->addChild( selector->createVertexHighlighter() ); |
---|
| 129 | //viewer.addEventHandler( selector.get() ); |
---|
| 130 | //viewer.setSceneData( root.get() ); |
---|
[307] | 131 | |
---|
[329] | 132 | // Avoid that the highlighter is culled away |
---|
[315] | 133 | //osg::CullSettings::CullingMode mode = viewer.getCamera()->getCullingMode(); |
---|
| 134 | //viewer.getCamera()->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) ); |
---|
[309] | 135 | |
---|
| 136 | // run the viewers main loop |
---|
| 137 | return viewer.run(); |
---|
[329] | 138 | } |
---|
| 139 | |
---|
| 140 | /* |
---|
| 141 | ToDo: |
---|
| 142 | * |
---|
| 143 | * distortionHandler::handle startet Intersections. Da jedoch das distortion Mesh keine Geometry der Scene mehr ist, gibt es keine Intersection |
---|
| 144 | * -> es muss die intersektion umgestellt werden, um das Distortion Mesh zu intersecten. |
---|
| 145 | * Es muss geprüft werdne, ob bei dne Mausverschiebungen die texturecoordinaten verschoben, oder das Distortion Mesh verschoben wird. |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | */ |
---|