From: timoore Date: Sat, 18 Aug 2007 22:07:11 +0000 (+0000) Subject: Really implement fgWarpMouse for osgviewer X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3f41c9f91baba081db751eca6f6706790ef936e2;p=flightgear.git 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 --- 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