VideoCommon: update FreeLook camera to add quaternion based rotation, fix orbital and fps implementations

This commit is contained in:
iwubcode 2021-03-12 00:02:06 -06:00
parent 8055919905
commit 80cf87158e
2 changed files with 23 additions and 6 deletions

View File

@ -102,15 +102,20 @@ public:
void Rotate(const Common::Vec3& amt) override void Rotate(const Common::Vec3& amt) override
{ {
if (amt.Length() == 0)
return;
m_rotation += amt; m_rotation += amt;
using Common::Quaternion; using Common::Quaternion;
const auto quat = m_rotate_quat =
(Quaternion::RotateX(m_rotation.x) * Quaternion::RotateY(m_rotation.y)).Normalized(); (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 void Reset() override
{ {
@ -153,15 +158,20 @@ public:
void Rotate(const Common::Vec3& amt) override void Rotate(const Common::Vec3& amt) override
{ {
if (amt.Length() == 0)
return;
m_rotation += amt; m_rotation += amt;
using Common::Quaternion; using Common::Quaternion;
const auto quat = m_rotate_quat =
(Quaternion::RotateX(m_rotation.x) * Quaternion::RotateY(m_rotation.y)).Normalized(); (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 void Reset() override
{ {
@ -246,6 +256,12 @@ void FreeLookCamera::Rotate(const Common::Vec3& amt)
m_dirty = true; m_dirty = true;
} }
void FreeLookCamera::Rotate(const Common::Quaternion& amt)
{
m_camera_controller->Rotate(amt);
m_dirty = true;
}
void FreeLookCamera::IncreaseFovX(float fov) void FreeLookCamera::IncreaseFovX(float fov)
{ {
m_fov_x += fov; m_fov_x += fov;

View File

@ -52,6 +52,7 @@ public:
void MoveForward(float amt); void MoveForward(float amt);
void Rotate(const Common::Vec3& amt); void Rotate(const Common::Vec3& amt);
void Rotate(const Common::Quaternion& amt);
void IncreaseFovX(float fov); void IncreaseFovX(float fov);
void IncreaseFovY(float fov); void IncreaseFovY(float fov);