我在下面编写了旋转立方体的代码,但是旋转不正确。我需要保持视图矩阵不变,但是我猜不出该怎么做。
代码:
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));
}
}