[7908] | 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-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
| 13 | version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
| 18 | |
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
| 23 | |
---|
| 24 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | // Original free version by: |
---|
| 30 | // Magic Software, Inc. |
---|
| 31 | // http://www.geometrictools.com/ |
---|
| 32 | // Copyright (c) 2000, All Rights Reserved |
---|
| 33 | |
---|
| 34 | #ifndef __Plane_H__ |
---|
| 35 | #define __Plane_H__ |
---|
| 36 | |
---|
| 37 | #include "OgrePrerequisites.h" |
---|
| 38 | |
---|
| 39 | #include "OgreVector3.h" |
---|
| 40 | |
---|
| 41 | namespace Ogre { |
---|
| 42 | |
---|
| 43 | /** Defines a plane in 3D space. |
---|
| 44 | @remarks |
---|
| 45 | A plane is defined in 3D space by the equation |
---|
| 46 | Ax + By + Cz + D = 0 |
---|
| 47 | @par |
---|
| 48 | This equates to a vector (the normal of the plane, whose x, y |
---|
| 49 | and z components equate to the coefficients A, B and C |
---|
| 50 | respectively), and a constant (D) which is the distance along |
---|
| 51 | the normal you have to go to move the plane back to the origin. |
---|
| 52 | */ |
---|
| 53 | class _OgreExport Plane |
---|
| 54 | { |
---|
| 55 | public: |
---|
| 56 | /** Default constructor - sets everything to 0. |
---|
| 57 | */ |
---|
| 58 | Plane (); |
---|
| 59 | Plane (const Plane& rhs); |
---|
| 60 | /** Construct a plane through a normal, and a distance to move the plane along the normal.*/ |
---|
| 61 | Plane (const Vector3& rkNormal, Real fConstant); |
---|
| 62 | /** Construct a plane using the 4 constants directly **/ |
---|
| 63 | Plane (Real a, Real b, Real c, Real d); |
---|
| 64 | Plane (const Vector3& rkNormal, const Vector3& rkPoint); |
---|
| 65 | Plane (const Vector3& rkPoint0, const Vector3& rkPoint1, |
---|
| 66 | const Vector3& rkPoint2); |
---|
| 67 | |
---|
| 68 | /** The "positive side" of the plane is the half space to which the |
---|
| 69 | plane normal points. The "negative side" is the other half |
---|
| 70 | space. The flag "no side" indicates the plane itself. |
---|
| 71 | */ |
---|
| 72 | enum Side |
---|
| 73 | { |
---|
| 74 | NO_SIDE, |
---|
| 75 | POSITIVE_SIDE, |
---|
| 76 | NEGATIVE_SIDE, |
---|
| 77 | BOTH_SIDE |
---|
| 78 | }; |
---|
| 79 | |
---|
| 80 | Side getSide (const Vector3& rkPoint) const; |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | returns the side where the aligneBox is. the flag BOTH_SIDE indicates an intersecting box. |
---|
| 84 | one corner ON the plane is sufficient to consider the box and the plane intersecting. |
---|
| 85 | */ |
---|
| 86 | Side getSide (const AxisAlignedBox& rkBox) const; |
---|
| 87 | |
---|
| 88 | /** Returns which side of the plane that the given box lies on. |
---|
| 89 | The box is defined as centre/half-size pairs for effectively. |
---|
| 90 | @param centre The centre of the box. |
---|
| 91 | @param halfSize The half-size of the box. |
---|
| 92 | @returns |
---|
| 93 | POSITIVE_SIDE if the box complete lies on the "positive side" of the plane, |
---|
| 94 | NEGATIVE_SIDE if the box complete lies on the "negative side" of the plane, |
---|
| 95 | and BOTH_SIDE if the box intersects the plane. |
---|
| 96 | */ |
---|
| 97 | Side getSide (const Vector3& centre, const Vector3& halfSize) const; |
---|
| 98 | |
---|
| 99 | /** This is a pseudodistance. The sign of the return value is |
---|
| 100 | positive if the point is on the positive side of the plane, |
---|
| 101 | negative if the point is on the negative side, and zero if the |
---|
| 102 | point is on the plane. |
---|
| 103 | @par |
---|
| 104 | The absolute value of the return value is the true distance only |
---|
| 105 | when the plane normal is a unit length vector. |
---|
| 106 | */ |
---|
| 107 | Real getDistance (const Vector3& rkPoint) const; |
---|
| 108 | |
---|
| 109 | /** Redefine this plane based on 3 points. */ |
---|
| 110 | void redefine(const Vector3& rkPoint0, const Vector3& rkPoint1, |
---|
| 111 | const Vector3& rkPoint2); |
---|
| 112 | |
---|
| 113 | /** Redefine this plane based on a normal and a point. */ |
---|
| 114 | void redefine(const Vector3& rkNormal, const Vector3& rkPoint); |
---|
| 115 | |
---|
| 116 | /** Project a vector onto the plane. |
---|
| 117 | @remarks This gives you the element of the input vector that is perpendicular |
---|
| 118 | to the normal of the plane. You can get the element which is parallel |
---|
| 119 | to the normal of the plane by subtracting the result of this method |
---|
| 120 | from the original vector, since parallel + perpendicular = original. |
---|
| 121 | @param v The input vector |
---|
| 122 | */ |
---|
| 123 | Vector3 projectVector(const Vector3& v) const; |
---|
| 124 | |
---|
| 125 | /** Normalises the plane. |
---|
| 126 | @remarks |
---|
| 127 | This method normalises the plane's normal and the length scale of d |
---|
| 128 | is as well. |
---|
| 129 | @note |
---|
| 130 | This function will not crash for zero-sized vectors, but there |
---|
| 131 | will be no changes made to their components. |
---|
| 132 | @returns The previous length of the plane's normal. |
---|
| 133 | */ |
---|
| 134 | Real normalise(void); |
---|
| 135 | |
---|
| 136 | Vector3 normal; |
---|
| 137 | Real d; |
---|
| 138 | |
---|
| 139 | /// Comparison operator |
---|
| 140 | bool operator==(const Plane& rhs) const |
---|
| 141 | { |
---|
| 142 | return (rhs.d == d && rhs.normal == normal); |
---|
| 143 | } |
---|
| 144 | bool operator!=(const Plane& rhs) const |
---|
| 145 | { |
---|
| 146 | return (rhs.d != d && rhs.normal != normal); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | _OgreExport friend std::ostream& operator<< (std::ostream& o, const Plane& p); |
---|
| 150 | }; |
---|
| 151 | |
---|
| 152 | typedef std::vector<Plane> PlaneList; |
---|
| 153 | |
---|
| 154 | } // namespace Ogre |
---|
| 155 | |
---|
| 156 | #endif |
---|