From 915a7b40a131976f4bff8363bebcc2b6408d716d Mon Sep 17 00:00:00 2001 From: dibenedetto Date: Tue, 17 Mar 2009 18:59:20 +0000 Subject: [PATCH] call IntersectionRayTriangle in Intersection_Segment_Triangle instead of generic Intersection (missing overload). --- vcg/space/intersection3.h | 120 +++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/vcg/space/intersection3.h b/vcg/space/intersection3.h index c5d31b4e..1d73af92 100644 --- a/vcg/space/intersection3.h +++ b/vcg/space/intersection3.h @@ -439,9 +439,9 @@ namespace vcg { /* * Function computing the intersection between a line and a triangle. * from: - * Tomas Möller and Ben Trumbore, - * ``Fast, Minimum Storage Ray-Triangle Intersection'', - * journal of graphics tools, vol. 2, no. 1, pp. 21-28, 1997 + * Tomas Möller and Ben Trumbore, + * ``Fast, Minimum Storage Ray-Triangle Intersection'', + * journal of graphics tools, vol. 2, no. 1, pp. 21-28, 1997 * @param[in] line * @param[in] triangle vertices * @param[out] intersection the intersection point, meaningful only if the line intersects the triangle @@ -451,61 +451,61 @@ namespace vcg { template bool IntersectionLineTriangle( const Line3 & line, const Point3 & vert0, const Point3 & vert1, const Point3 & vert2, - T & t ,T & u, T & v) -{ - #define EPSIL 0.000001 - - vcg::Point3 edge1, edge2, tvec, pvec, qvec; - T det,inv_det; - - /* find vectors for two edges sharing vert0 */ - edge1 = vert1 - vert0; - edge2 = vert2 - vert0; - - /* begin calculating determinant - also used to calculate U parameter */ - pvec = line.Direction() ^ edge2; - - /* if determinant is near zero, line lies in plane of triangle */ - det = edge1 * pvec; - - /* calculate distance from vert0 to line origin */ - tvec = line.Origin() - vert0; - inv_det = 1.0 / det; - - qvec = tvec ^ edge1; - - if (det > EPSIL) - { - u = tvec * pvec ; - if ( u < 0.0 || u > det) - return 0; - - /* calculate V parameter and test bounds */ - v = line.Direction() * qvec; - if ( v < 0.0 || u + v > det) - return 0; - - } - else if(det < -EPSIL) - { - /* calculate U parameter and test bounds */ - u = tvec * pvec ; - if ( u > 0.0 || u < det) - return 0; - - /* calculate V parameter and test bounds */ - v = line.Direction() * qvec ; - if ( v > 0.0 || u + v < det) - return 0; - } - else return 0; /* line is parallell to the plane of the triangle */ - - t = edge2 * qvec * inv_det; - ( u) *= inv_det; - ( v) *= inv_det; - - return 1; -} + T & t ,T & u, T & v) +{ + #define EPSIL 0.000001 + + vcg::Point3 edge1, edge2, tvec, pvec, qvec; + T det,inv_det; + + /* find vectors for two edges sharing vert0 */ + edge1 = vert1 - vert0; + edge2 = vert2 - vert0; + + /* begin calculating determinant - also used to calculate U parameter */ + pvec = line.Direction() ^ edge2; + + /* if determinant is near zero, line lies in plane of triangle */ + det = edge1 * pvec; + + /* calculate distance from vert0 to line origin */ + tvec = line.Origin() - vert0; + inv_det = 1.0 / det; + + qvec = tvec ^ edge1; + + if (det > EPSIL) + { + u = tvec * pvec ; + if ( u < 0.0 || u > det) + return 0; + + /* calculate V parameter and test bounds */ + v = line.Direction() * qvec; + if ( v < 0.0 || u + v > det) + return 0; + + } + else if(det < -EPSIL) + { + /* calculate U parameter and test bounds */ + u = tvec * pvec ; + if ( u > 0.0 || u < det) + return 0; + + /* calculate V parameter and test bounds */ + v = line.Direction() * qvec ; + if ( v > 0.0 || u + v < det) + return 0; + } + else return 0; /* line is parallell to the plane of the triangle */ + + t = edge2 * qvec * inv_det; + ( u) *= inv_det; + ( v) *= inv_det; + + return 1; +} template bool IntersectionRayTriangle( const Ray3 & ray, const Point3 & vert0, @@ -680,8 +680,8 @@ bool Intersection_Segment_Triangle( const vcg::Segment3 & seg, ray.Set(seg.P0(),dir); //then control for each direction the intersection with triangle - if ((Intersection(ray,vert0,vert1,vert2,a,b,dist)) - ||(Intersection(ray,vert1,vert0,vert2,b,a,dist))) + if ((IntersectionRayTriangle(ray,vert0,vert1,vert2,dist,a,b)) + ||(IntersectionRayTriangle(ray,vert1,vert0,vert2,dist,b,a))) return (dist<(seg.P1()-seg.P0()).Norm()); else return(false);