Added a check for zero length line segment in bool LineSegment::intersect(const BoundingSphere& bs,float& r1,float& r2) const.

This commit is contained in:
Robert Osfield 2006-09-12 12:35:20 +00:00
parent bd5a40d82c
commit c7906d5412

View File

@ -180,6 +180,21 @@ bool LineSegment::intersect(const BoundingSphere& bs,float& r1,float& r2) const
Vec3 se = _e-_s;
float a = se.length2();
// check for zero length segment.
if (a==0.0)
{
// check if start point outside sphere radius
if (c>0.0) return false;
// length segment within radius of bounding sphere but zero length
// so return true, and set the ratio so the start point is the one
// to be used.
r1 = 1.0f;
r2 = 0.0f;
return true;
}
float b = sm*se*2.0f;
float d = b*b-4.0f*a*c;
@ -188,6 +203,7 @@ bool LineSegment::intersect(const BoundingSphere& bs,float& r1,float& r2) const
d = sqrtf(d);
float div = 1.0f/(2.0f*a);
r1 = (-b-d)*div;