OgrePlaneBoundedVolume.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __PlaneBoundedVolume_H_
#define __PlaneBoundedVolume_H_
// Precompiler options
#include "OgrePrerequisites.h"
#include "OgreAxisAlignedBox.h"
#include "OgreSphere.h"
#include "OgreMath.h"
#include "OgrePlane.h"
#include "OgreHeaderPrefix.h"
namespace Ogre {
class _OgreExport PlaneBoundedVolume
{
public:
typedef vector<Plane>::type PlaneList;
PlaneList planes;
Plane::Side outside;
PlaneBoundedVolume() :outside(Plane::NEGATIVE_SIDE) {}
PlaneBoundedVolume(Plane::Side theOutside)
: outside(theOutside) {}
inline bool intersects(const AxisAlignedBox& box) const
{
if (box.isNull()) return false;
if (box.isInfinite()) return true;
// Get centre of the box
Vector3 centre = box.getCenter();
// Get the half-size of the box
Vector3 halfSize = box.getHalfSize();
PlaneList::const_iterator i, iend;
iend = planes.end();
for (i = planes.begin(); i != iend; ++i)
{
const Plane& plane = *i;
Plane::Side side = plane.getSide(centre, halfSize);
if (side == outside)
{
// Found a splitting plane therefore return not intersecting
return false;
}
}
// couldn't find a splitting plane, assume intersecting
return true;
}
inline bool intersects(const Sphere& sphere) const
{
PlaneList::const_iterator i, iend;
iend = planes.end();
for (i = planes.begin(); i != iend; ++i)
{
const Plane& plane = *i;
// Test which side of the plane the sphere is
Real d = plane.getDistance(sphere.getCenter());
// Negate d if planes point inwards
if (outside == Plane::NEGATIVE_SIDE) d = -d;
if ( (d - sphere.getRadius()) > 0)
return false;
}
return true;
}
inline std::pair<bool, Real> intersects(const Ray& ray)
{
return Math::intersects(ray, planes, outside == Plane::POSITIVE_SIDE);
}
};
typedef vector<PlaneBoundedVolume>::type PlaneBoundedVolumeList;
}
#include "OgreHeaderSuffix.h"
#endif
Ogre::AxisAlignedBox::getHalfSize
Vector3 getHalfSize(void) const
Gets the half-size of the box.
Definition: OgreAxisAlignedBox.h:726
Ogre::Sphere::getCenter
const Vector3 & getCenter(void) const
Returns the center point of the sphere.
Definition: OgreSphere.h:73
OgreAxisAlignedBox.h
Ogre::AxisAlignedBox::getCenter
Vector3 getCenter(void) const
Gets the centre of the box.
Definition: OgreAxisAlignedBox.h:694
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::PlaneBoundedVolume
Represents a convex volume bounded by planes.
Definition: OgrePlaneBoundedVolume.h:49
Ogre::Sphere
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:51
OgrePlane.h
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::AxisAlignedBox::isNull
bool isNull(void) const
Returns true if the box is null i.e.
Definition: OgreAxisAlignedBox.h:536
Ogre::Plane
Defines a plane in 3D space.
Definition: OgrePlane.h:61
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::Plane::Side
Side
The "positive side" of the plane is the half space to which the plane normal points.
Definition: OgrePlane.h:80
OgrePrerequisites.h
Ogre::PlaneBoundedVolume::PlaneBoundedVolume
PlaneBoundedVolume()
Definition: OgrePlaneBoundedVolume.h:57
Ogre::PlaneBoundedVolume::planes
PlaneList planes
Publicly accessible plane list, you can modify this direct.
Definition: OgrePlaneBoundedVolume.h:54
Ogre::PlaneBoundedVolumeList
vector< PlaneBoundedVolume >::type PlaneBoundedVolumeList
Definition: OgrePlaneBoundedVolume.h:128
Ogre::PlaneBoundedVolume::intersects
bool intersects(const AxisAlignedBox &box) const
Intersection test with AABB.
Definition: OgrePlaneBoundedVolume.h:65
Ogre::PlaneBoundedVolume::intersects
bool intersects(const Sphere &sphere) const
Intersection test with Sphere.
Definition: OgrePlaneBoundedVolume.h:96
OgreHeaderSuffix.h
Ogre::PlaneBoundedVolume::PlaneBoundedVolume
PlaneBoundedVolume(Plane::Side theOutside)
Constructor, determines which side is deemed to be &#39;outside&#39;.
Definition: OgrePlaneBoundedVolume.h:59
Ogre
Definition: OgreAndroidLogListener.h:34
OgreMath.h
Ogre::Plane::POSITIVE_SIDE
Definition: OgrePlane.h:83
Ogre::Math::intersects
static std::pair< bool, Real > intersects(const Ray &ray, const Plane &plane)
Ray / plane intersection, returns boolean result and distance.
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::Plane::NEGATIVE_SIDE
Definition: OgrePlane.h:84
OgreHeaderPrefix.h
Ogre::Sphere::getRadius
Real getRadius(void) const
Returns the radius of the sphere.
Definition: OgreSphere.h:67
Ogre::PlaneBoundedVolume::PlaneList
vector< Plane >::type PlaneList
Definition: OgrePlaneBoundedVolume.h:52
Ogre::Plane::getSide
Side getSide(const Vector3 &rkPoint) const
Ogre::AxisAlignedBox::isInfinite
bool isInfinite(void) const
Returns true if the box is infinite.
Definition: OgreAxisAlignedBox.h:557
Ogre::AxisAlignedBox
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:54
OgreSphere.h
Ogre::PlaneBoundedVolume::outside
Plane::Side outside
Definition: OgrePlaneBoundedVolume.h:55
Ogre::PlaneBoundedVolume::intersects
std::pair< bool, Real > intersects(const Ray &ray)
Intersection test with a Ray.
Definition: OgrePlaneBoundedVolume.h:121
Ogre::Ray
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
Ogre::Plane::getDistance
Real getDistance(const Vector3 &rkPoint) const
This is a pseudodistance.

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