Introduction
I'm doing an OpenGL program in C. As of now I'm working on the 3D camera system and got the control right. Now I'm working on the mouse control. It works, but I have used two different ways to do it.
The problem
The two different ways are using a global variable and callback, and just using a local variable and function.
I don't know which one is better. One seems to loop over itself every time and the other only when the mouse moves, but uses a global variable.
For all the following code you will see that the Camera struct is defined as:
Camera camera = {
        .view = GLM_MAT4_IDENTITY_INIT,
        .pos = { 0.f,0.f,3.f },
        .target = { 0.f, 0.f, 0.f },
        .upAxe = { 0.0f, 1.0f, 0.0f },
        .front = { 0.0f, 0.0f, -1.0 },
        .yaw = -90.f,
        .pitch = 0.f,
        .lastX = SCR_HEIGHT / 2,
        .lastY = SCR_WIDTH / 2,
        .lastFrame = 0.0f,
        .deltaTime = 0.0f
};
The code
First the "global" way:
I have only shown the intended part of the code; other code is not pertinent.
main.c:
void mouseCallBack(GLFWwindow * window, double xpos, double ypos);
Camera camera = {
    .view = GLM_MAT4_IDENTITY_INIT,
    .pos = { 0.f,0.f,3.f },
    .target = { 0.f, 0.f, 0.f },
    .upAxe = { 0.0f, 1.0f, 0.0f },
    .front = { 0.0f, 0.0f, -1.0 },
    .yaw = -90.f,
    .pitch = 0.f,
    .lastX = SCR_HEIGHT / 2,
    .lastY = SCR_WIDTH / 2,
    .lastFrame = 0.0f,
    .deltaTime = 0.0f
};
int main()
{
    glfwSetCursorPosCallback(window, mouseCallBack);
    while (!glfwWindowShouldClose(window))
    {
    }
}
void mouseCallBack(GLFWwindow * window, double xpos, double ypos)
{
    float xoffset = xpos - camera.lastX;
    float yoffset = camera.lastY - ypos;
    camera.lastX = xpos;
    camera.lastY = ypos;
    float sensivity = 0.05f;
    xoffset *= sensivity;
    yoffset *= sensivity;
    camera.yaw += xoffset;
    camera.pitch += yoffset;
    if (camera.pitch > 89.f) camera.pitch = 89.f;
    if (camera.pitch < -89.f) camera.pitch = -89.f;
    vec3 front;
    front[0] = cos(glm_rad(camera.yaw)) * cos(glm_rad(camera.pitch));
    front[1] = sin(glm_rad(camera.pitch));
    front[2] = sin(glm_rad(camera.yaw)) * cos(glm_rad(camera.pitch));
    glm_normalize_to(front, camera.front);
}
The function and local way:
int main()
{ 
    Camera camera = {
            .view = GLM_MAT4_IDENTITY_INIT,
            .pos = { 0.f,0.f,3.f },
            .target = { 0.f, 0.f, 0.f },
            .upAxe = { 0.0f, 1.0f, 0.0f },
            .front = { 0.0f, 0.0f, -1.0 }
    };
    camera.yaw = 0.f;
    camera.pitch = 0.f;
    camera.lastX = SCR_HEIGHT / 2;
    camera.lastY = SCR_WIDTH / 2;
    camera.lastFrame = 0.0f;
    camera.deltaTime = 0.0f;
    while (!glfwWindowShouldClose(window))
    {
        //input
        processMouse(window, &camera);
    }
}
and in GLFWfunction.c:
void processMouse(GLFWwindow * window, Camera * camera)
{
    double xpos;
    double ypos;
    glfwGetCursorPos(window, &xpos, &ypos);
    if (xpos != camera->lastX || ypos != camera->lastY)
    {
        float xoffset = xpos - camera->lastX;
        float yoffset = camera->lastY - ypos;
        float sensivity = 0.1f;
        xoffset *= sensivity;
        yoffset *= sensivity;
        camera->yaw += xoffset;
        camera->pitch += yoffset;
        if (camera->pitch > 89.0f) camera->pitch = 89.f;
        if (camera->pitch < -89.0f) camera->pitch = -89.f;
        vec3 front;
        front[0] = cos(glm_rad(camera->pitch)) * cos(glm_rad(camera->yaw));
        front[1] = sin(glm_rad(camera->pitch));
        front[2] = sin(glm_rad(camera->yaw)) * cos(glm_rad(camera->pitch));
        glm_normalize_to(front, camera->front);
        camera->lastX = xpos;
        camera->lastY = ypos;
    }
}
What would you choose? My eyes tell me that the global alternative is good and clean, but contradict a bit of the C logic whereas the function one is good but is poorly written.
glfwGetCursorPos(). \$\endgroup\$