3.2.3 [opt] Rotate the Scene with Keyboard
GLFW key_callback
glm::mat4 matRoot = glm::mat4(1.0);
float rot_x = 0;
float rot_y = 0;
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_LEFT ) {
rot_y -= 5.0;
} else if (key == GLFW_KEY_RIGHT /*&& action == GLFW_PRESS*/) {
rot_y += 5.0;
} if (key == GLFW_KEY_DOWN ) {
rot_x += 5.0;
} else if (key == GLFW_KEY_UP) {
rot_x -= 5.0;
}
glm::mat4 mat_rot_y = glm::rotate(glm::radians(rot_y), glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 mat_rot_x = glm::rotate(glm::radians(rot_x), glm::vec3(1.0f, 0.0f, 0.0f));
matRoot = mat_rot_x * mat_rot_y;
}Set key_callback
Draw with a root matrix

Last updated