source: experimental/distortionNG/main.cpp @ 340

Last change on this file since 340 was 340, checked in by Torben Dannhauer, 12 years ago

The intersection works and the selector highlighter is set and displayed correctly.
Next steps:

  • use a variable to control whether distortion setup is active or not. temporarily track the Ctrl Key to enably(push or disable(release) the edit mode.
  • Hide the highlighter and disable the intersection/drag tracking on diabled edit mode.
  • catch up dragging values and translate them in the correct coordinate frame.
  • apply dragging values:
  • a) either on the texture coordinate while the grid is constant,
  • b) or apply them on the grid node coordinates while the texture coordinates are constant (check/compare solutions!)



File size: 5.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        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.
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    {
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                }
116    }
117        viewer.setSceneData( rootnode );
118
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) );
123
124        //osg::ref_ptr<distortionHandler> selector = new distortionHandler( viewer.getCamera() );
125
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() );
131
132        // Avoid that the highlighter is culled away
133        //osg::CullSettings::CullingMode mode = viewer.getCamera()->getCullingMode();
134        //viewer.getCamera()->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) );
135       
136        // run the viewers main loop
137        return viewer.run();
138}
139
140/*
141ToDo:
142
143The intersection works and the selector highlighter is set and displayed correctly.
144Next steps:
145 * use a variable to control whether distortion setup is active or not. temporarily track the Ctrl Key to enably(push or disable(release) the edit mode.
146 * Hide the highlighter and disable the intersection/drag tracking on diabled edit mode.
147 * catch up dragging values and translate them in the correct coordinate frame.
148 * apply dragging values:
149 *      a) either on the texture coordinate while the grid is constant,
150 *  b) or apply them on the grid node coordinates while the texture coordinates are constant (check/compare solutions!)
151 *
152 
153
154*/
Note: See TracBrowser for help on using the repository browser.