用键旋转对象

时间:2018-10-08 17:28:06

标签: opengl glfw glew opengl-3

我在下面编写了旋转立方体的代码,但是旋转不正确。我需要保持视图矩阵不变,但是我猜不出该怎么做。

代码:

void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
{
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
        glfwSetWindowShouldClose(window, GL_TRUE);
    if (key == GLFW_KEY_UP) 
    {
        model = rotate(model, 0.08f, vec3(1.0f, 0.0f, 0.0f));
    }
    if (key == GLFW_KEY_DOWN)
    {
        model = rotate(model, 0.08f, vec3(-1.0f, 0.0f, 0.0f));
    }
    if (key == GLFW_KEY_RIGHT)
    {
        model = rotate(model, 0.08f, vec3(0.0f, 1.0f, 0.0f));
    }
    if (key == GLFW_KEY_LEFT)
    {
        model = rotate(model, 0.08f, vec3(0.0f, -1.0f, 0.0f));
    }
}

0 个答案:

没有答案