Skip to content

Commit

Permalink
All the current tests pass now!
Browse files Browse the repository at this point in the history
  • Loading branch information
renaudbedard committed Feb 28, 2013
1 parent 16f0b64 commit 4507d09
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions MonoGame.Framework/Ray.cs
Expand Up @@ -88,8 +88,7 @@ public override int GetHashCode()
{
const float Epsilon = 1e-6f;

float tMin = float.MaxValue,
tMax = float.MinValue;
float? tMin = null, tMax = null;

if (Math.Abs(Direction.X) < Epsilon)
{
Expand Down Expand Up @@ -126,11 +125,11 @@ public override int GetHashCode()
tMaxY = temp;
}

if (tMin > tMaxY || tMinY > tMax)
if ((tMin.HasValue && tMin > tMaxY) || (tMax.HasValue && tMinY > tMax))
return null;

if (tMinY > tMin) tMin = tMinY;
if (tMaxY < tMax) tMax = tMaxY;
if (!tMin.HasValue || tMinY > tMin) tMin = tMinY;
if (!tMax.HasValue || tMaxY < tMax) tMax = tMaxY;
}

if (Math.Abs(Direction.Z) < Epsilon)
Expand All @@ -150,12 +149,17 @@ public override int GetHashCode()
tMaxZ = temp;
}

if (tMin > tMaxZ || tMinZ > tMax)
if ((tMin.HasValue && tMin > tMaxZ) || (tMax.HasValue && tMinZ > tMax))
return null;

if (tMinZ > tMin) tMin = tMinZ;
if (!tMin.HasValue || tMinZ > tMin) tMin = tMinZ;
if (!tMax.HasValue || tMaxZ < tMax) tMax = tMaxZ;
}

// having a positive tMin and a negative tMax means the ray is inside the box
// we expect the intesection distance to be 0 in that case
if ((tMin.HasValue && tMin < 0) && tMax > 0) return 0;

// a negative tMin means that the intersection point is behind the ray's origin
// we discard these as not hitting the AABB
if (tMin < 0) return null;
Expand Down

0 comments on commit 4507d09

Please sign in to comment.