Browse Source

Fix initial GetMouseDelta on GLFW

The initial mouse delta is often very large, depending on where the
cursor was before the window opened. This is because the first mouse
delta is the x/y coordinates your cursor entered the screen from. This
can (and often does) cause the free camera to make a sudden jump when
its moved for the first time.

The solution to this is to initialize the previousPosition and the
currentPosition to the same value on the first mouse input, essentially
ignoring the first mouse delta.
pull/4663/head
vent 1 week ago
parent
commit
958952f617
1 changed files with 7 additions and 0 deletions
  1. +7
    -0
      src/platforms/rcore_desktop_glfw.c

+ 7
- 0
src/platforms/rcore_desktop_glfw.c View File

@ -1873,6 +1873,13 @@ static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
CORE.Input.Mouse.currentPosition.y = (float)y; CORE.Input.Mouse.currentPosition.y = (float)y;
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition; CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
static bool firstMouseInput = true;
if (firstMouseInput)
{
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
firstMouseInput = false;
}
#if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES) #if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
// Process mouse events as touches to be able to use mouse-gestures // Process mouse events as touches to be able to use mouse-gestures
GestureEvent gestureEvent = { 0 }; GestureEvent gestureEvent = { 0 };

Loading…
Cancel
Save