LWJGL 鼠标无限移动

LWJGL unlimited mouse movement

我想知道在 "unlimited mouse movement" 上有什么好的方法? (就像在第一人称游戏中,你可以无限地环顾四周)

我正在使用 OpenGL 和 LWJGL(它为 Java 提供绑定)。我有以下可能的绑定:https://www.lwjgl.org/customize(在目录下列出) 目前我只使用GLFW来处理鼠标输入。

我目前的做法如下,但显然光标最终到达屏幕边缘:

public class MouseInput {

    private final Vector2d previousPosition;
    private final Vector2d currentPosition;

    private final Vector2f displayVector;

    private boolean inWindow = false;

    // [some code here]

    public void init() {

        glfwSetCursorPosCallback(window.getHandle(), (windowHandle, xpos, ypos) -> {
            currentPosition.x = xpos;
            currentPosition.y = ypos;
        });

        glfwSetCursorEnterCallback(window.getHandle(), (windowHandle, entered) -> {
            inWindow = entered;
        });

        // [some code here]

    }

    public void input() {

        displayVector.x = 0;
        displayVector.y = 0;

        if (previousPosition.x > 0 && previousPosition.y > 0 && inWindow) {

            double deltaX = currentPosition.x - previousPosition.x;
            double deltaY = currentPosition.y - previousPosition.y;

            if (deltaX != 0) {
                displayVector.y = (float) deltaX;
            }
            if (deltaY != 0) {
                displayVector.x = (float) deltaY;
            }

        }

        previousPosition.x = currentPosition.x;
        previousPosition.y = currentPosition.y;

    }

    // [some code here]

}

现在我可以在其他地方使用计算出的 displayVector 来旋转相机。

我必须使用不同于 GLFW 的东西吗?我尝试在每次 input() 后将光标的位置设置回中心,但这是非常错误的。

我不是在寻找我的代码的更正,而是在寻找一种好的方法,这是最佳实践。

glfwSetInputMode():

  • GLFW_CURSOR_DISABLED hides and grabs the cursor, providing virtual and unlimited cursor movement. This is useful for implementing for example 3D camera controls.