]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/SGIntersect.hxx
Extend SGSubsystemGroup, to allow running a fixed dt time, internally
[simgear.git] / simgear / math / SGIntersect.hxx
index 6ffffeb89d222396f1c355bffd2d46bf5b7bc1d4..24741f6409bd78dcfeb603525aab6cbd0a474592 100644 (file)
@@ -38,25 +38,11 @@ intersects(const SGBox<T1>& box, const SGSphere<T2>& 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<T1> closest = box.getClosestPoint(sphere.getCenter());
+  return distSqr(closest, SGVec3<T1>(sphere.getCenter())) <= sphere.getRadius2();
 }
 // make it symmetric
 template<typename T1, typename T2>
@@ -572,13 +558,15 @@ closestPoint(const SGTriangle<T>& tri, const SGVec3<T>& 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<T>& tri, const SGSphere<T2>& 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) {