]> git.tdb.fi Git - libs/gl.git/blobdiff - source/camera.cpp
Store and expose the projection matrix
[libs/gl.git] / source / camera.cpp
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()