X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcamera.cpp;h=ae35f632438df2d9a7a8a416f838deabde6b8320;hb=3b159edbe4e80a2bc19c4c2fcd42cb996b9fbfe0;hp=d119e1eff1b67245b9fca74c4058b5d5077af8e3;hpb=af7ffc9c72e30ae377476f76a51a6676dd6e89aa;p=libs%2Fgl.git diff --git a/source/camera.cpp b/source/camera.cpp index d119e1ef..ae35f632 100644 --- a/source/camera.cpp +++ b/source/camera.cpp @@ -56,6 +56,12 @@ void Camera::set_frustum_axis(float x, float y) update_projection_matrix(); } +void Camera::set_frustum_rotation(const Geometry::Angle &r) +{ + rotate = r; + update_projection_matrix(); +} + void Camera::set_position(const Vector3 &p) { position = p; @@ -93,10 +99,15 @@ Vector3 Camera::project(const Vector3 &p) const 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; @@ -115,6 +126,7 @@ void Camera::update_projection_matrix() 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()