X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmath%2FSGIntersect.hxx;h=24741f6409bd78dcfeb603525aab6cbd0a474592;hb=cc9b817f0e20a879cd23ce7f8014b2dc6a5d493e;hp=6ffffeb89d222396f1c355bffd2d46bf5b7bc1d4;hpb=006f90997a8eef6704de2511e38fcc786672308d;p=simgear.git diff --git a/simgear/math/SGIntersect.hxx b/simgear/math/SGIntersect.hxx index 6ffffeb8..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 @@ -572,13 +558,15 @@ closestPoint(const SGTriangle& tri, const SGVec3& p) T u = b*e - c*d; T v = b*d - a*e; +/* // Regions // \2| // \| - // |\ + // |\ // 3 |0\ 1 //---------- // 4 | 5 \ 6 +*/ if (u + v <= det) { if (u < 0) { @@ -766,13 +754,15 @@ intersects(const SGTriangle& tri, const SGSphere& sphere) T u = b*e - c*d; T v = b*d - a*e; +/* // Regions // \2| // \| - // |\ + // |\ // 3 |0\ 1 //---------- // 4 | 5 \ 6 +*/ if (u + v <= det) { if (u < 0) {