Hello Guest

mouse speed depends on fps

  • 2 Replies
mouse speed depends on fps
« on: February 05, 2021, 19:41:36 »
I'm working on a pseudo-3D raycasting game and I want to implement looking with the mouse. I tried to make it independent from fps by multiplying the mouse input with the time between frames. Here's my code:
Code: [Select]
    public void mouseLook() {
        GLFW.glfwGetCursorPos(Window.window, mouseX, mouseY);

        viewAngle += (mouseX.get(0) - (Window.width / 2.0)) * Window.frameTime;
        if (viewAngle > 2 * Math.PI) viewAngle -= 2 * Math.PI;
        if (viewAngle < 0) viewAngle += 2 * Math.PI;
        dX = Math.cos(viewAngle);
        dY = Math.sin(viewAngle);
        GLFW.glfwSetCursorPos(Window.window, Window.width / 2.0, Window.height / 2.0);
What am I doing wrong?

Re: mouse speed depends on fps
« Reply #1 on: March 14, 2021, 04:47:17 »
Well, first off, it depends on what you're using to retrieve the input data, and from what I can see you're not using any type of event handler from within your own application.

When are you calling this method? in the rendering cycle?
If thats so, then it will obviously depend on the number of calls your rendering will have (thus FPS dependant)

My suggestion is to use (or take a look at) the glfwSetCursorPosCallback() method in order to retrieve the event when the mouse is moved.

Re: mouse speed depends on fps
« Reply #2 on: April 26, 2021, 02:06:12 »
Thanks for this thoughtful response. This helps quite a bit.