From f4ec24c552f38eac365c677e495882ee069cf5aa Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Fri, 23 Jan 2009 14:33:13 +0000 Subject: [PATCH] Restored Ray-Triangle Intersection (as an extension of IntersectionLineTriangle) --- vcg/space/intersection3.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/vcg/space/intersection3.h b/vcg/space/intersection3.h index 3c44f455..c5d31b4e 100644 --- a/vcg/space/intersection3.h +++ b/vcg/space/intersection3.h @@ -507,6 +507,18 @@ bool IntersectionLineTriangle( const Line3 & line, const Point3 & vert0, return 1; } +template +bool IntersectionRayTriangle( const Ray3 & ray, const Point3 & vert0, + const Point3 & vert1, const Point3 & vert2, + T & t ,T & u, T & v) +{ + Line3 line(ray.Origin(), ray.Direction()); + if (IntersectionLineTriangle(line, vert0, vert1, vert2, t, u, v)) + { + if (t <= 0) return 0; + else return 1; + }else return 0; +} // line-box template @@ -843,13 +855,13 @@ public: template inline bool operator () (const TRIANGLETYPE & f, const Ray3 & ray, SCALARTYPE & t) { typedef SCALARTYPE ScalarType; - ScalarType a; - ScalarType b; + ScalarType u; + ScalarType v; - bool bret = Intersection(ray, Point3::Construct(f.P(0)), Point3::Construct(f.P(1)), Point3::Construct(f.P(2)), a, b, t); + bool bret = IntersectionRayTriangle(ray, Point3::Construct(f.P(0)), Point3::Construct(f.P(1)), Point3::Construct(f.P(2)), t, u, v); if (BACKFACETEST) { if (!bret) { - bret = Intersection(ray, Point3::Construct(f.P(0)), Point3::Construct(f.P(2)), Point3::Construct(f.P(1)), a, b, t); + bret = IntersectionRayTriangle(ray, Point3::Construct(f.P(0)), Point3::Construct(f.P(2)), Point3::Construct(f.P(1)), t, u, v); } } return (bret); @@ -857,8 +869,6 @@ public: }; - - /*@}*/