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)
}
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;
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()
Vector3 up_dir;
Matrix view_matrix;
Matrix object_matrix;
+ Matrix proj_matrix;
public:
Camera();
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;
void apply() const;
private:
+ void update_projection_matrix();
void update_object_matrix();
};