float s = dets / denominator;
float t = dett / denominator;
//The points of intersection.
Vector3 point1 = ray1.Position + (s * ray1.Direction);
Vector3 point2 = ray2.Position + (t * ray2.Direction);
both s and t should be non-negative numbers because rays have a starting point.
I had to add this code after computing s and t.
if (s < 0 || t < 0)
{
point = Vector3.Zero;
return false;
}
Also, I added the else in this section when the Rays are parallel but not on top of each other:
//Lines are parallel.
if (MathUtil.IsZero(denominator))
{
//Lines are parallel and on top of each other.
if (MathUtil.NearEqual(ray2.Position.X, ray1.Position.X) &&
MathUtil.NearEqual(ray2.Position.Y, ray1.Position.Y) &&
MathUtil.NearEqual(ray2.Position.Z, ray1.Position.Z))
{
point = Vector3.Zero;
return true;
}
else
{
point = Vector3.Zero;
return false;
}
}
When finding the intersection point:
both s and t should be non-negative numbers because rays have a starting point.
I had to add this code after computing s and t.
Also, I added the else in this section when the Rays are parallel but not on top of each other: