00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __PlaneBoundedVolume_H_
00026 #define __PlaneBoundedVolume_H_
00027
00028
00029 #include "peonstdafx.h"
00030 #include "AxisAlignedBox.h"
00031 #include "Sphere.h"
00032 #include "MathUnit.h"
00033 #include "Plane.h"
00034
00035 namespace peon {
00036
00039 class _PeonExport PlaneBoundedVolume
00040 {
00041 public:
00042 typedef std::vector<Plane> PlaneList;
00044 PlaneList planes;
00045 Plane::Side outside;
00046
00047 PlaneBoundedVolume() :outside(Plane::NEGATIVE_SIDE) {}
00049 PlaneBoundedVolume(Plane::Side theOutside)
00050 : outside(theOutside) {}
00051
00055 inline bool intersects(const AxisAlignedBox& box) const
00056 {
00057 if (box.isNull()) return false;
00058
00059 const Vector3* points = box.getAllCorners();
00060 PlaneList::const_iterator i, iend;
00061 iend = planes.end();
00062 for (i = planes.begin(); i != iend; ++i)
00063 {
00064 const Plane& plane = *i;
00065
00066
00067
00068
00069 bool splittingPlane = true;
00070 for (int corner = 0; corner < 8; ++corner)
00071 {
00072 if (plane.getSide(points[corner]) != outside)
00073 {
00074
00075 splittingPlane = false;
00076 break;
00077 }
00078 }
00079 if (splittingPlane)
00080 {
00081
00082 return false;
00083 }
00084 }
00085
00086
00087 return true;
00088
00089 }
00093 inline bool intersects(const Sphere& sphere) const
00094 {
00095 PlaneList::const_iterator i, iend;
00096 iend = planes.end();
00097 for (i = planes.begin(); i != iend; ++i)
00098 {
00099 const Plane& plane = *i;
00100
00101
00102 Real d = plane.getDistance(sphere.getCenter());
00103
00104 if (outside == Plane::NEGATIVE_SIDE) d = -d;
00105
00106 if ( (d - sphere.getRadius()) > 0)
00107 return false;
00108 }
00109
00110 return true;
00111
00112 }
00113
00118 inline std::pair<bool, Real> intersects(const Ray& ray)
00119 {
00120 return MathUnit::intersects(ray, planes, outside == Plane::POSITIVE_SIDE);
00121 }
00122
00123 };
00124
00125 typedef std::vector<PlaneBoundedVolume> PlaneBoundedVolumeList;
00126
00127
00128 }
00129
00130 #endif
00131