From 825be3e1e7e75fd2ef65f43632e8f90b60e7c2b1 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 12 Sep 2014 08:40:48 -0700 Subject: [PATCH] fix for ray-vs-AACubeShape intersection test --- libraries/shared/src/AACubeShape.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/shared/src/AACubeShape.cpp b/libraries/shared/src/AACubeShape.cpp index 1fa41bb521..131885864b 100644 --- a/libraries/shared/src/AACubeShape.cpp +++ b/libraries/shared/src/AACubeShape.cpp @@ -36,11 +36,12 @@ bool AACubeShape::findRayIntersection(RayIntersectionInfo& intersection) const { } // check for tuncated/short ray - const float maxBA = glm::min(intersection._rayLength, intersection._hitDistance) + halfSide; - if (maxBA * maxBA > a * a + b2) { + // maxLength = maximum possible distance between rayStart and center of cube + const float maxLength = glm::min(intersection._rayLength, intersection._hitDistance) + r; + float maxBA2 = maxLength * maxLength; + if (a * a + b2 > maxLength * maxLength) { // ray is not long enough to reach cube's bounding sphere - // NOTE: we don't fall in here when ray's length if FLT_MAX because maxBA^2 will be NaN - // and all NaN comparisons are false + // NOTE: we don't fall in here when ray's length if FLT_MAX because maxLength^2 will be inf or nan return false; }