]> git.mxchange.org Git - flightgear.git/commitdiff
Really implement fgWarpMouse for osgviewer
authortimoore <timoore>
Sat, 18 Aug 2007 22:07:11 +0000 (22:07 +0000)
committertimoore <timoore>
Sat, 18 Aug 2007 22:07:11 +0000 (22:07 +0000)
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

index fd850e6167e43cb1cd1525105bbac1c009269c82..25a23643d6496301428ed46a1bafad87be38190b 100644 (file)
@@ -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