From f6261d2a45e12985f34c3933b7f070ddb51c3a05 Mon Sep 17 00:00:00 2001 From: mcallieri Date: Mon, 12 Dec 2005 16:52:55 +0000 Subject: [PATCH] Added Unproject, from 2D local space + Zdepth to 3D camera space. Added ViewportToLocal, inverse of LocalToViewport --- vcg/math/camera.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/vcg/math/camera.h b/vcg/math/camera.h index 9c53f2a3..107cfe4f 100644 --- a/vcg/math/camera.h +++ b/vcg/math/camera.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.24 2005/12/01 01:03:37 cignoni +Removed excess ';' from end of template functions, for gcc compiling + Revision 1.23 2005/10/12 16:43:32 ponchio Added IsOrtho... @@ -203,7 +206,9 @@ public: /// project a point from space 3d (in the reference system of the camera) to the camera's plane /// the result is in absolute coordinates inline vcg::Point2 Project(const vcg::Point3 & p); + inline vcg::Point3 UnProject(const vcg::Point2 & p, const S & d); inline vcg::Point2 LocalToViewport(const vcg::Point2 & p); + inline vcg::Point2 ViewportToLocal(const vcg::Point2 & p); inline vcg::Point2 LocalTo_0_1(const vcg::Point2 & p); inline vcg::Point2 LocalTo_neg1_1(const vcg::Point2 & p); }; @@ -221,6 +226,21 @@ vcg::Point2 Camera::Project(const vcg::Point3 & p){ return q; } +/// project back a 2D point on LOCAL plane + Zdepth to 3D camera space coord +template +vcg::Point3 Camera::UnProject(const vcg::Point2 & p, const S & d) +{ + vcg::Point3 np = Point3(p[0], p[1], d); + + if(!IsOrtho()) + { + np[0] /= f/d; + np[1] /= f/d; + } + + return np; +} + template vcg::Point2 Camera::LocalToViewport(const vcg::Point2 & p){ vcg::Point2 ps; @@ -229,6 +249,14 @@ vcg::Point2 Camera::LocalToViewport(const vcg::Point2 & p){ return ps; } +template +vcg::Point2 Camera::ViewportToLocal(const vcg::Point2 & p){ + vcg::Point2 ps; + ps[0] = (p[0]-c.X()) * s.X(); + ps[1] = (p[1]-c.Y()) * s.Y(); + return ps; +} + template vcg::Point2 Camera::LocalTo_0_1(const vcg::Point2 & p){ vcg::Point2 ps;