From 8be97a7871c2ad29a9ca6f71ab71e5b7aabbdaba Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 10 Mar 2014 00:24:26 +0100 Subject: [PATCH] Quaternion camera. --- Escape-the-Dawn/Camera.cpp | 58 +++++++++++++++++++++----------------- Escape-the-Dawn/Camera.h | 16 +++++++---- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/Escape-the-Dawn/Camera.cpp b/Escape-the-Dawn/Camera.cpp index 6deeed0..542864d 100644 --- a/Escape-the-Dawn/Camera.cpp +++ b/Escape-the-Dawn/Camera.cpp @@ -8,30 +8,30 @@ Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip) m_FarClip = farClip; m_Position = glm::vec3(0.0); - m_Pitch = 0.f; - m_Yaw = 0.f; + /*m_Pitch = 0.f; + m_Yaw = 0.f;*/ UpdateProjectionMatrix(); UpdateViewMatrix(); } -glm::vec3 Camera::Forward() -{ - return glm::rotate(glm::vec3(0.f, 0.f, -1.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f)); -} +//glm::vec3 Camera::Forward() +//{ +// return glm::rotate(glm::vec3(0.f, 0.f, -1.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f)); +//} +// +//glm::vec3 Camera::Right() +//{ +// return glm::rotate(glm::vec3(1.f, 0.f, 0.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f)); +//} -glm::vec3 Camera::Right() -{ - return glm::rotate(glm::vec3(1.f, 0.f, 0.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f)); -} - -glm::mat4 Camera::Orientation() -{ - glm::mat4 orientation(1.f); - orientation = glm::rotate(orientation, m_Pitch, glm::vec3(1.f, 0.f, 0.f)); - orientation = glm::rotate(orientation, m_Yaw, glm::vec3(0.f, 1.f, 0.f)); - return orientation; -} +//glm::mat4 Camera::Orientation() +//{ +// glm::mat4 orientation(1.f); +// orientation = glm::rotate(orientation, m_Pitch, glm::vec3(1.f, 0.f, 0.f)); +// orientation = glm::rotate(orientation, m_Yaw, glm::vec3(0.f, 1.f, 0.f)); +// return orientation; +//} void Camera::AspectRatio(float val) { @@ -46,17 +46,23 @@ void Camera::Position(glm::vec3 val) } -void Camera::Pitch(float val) +void Camera::Orientation(glm::quat val) { - m_Pitch = val; + m_Orientation = val; UpdateViewMatrix(); } -void Camera::Yaw(float val) -{ - m_Yaw = val; - UpdateViewMatrix(); -} +//void Camera::Pitch(float val) +//{ +// m_Pitch = val; +// UpdateViewMatrix(); +//} +// +//void Camera::Yaw(float val) +//{ +// m_Yaw = val; +// UpdateViewMatrix(); +//} void Camera::UpdateProjectionMatrix() { @@ -70,5 +76,5 @@ void Camera::UpdateProjectionMatrix() void Camera::UpdateViewMatrix() { - m_ViewMatrix = glm::translate(Orientation(), -m_Position); + m_ViewMatrix = glm::translate(glm::toMat4(m_Orientation), -m_Position); } diff --git a/Escape-the-Dawn/Camera.h b/Escape-the-Dawn/Camera.h index 0b6ecb5..caf217c 100644 --- a/Escape-the-Dawn/Camera.h +++ b/Escape-the-Dawn/Camera.h @@ -6,6 +6,8 @@ #include #include #include +#include +#include class Camera { @@ -14,7 +16,7 @@ public: glm::vec3 Forward(); glm::vec3 Right(); - glm::mat4 Orientation(); + glm::quat Orientation(); float AspectRatio() const { return m_AspectRatio; } void AspectRatio(float val); @@ -22,10 +24,13 @@ public: glm::vec3 Position() const { return m_Position; } void Position(glm::vec3 val); - float Pitch() const { return m_Pitch; } + glm::quat Orientation() const { return m_Orientation; } + void Orientation(glm::quat val); + + /*float Pitch() const { return m_Pitch; } void Pitch(float val); float Yaw() const { return m_Yaw; } - void Yaw(float val); + void Yaw(float val);*/ glm::mat4 ProjectionMatrix() const { return m_ProjectionMatrix; } void ProjectionMatrix(glm::mat4 val) { m_ProjectionMatrix = val; } @@ -43,8 +48,9 @@ private: float m_FarClip; glm::vec3 m_Position; - float m_Pitch; - float m_Yaw; + glm::quat m_Orientation; + //float m_Pitch; + //float m_Yaw; glm::mat4 m_ProjectionMatrix; glm::mat4 m_ViewMatrix;