<html> <head> <title>OgrePlaneBoundedVolume.h Source File - OGRE Documentation</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link type="text/css" rel="stylesheet" href="style.css"> </head> <body> <!-- Generated by Doxygen 1.3.6 --> <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div> <h1>OgrePlaneBoundedVolume.h</h1><a href="OgrePlaneBoundedVolume_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span> 00002 <span class="comment">-----------------------------------------------------------------------------</span> 00003 <span class="comment">This source file is part of OGRE</span> 00004 <span class="comment">(Object-oriented Graphics Rendering Engine)</span> 00005 <span class="comment">For the latest info, see http://www.ogre3d.org/</span> 00006 <span class="comment"></span> 00007 <span class="comment">Copyright (c) 2000-2005 The OGRE Team</span> 00008 <span class="comment">Also see acknowledgements in Readme.html</span> 00009 <span class="comment"></span> 00010 <span class="comment">This program is free software; you can redistribute it and/or modify it under</span> 00011 <span class="comment">the terms of the GNU Lesser General Public License as published by the Free Software</span> 00012 <span class="comment">Foundation; either version 2 of the License, or (at your option) any later</span> 00013 <span class="comment">version.</span> 00014 <span class="comment"></span> 00015 <span class="comment">This program is distributed in the hope that it will be useful, but WITHOUT</span> 00016 <span class="comment">ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS</span> 00017 <span class="comment">FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</span> 00018 <span class="comment"></span> 00019 <span class="comment">You should have received a copy of the GNU Lesser General Public License along with</span> 00020 <span class="comment">this program; if not, write to the Free Software Foundation, Inc., 59 Temple</span> 00021 <span class="comment">Place - Suite 330, Boston, MA 02111-1307, USA, or go to</span> 00022 <span class="comment">http://www.gnu.org/copyleft/lesser.txt.</span> 00023 <span class="comment">-----------------------------------------------------------------------------</span> 00024 <span class="comment">*/</span> 00025 <span class="preprocessor">#ifndef __PlaneBoundedVolume_H_</span> 00026 <span class="preprocessor"></span><span class="preprocessor">#define __PlaneBoundedVolume_H_</span> 00027 <span class="preprocessor"></span> 00028 <span class="comment">// Precompiler options</span> 00029 <span class="preprocessor">#include "<a class="code" href="OgrePrerequisites_8h.html">OgrePrerequisites.h</a>"</span> 00030 <span class="preprocessor">#include "<a class="code" href="OgreAxisAlignedBox_8h.html">OgreAxisAlignedBox.h</a>"</span> 00031 <span class="preprocessor">#include "<a class="code" href="OgreSphere_8h.html">OgreSphere.h</a>"</span> 00032 <span class="preprocessor">#include "<a class="code" href="OgreMath_8h.html">OgreMath.h</a>"</span> 00033 <span class="preprocessor">#include "<a class="code" href="OgrePlane_8h.html">OgrePlane.h</a>"</span> 00034 00035 <span class="keyword">namespace </span>Ogre { 00036 <a name="l00039"></a><a class="code" href="classOgre_1_1PlaneBoundedVolume.html">00039</a> <span class="keyword">class </span><a class="code" href="OgrePlatform_8h.html#a13">_OgreExport</a> PlaneBoundedVolume 00040 { 00041 <span class="keyword">public</span>: <a name="l00042"></a><a class="code" href="classOgre_1_1PlaneBoundedVolume.html#Ogre_1_1PlaneBoundedVolumew0">00042</a> <span class="keyword">typedef</span> std::vector<Plane> <a class="code" href="namespaceOgre.html#a410">PlaneList</a>; <a name="l00044"></a><a class="code" href="classOgre_1_1PlaneBoundedVolume.html#Ogre_1_1PlaneBoundedVolumeo0">00044</a> <a class="code" href="namespaceOgre.html#a410">PlaneList</a> planes; <a name="l00045"></a><a class="code" href="classOgre_1_1PlaneBoundedVolume.html#Ogre_1_1PlaneBoundedVolumeo1">00045</a> Plane::Side outside; 00046 <a name="l00047"></a><a class="code" href="classOgre_1_1PlaneBoundedVolume.html#Ogre_1_1PlaneBoundedVolumea0">00047</a> PlaneBoundedVolume() :outside(<a class="code" href="classOgre_1_1Plane.html">Plane</a>::NEGATIVE_SIDE) {} <a name="l00049"></a><a class="code" href="classOgre_1_1PlaneBoundedVolume.html#Ogre_1_1PlaneBoundedVolumea1">00049</a> PlaneBoundedVolume(Plane::Side theOutside) 00050 : outside(theOutside) {} 00051 <a name="l00055"></a><a class="code" href="classOgre_1_1PlaneBoundedVolume.html#Ogre_1_1PlaneBoundedVolumea2">00055</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> intersects(<span class="keyword">const</span> <a class="code" href="classOgre_1_1AxisAlignedBox.html">AxisAlignedBox</a>& box)<span class="keyword"> const</span> 00056 <span class="keyword"> </span>{ 00057 <span class="keywordflow">if</span> (box.<a class="code" href="classOgre_1_1AxisAlignedBox.html#Ogre_1_1AxisAlignedBoxa16">isNull</a>()) <span class="keywordflow">return</span> <span class="keyword">false</span>; 00058 <span class="comment">// If all points are on outside of any plane, we fail</span> 00059 <span class="keyword">const</span> <a class="code" href="classOgre_1_1Vector3.html">Vector3</a>* points = box.<a class="code" href="classOgre_1_1AxisAlignedBox.html#Ogre_1_1AxisAlignedBoxa11">getAllCorners</a>(); 00060 PlaneList::const_iterator i, iend; 00061 iend = planes.end(); 00062 <span class="keywordflow">for</span> (i = planes.begin(); i != iend; ++i) 00063 { 00064 <span class="keyword">const</span> <a class="code" href="classOgre_1_1Plane.html">Plane</a>& plane = *i; 00065 00066 <span class="comment">// Test which side of the plane the corners are</span> 00067 <span class="comment">// Intersection fails when at all corners are on the</span> 00068 <span class="comment">// outside of one plane</span> 00069 <span class="keywordtype">bool</span> splittingPlane = <span class="keyword">true</span>; 00070 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> corner = 0; corner < 8; ++corner) 00071 { 00072 <span class="keywordflow">if</span> (plane.<a class="code" href="classOgre_1_1Plane.html#Ogre_1_1Planea5">getSide</a>(points[corner]) != outside) 00073 { 00074 <span class="comment">// this point is on the wrong side</span> 00075 splittingPlane = <span class="keyword">false</span>; 00076 <span class="keywordflow">break</span>; 00077 } 00078 } 00079 <span class="keywordflow">if</span> (splittingPlane) 00080 { 00081 <span class="comment">// Found a splitting plane therefore return not intersecting</span> 00082 <span class="keywordflow">return</span> <span class="keyword">false</span>; 00083 } 00084 } 00085 00086 <span class="comment">// couldn't find a splitting plane, assume intersecting</span> 00087 <span class="keywordflow">return</span> <span class="keyword">true</span>; 00088 00089 } <a name="l00093"></a><a class="code" href="classOgre_1_1PlaneBoundedVolume.html#Ogre_1_1PlaneBoundedVolumea3">00093</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> intersects(<span class="keyword">const</span> <a class="code" href="classOgre_1_1Sphere.html">Sphere</a>& sphere)<span class="keyword"> const</span> 00094 <span class="keyword"> </span>{ 00095 PlaneList::const_iterator i, iend; 00096 iend = planes.end(); 00097 <span class="keywordflow">for</span> (i = planes.begin(); i != iend; ++i) 00098 { 00099 <span class="keyword">const</span> <a class="code" href="classOgre_1_1Plane.html">Plane</a>& plane = *i; 00100 00101 <span class="comment">// Test which side of the plane the sphere is</span> 00102 <a class="code" href="namespaceOgre.html#a420">Real</a> d = plane.<a class="code" href="classOgre_1_1Plane.html#Ogre_1_1Planea6">getDistance</a>(sphere.<a class="code" href="classOgre_1_1Sphere.html#Ogre_1_1Spherea4">getCenter</a>()); 00103 <span class="comment">// Negate d if planes point inwards</span> 00104 <span class="keywordflow">if</span> (outside == Plane::NEGATIVE_SIDE) d = -d; 00105 00106 <span class="keywordflow">if</span> ( (d - sphere.<a class="code" href="classOgre_1_1Sphere.html#Ogre_1_1Spherea2">getRadius</a>()) > 0) 00107 <span class="keywordflow">return</span> <span class="keyword">false</span>; 00108 } 00109 00110 <span class="keywordflow">return</span> <span class="keyword">true</span>; 00111 00112 } 00113 <a name="l00118"></a><a class="code" href="classOgre_1_1PlaneBoundedVolume.html#Ogre_1_1PlaneBoundedVolumea4">00118</a> <span class="keyword">inline</span> std::pair<bool, Real> intersects(<span class="keyword">const</span> <a class="code" href="classOgre_1_1Ray.html">Ray</a>& ray) 00119 { 00120 <span class="keywordflow">return</span> Math::intersects(ray, planes, outside == Plane::POSITIVE_SIDE); 00121 } 00122 00123 }; 00124 <a name="l00125"></a><a class="code" href="namespaceOgre.html#a411">00125</a> <span class="keyword">typedef</span> std::vector<PlaneBoundedVolume> <a class="code" href="namespaceOgre.html#a411">PlaneBoundedVolumeList</a>; 00126 00127 00128 } 00129 00130 <span class="preprocessor">#endif</span> 00131 <span class="preprocessor"></span> </pre></div><p> Copyright © 2000-2005 by The OGRE Team<br /> Last modified Wed Feb 23 00:19:11 2005 </p> </body> </html>