]> Dogcows Code - chaz/yoink/blobdiff - src/moof/plane.cc
the massive refactoring effort
[chaz/yoink] / src / moof / plane.cc
diff --git a/src/moof/plane.cc b/src/moof/plane.cc
new file mode 100644 (file)
index 0000000..4a175b0
--- /dev/null
@@ -0,0 +1,51 @@
+
+/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
+**]  All rights reserved.
+*
+* vi:ts=4 sw=4 tw=75
+*
+* Distributable under the terms and conditions of the 2-clause BSD license;
+* see the file COPYING for a complete text of the license.
+*
+**************************************************************************/
+
+#include "aabb.hh"
+#include "plane.hh"
+#include "sphere.hh"
+
+
+namespace moof {
+
+
+plane::halfspace plane::intersects(const aabb<3>& aabb) const
+{
+       vector3 corners[8];
+       int nPositive = 8;
+
+       aabb.get_corners(corners);
+
+       for (int i = 0; i < 8; ++i)
+       {
+               if (intersects(corners[i]) == negative)
+               {
+                       --nPositive;
+               }
+       }
+
+       if (nPositive == 0)      return negative;
+       else if (nPositive == 8) return positive;
+       else                     return intersecting;
+}
+
+plane::halfspace plane::intersects(const sphere<3>& sphere) const
+{
+       scalar distance = distance_to_point(sphere.point);
+
+       if (distance < -sphere.radius)     return negative;
+       else if (distance < sphere.radius) return intersecting;
+       else                               return positive;
+}
+
+
+} // namespace moof
+
This page took 0.021171 seconds and 4 git commands to generate.