source: experimental/distortionNG/main.cpp @ 309

Last change on this file since 309 was 309, checked in by Torben Dannhauer, 13 years ago

first try to select a vertex in a mesh.
Nextstep: catch mouse drags from the GA, transform into mesh CF and modify vertex.

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