Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# 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 © 2000-2004 The OGRE Team
    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 */
    00025 #ifndef __PlaneBoundedVolume_H_
    00026 #define __PlaneBoundedVolume_H_
    00027
    00028 // Precompiler options
    00029 #include "OgrePrerequisites.h"
    00030 #include "OgreAxisAlignedBox.h"
    00031 #include "OgreSphere.h"
    00032 #include "OgreMath.h"
    00033 #include "OgrePlane.h"
    00034
    00035 namespace Ogre {
    00036
    00039     class _OgreExport 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             // If all points are on outside of any plane, we fail
    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                 // Test which side of the plane the corners are
    00067                 // Intersection fails when at all corners are on the
    00068                 // outside of one plane
    00069                 bool splittingPlane = true;
    00070                 for (int corner = 0; corner < 8; ++corner)
    00071                 {
    00072                     if (plane.getSide(points[corner]) != outside)
    00073                     {
    00074                         // this point is on the wrong side
    00075                         splittingPlane = false;
    00076                         break;
    00077                     }
    00078                 }
    00079                 if (splittingPlane)
    00080                 {
    00081                     // Found a splitting plane therefore return not intersecting
    00082                     return false;
    00083                 }
    00084             }
    00085
    00086             // couldn't find a splitting plane, assume intersecting
    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                 // Test which side of the plane the sphere is
    00102                 Real d = plane.getDistance(sphere.getCenter());
    00103                 // Negate d if planes point inwards
    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
    00114
    00115
    00116
    00117     };
    00118
    00119     typedef std::vector<PlaneBoundedVolume> PlaneBoundedVolumeList;
    00120
    00121
    00122 }
    00123
    00124 #endif
    00125

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:39 2004