diff --git a/src/camera.cpp b/src/camera.cpp index b44fd048..90423dc1 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -31,6 +31,8 @@ Camera::Camera(vec3 const &position, vec3 const &target, vec3 const &up) m_gamegroup = GAMEGROUP_BEFORE; m_drawgroup = DRAWGROUP_CAMERA; + /* Create a default perspective */ + SetPerspective(45.f, 800.f, 600.f, -1000.f, 1000.f); SetPosition(position); } @@ -43,6 +45,17 @@ void Camera::SetPosition(vec3 const &pos) m_position = pos; } +void Camera::SetOrtho(float width, float height, float near, float far) +{ + m_proj_matrix = mat4::ortho(width, height, near, far); +} + +void Camera::SetPerspective(float fov, float width, float height, + float near, float far) +{ + m_proj_matrix = mat4::perspective(fov, width, height, near, far); +} + mat4 const &Camera::GetViewMatrix() { return m_view_matrix; @@ -81,8 +94,6 @@ void Camera::TickGame(float seconds) m_target += vec3(rightleft, 0, -updown) * 200.f * seconds; m_view_matrix = mat4::lookat(m_position, m_target, m_up); - m_proj_matrix = mat4::perspective(45.0f, 640.0f, 480.0f, 1.f, 10000.0f); - //m_proj_matrix = mat4::ortho(-160, 160, -120, 120, .1f, 2000.0f); } void Camera::TickDraw(float seconds) diff --git a/src/camera.h b/src/camera.h index 0e6bf68d..03632328 100644 --- a/src/camera.h +++ b/src/camera.h @@ -30,6 +30,9 @@ public: char const *GetName() { return ""; } void SetPosition(vec3 const &pos); + void SetOrtho(float width, float height, float near, float far); + void SetPerspective(float fov, float width, float height, + float near, float far); mat4 const &GetViewMatrix(); mat4 const &GetProjMatrix(); diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 008ebb92..7a708bbc 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -1814,6 +1814,7 @@ template struct Mat4 /* Helpers for projection matrices */ static Mat4 ortho(T left, T right, T bottom, T top, T near, T far); + static Mat4 ortho(T width, T height, T near, T far); static Mat4 frustum(T left, T right, T bottom, T top, T near, T far); static Mat4 perspective(T fov_y, T width, T height, T near, T far); diff --git a/src/math/vector.cpp b/src/math/vector.cpp index 13b9904b..2451d292 100644 --- a/src/math/vector.cpp +++ b/src/math/vector.cpp @@ -658,6 +658,13 @@ template<> mat4 mat4::ortho(float left, float right, float bottom, return ret; } +template<> mat4 mat4::ortho(float width, float height, + float near, float far) +{ + return mat4::ortho(-0.5f * width, 0.5f * width, + -0.5f * height, 0.5f * height, near, far); +} + template<> mat4 mat4::frustum(float left, float right, float bottom, float top, float near, float far) {