]> git.tdb.fi Git - libs/gl.git/commitdiff
Store and expose the projection matrix
authorMikko Rasa <tdb@tdb.fi>
Mon, 25 Nov 2013 14:23:51 +0000 (16:23 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 25 Nov 2013 14:24:18 +0000 (16:24 +0200)
source/camera.cpp
source/camera.h

index 0afa033c1348bf43a4fae8f57072c798a625e79d..df4119a9e20b663503f6a14858a4633ca064a1e9 100644 (file)
@@ -20,23 +20,27 @@ Camera::Camera():
 void Camera::set_field_of_view(const Geometry::Angle<float> &f)
 {
        fov = f;
+       update_projection_matrix();
 }
 
 void Camera::set_aspect(float a)
 {
        aspect = a;
+       update_projection_matrix();
 }
 
 void Camera::set_depth_clip(float n, float f)
 {
        clip_near = n;
        clip_far = f;
+       update_projection_matrix();
 }
 
 void Camera::set_frustum_axis(float x, float y)
 {
        frustum_x = x;
        frustum_y = y;
+       update_projection_matrix();
 }
 
 void Camera::set_position(const Vector3 &p)
@@ -81,6 +85,12 @@ Vector4 Camera::unproject(const Vector4 &p) const
 }
 
 void Camera::apply() const
+{
+       MatrixStack::projection() = proj_matrix;
+       MatrixStack::modelview() = view_matrix;
+}
+
+void Camera::update_projection_matrix()
 {
        float frustum_h = tan(fov/2.0f)*clip_near;
        float frustum_w = frustum_h*aspect;
@@ -88,8 +98,7 @@ void Camera::apply() const
        float right = frustum_w*(frustum_x+1.0f);
        float bottom = frustum_h*(frustum_y-1.0f);
        float top = frustum_h*(frustum_y+1.0f);
-       MatrixStack::projection() = Matrix::frustum(left, right, bottom, top, clip_near, clip_far);
-       MatrixStack::modelview() = view_matrix;
+       proj_matrix = Matrix::frustum(left, right, bottom, top, clip_near, clip_far);
 }
 
 void Camera::update_object_matrix()
index 634557607c112abdd619e622203cfafe1b9eddd0..bfcc2987d860b8e258e3f4fa6bcaad3906853295 100644 (file)
@@ -22,6 +22,7 @@ private:
        Vector3 up_dir;
        Matrix view_matrix;
        Matrix object_matrix;
+       Matrix proj_matrix;
 
 public:
        Camera();
@@ -54,6 +55,9 @@ public:
        to world space. */
        const Matrix &get_object_matrix() const { return object_matrix; }
 
+       /** Returns the projection matrix. */
+       const Matrix &get_projection_matrix() const { return proj_matrix; }
+
        Vector3 project(const Vector4 &) const;
        Vector3 project(const Vector3 &) const;
        Vector4 unproject(const Vector4 &) const;
@@ -61,6 +65,7 @@ public:
        void apply() const;
 
 private:
+       void update_projection_matrix();
        void update_object_matrix();
 };