My Project
ParaPlaneBoundedVolume.h
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2006 Torus Knot Software Ltd
8 Also see acknowledgements in Readme.html
9 
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
13 version.
14 
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22 http://www.gnu.org/copyleft/lesser.txt.
23 
24 You may alternatively use this source under the terms of a specific version of
25 the OGRE Unrestricted License provided you have obtained such a license from
26 Torus Knot Software Ltd.
27 -----------------------------------------------------------------------------
28 */
29 #ifndef __PlaneBoundedVolume_H_
30 #define __PlaneBoundedVolume_H_
31 
32 // Precompiler options
33 #include "ParaEngine.h"
34 #include "ParaAxisAlignedBox.h"
35 #include "ParaSphere.h"
36 #include "ParaMath.h"
37 #include "ParaPlane.h"
38 
39 namespace ParaEngine {
40 
44  {
45  public:
46  typedef std::vector<Plane> PlaneList;
48  PlaneList planes;
49  Plane::Side outside;
50 
51  PlaneBoundedVolume() :outside(Plane::NEGATIVE_SIDE) {}
54  : outside(theOutside) {}
55 
59  inline bool intersects(const AxisAlignedBox& box) const
60  {
61  if (box.isNull()) return false;
62  if (box.isInfinite()) return true;
63 
64  // Get centre of the box
65  Vector3 centre = box.getCenter();
66  // Get the half-size of the box
67  Vector3 halfSize = box.getHalfSize();
68 
69  PlaneList::const_iterator i, iend;
70  iend = planes.end();
71  for (i = planes.begin(); i != iend; ++i)
72  {
73  const Plane& plane = *i;
74 
75  Plane::Side side = plane.getSide(centre, halfSize);
76  if (side == outside)
77  {
78  // Found a splitting plane therefore return not intersecting
79  return false;
80  }
81  }
82 
83  // couldn't find a splitting plane, assume intersecting
84  return true;
85 
86  }
90  inline bool intersects(const Sphere& sphere) const
91  {
92  PlaneList::const_iterator i, iend;
93  iend = planes.end();
94  for (i = planes.begin(); i != iend; ++i)
95  {
96  const Plane& plane = *i;
97 
98  // Test which side of the plane the sphere is
99  float d = plane.getDistance(sphere.getCenter());
100  // Negate d if planes point inwards
101  if (outside == Plane::NEGATIVE_SIDE) d = -d;
102 
103  if ( (d - sphere.getRadius()) > 0)
104  return false;
105  }
106 
107  return true;
108 
109  }
110 
115  inline std::pair<bool, float> intersects(const Ray& ray)
116  {
117  return Math::intersects(ray, planes, outside == Plane::POSITIVE_SIDE);
118  }
119 
120  };
121 
122  typedef std::vector<PlaneBoundedVolume> PlaneBoundedVolumeList;
123 
124 
125 }
126 
127 #endif
128 
float getRadius(void) const
Returns the radius of the sphere.
Definition: ParaSphere.h:62
bool isInfinite(void) const
Returns true if the box is infinite.
Definition: ParaAxisAlignedBox.cpp:242
different physics engine has different winding order.
Definition: EventBinding.h:32
static std::pair< bool, float > intersects(const Ray &ray, const Plane &plane)
Ray / plane intersection, returns boolean result and distance.
Definition: ParaMath.cpp:316
bool intersects(const Sphere &sphere) const
Intersection test with Sphere.
Definition: ParaPlaneBoundedVolume.h:90
const Vector3 & getCenter(void) const
Returns the center point of the sphere.
Definition: ParaSphere.h:68
float getDistance(const Vector3 &rkPoint) const
This is a pseudo distance.
Definition: ParaPlane.cpp:50
A sphere primitive, mostly used for bounds checking.
Definition: ParaSphere.h:46
bool intersects(const AxisAlignedBox &box) const
Intersection test with AABB.
Definition: ParaPlaneBoundedVolume.h:59
Vector3 getCenter(void) const
Gets the centre of the box.
Definition: ParaAxisAlignedBox.cpp:105
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
Side
The "positive side" of the plane is the half space to which the plane normal points.
Definition: ParaPlane.h:32
std::pair< bool, float > intersects(const Ray &ray)
Intersection test with a Ray.
Definition: ParaPlaneBoundedVolume.h:115
PlaneBoundedVolume(Plane::Side theOutside)
Constructor, determines which side is deemed to be &#39;outside&#39;.
Definition: ParaPlaneBoundedVolume.h:53
Representation of a ray in space, i.e.
Definition: ParaRay.h:41
Defines a plane in 3D space.
Definition: ParaPlane.h:23
Represents a convex volume bounded by planes.
Definition: ParaPlaneBoundedVolume.h:43
bool isNull(void) const
Returns true if the box is null i.e.
Definition: ParaAxisAlignedBox.cpp:257
A 3D box aligned with the x/y/z axes.
Definition: ParaAxisAlignedBox.h:16
PlaneList planes
Publicly accessible plane list, you can modify this direct.
Definition: ParaPlaneBoundedVolume.h:48
Vector3 getHalfSize(void) const
Gets the half-size of the box.
Definition: ParaAxisAlignedBox.cpp:61