source: experimental/distortionNG/DistortionManipulator.cpp @ 348

Last change on this file since 348 was 348, checked in by Torben Dannhauer, 12 years ago
File size: 5.7 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 "DistortionManipulator.h"
20
21#include<osgViewer/Viewer>
22
23using namespace osg;
24using namespace osgViewer;
25
26
27DistortionManipulator::DistortionManipulator()
28{
29        activeSetupMode = DISABLED;
30        activeDistortionMode = MESH;
31        activeManualSetupMode = DISTORTION;
32        activeVisualizationMode = NONE;
33}
34
35DistortionManipulator::~DistortionManipulator()
36{
37}
38
39void DistortionManipulator::getUsage(osg::ApplicationUsage& usage) const
40{
41    usage.addKeyboardMouseBinding("Keypad 7","Show distortion mesh / intensity map / none.");
42        usage.addKeyboardMouseBinding("Keypad 8","Save distortion set.");       // via plugin
43        usage.addKeyboardMouseBinding("Keypad 4","Toggles Setup Mode between DISABLED, MANUAL & DELEGATED.");
44        usage.addKeyboardMouseBinding("Keypad 5","MANUAL Mode: Toggle between blending & distortion setup.");
45        usage.addKeyboardMouseBinding("Keypad 6","MANUAL Mode: Toggle if distortion drags affect mesh or rtt texture coordinates.");    // Defaults to Mesh
46        usage.addKeyboardMouseBinding("Keypad 1","Reset distortion.");
47        usage.addKeyboardMouseBinding("Keypad 2","Reset intensity blending.");
48}
49
50bool DistortionManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* obj, osg::NodeVisitor* nv)
51{
52        osgViewer::View* viewer = dynamic_cast<osgViewer::View*>(&aa);
53                if ( viewer )
54                {
55                        //osg::notify(osg::ALWAYS)<<"viewer!"<<std::endl;
56                }
57
58        switch(ea.getEventType())
59    {
60        case(osgGA::GUIEventAdapter::MOVE): break;
61        case(osgGA::GUIEventAdapter::DRAG):
62                {
63                        osg::notify(osg::ALWAYS)<<"DRAG!"<<std::endl;
64                        break;
65                }
66        case(osgGA::GUIEventAdapter::PUSH):
67                {
68                        if(ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
69                        {
70                                osg::notify(osg::ALWAYS)<<"mouse click left!"<<std::endl;
71                        }
72                        break;
73                }
74        case(osgGA::GUIEventAdapter::RELEASE): break;
75        case(osgGA::GUIEventAdapter::KEYDOWN):
76                {
77                        if (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_End)    // KP 1: reset distortion
78                        {
79                                resetDistortion();
80                                return(true);
81                        }
82                        if (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Down)   // KP 2: reset intensity map
83                        {
84                                resetIntensityMap();
85                                return(true);
86                        }
87                        if (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Left)   // KP 4: Toggles Setup Mode between DISABLED, MANUAL & DELEGATED.
88                        {
89                                switch(activeSetupMode)
90                                {
91                                        case DISABLED : activeSetupMode = MANUAL; break;
92                                        case MANUAL : activeSetupMode = DELEGATED; break;
93                                        case DELEGATED : activeSetupMode = DISABLED; break;
94                                }
95
96                                osg::notify(osg::ALWAYS)<<"KEY_KP_4 : Setup Mode now "<<activeSetupMode<<std::endl;
97                                return(true);
98                        }
99                        if (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Begin)  // KP 5: MANUAL Mode: Toggle between blending & distortion setup.
100                        {
101
102                                activeManualSetupMode = (activeManualSetupMode==DISTORTION?BLENDING:DISTORTION);
103                                osg::notify(osg::ALWAYS)<<"KEY_KP_5 : activeManualSetupMode is now "<<activeManualSetupMode<<std::endl;
104                                return(true);
105                        }
106                        if (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Right)  // KP 6: MANUAL Mode: Toggle if distortion drags affect mesh or rtt texture coordinates -> defaults to Mesh
107                        {
108                                activeDistortionMode = (activeDistortionMode==MESH?TEXCOORDINATES:MESH);
109                                osg::notify(osg::ALWAYS)<<"KEY_KP_6 : activeDistortionMode is now "<<activeDistortionMode<<std::endl;
110                                return(true);
111                        }
112                        if (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Home)   // KP 7: Show distortion mesh / intensity map / none.
113                        {
114                                switch(activeVisualizationMode)
115                                {       
116                                        case DISTORTION_MESH : activeVisualizationMode = INTENSITY_MAP; break;
117                                        case INTENSITY_MAP : activeVisualizationMode = NONE; break;
118                                        case NONE : activeVisualizationMode = DISTORTION_MESH; break;
119                                }
120                                osg::notify(osg::ALWAYS)<<"KEY_KP_7 : activeVisualizationMode is now "<<activeVisualizationMode<<std::endl;
121                                return(true);
122                        }
123                        if (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Up)     // KP 8: Save distortion set     via plugin
124                        {
125                                osg::notify(osg::ALWAYS)<<"KEY_KP_8 : todo: Save DistortionContainer"<<std::endl;
126                                return(true);
127                        }
128                       
129
130                        return false;   // Event ignored
131                }
132        case(osgGA::GUIEventAdapter::KEYUP): break;
133                case(osgGA::GUIEventAdapter::FRAME):
134                {
135                        //osg::notify(osg::ALWAYS)<<"FRAME!"<<std::endl;
136                        break;
137                }
138        case (osgGA::GUIEventAdapter::RESIZE):  // todo: adapt distortion mesh to new screen size
139                {
140                        osg::notify(osg::ALWAYS)<<"RESIZE!"<<std::endl;
141                        break;
142                }
143
144        default:
145            return false;
146    }
147    return false;
148}
149
150void DistortionManipulator::resetIntensityMap()
151{
152        osg::notify(osg::ALWAYS)<<"ToDo: resetIntensityMap()"<<std::endl;
153}
154
155void DistortionManipulator::resetDistortion()
156{
157        osg::notify(osg::ALWAYS)<<"ToDo: resetDistortion()"<<std::endl;
158}
Note: See TracBrowser for help on using the repository browser.