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;
Vector4 Camera::unproject(const Vector4 &p) const
{
Vector4 r = invert(proj_matrix)*Vector4(p.x, p.y, p.z, 1.0f);
- r = object_matrix*Vector4(r.x, r.y, r.z, p.w);
+ r = object_matrix*Vector4(r.x/r.w, r.y/r.w, r.z/r.w, p.w);
return r;
}
+Vector3 Camera::unproject(const Vector3 &p) const
+{
+ return unproject(Vector4(p.x, p.y, p.z, 1.0f)).slice<3>(0);
+}
+
void Camera::apply() const
{
MatrixStack::projection() = proj_matrix;
void Camera::update_projection_matrix()
{
- float frustum_h = tan(fov/2.0f)*clip_near;
+ float frustum_h = (fov!=Geometry::Angle<float>::zero() ? tan(fov/2.0f)*clip_near : height/2);
float frustum_w = frustum_h*aspect;
float left = frustum_w*(frustum_x-1.0f);
float right = frustum_w*(frustum_x+1.0f);
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()