BUG: wrong radius comparison in MathUtils::capsuleCapsuleOverlap()
by Manoel Neto · in Torque 3D Professional · 06/18/2009 (3:20 pm) · 1 replies
bool capsuleCapsuleOverlap(const Point3F & a1, const Point3F & b1, F32 rad1, const Point3F & a2, const Point3F & b2, F32 rad2)
{
F32 s,t;
Point3F c1,c2;
F32 dist = segmentSegmentNearest(a1,b1,a2,b2,s,t,c1,c2);
return dist <= rad1*rad1+rad2*rad2;
}The variable "dist" is actually a squared distance (there should be a note of this in segmentSegmentNearest()), and its being wrongly compared to the sum of the squares of the capsules' radius, when the correct is to compare it to the square of the sum of the capsules' radius. The correct should be:
bool capsuleCapsuleOverlap(const Point3F & a1, const Point3F & b1, F32 rad1, const Point3F & a2, const Point3F & b2, F32 rad2)
{
F32 s,t;
Point3F c1,c2;
F32 dist = segmentSegmentNearest(a1,b1,a2,b2,s,t,c1,c2);
return dist <= (rad1+rad2)*(rad1+rad2);
}About the author
Torque 3D Owner Kenneth Holst
Default Studio Name