OGRE: OgrePlaneBoundedVolume.h Source File - OGRE Documentation

# OgrePlaneBoundedVolume.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __PlaneBoundedVolume_H_
    00030 #define __PlaneBoundedVolume_H_
    00031
    00032 // Precompiler options
    00033 #include "OgrePrerequisites.h"
    00034 #include "OgreAxisAlignedBox.h"
    00035 #include "OgreSphere.h"
    00036 #include "OgreMath.h"
    00037 #include "OgrePlane.h"
    00038
    00039 namespace Ogre {
    00040
    00043     class _OgreExport PlaneBoundedVolume
    00044     {
    00045     public:
    00046         typedef std::vector<Plane> PlaneList;
    00048         PlaneList planes;
    00049         Plane::Side outside;
    00050
    00051         PlaneBoundedVolume() :outside(Plane::NEGATIVE_SIDE) {}
    00053         PlaneBoundedVolume(Plane::Side theOutside)
    00054             : outside(theOutside) {}
    00055
    00059         inline bool intersects(const AxisAlignedBox& box) const
    00060         {
    00061             if (box.isNull()) return false;
    00062             if (box.isInfinite()) return true;
    00063
    00064             // Get centre of the box
    00065             Vector3 centre = box.getCenter();
    00066             // Get the half-size of the box
    00067             Vector3 halfSize = box.getHalfSize();
    00068
    00069             PlaneList::const_iterator i, iend;
    00070             iend = planes.end();
    00071             for (i = planes.begin(); i != iend; ++i)
    00072             {
    00073                 const Plane& plane = *i;
    00074
    00075                 Plane::Side side = plane.getSide(centre, halfSize);
    00076                 if (side == outside)
    00077                 {
    00078                     // Found a splitting plane therefore return not intersecting
    00079                     return false;
    00080                 }
    00081             }
    00082
    00083             // couldn't find a splitting plane, assume intersecting
    00084             return true;
    00085
    00086         }
    00090         inline bool intersects(const Sphere& sphere) const
    00091         {
    00092             PlaneList::const_iterator i, iend;
    00093             iend = planes.end();
    00094             for (i = planes.begin(); i != iend; ++i)
    00095             {
    00096                 const Plane& plane = *i;
    00097
    00098                 // Test which side of the plane the sphere is
    00099                 Real d = plane.getDistance(sphere.getCenter());
    00100                 // Negate d if planes point inwards
    00101                 if (outside == Plane::NEGATIVE_SIDE) d = -d;
    00102
    00103                 if ( (d - sphere.getRadius()) > 0)
    00104                     return false;
    00105             }
    00106
    00107             return true;
    00108
    00109         }
    00110
    00115         inline std::pair<bool, Real> intersects(const Ray& ray)
    00116         {
    00117             return Math::intersects(ray, planes, outside == Plane::POSITIVE_SIDE);
    00118         }
    00119
    00120     };
    00121
    00122     typedef std::vector<PlaneBoundedVolume> PlaneBoundedVolumeList;
    00123
    00124
    00125 }
    00126
    00127 #endif
    00128

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:19 2009