X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmath%2FSGIntersect.hxx;h=46bdb427d0e027c388be42a3997858eeed1ec4ac;hb=3bcd0bafd5fba1eebadfd1cb8a7294d665cf1932;hp=533bd2dc005db90668737ec250fdd1a64db4ead2;hpb=992a057a1b3e2059b5bb03d00d05f9197f816c5d;p=simgear.git diff --git a/simgear/math/SGIntersect.hxx b/simgear/math/SGIntersect.hxx index 533bd2dc..46bdb427 100644 --- a/simgear/math/SGIntersect.hxx +++ b/simgear/math/SGIntersect.hxx @@ -18,6 +18,8 @@ #ifndef SGIntersect_HXX #define SGIntersect_HXX +#include + template inline bool intersects(const SGSphere& s1, const SGSphere& s2) @@ -38,25 +40,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 @@ -265,11 +253,11 @@ intersects(SGVec3& dst, const SGLineSegment& lineSegment, const SGPlane // The negative numerator for the \alpha expression T num = plane.getPositiveDist(); - num -= dot(plane.getNormal(), lineSegment.getOrigin()); + num -= dot(plane.getNormal(), lineSegment.getStart()); // If the numerator is zero, we have the lines origin included in the plane if (fabs(num) <= SGLimits::min()) { - dst = lineSegment.getOrigin(); + dst = lineSegment.getStart(); return true; } @@ -291,7 +279,7 @@ intersects(SGVec3& dst, const SGLineSegment& lineSegment, const SGPlane if (1 < alpha) return false; - dst = lineSegment.getOrigin() + alpha*lineSegment.getDirection(); + dst = lineSegment.getStart() + alpha*lineSegment.getDirection(); return true; } // make it symmetric