Spinning Topp Logo BlackTopp Studios
inc
plane.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _plane_h
41 #define _plane_h
42 
43 #include "vector3.h"
44 
45 #ifndef SWIG
46  #include "XML/xml.h"
47 #endif
48 
49 namespace Ogre
50 {
51  class Plane;
52 }
53 
54 namespace Mezzanine
55 {
56  class AxisAlignedBox;
57  class Ray;
58  class Sphere;
59  ///////////////////////////////////////////////////////////////////////////////
60  /// @brief This is used to represent a flat infinite slice of the game world
61  /// @details The Normal value represents how rotated the plane will be, and
62  /// The Distance with represent how far you need to move down a line perpendicular
63  /// to the plane, (ie the normal, which is defined by the Normal value) from the
64  /// Origin.
66  {
67  public:
68  /// @brief An enum used to describe which side of the plane the result of a query is on.
69  enum Side
70  {
71  S_None = 0,
72  S_Positive = 1,
73  S_Negative = 2,
74  S_Both = 3
75  };
76  /// @brief This is a type used for the return of a ray intersection test.
77  /// @details This type provides more verbose return data that can be used for further tests. @n @n
78  /// The first member stores whether or not there was a hit. The second member stores the point where it was hit.
79  typedef std::pair<Boole,Vector3> RayTestResult;
80 
81  ///////////////////////////////////////////////////////////////////////////////
82  // Public Data Members
83 
84  /// @brief The rotation of the plane
86  /// @brief How from from the origin the plane is
88 
89  ///////////////////////////////////////////////////////////////////////////////
90  // Construction and Destruction
91 
92  /// @brief Default constructor
93  Plane();
94  /// @brief Copy constructor.
95  /// @param Other The other plane to copy from.
96  Plane(const Plane& Other);
97  /// @brief Descriptive constructor.
98  /// @param Norm The positive direction of the plane.
99  /// @param Constant The Constant distance of the origin with which to project the plane.
100  Plane(const Vector3& Norm, const Real Constant);
101  /// @brief Dual Vector constructor.
102  /// @param Norm The positive direction of the plane.
103  /// @param Point The "origin" point of the plane in 3D space.
104  Plane(const Vector3& Norm, const Vector3& Point);
105  /// @brief Triangle constructor.
106  /// @param First This is one point in the triangle.
107  /// @param Second This is another point in the triangle.
108  /// @param Third This is one point in the triangle.
109  Plane(const Vector3& First, const Vector3& Second, const Vector3& Third);
110  /// @brief Compatibility constructor.
111  /// @param InternalPlane This is the Ogre::Plane to copy from.
112  explicit Plane(const Ogre::Plane& InternalPlane);
113  /// @brief Class destructor.
114  ~Plane();
115 
116  ///////////////////////////////////////////////////////////////////////////////
117  // Utility
118 
119  /// @brief Defines the dimensions of this plane explicitly.
120  /// @param Norm The positive direction of the plane.
121  /// @param Constant The Constant with which to project the plane.
122  void Define(const Vector3& Norm, const Real Constant);
123  /// @brief Defines the dimensions of this plane based on an origin and direction.
124  /// @param Norm The positive direction of the plane.
125  /// @param Point The "origin" point of the plane in 3D space.
126  void Define(const Vector3& Norm, const Vector3& Point);
127  /// @brief Defines the dimensions of this plane from a triangle in 3D space.
128  /// @param First This is one point in the triangle.
129  /// @param Second This is another point in the triangle.
130  /// @param Third This is one point in the triangle.
131  void Define(const Vector3& First, const Vector3& Second, const Vector3& Third);
132 
133  /// @brief Gets which side of the plane a point in 3D space is.
134  /// @param Point The point in 3D space to determine on which side of the plane it lies.
135  /// @return Returns a Side enum value, indicating which side of the plane the point is on.
136  Side GetSide(const Vector3& Point) const;
137  /// @brief Gets which side of the plane a box shape is.
138  /// @param Center The point in 3D space where the center of the box is.
139  /// @param HalfSize Half of the total size on each axis.
140  /// @return Returns a Side enum value indicating which side of the plane the box is on.
141  Side GetSide(const Vector3& Center, const Vector3& HalfSize) const;
142  /// @brief Gets the distance from the plane to a point in 3D space.
143  /// @note This function will only return a true unit distance if the Normal member of this class is properly normalized. Take care when altering it's value.
144  /// @param Point The point in 3D space to get the distance to.
145  /// @return Returns the distance from the plane to the specified point. Positive values mean the point is on the positive side, and vice versa.
146  Real GetDistance(const Vector3& Point) const;
147 
148  /// @brief Gets the overlap of two Planes expressed as a Ray.
149  /// @note The "IsOverlapping" method overload that accepts a Plane is a fairly quick and easy check you could perform prior to this method to ensure you get valid results.
150  /// @param Other The other Plane to compare with.
151  /// @return Returns a Ray expressing the overlapping portions of the two Planes, or a blank/default Ray if they don't overlap.
152  Ray GetOverlap(const Plane& Other) const;
153 
154  /// @brief Checks to see if a sphere overlaps with this Plane.
155  /// @param ToCheck The sphere to check for overlap.
156  /// @return Returns true if the provided sphere overlaps with this Plane, false otherwise.
157  Boole IsOverlapping(const Sphere& ToCheck) const;
158  /// @brief Checks to see if an AABB overlaps with this Plane.
159  /// @param ToCheck The AABB to check for overlap.
160  /// @return Returns true if the AABB overlaps with this Plane, false otherwise.
161  Boole IsOverlapping(const AxisAlignedBox& ToCheck) const;
162  /// @brief Checks to see if another Plane intersects this one.
163  /// @param ToCheck The other Plane to check for intersection.
164  /// @return Returns true if the provided Plane intersects with this Plane, false otherwise.
165  Boole IsOverlapping(const Plane& ToCheck) const;
166  /// @brief Checks to see if a ray intersects this Plane.
167  /// @param ToCheck The ray to check for a hit.
168  /// @return Returns true if the ray intersects this Plane, false otherwise.
169  RayTestResult Intersects(const Ray& ToCheck) const;
170 
171  ///////////////////////////////////////////////////////////////////////////////
172  // Conversion Methods
173 
174  /// @brief Changes this Plane to match the Ogre Plane.
175  /// @param InternalPlane The Ogre::Plane to copy.
176  void ExtractOgrePlane(const Ogre::Plane& InternalPlane);
177  /// @brief Gets an Ogre::Plane that contains this Planes information.
178  /// @return This returns an Ogre::Plane that contains the same information as this Planes information.
179  Ogre::Plane GetOgrePlane() const;
180 
181  ///////////////////////////////////////////////////////////////////////////////
182  // Serialization
183 
184  /// @brief Convert this class to an XML::Node ready for serialization.
185  /// @param ParentNode The point in the XML hierarchy that all this shape should be appended to.
186  void ProtoSerialize(XML::Node& ParentNode) const;
187  /// @brief Take the data stored in an XML Node and overwrite this object with it.
188  /// @param SelfRoot An XML::Node containing the data to populate this class with.
189  void ProtoDeSerialize(const XML::Node& SelfRoot);
190 
191  /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
192  /// @return A string containing the name of this class.
193  static String GetSerializableName();
194 
195  ///////////////////////////////////////////////////////////////////////////////
196  // Operators
197 
198  /// @brief Assignment operator.
199  /// @param Other The other Plane to copy from.
200  void operator=(const Plane& Other);
201 
202  /// @brief The assignment operator from Ogre::Plane to Mezzanine::Plane.
203  /// @param InternalPlane The Ogre::Plane to take data from.
204  void operator=(const Ogre::Plane& InternalPlane);
205 
206  /// @brief Equality operator.
207  /// @param Other The other Plane to compare with.
208  /// @return Returns true if this Plane is the same as the other provided Plane, false otherwise.
209  Boole operator==(const Plane& Other) const;
210  /// @brief Inequality operator.
211  /// @param Other The other Plane to compare with.
212  /// @return Returns true if this Plane is not the same as the other provided Plane, false otherwise.
213  Boole operator!=(const Plane& Other) const;
214  };//Plane
215 }//Mezzanine
216 
217 #ifndef SWIG
218 /// @brief Streaming output operator
219 /// @details This converts the data of the Plane into a snippet of xml Ideal for sending to a log or cout.
220 /// @param stream This is the stream we send our data to.
221 /// @return This returns an std::ostream which now contains our data.
222 std::ostream& MEZZ_LIB operator << (std::ostream& stream, const Mezzanine::Plane& x);
223 
224 /// @brief Used to de-serialize from a stream.
225 /// @details This reads XML input and attempts to Populate a plane.
226 /// @param stream This is the stream we get our data from.
227 /// @param x The Mezzanine::Plane to store the deserialized Plane in.
228 /// @return This returns an std::ostream to allow operator chaining.
229 /// @throw Can throw any exception that any function in the Mezzanine::xml namespace could throw in addition to a Mezzanine::Exception if the serialization version doesn't match.
230 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::Plane& x);
231 
232 /// @brief Converts an XML node into a Mezzanine::Plane
233 /// @details TThis will convert an XML::Node will a valid serialized Mezzanine::Vector3 into a Mezzanine::Vector3
234 /// @param OneNode This is the XML::Node we get our data from. It should contain a serialized Mezzanine::Plane.
235 /// @param x The Mezzanine::Plane to store the deserialized Plane in.
236 /// @return This returns an XML::Node refernce to allow operator chaining.
237 /// @throw Can throw any exception that any function in the Mezzanine::xml namespace could throw in addition to a Mezzanine::Exception if the serialization version doesn't match.
239 #endif
240 
241 #endif
This is a generic sphere class used for spacial queries.
Definition: sphere.h:62
std::ostream & operator<<(std::ostream &stream, const Mezzanine::LinearInterpolator< T > &Lint)
Used to Serialize an Mezzanine::LinearInterpolator to a human readable stream.
Definition: interpolator.h:433
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
This is used to represent a flat infinite slice of the game world.
Definition: plane.h:65
Real Distance
How from from the origin the plane is.
Definition: plane.h:87
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
Vector3 Normal
The rotation of the plane.
Definition: plane.h:85
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
std::istream & operator>>(std::istream &stream, Mezzanine::LinearInterpolator< T > &Lint)
Used to de-serialize an Mezzanine::LinearInterpolator from a stream.
Definition: interpolator.h:448
std::pair< Boole, Vector3 > RayTestResult
This is a type used for the return of a ray intersection test.
Definition: plane.h:79
Side
An enum used to describe which side of the plane the result of a query is on.
Definition: plane.h:69
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
This represents a line placed in 3D space and is used with spacial queries.
Definition: ray.h:67
This is a utility class used to represent the Axis-Aligned Bounding Boxes of objects in various subsy...