From c90cc1f31a285ed2ef21a21b5610837425d1ef51 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 13 Nov 2014 23:08:14 +0200 Subject: [PATCH] Add orthographic mode to Camera --- source/camera.cpp | 15 ++++++++++++++- source/camera.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/source/camera.cpp b/source/camera.cpp index fca3ea33..a0c89e0e 100644 --- a/source/camera.cpp +++ b/source/camera.cpp @@ -7,6 +7,7 @@ namespace GL { Camera::Camera(): fov(Geometry::Angle::from_turns(0.125)), + height(0), aspect(4.0/3.0), clip_near(0.1), clip_far(10), @@ -26,6 +27,15 @@ void Camera::set_field_of_view(const Geometry::Angle &f) update_projection_matrix(); } +void Camera::set_orthographic(float w, float h) +{ + fov = Geometry::Angle::zero(); + height = h; + if(w) + aspect = w/h; + update_projection_matrix(); +} + void Camera::set_aspect(float a) { aspect = a; @@ -101,7 +111,10 @@ void Camera::update_projection_matrix() float right = frustum_w*(frustum_x+1.0f); float bottom = frustum_h*(frustum_y-1.0f); float top = frustum_h*(frustum_y+1.0f); - proj_matrix = Matrix::frustum(left, right, bottom, top, clip_near, clip_far); + if(fov>Geometry::Angle::zero()) + proj_matrix = Matrix::frustum(left, right, bottom, top, clip_near, clip_far); + else + proj_matrix = Matrix::ortho(left, right, bottom, top, clip_near, clip_far); } void Camera::update_object_matrix() diff --git a/source/camera.h b/source/camera.h index bfcc2987..9a525e6b 100644 --- a/source/camera.h +++ b/source/camera.h @@ -11,6 +11,7 @@ class Camera { private: Geometry::Angle fov; + float height; float aspect; // Some compilers have "near" and "far" keywords float clip_near; @@ -28,6 +29,7 @@ public: Camera(); void set_field_of_view(const Geometry::Angle &); + void set_orthographic(float, float); void set_aspect(float); void set_depth_clip(float, float); void set_frustum_axis(float, float); -- 2.45.2