Skip to content

Commit

Permalink
explicitly provide unsigned & signed versions of sphere/ray intersect
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed Oct 26, 2016
1 parent d54274e commit 7a93b87
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions queries/RayIntersection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ private RayIntersection()

// basic ray-sphere intersection
public static bool Sphere(Vector3f vOrigin, Vector3f vDirection, Vector3f vCenter, float fRadius, out float fRayT)
{
bool bHit = SphereSigned(vOrigin, vDirection, vCenter, fRadius, out fRayT);
fRayT = Math.Abs(fRayT);
return bHit;
}

public static bool SphereSigned(Vector3f vOrigin, Vector3f vDirection, Vector3f vCenter, float fRadius, out float fRayT)
{
fRayT = 0.0f;
Vector3f m = vOrigin - vCenter;
Expand All @@ -32,11 +39,6 @@ public static bool Sphere(Vector3f vOrigin, Vector3f vDirection, Vector3f vCente
// Ray now found to intersect sphere, compute smallest t value of intersection
fRayT = -b - (float)Math.Sqrt(discr);

// If t is negative, ray started inside sphere so clamp t to zero
// [RMS] disabling this...want to know this info
//if (fRayT < 0.0f)
// fRayT = 0.0f;

return true;
}
}
Expand Down

0 comments on commit 7a93b87

Please sign in to comment.