diff --git a/src/Magnum/Math/Geometry/Intersection.h b/src/Magnum/Math/Geometry/Intersection.h index 06d557c4e..8d846d3e9 100644 --- a/src/Magnum/Math/Geometry/Intersection.h +++ b/src/Magnum/Math/Geometry/Intersection.h @@ -166,29 +166,23 @@ template bool Intersection::pointFrustum(const Vector3& point, const } template bool Intersection::boxFrustum(const Range3D& box, const Frustum& frustum) { - /* Create the 8 vertices of the box from the 2 given vertices min and max - Check for each corner of an octant whether it is inside the frustum. If - only some of the corners are inside, the octant requires further checks. */ - Int planes = 0; - for(const Vector4& plane: frustum.planes()) { - Int corners = 0; + bool cornerHit = 0; for(UnsignedByte c = 0; c != 8; ++c) { const Vector3 corner = Math::lerp(box.min(), box.max(), Math::BoolVector<3>{c}); - if(Distance::pointPlaneScaled(corner, plane) >= T(0)) - ++corners; + if(Distance::pointPlaneScaled(corner, plane) >= T(0)) { + cornerHit = true; + break; + } } /* All corners are outside this plane */ - if(corners == 0) return false; - - if(corners == 8) ++planes; + if(!cornerHit) return false; } /** @todo potentially check corners here to avoid false positives */ - /* if(planes == 6) return true; */ return true; }