call IntersectionRayTriangle in Intersection_Segment_Triangle instead of generic Intersection (missing overload).

This commit is contained in:
Marco Di Benedetto 2009-03-17 18:59:20 +00:00
parent eeacaeff3b
commit 915a7b40a1
1 changed files with 60 additions and 60 deletions

View File

@ -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<class T>
bool IntersectionLineTriangle( const Line3<T> & line, const Point3<T> & vert0,
const Point3<T> & vert1, const Point3<T> & vert2,
T & t ,T & u, T & v)
{
#define EPSIL 0.000001
vcg::Point3<T> 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<T> 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<class T>
bool IntersectionRayTriangle( const Ray3<T> & ray, const Point3<T> & vert0,
@ -680,8 +680,8 @@ bool Intersection_Segment_Triangle( const vcg::Segment3<ScalarType> & seg,
ray.Set(seg.P0(),dir);
//then control for each direction the intersection with triangle
if ((Intersection<ScalarType>(ray,vert0,vert1,vert2,a,b,dist))
||(Intersection<ScalarType>(ray,vert1,vert0,vert2,b,a,dist)))
if ((IntersectionRayTriangle<ScalarType>(ray,vert0,vert1,vert2,dist,a,b))
||(IntersectionRayTriangle<ScalarType>(ray,vert1,vert0,vert2,dist,b,a)))
return (dist<(seg.P1()-seg.P0()).Norm());
else
return(false);