From 80cf87158ec494dd0a5c57ee37fb63b000e11194 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Fri, 12 Mar 2021 00:02:06 -0600 Subject: [PATCH] VideoCommon: update FreeLook camera to add quaternion based rotation, fix orbital and fps implementations --- Source/Core/VideoCommon/FreeLookCamera.cpp | 28 +++++++++++++++++----- Source/Core/VideoCommon/FreeLookCamera.h | 1 + 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Source/Core/VideoCommon/FreeLookCamera.cpp b/Source/Core/VideoCommon/FreeLookCamera.cpp index 5526ff50f0..25eb2a7c89 100644 --- a/Source/Core/VideoCommon/FreeLookCamera.cpp +++ b/Source/Core/VideoCommon/FreeLookCamera.cpp @@ -102,15 +102,20 @@ public: void Rotate(const Common::Vec3& amt) override { + if (amt.Length() == 0) + return; + m_rotation += amt; using Common::Quaternion; - const auto quat = + m_rotate_quat = (Quaternion::RotateX(m_rotation.x) * Quaternion::RotateY(m_rotation.y)).Normalized(); - Rotate(quat); } - void Rotate(const Common::Quaternion& quat) override { m_rotate_quat = quat; } + void Rotate(const Common::Quaternion& quat) override + { + Rotate(Common::FromQuaternionToEuler(quat)); + } void Reset() override { @@ -153,15 +158,20 @@ public: void Rotate(const Common::Vec3& amt) override { + if (amt.Length() == 0) + return; + m_rotation += amt; using Common::Quaternion; - const auto quat = + m_rotate_quat = (Quaternion::RotateX(m_rotation.x) * Quaternion::RotateY(m_rotation.y)).Normalized(); - Rotate(quat); } - void Rotate(const Common::Quaternion& quat) override { m_rotate_quat = quat; } + void Rotate(const Common::Quaternion& quat) override + { + Rotate(Common::FromQuaternionToEuler(quat)); + } void Reset() override { @@ -246,6 +256,12 @@ void FreeLookCamera::Rotate(const Common::Vec3& amt) m_dirty = true; } +void FreeLookCamera::Rotate(const Common::Quaternion& amt) +{ + m_camera_controller->Rotate(amt); + m_dirty = true; +} + void FreeLookCamera::IncreaseFovX(float fov) { m_fov_x += fov; diff --git a/Source/Core/VideoCommon/FreeLookCamera.h b/Source/Core/VideoCommon/FreeLookCamera.h index f4a3242905..389c4cc5cf 100644 --- a/Source/Core/VideoCommon/FreeLookCamera.h +++ b/Source/Core/VideoCommon/FreeLookCamera.h @@ -52,6 +52,7 @@ public: void MoveForward(float amt); void Rotate(const Common::Vec3& amt); + void Rotate(const Common::Quaternion& amt); void IncreaseFovX(float fov); void IncreaseFovY(float fov);