Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgrePlane.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 6.1 KB
Line 
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-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28// This file is based on material originally from:
29// Geometric Tools, LLC
30// Copyright (c) 1998-2010
31// Distributed under the Boost Software License, Version 1.0.
32// http://www.boost.org/LICENSE_1_0.txt
33// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
34
35
36#ifndef __Plane_H__
37#define __Plane_H__
38
39#include "OgrePrerequisites.h"
40
41#include "OgreVector3.h"
42
43namespace Ogre {
44
45        /** \addtogroup Core
46        *  @{
47        */
48        /** \addtogroup Math
49        *  @{
50        */
51        /** Defines a plane in 3D space.
52        @remarks
53            A plane is defined in 3D space by the equation
54            Ax + By + Cz + D = 0
55        @par
56            This equates to a vector (the normal of the plane, whose x, y
57            and z components equate to the coefficients A, B and C
58            respectively), and a constant (D) which is the distance along
59            the normal you have to go to move the plane back to the origin.
60     */
61    class _OgreExport Plane
62    {
63    public:
64        /** Default constructor - sets everything to 0.
65        */
66        Plane ();
67        Plane (const Plane& rhs);
68        /** Construct a plane through a normal, and a distance to move the plane along the normal.*/
69        Plane (const Vector3& rkNormal, Real fConstant);
70                /** Construct a plane using the 4 constants directly **/
71                Plane (Real a, Real b, Real c, Real d);
72        Plane (const Vector3& rkNormal, const Vector3& rkPoint);
73        Plane (const Vector3& rkPoint0, const Vector3& rkPoint1,
74            const Vector3& rkPoint2);
75
76        /** The "positive side" of the plane is the half space to which the
77            plane normal points. The "negative side" is the other half
78            space. The flag "no side" indicates the plane itself.
79        */
80        enum Side
81        {
82            NO_SIDE,
83            POSITIVE_SIDE,
84            NEGATIVE_SIDE,
85            BOTH_SIDE
86        };
87
88        Side getSide (const Vector3& rkPoint) const;
89
90        /**
91        Returns the side where the alignedBox is. The flag BOTH_SIDE indicates an intersecting box.
92        One corner ON the plane is sufficient to consider the box and the plane intersecting.
93        */
94        Side getSide (const AxisAlignedBox& rkBox) const;
95
96        /** Returns which side of the plane that the given box lies on.
97            The box is defined as centre/half-size pairs for effectively.
98        @param centre The centre of the box.
99        @param halfSize The half-size of the box.
100        @return
101            POSITIVE_SIDE if the box complete lies on the "positive side" of the plane,
102            NEGATIVE_SIDE if the box complete lies on the "negative side" of the plane,
103            and BOTH_SIDE if the box intersects the plane.
104        */
105        Side getSide (const Vector3& centre, const Vector3& halfSize) const;
106
107        /** This is a pseudodistance. The sign of the return value is
108            positive if the point is on the positive side of the plane,
109            negative if the point is on the negative side, and zero if the
110            point is on the plane.
111            @par
112            The absolute value of the return value is the true distance only
113            when the plane normal is a unit length vector.
114        */
115        Real getDistance (const Vector3& rkPoint) const;
116
117        /** Redefine this plane based on 3 points. */
118        void redefine(const Vector3& rkPoint0, const Vector3& rkPoint1,
119            const Vector3& rkPoint2);
120
121                /** Redefine this plane based on a normal and a point. */
122                void redefine(const Vector3& rkNormal, const Vector3& rkPoint);
123
124                /** Project a vector onto the plane.
125                @remarks This gives you the element of the input vector that is perpendicular
126                        to the normal of the plane. You can get the element which is parallel
127                        to the normal of the plane by subtracting the result of this method
128                        from the original vector, since parallel + perpendicular = original.
129                @param v The input vector
130                */
131                Vector3 projectVector(const Vector3& v) const;
132
133        /** Normalises the plane.
134            @remarks
135                This method normalises the plane's normal and the length scale of d
136                is as well.
137            @note
138                This function will not crash for zero-sized vectors, but there
139                will be no changes made to their components.
140            @return The previous length of the plane's normal.
141        */
142        Real normalise(void);
143
144                Vector3 normal;
145        Real d;
146
147        /// Comparison operator
148        bool operator==(const Plane& rhs) const
149        {
150            return (rhs.d == d && rhs.normal == normal);
151        }
152        bool operator!=(const Plane& rhs) const
153        {
154            return (rhs.d != d || rhs.normal != normal);
155        }
156
157        _OgreExport friend std::ostream& operator<< (std::ostream& o, const Plane& p);
158    };
159
160    typedef vector<Plane>::type PlaneList;
161        /** @} */
162        /** @} */
163
164} // namespace Ogre
165
166#endif
Note: See TracBrowser for help on using the repository browser.