X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmath%2FSGIntersect.hxx;h=24741f6409bd78dcfeb603525aab6cbd0a474592;hb=cc9b817f0e20a879cd23ce7f8014b2dc6a5d493e;hp=533bd2dc005db90668737ec250fdd1a64db4ead2;hpb=992a057a1b3e2059b5bb03d00d05f9197f816c5d;p=simgear.git diff --git a/simgear/math/SGIntersect.hxx b/simgear/math/SGIntersect.hxx index 533bd2dc..24741f64 100644 --- a/simgear/math/SGIntersect.hxx +++ b/simgear/math/SGIntersect.hxx @@ -38,25 +38,11 @@ intersects(const SGBox& box, const SGSphere& sphere) { if (sphere.empty()) return false; - // Is more or less trivially included in the next tests - // if (box.empty()) - // return false; - - if (sphere.getCenter().x() < box.getMin().x() - sphere.getRadius()) - return false; - if (sphere.getCenter().y() < box.getMin().y() - sphere.getRadius()) - return false; - if (sphere.getCenter().z() < box.getMin().z() - sphere.getRadius()) + if (box.empty()) return false; - if (box.getMax().x() + sphere.getRadius() < sphere.getCenter().x()) - return false; - if (box.getMax().y() + sphere.getRadius() < sphere.getCenter().y()) - return false; - if (box.getMax().z() + sphere.getRadius() < sphere.getCenter().z()) - return false; - - return true; + SGVec3 closest = box.getClosestPoint(sphere.getCenter()); + return distSqr(closest, SGVec3(sphere.getCenter())) <= sphere.getRadius2(); } // make it symmetric template