From c9fe85c9f480ac116006296a3e8b0b1feb95bedd Mon Sep 17 00:00:00 2001 From: Elliot Woods Date: Sat, 3 Mar 2012 14:16:39 +0000 Subject: [PATCH] added projectPoint --- src/ofxRay/ofProjector.cpp | 7 +++++++ src/ofxRay/ofProjector.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/ofxRay/ofProjector.cpp b/src/ofxRay/ofProjector.cpp index 6723628..0f7d021 100644 --- a/src/ofxRay/ofProjector.cpp +++ b/src/ofxRay/ofProjector.cpp @@ -199,4 +199,11 @@ namespace ofxRay { ofMatrix4x4 Projector::getViewProjectionMatrix() const { return this->getViewMatrix() * this->getProjectionMatrix(); } + + //---------- + ofVec3f Projector::projectPoint(const ofVec3f& point) const { + ofVec4f point4(point.x, point.y, point.z, 1.0f); + point4 = point4 * this->getViewProjectionMatrix(); + return ofVec3f(point4.x / point4.w, point4.y / point4.w, point4.z / point4.w); + } } \ No newline at end of file diff --git a/src/ofxRay/ofProjector.h b/src/ofxRay/ofProjector.h index 0ec774f..b80d066 100644 --- a/src/ofxRay/ofProjector.h +++ b/src/ofxRay/ofProjector.h @@ -51,6 +51,8 @@ namespace ofxRay { ofMatrix4x4 getProjectionMatrix() const; ofMatrix4x4 getViewProjectionMatrix() const; + ofVec3f projectPoint(const ofVec3f& point) const; + protected: int width; int height;