source: GTP/trunk/Lib/Geom/OgreStuff/include/OgrePlane.h @ 1809

Revision 1809, 4.1 KB checked in by gumbau, 18 years ago (diff)
RevLine 
[1809]1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25// Original free version by:
26// Magic Software, Inc.
27// http://www.geometrictools.com/
28// Copyright (c) 2000, All Rights Reserved
29
30#ifndef __Plane_H__
31#define __Plane_H__
32
33#include "OgrePrerequisites.h"
34
35#include "OgreVector3.h"
36
37namespace Ogre {
38
39    /** Defines a plane in 3D space.
40        @remarks
41            A plane is defined in 3D space by the equation
42            Ax + By + Cz + D = 0
43        @par
44            This equates to a vector (the normal of the plane, whose x, y
45            and z components equate to the coefficients A, B and C
46            respectively), and a constant (D) which is the distance along
47            the normal you have to go to move the plane back to the origin.
48     */
49    class _OgreExport Plane
50    {
51    public:
52        /** Default constructor - sets everything to 0.
53        */
54        Plane ();
55        Plane (const Plane& rhs);
56        /** Construct a plane through a normal, and a distance to move the plane along the normal.*/
57        Plane (const Vector3& rkNormal, Real fConstant);
58        Plane (const Vector3& rkNormal, const Vector3& rkPoint);
59        Plane (const Vector3& rkPoint0, const Vector3& rkPoint1,
60            const Vector3& rkPoint2);
61
62        /** The "positive side" of the plane is the half space to which the
63            plane normal points. The "negative side" is the other half
64            space. The flag "no side" indicates the plane itself.
65        */
66        enum Side
67        {
68            NO_SIDE,
69            POSITIVE_SIDE,
70            NEGATIVE_SIDE
71        };
72
73        Side getSide (const Vector3& rkPoint) const;
74
75        /** This is a pseudodistance. The sign of the return value is
76            positive if the point is on the positive side of the plane,
77            negative if the point is on the negative side, and zero if the
78            point is on the plane.
79            @par
80            The absolute value of the return value is the true distance only
81            when the plane normal is a unit length vector.
82        */
83        Real getDistance (const Vector3& rkPoint) const;
84
85        /** Redefine this plane based on 3 points. */
86        void redefine(const Vector3& rkPoint0, const Vector3& rkPoint1,
87            const Vector3& rkPoint2);
88
89                /** Project a vector onto the plane.
90                @remarks This gives you the element of the input vector that is perpendicular
91                        to the normal of the plane. You can get the element which is parallel
92                        to the normal of the plane by subtracting the result of this method
93                        from the original vector, since parallel + perpendicular = original.
94                @param v The input vector
95                */
96                Vector3 projectVector(const Vector3& v);
97
98                Vector3 normal;
99        Real d;
100        /// Comparison operator
101        bool operator==(const Plane& rhs) const
102        {
103            return (rhs.d == d && rhs.normal == normal);
104        }
105
106        _OgreExport friend std::ostream& operator<< (std::ostream& o, Plane& p);
107    };
108
109    typedef std::vector<Plane> PlaneList;
110
111} // namespace Ogre
112
113#endif
Note: See TracBrowser for help on using the repository browser.