source: experimental/distortionNG/main.cpp @ 313

Last change on this file since 313 was 313, checked in by Torben Dannhauer, 13 years ago
File size: 4.9 KB
Line 
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 "extViewer.h"
20#include "distortionNG.h"
21
22#include <osg/ArgumentParser>
23#include <osg/PolygonOffset>
24
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>
37int main(int argc, char** argv)
38{
39    osg::ArgumentParser arguments(&argc, argv);
40
41    // construct the viewer.
42    extViewer viewer(arguments);
43
44    // set up the camera manipulators.
45    {
46        osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
47
48        keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
49        keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
50        keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
51        keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
52
53        std::string pathfile;
54        char keyForAnimationPath = '5';
55        while (arguments.read("-p",pathfile))
56        {
57            osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
58            if (apm || !apm->valid()) 
59            {
60                unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
61                keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
62                keyswitchManipulator->selectMatrixManipulator(num);
63                ++keyForAnimationPath;
64            }
65        }
66
67        viewer.setCameraManipulator( keyswitchManipulator.get() );
68    }
69
70
71    // add the state manipulator
72    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
73
74    // add the stats handler
75    viewer.addEventHandler(new osgViewer::StatsHandler);
76
77    // add the record camera path handler
78    viewer.addEventHandler(new osgViewer::RecordCameraPathHandler);
79
80    // add the window size toggle handler
81    viewer.addEventHandler(new osgViewer::WindowSizeHandler);
82
83        // add the thread model handler
84    viewer.addEventHandler(new osgViewer::ThreadingHandler);
85
86    // add the help handler
87    viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
88
89    // add the LOD Scale handler
90    viewer.addEventHandler(new osgViewer::LODScaleHandler);
91
92    // add the screen capture handler
93    viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
94
95    // load the nodes from the commandline arguments.
96    osg::Node* rootnode = osgDB::readNodeFiles(arguments);
97
98    if (!rootnode)
99    {
100                rootnode = osgDB::readNodeFile("cow.osgt");
101                if(!rootnode)
102                {
103                        osg::notify(osg::WARN)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl;
104                        return 1;
105                }
106    }
107
108        osg::ref_ptr<osg::Geode> geode = new osg::Geode;
109        geode->addDrawable( extViewer::createMesh(16, 9) );
110        geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
111        geode->getOrCreateStateSet()->setAttributeAndModes( new osg::PolygonOffset(1.0f, 1.0f) );
112
113        osg::ref_ptr<distortionHandler> selector = new distortionHandler( viewer.getCamera() );
114
115        osg::ref_ptr<osg::Group> root = new osg::Group;
116        root->addChild( geode.get() );
117        root->addChild( selector->createVertexHighlighter() );
118
119        viewer.addEventHandler( selector.get() );
120        viewer.setSceneData( root.get() );
121
122        // Avoid that the highlighter is culled away
123        osg::CullSettings::CullingMode mode = viewer.getCamera()->getCullingMode();
124        viewer.getCamera()->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) );
125       
126        // run the viewers main loop
127        return viewer.run();
128}
Note: See TracBrowser for help on using the repository browser.