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