1 #ifndef FGMANIPULATOR_H
2 #define FGMANIPULATOR_H 1
6 #include <osgGA/MatrixManipulator>
7 #include <osgViewer/ViewerEventHandlers>
11 class FGManipulator : public osgGA::MatrixManipulator {
15 virtual ~FGManipulator() {}
17 virtual const char* className() const {return "FGManipulator"; }
19 /** set the position of the matrix manipulator using a 4x4 Matrix.*/
20 virtual void setByMatrix(const osg::Matrixd& matrix);
22 virtual void setByInverseMatrix(const osg::Matrixd& matrix)
23 { setByMatrix(osg::Matrixd::inverse(matrix)); }
25 /** get the position of the manipulator as 4x4 Matrix.*/
26 virtual osg::Matrixd getMatrix() const;
28 /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
29 virtual osg::Matrixd getInverseMatrix() const;
31 virtual void setNode(osg::Node* node);
33 const osg::Node* getNode() const;
37 virtual void init(const osgGA::GUIEventAdapter& ea,
38 osgGA::GUIActionAdapter& us);
40 virtual bool handle(const osgGA::GUIEventAdapter& ea,
41 osgGA::GUIActionAdapter& us);
43 void setIdleHandler(fgIdleHandler idleHandler)
45 this->idleHandler = idleHandler;
48 fgIdleHandler getIdleHandler() const
53 void setDrawHandler(fgDrawHandler drawHandler)
55 this->drawHandler = drawHandler;
58 fgDrawHandler getDrawHandler() const
63 void setWindowResizeHandler(fgWindowResizeHandler windowResizeHandler)
65 this->windowResizeHandler = windowResizeHandler;
68 fgWindowResizeHandler getWindowResizeHandler() const
70 return windowResizeHandler;
73 void setKeyHandler(fgKeyHandler keyHandler)
75 this->keyHandler = keyHandler;
78 fgKeyHandler getKeyHandler() const
83 void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
85 this->mouseClickHandler = mouseClickHandler;
88 fgMouseClickHandler getMouseClickHandler()
90 return mouseClickHandler;
93 void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
95 this->mouseMotionHandler = mouseMotionHandler;
98 fgMouseMotionHandler getMouseMotionHandler()
100 return mouseMotionHandler;
103 int getCurrentModifiers() const
105 return currentModifiers;
108 void setMouseWarped()
113 void setPosition(const osg::Vec3d position) { this->position = position; }
114 void setAttitude(const osg::Quat attitude) { this->attitude = attitude; }
116 /** Whether or not resizing is supported. It might not be when
117 * using multiple displays.
119 bool getResizable() { return resizable; }
120 void setResizable(bool _resizable) { resizable = _resizable; }
122 bool getUseEventModifiers() { return useEventModifiers; }
123 void setUseEventModifiers(bool val) { useEventModifiers = val; }
125 osg::ref_ptr<osg::Node> _node;
126 fgIdleHandler idleHandler;
127 fgDrawHandler drawHandler;
128 fgWindowResizeHandler windowResizeHandler;
129 fgKeyHandler keyHandler;
130 fgMouseClickHandler mouseClickHandler;
131 fgMouseMotionHandler mouseMotionHandler;
132 osg::ref_ptr<osgViewer::StatsHandler> statsHandler;
133 osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
134 int currentModifiers;
135 // work-around for OSG bug
137 typedef std::map<int, osgGA::GUIEventAdapter::ModKeyMask> KeyMaskMap;
138 KeyMaskMap keyMaskMap;
139 std::map<int, int> numlockKeyMap;
142 void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
145 // workaround for osgViewer double scroll events
146 bool scrollButtonPressed;
147 int release_keys[128];
148 // When the viewer is embedded, the host toolkit may deliver a
149 // valid event mask but not control keys.
150 bool useEventModifiers;
151 void handleStats(osgGA::GUIActionAdapter& us);