mouse speed depends on fps

Started by vavris, February 05, 2021, 19:41:36

Previous topic - Next topic

vavris

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:
    public void mouseLook() {
        GLFW.glfwGetCursorPos(Window.window, mouseX, mouseY);
        mouseX.rewind();
        mouseY.rewind();

        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?

Jakes

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.

raegiles

Thanks for this thoughtful response. This helps quite a bit.
Cheers!