]> git.tdb.fi Git - libs/gl.git/commitdiff
Support rotating the camera frustum
authorMikko Rasa <tdb@tdb.fi>
Tue, 2 Aug 2016 22:26:37 +0000 (01:26 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 2 Aug 2016 22:26:37 +0000 (01:26 +0300)
The rotation is applied as the very last step of projection, alllowing
screen rotation to be easily implemented in software.

source/camera.cpp
source/camera.h

index d119e1eff1b67245b9fca74c4058b5d5077af8e3..ba8ff718d136744dbff8261d73b887a21258ef76 100644 (file)
@@ -56,6 +56,12 @@ void Camera::set_frustum_axis(float x, float y)
        update_projection_matrix();
 }
 
+void Camera::set_frustum_rotation(const Geometry::Angle<float> &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()
index 9a525e6b1d51077af5f06874ba0a4a56a3b6505d..f814e9d7cac17898fe8a4c1716910079632bfe2d 100644 (file)
@@ -18,6 +18,7 @@ private:
        float clip_far;
        float frustum_x;
        float frustum_y;
+       Geometry::Angle<float> 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<float> &);
        const Geometry::Angle<float> &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<float> &get_frustum_rotation() const { return rotate; }
 
        void set_position(const Vector3 &);
        void set_look_direction(const Vector3 &);