OgrePlaneBoundedVolume.h
Go to the documentation of this file.
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-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __PlaneBoundedVolume_H_
29 #define __PlaneBoundedVolume_H_
30 
31 // Precompiler options
32 #include "OgrePrerequisites.h"
33 #include "OgreAxisAlignedBox.h"
34 #include "OgreSphere.h"
35 #include "OgreMath.h"
36 #include "OgrePlane.h"
37 #include "OgreHeaderPrefix.h"
38 
39 namespace Ogre {
40 
50  {
51  public:
56 
57  PlaneBoundedVolume() :outside(Plane::NEGATIVE_SIDE) {}
60  : outside(theOutside) {}
61 
65  inline bool intersects(const AxisAlignedBox& box) const
66  {
67  if (box.isNull()) return false;
68  if (box.isInfinite()) return true;
69 
70  // Get centre of the box
71  Vector3 centre = box.getCenter();
72  // Get the half-size of the box
73  Vector3 halfSize = box.getHalfSize();
74 
75  PlaneList::const_iterator i, iend;
76  iend = planes.end();
77  for (i = planes.begin(); i != iend; ++i)
78  {
79  const Plane& plane = *i;
80 
81  Plane::Side side = plane.getSide(centre, halfSize);
82  if (side == outside)
83  {
84  // Found a splitting plane therefore return not intersecting
85  return false;
86  }
87  }
88 
89  // couldn't find a splitting plane, assume intersecting
90  return true;
91 
92  }
96  inline bool intersects(const Sphere& sphere) const
97  {
98  PlaneList::const_iterator i, iend;
99  iend = planes.end();
100  for (i = planes.begin(); i != iend; ++i)
101  {
102  const Plane& plane = *i;
103 
104  // Test which side of the plane the sphere is
105  Real d = plane.getDistance(sphere.getCenter());
106  // Negate d if planes point inwards
107  if (outside == Plane::NEGATIVE_SIDE) d = -d;
108 
109  if ( (d - sphere.getRadius()) > 0)
110  return false;
111  }
112 
113  return true;
114 
115  }
116 
121  inline std::pair<bool, Real> intersects(const Ray& ray)
122  {
123  return Math::intersects(ray, planes, outside == Plane::POSITIVE_SIDE);
124  }
125 
126  };
127 
129 
133 }
134 
135 #include "OgreHeaderSuffix.h"
136 
137 #endif
138 
OgreHeaderSuffix.h
Ogre::PlaneBoundedVolume::intersects
std::pair< bool, Real > intersects(const Ray &ray)
Intersection test with a Ray.
Definition: OgrePlaneBoundedVolume.h:121
Ogre::Plane::NEGATIVE_SIDE
@ NEGATIVE_SIDE
Definition: OgrePlane.h:84
Ogre
Definition: OgreAndroidLogListener.h:35
Ogre::Plane
Defines a plane in 3D space.
Definition: OgrePlane.h:62
Ogre::PlaneBoundedVolume::intersects
bool intersects(const Sphere &sphere) const
Intersection test with Sphere.
Definition: OgrePlaneBoundedVolume.h:96
Ogre::PlaneBoundedVolume::PlaneBoundedVolume
PlaneBoundedVolume()
Definition: OgrePlaneBoundedVolume.h:57
Ogre::AxisAlignedBox::isInfinite
bool isInfinite(void) const
Returns true if the box is infinite.
Definition: OgreAxisAlignedBox.h:557
Ogre::Sphere::getRadius
Real getRadius(void) const
Returns the radius of the sphere.
Definition: OgreSphere.h:67
Ogre::Plane::Side
Side
The "positive side" of the plane is the half space to which the plane normal points.
Definition: OgrePlane.h:81
Ogre::PlaneBoundedVolume::intersects
bool intersects(const AxisAlignedBox &box) const
Intersection test with AABB.
Definition: OgrePlaneBoundedVolume.h:65
Ogre::Plane::getSide
Side getSide(const Vector3 &rkPoint) const
Ogre::AxisAlignedBox::getCenter
Vector3 getCenter(void) const
Gets the centre of the box.
Definition: OgreAxisAlignedBox.h:694
Ogre::Plane::POSITIVE_SIDE
@ POSITIVE_SIDE
Definition: OgrePlane.h:83
Ogre::PlaneBoundedVolume::PlaneBoundedVolume
PlaneBoundedVolume(Plane::Side theOutside)
Constructor, determines which side is deemed to be 'outside'.
Definition: OgrePlaneBoundedVolume.h:59
Ogre::PlaneBoundedVolume::outside
Plane::Side outside
Definition: OgrePlaneBoundedVolume.h:55
OgreHeaderPrefix.h
OgreSphere.h
OgrePrerequisites.h
Ogre::Plane::getDistance
Real getDistance(const Vector3 &rkPoint) const
This is a pseudodistance.
Ogre::AxisAlignedBox::isNull
bool isNull(void) const
Returns true if the box is null i.e.
Definition: OgreAxisAlignedBox.h:536
Ogre::Sphere::getCenter
const Vector3 & getCenter(void) const
Returns the center point of the sphere.
Definition: OgreSphere.h:73
Ogre::AxisAlignedBox
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:55
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::Sphere
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:52
OgrePlane.h
OgreMath.h
Ogre::PlaneBoundedVolume
Represents a convex volume bounded by planes.
Definition: OgrePlaneBoundedVolume.h:50
Ogre::Math::intersects
static std::pair< bool, Real > intersects(const Ray &ray, const Plane &plane)
Ray / plane intersection, returns boolean result and distance.
Ogre::PlaneBoundedVolume::PlaneList
vector< Plane >::type PlaneList
Definition: OgrePlaneBoundedVolume.h:52
Ogre::AxisAlignedBox::getHalfSize
Vector3 getHalfSize(void) const
Gets the half-size of the box.
Definition: OgreAxisAlignedBox.h:726
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::PlaneBoundedVolumeList
vector< PlaneBoundedVolume >::type PlaneBoundedVolumeList
Definition: OgrePlaneBoundedVolume.h:128
Ogre::PlaneBoundedVolume::planes
PlaneList planes
Publicly accessible plane list, you can modify this direct.
Definition: OgrePlaneBoundedVolume.h:54
OgreAxisAlignedBox.h
Ogre::vector
Definition: OgrePrerequisites.h:492
Ogre::Ray
Representation of a ray in space, i.e.
Definition: OgreRay.h:47
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:52

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.