X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fmoof%2Fplane.cc;fp=src%2Fmoof%2Fplane.cc;h=4a175b0932cc0ded5f8039bcf3491cc6d215b3c3;hb=831f04d4bc19a390415ac0bbac4331c7a65509bc;hp=0000000000000000000000000000000000000000;hpb=299af4f2047e767e5d79501c26444473bda64c64;p=chaz%2Fyoink diff --git a/src/moof/plane.cc b/src/moof/plane.cc new file mode 100644 index 0000000..4a175b0 --- /dev/null +++ b/src/moof/plane.cc @@ -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 +