From 3f41c9f91baba081db751eca6f6706790ef936e2 Mon Sep 17 00:00:00 2001 From: timoore Date: Sat, 18 Aug 2007 22:07:11 +0000 Subject: [PATCH] Really implement fgWarpMouse for osgviewer This fixes a bug that caused both the x and y values of the mouse to be reset when the cursor was recentered due to hitting the screen edge. Based on a suggested patch from Stuart Buchanan --- src/Main/fg_os_osgviewer.cxx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Main/fg_os_osgviewer.cxx b/src/Main/fg_os_osgviewer.cxx index fd850e616..25a23643d 100644 --- a/src/Main/fg_os_osgviewer.cxx +++ b/src/Main/fg_os_osgviewer.cxx @@ -250,8 +250,17 @@ int fgGetKeyModifiers() void fgWarpMouse(int x, int y) { - // Hack, currently the pointer is just recentered. So, we know the relative coordinates ... - viewer->requestWarpPointer(0, 0); + // Hack, currently the pointer is just recentered. So, we know the + // relative coordinates ... + if (!mainCamera.valid()) { + viewer->requestWarpPointer(0, 0); + return; + } + float xsize = (float)mainCamera->getGraphicsContext()->getTraits()->width; + float ysize = (float)mainCamera->getGraphicsContext()->getTraits()->height; + viewer->requestWarpPointer(2.0f * (float)x / xsize - 1.0f, + 1.0f - 2.0f * (float)y / ysize); + } // Noop -- 2.39.5