JoeyDeVries/LearnOpenGL

Camera chapter: don't use firstMouse variable

SuperSamus opened this issue · 1 comments

On the Camera chapter, in order to avoid a large sudden jump whenever the window first receives focus of your mouse cursor, a boolean variable (firstMouse) is used.
However I think it would be much cleaner if instead lastX and lastY were initialized with glfwGetCursorPos right after glfw initialization. This way we can ditch this boolean variable entirely.

It's also possible to poll the cursor enter event like this:

// Called in main()
glfwSetCursorEnterCallback(window, cursor_enter_callback);

void cursor_enter_callback(GLFWwindow* window, int entered) {
    if (entered)
    {
        glfwGetCursorPos(window, &lastX, &lastY);
    }
}

EDIT: Changed * to &.

I think there's a small issue with your example. In the tutorials lastX and lastY are doubles. So we would have to do something like this:

// Called in main()
glfwSetCursorEnterCallback(window, cursor_enter_callback);

void cursor_enter_callback(GLFWwindow* window, int entered)
{
    if (entered)
    {
        double nX, nY;
        glfwGetCursorPos(window, &nX, &nY);
        lastX = nX;
        lastY = nY;
    }
}