THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/09/2010 at 11:36, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R12
Platform: Windows ; Mac OSX ;
Language(s) : C++ ;
---------
"Process.RayTriangleIntersect.I is outside T.a"
The following method is returning this error (near end of method) in Cinema 4D R12. It works perfectly in R9.1->R11.5. No idea what to do. I shouldn't be changing MY working algorithms for new builds!
// Process.RayTriangleIntersect
//*---------------------------------------------------------------------------*
Bool Process::RayTriangleIntersect(const Vector& p0, const Vector& p1, const Vector& lv0, const Vector& lv1, const Vector& lv2)
//*---------------------------------------------------------------------------*
{
// get triangle edge vectors and plane normal
Vector u = lv1 - lv0;
Vector v = lv2 - lv0;
Vector n = u % v; // cross product
// triangle is degenerate
if (n == (Vector)0)
{
GePrint("Process.RayTriangleIntersect.Degenerate Triangle");
return FALSE; // do not deal with this case
}
// ray vectors
// params to calc ray-plane intersect
Vector dir = p1 - p0; // ray direction vector
Real b = n * dir;
// ray is parallel to triangle plane
if (Abs(b) < 0.00000001)
{
// ray lies in triangle plane
//if (a == 0) return FALSE;
// ray disjoint from plane
GePrint("Process.RayTriangleIntersect.Ray Parallel Triangle Plane");
return FALSE;
}
Real a = -(n * (p0 - lv0));
// get intersect point of ray with triangle plane
Real r = a / b;
// ray goes away from triangle
if (r < 0.0)
{
GePrint("Process.RayTriangleIntersect.No Intersect");
return FALSE; // => no intersect
}
// for a segment, also test if (r > 1.0) => no intersect
// intersect point of ray and plane
hitpos = p0 + r * dir;
// is I inside T?
n = hitpos - lv0;
Vector wu = n * u;
Vector wv = n * v;
n = u * v;
u = u * u;
v = v * v;
Real D = 1.0 / (n * n - u * v);
// get and test parametric coords
a = (n * wv - v * wu) * D;
// I is outside T
if ((a < 0.0) || (a > 1.0))
{
GePrint("Process.RayTriangleIntersect.I is outside T.a");
return FALSE;
}
b = (n * wu - u * wv) * D;
// I is outside T
if ((b < 0.0) || ((a + b) > 1.0))
{
GePrint("Process.RayTriangleIntersect.I is outside T.b");
return FALSE;
}
// I is in T
return TRUE;
}