[5] | 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 | Plane (const Vector3& rkNormal, const Vector3& rkPoint); |
---|
| 63 | Plane (const Vector3& rkPoint0, const Vector3& rkPoint1, |
---|
| 64 | const Vector3& rkPoint2); |
---|
| 65 | |
---|
| 66 | /** The "positive side" of the plane is the half space to which the |
---|
| 67 | plane normal points. The "negative side" is the other half |
---|
| 68 | space. The flag "no side" indicates the plane itself. |
---|
| 69 | */ |
---|
| 70 | enum Side |
---|
| 71 | { |
---|
| 72 | NO_SIDE, |
---|
| 73 | POSITIVE_SIDE, |
---|
| 74 | NEGATIVE_SIDE, |
---|
| 75 | BOTH_SIDE |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | Side getSide (const Vector3& rkPoint) const; |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | returns the side where the aligneBox is. the flag BOTH_SIDE indicates an intersecting box. |
---|
| 82 | one corner ON the plane is sufficient to consider the box and the plane intersecting. |
---|
| 83 | */ |
---|
| 84 | Side getSide (const AxisAlignedBox& rkBox) const; |
---|
| 85 | |
---|
| 86 | /** Returns which side of the plane that the given box lies on. |
---|
| 87 | The box is defined as centre/half-size pairs for effectively. |
---|
| 88 | @param centre The centre of the box. |
---|
| 89 | @param halfSize The half-size of the box. |
---|
| 90 | @returns |
---|
| 91 | POSITIVE_SIDE if the box complete lies on the "positive side" of the plane, |
---|
| 92 | NEGATIVE_SIDE if the box complete lies on the "negative side" of the plane, |
---|
| 93 | and BOTH_SIDE if the box intersects the plane. |
---|
| 94 | */ |
---|
| 95 | Side getSide (const Vector3& centre, const Vector3& halfSize) const; |
---|
| 96 | |
---|
| 97 | /** This is a pseudodistance. The sign of the return value is |
---|
| 98 | positive if the point is on the positive side of the plane, |
---|
| 99 | negative if the point is on the negative side, and zero if the |
---|
| 100 | point is on the plane. |
---|
| 101 | @par |
---|
| 102 | The absolute value of the return value is the true distance only |
---|
| 103 | when the plane normal is a unit length vector. |
---|
| 104 | */ |
---|
| 105 | Real getDistance (const Vector3& rkPoint) const; |
---|
| 106 | |
---|
| 107 | /** Redefine this plane based on 3 points. */ |
---|
| 108 | void redefine(const Vector3& rkPoint0, const Vector3& rkPoint1, |
---|
| 109 | const Vector3& rkPoint2); |
---|
| 110 | |
---|
| 111 | /** Redefine this plane based on a normal and a point. */ |
---|
| 112 | void redefine(const Vector3& rkNormal, const Vector3& rkPoint); |
---|
| 113 | |
---|
| 114 | /** Project a vector onto the plane. |
---|
| 115 | @remarks This gives you the element of the input vector that is perpendicular |
---|
| 116 | to the normal of the plane. You can get the element which is parallel |
---|
| 117 | to the normal of the plane by subtracting the result of this method |
---|
| 118 | from the original vector, since parallel + perpendicular = original. |
---|
| 119 | @param v The input vector |
---|
| 120 | */ |
---|
| 121 | Vector3 projectVector(const Vector3& v) const; |
---|
| 122 | |
---|
| 123 | /** Normalises the plane. |
---|
| 124 | @remarks |
---|
| 125 | This method normalises the plane's normal and the length scale of d |
---|
| 126 | is as well. |
---|
| 127 | @note |
---|
| 128 | This function will not crash for zero-sized vectors, but there |
---|
| 129 | will be no changes made to their components. |
---|
| 130 | @returns The previous length of the plane's normal. |
---|
| 131 | */ |
---|
| 132 | Real normalise(void); |
---|
| 133 | |
---|
| 134 | Vector3 normal; |
---|
| 135 | Real d; |
---|
| 136 | |
---|
| 137 | /// Comparison operator |
---|
| 138 | bool operator==(const Plane& rhs) const |
---|
| 139 | { |
---|
| 140 | return (rhs.d == d && rhs.normal == normal); |
---|
| 141 | } |
---|
| 142 | bool operator!=(const Plane& rhs) const |
---|
| 143 | { |
---|
| 144 | return (rhs.d != d && rhs.normal != normal); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | _OgreExport friend std::ostream& operator<< (std::ostream& o, const Plane& p); |
---|
| 148 | }; |
---|
| 149 | |
---|
| 150 | typedef std::vector<Plane> PlaneList; |
---|
| 151 | |
---|
| 152 | } // namespace Ogre |
---|
| 153 | |
---|
| 154 | #endif |
---|