2007-05-21 17:50:02 +00:00
|
|
|
#ifndef FGMANIPULATOR_H
|
|
|
|
#define FGMANIPULATOR_H 1
|
|
|
|
|
2007-06-16 09:39:56 +00:00
|
|
|
#include <map>
|
2007-05-21 17:50:02 +00:00
|
|
|
#include <osg/Quat>
|
|
|
|
#include <osgGA/MatrixManipulator>
|
2008-04-20 18:24:52 +00:00
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
2007-05-21 17:50:02 +00:00
|
|
|
|
|
|
|
#include "fg_os.hxx"
|
|
|
|
|
|
|
|
class FGManipulator : public osgGA::MatrixManipulator {
|
|
|
|
public:
|
2007-06-16 09:39:56 +00:00
|
|
|
FGManipulator();
|
|
|
|
|
2007-05-21 17:50:02 +00:00
|
|
|
virtual ~FGManipulator() {}
|
|
|
|
|
|
|
|
virtual const char* className() const {return "FGManipulator"; }
|
|
|
|
|
|
|
|
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
|
|
|
virtual void setByMatrix(const osg::Matrixd& matrix);
|
|
|
|
|
|
|
|
virtual void setByInverseMatrix(const osg::Matrixd& matrix)
|
|
|
|
{ setByMatrix(osg::Matrixd::inverse(matrix)); }
|
|
|
|
|
|
|
|
/** get the position of the manipulator as 4x4 Matrix.*/
|
|
|
|
virtual osg::Matrixd getMatrix() const;
|
|
|
|
|
|
|
|
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
|
|
|
|
virtual osg::Matrixd getInverseMatrix() const;
|
|
|
|
|
|
|
|
virtual void setNode(osg::Node* node);
|
|
|
|
|
|
|
|
const osg::Node* getNode() const;
|
|
|
|
|
|
|
|
osg::Node* getNode();
|
|
|
|
|
|
|
|
virtual void init(const osgGA::GUIEventAdapter& ea,
|
|
|
|
osgGA::GUIActionAdapter& us);
|
|
|
|
|
|
|
|
virtual bool handle(const osgGA::GUIEventAdapter& ea,
|
|
|
|
osgGA::GUIActionAdapter& us);
|
|
|
|
|
|
|
|
void setIdleHandler(fgIdleHandler idleHandler)
|
|
|
|
{
|
|
|
|
this->idleHandler = idleHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgIdleHandler getIdleHandler() const
|
|
|
|
{
|
|
|
|
return idleHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDrawHandler(fgDrawHandler drawHandler)
|
|
|
|
{
|
|
|
|
this->drawHandler = drawHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgDrawHandler getDrawHandler() const
|
|
|
|
{
|
|
|
|
return drawHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setWindowResizeHandler(fgWindowResizeHandler windowResizeHandler)
|
|
|
|
{
|
|
|
|
this->windowResizeHandler = windowResizeHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgWindowResizeHandler getWindowResizeHandler() const
|
|
|
|
{
|
|
|
|
return windowResizeHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setKeyHandler(fgKeyHandler keyHandler)
|
|
|
|
{
|
|
|
|
this->keyHandler = keyHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgKeyHandler getKeyHandler() const
|
|
|
|
{
|
|
|
|
return keyHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
|
|
|
|
{
|
|
|
|
this->mouseClickHandler = mouseClickHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgMouseClickHandler getMouseClickHandler()
|
|
|
|
{
|
|
|
|
return mouseClickHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
|
|
|
|
{
|
|
|
|
this->mouseMotionHandler = mouseMotionHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgMouseMotionHandler getMouseMotionHandler()
|
|
|
|
{
|
|
|
|
return mouseMotionHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getCurrentModifiers() const
|
|
|
|
{
|
|
|
|
return currentModifiers;
|
|
|
|
}
|
2007-08-19 05:29:00 +00:00
|
|
|
|
|
|
|
void setMouseWarped()
|
|
|
|
{
|
|
|
|
mouseWarped = true;
|
|
|
|
}
|
|
|
|
|
2007-05-21 17:50:02 +00:00
|
|
|
void setPosition(const osg::Vec3d position) { this->position = position; }
|
|
|
|
void setAttitude(const osg::Quat attitude) { this->attitude = attitude; }
|
|
|
|
|
2007-07-01 16:39:52 +00:00
|
|
|
/** Whether or not resizing is supported. It might not be when
|
|
|
|
* using multiple displays.
|
|
|
|
*/
|
|
|
|
bool getResizable() { return resizable; }
|
|
|
|
void setResizable(bool _resizable) { resizable = _resizable; }
|
|
|
|
|
2007-12-07 09:11:46 +00:00
|
|
|
bool getUseEventModifiers() { return useEventModifiers; }
|
|
|
|
void setUseEventModifiers(bool val) { useEventModifiers = val; }
|
2007-05-21 17:50:02 +00:00
|
|
|
protected:
|
|
|
|
osg::ref_ptr<osg::Node> _node;
|
|
|
|
fgIdleHandler idleHandler;
|
|
|
|
fgDrawHandler drawHandler;
|
|
|
|
fgWindowResizeHandler windowResizeHandler;
|
|
|
|
fgKeyHandler keyHandler;
|
|
|
|
fgMouseClickHandler mouseClickHandler;
|
|
|
|
fgMouseMotionHandler mouseMotionHandler;
|
2008-04-20 18:24:52 +00:00
|
|
|
osg::ref_ptr<osgViewer::StatsHandler> statsHandler;
|
|
|
|
osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
|
2007-05-21 17:50:02 +00:00
|
|
|
int currentModifiers;
|
2007-06-16 09:39:56 +00:00
|
|
|
// work-around for OSG bug
|
|
|
|
int osgModifiers;
|
|
|
|
typedef std::map<int, osgGA::GUIEventAdapter::ModKeyMask> KeyMaskMap;
|
|
|
|
KeyMaskMap keyMaskMap;
|
2007-07-01 16:39:52 +00:00
|
|
|
std::map<int, int> numlockKeyMap;
|
2007-05-21 17:50:02 +00:00
|
|
|
osg::Vec3d position;
|
|
|
|
osg::Quat attitude;
|
|
|
|
void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
|
2007-07-01 16:39:52 +00:00
|
|
|
bool resizable;
|
2007-08-19 05:29:00 +00:00
|
|
|
bool mouseWarped;
|
2007-08-20 21:38:25 +00:00
|
|
|
// workaround for osgViewer double scroll events
|
|
|
|
bool scrollButtonPressed;
|
2007-11-12 19:29:08 +00:00
|
|
|
int release_keys[128];
|
2007-12-07 09:11:46 +00:00
|
|
|
// When the viewer is embedded, the host toolkit may deliver a
|
|
|
|
// valid event mask but not control keys.
|
|
|
|
bool useEventModifiers;
|
2008-04-20 18:24:52 +00:00
|
|
|
void handleStats(osgGA::GUIActionAdapter& us);
|
2007-05-21 17:50:02 +00:00
|
|
|
};
|
|
|
|
#endif
|