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:
parent
3f41c9f91b
commit
86c1a089a4
3 changed files with 16 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue