From 96a5473c8ba1f54f2ea7ae7492d1edd21058a040 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Fri, 21 Jun 2024 12:40:11 +0200 Subject: [PATCH] Improve camera More intuitive controls. This also makes it trivial to switch over to using the euler angles as the state variables, which eliminates roll --- src/utilities/camera.hpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/utilities/camera.hpp b/src/utilities/camera.hpp index bbfe338..44d7973 100644 --- a/src/utilities/camera.hpp +++ b/src/utilities/camera.hpp @@ -84,8 +84,8 @@ namespace Gloom } // Keep track of pitch and yaw for the current frame - fYaw = xpos - lastXPos; - fPitch = ypos - lastYPos; + fYaw = (xpos - lastXPos) * cMouseSensitivity; + fPitch = (ypos - lastYPos) * cMouseSensitivity; // Update last known cursor position lastXPos = xpos; @@ -143,10 +143,6 @@ namespace Gloom /* Update the view matrix based on the current information */ void updateViewMatrix() { - // Adjust cursor movement using the specified sensitivity - fPitch *= cMouseSensitivity; - fYaw *= cMouseSensitivity; - // Create quaternions given the current pitch and yaw glm::quat qPitch = glm::quat(glm::vec3(fPitch, 0.0f, 0.0f)); glm::quat qYaw = glm::quat(glm::vec3(0.0f, fYaw, 0.0f)); @@ -156,7 +152,7 @@ namespace Gloom fYaw = 0.0f; // Update camera quaternion and normalise - cQuaternion = qYaw * qPitch * cQuaternion; + cQuaternion = qPitch * qYaw * cQuaternion; cQuaternion = glm::normalize(cQuaternion); // Build rotation matrix using the camera quaternion