Quaternion camera.

This commit is contained in:
2014-03-10 00:24:26 +01:00
parent ce6b570520
commit 8be97a7871
2 changed files with 43 additions and 31 deletions
+32 -26
View File
@@ -8,30 +8,30 @@ Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip)
m_FarClip = farClip; m_FarClip = farClip;
m_Position = glm::vec3(0.0); m_Position = glm::vec3(0.0);
m_Pitch = 0.f; /*m_Pitch = 0.f;
m_Yaw = 0.f; m_Yaw = 0.f;*/
UpdateProjectionMatrix(); UpdateProjectionMatrix();
UpdateViewMatrix(); UpdateViewMatrix();
} }
glm::vec3 Camera::Forward() //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)); // 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() //glm::mat4 Camera::Orientation()
{ //{
return glm::rotate(glm::vec3(1.f, 0.f, 0.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f)); // 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));
glm::mat4 Camera::Orientation() // return 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) 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(); UpdateViewMatrix();
} }
void Camera::Yaw(float val) //void Camera::Pitch(float val)
{ //{
m_Yaw = val; // m_Pitch = val;
UpdateViewMatrix(); // UpdateViewMatrix();
} //}
//
//void Camera::Yaw(float val)
//{
// m_Yaw = val;
// UpdateViewMatrix();
//}
void Camera::UpdateProjectionMatrix() void Camera::UpdateProjectionMatrix()
{ {
@@ -70,5 +76,5 @@ void Camera::UpdateProjectionMatrix()
void Camera::UpdateViewMatrix() void Camera::UpdateViewMatrix()
{ {
m_ViewMatrix = glm::translate(Orientation(), -m_Position); m_ViewMatrix = glm::translate(glm::toMat4(m_Orientation), -m_Position);
} }
+11 -5
View File
@@ -6,6 +6,8 @@
#include <glm/gtc/constants.hpp> #include <glm/gtc/constants.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/rotate_vector.hpp> #include <glm/gtx/rotate_vector.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
class Camera class Camera
{ {
@@ -14,7 +16,7 @@ public:
glm::vec3 Forward(); glm::vec3 Forward();
glm::vec3 Right(); glm::vec3 Right();
glm::mat4 Orientation(); glm::quat Orientation();
float AspectRatio() const { return m_AspectRatio; } float AspectRatio() const { return m_AspectRatio; }
void AspectRatio(float val); void AspectRatio(float val);
@@ -22,10 +24,13 @@ public:
glm::vec3 Position() const { return m_Position; } glm::vec3 Position() const { return m_Position; }
void Position(glm::vec3 val); 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); void Pitch(float val);
float Yaw() const { return m_Yaw; } float Yaw() const { return m_Yaw; }
void Yaw(float val); void Yaw(float val);*/
glm::mat4 ProjectionMatrix() const { return m_ProjectionMatrix; } glm::mat4 ProjectionMatrix() const { return m_ProjectionMatrix; }
void ProjectionMatrix(glm::mat4 val) { m_ProjectionMatrix = val; } void ProjectionMatrix(glm::mat4 val) { m_ProjectionMatrix = val; }
@@ -43,8 +48,9 @@ private:
float m_FarClip; float m_FarClip;
glm::vec3 m_Position; glm::vec3 m_Position;
float m_Pitch; glm::quat m_Orientation;
float m_Yaw; //float m_Pitch;
//float m_Yaw;
glm::mat4 m_ProjectionMatrix; glm::mat4 m_ProjectionMatrix;
glm::mat4 m_ViewMatrix; glm::mat4 m_ViewMatrix;