call IntersectionRayTriangle in Intersection_Segment_Triangle instead of generic Intersection (missing overload).
This commit is contained in:
parent
eeacaeff3b
commit
915a7b40a1
|
@ -439,9 +439,9 @@ namespace vcg {
|
||||||
/*
|
/*
|
||||||
* Function computing the intersection between a line and a triangle.
|
* Function computing the intersection between a line and a triangle.
|
||||||
* from:
|
* from:
|
||||||
* Tomas Möller and Ben Trumbore,
|
* Tomas Möller and Ben Trumbore,
|
||||||
* ``Fast, Minimum Storage Ray-Triangle Intersection'',
|
* ``Fast, Minimum Storage Ray-Triangle Intersection'',
|
||||||
* journal of graphics tools, vol. 2, no. 1, pp. 21-28, 1997
|
* journal of graphics tools, vol. 2, no. 1, pp. 21-28, 1997
|
||||||
* @param[in] line
|
* @param[in] line
|
||||||
* @param[in] triangle vertices
|
* @param[in] triangle vertices
|
||||||
* @param[out] intersection the intersection point, meaningful only if the line intersects the triangle
|
* @param[out] intersection the intersection point, meaningful only if the line intersects the triangle
|
||||||
|
@ -451,61 +451,61 @@ namespace vcg {
|
||||||
template<class T>
|
template<class T>
|
||||||
bool IntersectionLineTriangle( const Line3<T> & line, const Point3<T> & vert0,
|
bool IntersectionLineTriangle( const Line3<T> & line, const Point3<T> & vert0,
|
||||||
const Point3<T> & vert1, const Point3<T> & vert2,
|
const Point3<T> & vert1, const Point3<T> & vert2,
|
||||||
T & t ,T & u, T & v)
|
T & t ,T & u, T & v)
|
||||||
{
|
{
|
||||||
#define EPSIL 0.000001
|
#define EPSIL 0.000001
|
||||||
|
|
||||||
vcg::Point3<T> edge1, edge2, tvec, pvec, qvec;
|
vcg::Point3<T> edge1, edge2, tvec, pvec, qvec;
|
||||||
T det,inv_det;
|
T det,inv_det;
|
||||||
|
|
||||||
/* find vectors for two edges sharing vert0 */
|
/* find vectors for two edges sharing vert0 */
|
||||||
edge1 = vert1 - vert0;
|
edge1 = vert1 - vert0;
|
||||||
edge2 = vert2 - vert0;
|
edge2 = vert2 - vert0;
|
||||||
|
|
||||||
/* begin calculating determinant - also used to calculate U parameter */
|
/* begin calculating determinant - also used to calculate U parameter */
|
||||||
pvec = line.Direction() ^ edge2;
|
pvec = line.Direction() ^ edge2;
|
||||||
|
|
||||||
/* if determinant is near zero, line lies in plane of triangle */
|
/* if determinant is near zero, line lies in plane of triangle */
|
||||||
det = edge1 * pvec;
|
det = edge1 * pvec;
|
||||||
|
|
||||||
/* calculate distance from vert0 to line origin */
|
/* calculate distance from vert0 to line origin */
|
||||||
tvec = line.Origin() - vert0;
|
tvec = line.Origin() - vert0;
|
||||||
inv_det = 1.0 / det;
|
inv_det = 1.0 / det;
|
||||||
|
|
||||||
qvec = tvec ^ edge1;
|
qvec = tvec ^ edge1;
|
||||||
|
|
||||||
if (det > EPSIL)
|
if (det > EPSIL)
|
||||||
{
|
{
|
||||||
u = tvec * pvec ;
|
u = tvec * pvec ;
|
||||||
if ( u < 0.0 || u > det)
|
if ( u < 0.0 || u > det)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* calculate V parameter and test bounds */
|
/* calculate V parameter and test bounds */
|
||||||
v = line.Direction() * qvec;
|
v = line.Direction() * qvec;
|
||||||
if ( v < 0.0 || u + v > det)
|
if ( v < 0.0 || u + v > det)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(det < -EPSIL)
|
else if(det < -EPSIL)
|
||||||
{
|
{
|
||||||
/* calculate U parameter and test bounds */
|
/* calculate U parameter and test bounds */
|
||||||
u = tvec * pvec ;
|
u = tvec * pvec ;
|
||||||
if ( u > 0.0 || u < det)
|
if ( u > 0.0 || u < det)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* calculate V parameter and test bounds */
|
/* calculate V parameter and test bounds */
|
||||||
v = line.Direction() * qvec ;
|
v = line.Direction() * qvec ;
|
||||||
if ( v > 0.0 || u + v < det)
|
if ( v > 0.0 || u + v < det)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else return 0; /* line is parallell to the plane of the triangle */
|
else return 0; /* line is parallell to the plane of the triangle */
|
||||||
|
|
||||||
t = edge2 * qvec * inv_det;
|
t = edge2 * qvec * inv_det;
|
||||||
( u) *= inv_det;
|
( u) *= inv_det;
|
||||||
( v) *= inv_det;
|
( v) *= inv_det;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
bool IntersectionRayTriangle( const Ray3<T> & ray, const Point3<T> & vert0,
|
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);
|
ray.Set(seg.P0(),dir);
|
||||||
|
|
||||||
//then control for each direction the intersection with triangle
|
//then control for each direction the intersection with triangle
|
||||||
if ((Intersection<ScalarType>(ray,vert0,vert1,vert2,a,b,dist))
|
if ((IntersectionRayTriangle<ScalarType>(ray,vert0,vert1,vert2,dist,a,b))
|
||||||
||(Intersection<ScalarType>(ray,vert1,vert0,vert2,b,a,dist)))
|
||(IntersectionRayTriangle<ScalarType>(ray,vert1,vert0,vert2,dist,b,a)))
|
||||||
return (dist<(seg.P1()-seg.P0()).Norm());
|
return (dist<(seg.P1()-seg.P0()).Norm());
|
||||||
else
|
else
|
||||||
return(false);
|
return(false);
|
||||||
|
|
Loading…
Reference in New Issue