Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore_desktop] Inacurate mouse delta with DisableCursor() #3875

Closed
freakmangd opened this issue Mar 17, 2024 · 3 comments
Closed

[rcore_desktop] Inacurate mouse delta with DisableCursor() #3875

freakmangd opened this issue Mar 17, 2024 · 3 comments
Labels
platform: Linux Linux platform

Comments

@freakmangd
Copy link
Contributor

Issue description

When running the "3d camera free" on Linux in both web and desktop, GetMouseDelta() is more biased to mouse movements up and to the left. This becomes more noticeable as the frames per second increase.

These can fix the issue without changing raylib's source:

  • Using the SDL backend
  • Replacing DisableCursor() with HideCursor(), with the obvious downside of not locking the cursor anymore.

This is sourced within GLFW when using GLFW_CURSOR_DISABLED without GLFW_RAW_MOUSE_MOTION, as can be seen with this code also exhibiting the issue:

  glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

  double curx = 0, cury = 0;
  double lastx = 0, lasty = 0;

  while (!glfwWindowShouldClose(window)) {
    lastx = curx;
    lasty = cury;

    double xpos, ypos;
    glfwGetCursorPos(window, &curx, &cury);

    double deltax = curx - lastx, deltay = cury - lasty;

    if (deltax < 0) {
      negatives += deltax;
    } else {
      positives += deltax;
    }

    if (deltay < 0) {
      negatives += deltay;
    } else {
      positives += deltay;
    }

    printf("%f %f\n", negatives, positives);

    // ...
  }

When moving your mouse in a circle, the negatives are consistently larger (in absolute value) than the positives, leading to the up-left drift:
-10995.000000 7994.000000 => abs difference of 3001
-23081.000000 17624.000000 => abs difference of 5457
-35581.000000 29573.000000 => abs difference of 5908

When adding these lines:

  if (glfwRawMouseMotionSupported())
    glfwSetInputMode(window, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);

The issue disappears:
-27196.000000 27147.000000 => abs difference of 49
-65799.000000 65810.000000 => abs difference of 11
-73800.000000 73830.000000 => abs difference of 30

#3874 implements this fix for rcore_desktop.

Light testing on Windows showed no effect, another reported case was on Arch Linux.

Environment

Platform backend: DESKTOP (GLFW)
OS: Pop!_OS Ubuntu x64
OpenGL version: 4.6 (Compatibility Profile) Mesa 24.0.0-1pop0170687273522.04~0fa430c
GPU: NVIDIA Corporation GA106M [GeForce RTX 3060 Mobile / Max-Q] / Mesa Intel® UH
(Laptop integrated Intel graphics card and a discrete RTX 3060)

Issue Screenshot

mouse_bug_showcase.mp4

In this video I'm moving my mouse in a circle, and the cube is very quickly moving down and to the right, which comes from mouse movements being more sensitive up and to the left.

Code Example

"3d camera free", "3d camera first person", "3d picking", and most likely any example that uses DisableCursor() and GetMouseDelta() together on Linux.

@freakmangd freakmangd changed the title [rcore_desktop/rcore_web] Innacurate Mouse Delta When Using DisableCursor On Linux [rcore_desktop/rcore_web] Inacurate Mouse Delta When Using DisableCursor On Linux Mar 17, 2024
@raysan5 raysan5 added the platform: Linux Linux platform label Apr 21, 2024
@raysan5
Copy link
Owner

raysan5 commented Apr 21, 2024

@freakmangd After implementing #3874, is the issue still present on Linux?

Related issue on Web: #3916

@raysan5 raysan5 changed the title [rcore_desktop/rcore_web] Inacurate Mouse Delta When Using DisableCursor On Linux [rcore_desktop] Inacurate mouse delta with DisableCursor() Apr 21, 2024
@freakmangd
Copy link
Contributor Author

@raysan5 #3874 fixed the issue on desktop, but web still has this problem (or at least the examples page does) This issue can be closed if you want to use #3916 to track web

@raysan5 raysan5 closed this as completed Apr 22, 2024
@raysan5
Copy link
Owner

raysan5 commented Apr 22, 2024

@freakmangd Nice! Closing this issue! Web will be tracked on #3916.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Linux Linux platform
Projects
None yet
Development

No branches or pull requests

2 participants