From 86c1a089a42155241ab3640f50120ceeb3ba7c3d Mon Sep 17 00:00:00 2001 From: timoore Date: Sun, 19 Aug 2007 05:29:00 +0000 Subject: [PATCH] osgviewer mouse warp fixes After a mouse warp drop all pointer motion events for the entire frame. Author: Melchior FRANZ --- src/Main/FGManipulator.cxx | 9 ++++++++- src/Main/FGManipulator.hxx | 7 +++++++ src/Main/fg_os_osgviewer.cxx | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Main/FGManipulator.cxx b/src/Main/FGManipulator.cxx index 8bffc930a..416ecf529 100644 --- a/src/Main/FGManipulator.cxx +++ b/src/Main/FGManipulator.cxx @@ -13,7 +13,7 @@ FGManipulator::FGManipulator() : idleHandler(0), drawHandler(0), windowResizeHandler(0), keyHandler(0), mouseClickHandler(0), mouseMotionHandler(0), currentModifiers(0), - osgModifiers(0), resizable(true) + osgModifiers(0), resizable(true), mouseWarped(false) { using namespace osgGA; @@ -132,6 +132,7 @@ bool FGManipulator::handle(const osgGA::GUIEventAdapter& ea, (*idleHandler)(); if (drawHandler) (*drawHandler)(); + mouseWarped = false; return true; case osgGA::GUIEventAdapter::KEYDOWN: case osgGA::GUIEventAdapter::KEYUP: @@ -167,6 +168,12 @@ bool FGManipulator::handle(const osgGA::GUIEventAdapter& ea, } case osgGA::GUIEventAdapter::MOVE: 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); if (mouseMotionHandler) (*mouseMotionHandler)(x, y); diff --git a/src/Main/FGManipulator.hxx b/src/Main/FGManipulator.hxx index 78fb87202..5412ce6f3 100644 --- a/src/Main/FGManipulator.hxx +++ b/src/Main/FGManipulator.hxx @@ -103,6 +103,12 @@ public: { return currentModifiers; } + + void setMouseWarped() + { + mouseWarped = true; + } + void setPosition(const osg::Vec3d position) { this->position = position; } void setAttitude(const osg::Quat attitude) { this->attitude = attitude; } @@ -130,5 +136,6 @@ protected: osg::Quat attitude; void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers); bool resizable; + bool mouseWarped; }; #endif diff --git a/src/Main/fg_os_osgviewer.cxx b/src/Main/fg_os_osgviewer.cxx index 25a23643d..afd55c976 100644 --- a/src/Main/fg_os_osgviewer.cxx +++ b/src/Main/fg_os_osgviewer.cxx @@ -250,6 +250,7 @@ int fgGetKeyModifiers() void fgWarpMouse(int x, int y) { + globals->get_renderer()->getManipulator()->setMouseWarped(); // Hack, currently the pointer is just recentered. So, we know the // relative coordinates ... if (!mainCamera.valid()) { @@ -260,7 +261,6 @@ void fgWarpMouse(int x, int y) float ysize = (float)mainCamera->getGraphicsContext()->getTraits()->height; viewer->requestWarpPointer(2.0f * (float)x / xsize - 1.0f, 1.0f - 2.0f * (float)y / ysize); - } // Noop