X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcamera.cpp;fp=source%2Fcamera.cpp;h=df4119a9e20b663503f6a14858a4633ca064a1e9;hp=0afa033c1348bf43a4fae8f57072c798a625e79d;hb=ea3487f52f8621f07deb47fa1af22a85b8b23519;hpb=c6149a1e9f488f790378969ff655e6bc94369d16 diff --git a/source/camera.cpp b/source/camera.cpp index 0afa033c..df4119a9 100644 --- a/source/camera.cpp +++ b/source/camera.cpp @@ -20,23 +20,27 @@ Camera::Camera(): void Camera::set_field_of_view(const Geometry::Angle &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()