1
0
Fork 0

osgviewer mouse warp fixes

After a mouse warp drop all pointer motion events for the entire frame.

Author: Melchior FRANZ
This commit is contained in:
timoore 2007-08-19 05:29:00 +00:00
parent 3f41c9f91b
commit 86c1a089a4
3 changed files with 16 additions and 2 deletions

View file

@ -13,7 +13,7 @@
FGManipulator::FGManipulator() : FGManipulator::FGManipulator() :
idleHandler(0), drawHandler(0), windowResizeHandler(0), keyHandler(0), idleHandler(0), drawHandler(0), windowResizeHandler(0), keyHandler(0),
mouseClickHandler(0), mouseMotionHandler(0), currentModifiers(0), mouseClickHandler(0), mouseMotionHandler(0), currentModifiers(0),
osgModifiers(0), resizable(true) osgModifiers(0), resizable(true), mouseWarped(false)
{ {
using namespace osgGA; using namespace osgGA;
@ -132,6 +132,7 @@ bool FGManipulator::handle(const osgGA::GUIEventAdapter& ea,
(*idleHandler)(); (*idleHandler)();
if (drawHandler) if (drawHandler)
(*drawHandler)(); (*drawHandler)();
mouseWarped = false;
return true; return true;
case osgGA::GUIEventAdapter::KEYDOWN: case osgGA::GUIEventAdapter::KEYDOWN:
case osgGA::GUIEventAdapter::KEYUP: case osgGA::GUIEventAdapter::KEYUP:
@ -167,6 +168,12 @@ bool FGManipulator::handle(const osgGA::GUIEventAdapter& ea,
} }
case osgGA::GUIEventAdapter::MOVE: case osgGA::GUIEventAdapter::MOVE:
case osgGA::GUIEventAdapter::DRAG: case osgGA::GUIEventAdapter::DRAG:
// If we warped the mouse, then disregard all pointer motion
// events for this frame. We really want to flush the event
// queue of mouse events, but don't have the ability to do
// that with osgViewer.
if (mouseWarped)
return true;
eventToViewport(ea, us, x, y); eventToViewport(ea, us, x, y);
if (mouseMotionHandler) if (mouseMotionHandler)
(*mouseMotionHandler)(x, y); (*mouseMotionHandler)(x, y);

View file

@ -103,6 +103,12 @@ public:
{ {
return currentModifiers; return currentModifiers;
} }
void setMouseWarped()
{
mouseWarped = true;
}
void setPosition(const osg::Vec3d position) { this->position = position; } void setPosition(const osg::Vec3d position) { this->position = position; }
void setAttitude(const osg::Quat attitude) { this->attitude = attitude; } void setAttitude(const osg::Quat attitude) { this->attitude = attitude; }
@ -130,5 +136,6 @@ protected:
osg::Quat attitude; osg::Quat attitude;
void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers); void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
bool resizable; bool resizable;
bool mouseWarped;
}; };
#endif #endif

View file

@ -250,6 +250,7 @@ int fgGetKeyModifiers()
void fgWarpMouse(int x, int y) void fgWarpMouse(int x, int y)
{ {
globals->get_renderer()->getManipulator()->setMouseWarped();
// Hack, currently the pointer is just recentered. So, we know the // Hack, currently the pointer is just recentered. So, we know the
// relative coordinates ... // relative coordinates ...
if (!mainCamera.valid()) { if (!mainCamera.valid()) {
@ -260,7 +261,6 @@ void fgWarpMouse(int x, int y)
float ysize = (float)mainCamera->getGraphicsContext()->getTraits()->height; float ysize = (float)mainCamera->getGraphicsContext()->getTraits()->height;
viewer->requestWarpPointer(2.0f * (float)x / xsize - 1.0f, viewer->requestWarpPointer(2.0f * (float)x / xsize - 1.0f,
1.0f - 2.0f * (float)y / ysize); 1.0f - 2.0f * (float)y / ysize);
} }
// Noop // Noop