From: Mikko Rasa Date: Tue, 2 Aug 2016 22:26:37 +0000 (+0300) Subject: Support rotating the camera frustum X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=aa4d7203c90083af7fbcbe8368e55ad2f29d5ff1;p=libs%2Fgl.git Support rotating the camera frustum The rotation is applied as the very last step of projection, alllowing screen rotation to be easily implemented in software. --- diff --git a/source/camera.cpp b/source/camera.cpp index d119e1ef..ba8ff718 100644 --- a/source/camera.cpp +++ b/source/camera.cpp @@ -56,6 +56,12 @@ void Camera::set_frustum_axis(float x, float y) update_projection_matrix(); } +void Camera::set_frustum_rotation(const Geometry::Angle &r) +{ + rotate = r; + update_projection_matrix(); +} + void Camera::set_position(const Vector3 &p) { position = p; @@ -115,6 +121,7 @@ void Camera::update_projection_matrix() 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); + proj_matrix = Matrix::rotation(rotate, Vector3(0, 0, 1))*proj_matrix; } void Camera::update_object_matrix() diff --git a/source/camera.h b/source/camera.h index 9a525e6b..f814e9d7 100644 --- a/source/camera.h +++ b/source/camera.h @@ -18,6 +18,7 @@ private: float clip_far; float frustum_x; float frustum_y; + Geometry::Angle rotate; Vector3 position; Vector3 look_dir; Vector3 up_dir; @@ -33,10 +34,12 @@ public: void set_aspect(float); void set_depth_clip(float, float); void set_frustum_axis(float, float); + void set_frustum_rotation(const Geometry::Angle &); const Geometry::Angle &get_field_of_view() const { return fov; } float get_aspect() const { return aspect; } float get_near_clip() const { return clip_near; } float get_far_clip() const { return clip_far; } + const Geometry::Angle &get_frustum_rotation() const { return rotate; } void set_position(const Vector3 &); void set_look_direction(const Vector3 &);