1 #ifndef FGMANIPULATOR_H
2 #define FGMANIPULATOR_H 1
6 #include <osgGA/MatrixManipulator>
7 #include <osgViewer/ViewerEventHandlers>
13 class FGManipulator : public osgGA::MatrixManipulator {
17 virtual ~FGManipulator() {}
19 virtual const char* className() const {return "FGManipulator"; }
21 /** set the position of the matrix manipulator using a 4x4 Matrix.*/
22 virtual void setByMatrix(const osg::Matrixd& matrix);
24 virtual void setByInverseMatrix(const osg::Matrixd& matrix)
25 { setByMatrix(osg::Matrixd::inverse(matrix)); }
27 /** get the position of the manipulator as 4x4 Matrix.*/
28 virtual osg::Matrixd getMatrix() const;
30 /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
31 virtual osg::Matrixd getInverseMatrix() const;
33 virtual void setNode(osg::Node* node);
35 const osg::Node* getNode() const;
39 virtual void init(const osgGA::GUIEventAdapter& ea,
40 osgGA::GUIActionAdapter& us);
42 virtual bool handle(const osgGA::GUIEventAdapter& ea,
43 osgGA::GUIActionAdapter& us);
45 void setIdleHandler(fgIdleHandler idleHandler)
47 this->idleHandler = idleHandler;
50 fgIdleHandler getIdleHandler() const
55 void setDrawHandler(fgDrawHandler drawHandler)
57 this->drawHandler = drawHandler;
60 fgDrawHandler getDrawHandler() const
65 void setWindowResizeHandler(fgWindowResizeHandler windowResizeHandler)
67 this->windowResizeHandler = windowResizeHandler;
70 fgWindowResizeHandler getWindowResizeHandler() const
72 return windowResizeHandler;
75 void setKeyHandler(fgKeyHandler keyHandler)
77 this->keyHandler = keyHandler;
80 fgKeyHandler getKeyHandler() const
85 void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
87 this->mouseClickHandler = mouseClickHandler;
90 fgMouseClickHandler getMouseClickHandler()
92 return mouseClickHandler;
95 void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
97 this->mouseMotionHandler = mouseMotionHandler;
100 fgMouseMotionHandler getMouseMotionHandler()
102 return mouseMotionHandler;
105 int getCurrentModifiers() const
107 return currentModifiers;
110 void setMouseWarped()
115 void setPosition(const osg::Vec3d position) { this->position = position; }
116 void setAttitude(const osg::Quat attitude) { this->attitude = attitude; }
118 /** Whether or not resizing is supported. It might not be when
119 * using multiple displays.
121 bool getResizable() { return resizable; }
122 void setResizable(bool _resizable) { resizable = _resizable; }
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;
135 int currentModifiers;
136 std::map<int, int> numlockKeyMap;
139 void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
142 // workaround for osgViewer double scroll events
143 bool scrollButtonPressed;
144 int release_keys[128];
145 void handleStats(osgGA::GUIActionAdapter& us);
148 void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
149 void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
150 double& x, double& y);