]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix Camera::unproject
authorMikko Rasa <tdb@tdb.fi>
Mon, 24 Oct 2016 20:55:58 +0000 (23:55 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 24 Oct 2016 20:55:58 +0000 (23:55 +0300)
It was lacking un-perspective division.  There's also a Vector3 overload
now.

source/camera.cpp
source/camera.h

index ba8ff718d136744dbff8261d73b887a21258ef76..ae35f632438df2d9a7a8a416f838deabde6b8320 100644 (file)
@@ -99,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;
index f814e9d7cac17898fe8a4c1716910079632bfe2d..44d3bf33e6f7bf788f9e188f8ec91e8524084c30 100644 (file)
@@ -66,6 +66,7 @@ public:
        Vector3 project(const Vector4 &) const;
        Vector3 project(const Vector3 &) const;
        Vector4 unproject(const Vector4 &) const;
+       Vector3 unproject(const Vector3 &) const;
 
        void apply() const;