source: experimental/distortionNG/main.cpp @ 323

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