Spinning Topp Logo BlackTopp Studios
inc
sphere.h
Go to the documentation of this file.
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 _sphere_h
41 #define _sphere_h
42 
43 /// @file
44 /// @brief This file contains a generic Sphere class for math and spacial query.
45 
46 #include "vector3.h"
47 
48 namespace Ogre
49 {
50  class Sphere;
51 }
52 
53 namespace Mezzanine
54 {
55  class AxisAlignedBox;
56  class Plane;
57  class Ray;
58  ///////////////////////////////////////////////////////////////////////////////
59  /// @brief This is a generic sphere class used for spacial queries.
60  /// @details
61  ///////////////////////////////////////
63  {
64  public:
65  /// @brief This is a type used for the return of a ray intersection test.
66  /// @details This type provides more verbose return data that can be used for further tests. @n @n
67  /// The first member stores whether or not there was a hit. The second member stores ray containing the points where the ray entered and exited the sphere.
68  typedef std::pair<Boole,Ray> RayTestResult;
69 
70  ///////////////////////////////////////////////////////////////////////////////
71  // Public Data Members
72 
73  /// @brief The point in world space that is the center of the sphere.
75  /// @brief The radius of the sphere.
77 
78  ///////////////////////////////////////////////////////////////////////////////
79  // Construction and Destruction
80 
81  /// @brief Blank constructor.
82  Sphere();
83  /// @brief Copy constructor.
84  /// @param Other The other sphere to copy from.
85  Sphere(const Sphere& Other);
86  /// @brief Radius constructor.
87  /// @param SphereRadius The radius of the sphere.
88  Sphere(const Real SphereRadius);
89  /// @brief Descriptive constructor.
90  /// @param SphereCenter The point in world space that is the center of the sphere.
91  /// @param SphereRadius The radius of the sphere.
92  Sphere(const Vector3& SphereCenter, const Real SphereRadius);
93  /// @brief Internal constructor.
94  /// @param InternalSphere The internal Ogre Sphere to construct this Sphere from.
95  explicit Sphere(const Ogre::Sphere& InternalSphere);
96  /// @brief Class destructor.
97  ~Sphere();
98 
99  ///////////////////////////////////////////////////////////////////////////////
100  // Utility
101 
102  /// @brief Checks to see if a point is inside this sphere.
103  /// @param ToCheck The location to check to see if it is within this sphere.
104  /// @return Returns true if the point provided is within this sphere, false otherwise.
105  Boole IsInside(const Vector3& ToCheck) const;
106  /// @brief Checks to see if another sphere overlaps with this one.
107  /// @param ToCheck The other sphere to check for overlap.
108  /// @return Returns true if the provided sphere overlaps with this sphere, false otherwise.
109  Boole IsOverlapping(const Sphere& ToCheck) const;
110  /// @brief Checks to see if an AABB overlaps with this sphere.
111  /// @param ToCheck The AABB to check for overlap.
112  /// @return Returns true if the AABB overlaps with this sphere, false otherwise.
113  Boole IsOverlapping(const AxisAlignedBox& ToCheck) const;
114  /// @brief Checks to see if a plane intersects this sphere.
115  /// @param ToCheck The plane to check for intersection.
116  /// @return Returns true if the provided plane intersects with this sphere, false otherwise.
117  Boole IsOverlapping(const Plane& ToCheck) const;
118  /// @brief Checks to see if a ray intersects this sphere.
119  /// @param ToCheck The ray to check for a hit.
120  /// @return Returns a std::pair containing whether or not the ray hit, and if it did the subsection of the ray that went through the sphere.
121  RayTestResult Intersects(const Ray& ToCheck) const;
122 
123  ///////////////////////////////////////////////////////////////////////////////
124  // Conversion Methods
125 
126  /// @brief Changes this Sphere to match the Ogre Sphere.
127  /// @param InternalSphere The Ogre::Sphere to copy.
128  void ExtractOgreSphere(const Ogre::Sphere& InternalSphere);
129  /// @brief Gets an Ogre::Sphere that contains this Spheres information.
130  /// @return This returns an Ogre::Sphere that contains the same information as this Spheres information.
131  Ogre::Sphere GetOgreSphere() const;
132 
133  ///////////////////////////////////////////////////////////////////////////////
134  // Serialization
135 
136  /// @brief Convert this class to an XML::Node ready for serialization.
137  /// @param ParentNode The point in the XML hierarchy that all this shape should be appended to.
138  void ProtoSerialize(XML::Node& ParentNode) const;
139  /// @brief Take the data stored in an XML Node and overwrite this object with it.
140  /// @param SelfRoot An XML::Node containing the data to populate this class with.
141  void ProtoDeSerialize(const XML::Node& SelfRoot);
142 
143  /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
144  /// @return A string containing the name of this class.
145  static String GetSerializableName();
146 
147  ///////////////////////////////////////////////////////////////////////////////
148  // Operators
149 
150  /// @brief Assignment operator.
151  /// @param Other The other Sphere to copy from.
152  void operator=(const Sphere& Other);
153 
154  /// @brief The assignment operator from Ogre::Sphere to Mezzanine::Sphere.
155  /// @param InternalSphere The Ogre::Sphere to take data from.
156  void operator=(const Ogre::Sphere& InternalSphere);
157 
158  /// @brief Greater-than operator.
159  /// @note This operator compares the radii of both spheres.
160  /// @param Other The other Sphere to compare with.
161  /// @return Returns true if this Sphere is larger than the other provided Sphere, false otherwise.
162  Boole operator>(const Sphere& Other) const;
163  /// @brief Greater-than or equals-to operator.
164  /// @note This operator compares the radii of both spheres.
165  /// @param Other The other Sphere to compare with.
166  /// @return Returns true if this Sphere is larger than or equal to the other provided Sphere, false otherwise.
167  Boole operator<(const Sphere& Other) const;
168  /// @brief Less-than operator.
169  /// @note This operator compares the radii of both spheres.
170  /// @param Other The other Sphere to compare with.
171  /// @return Returns true if this Sphere is smaller than the other provided Sphere, false otherwise.
172  Boole operator>=(const Sphere& Other) const;
173  /// @brief Less-than or equals-to operator.
174  /// @note This operator compares the radii of both spheres.
175  /// @param Other The other Sphere to compare with.
176  /// @return Returns true if this Sphere is smaller than or equal to the other provided Sphere, false otherwise.
177  Boole operator<=(const Sphere& Other) const;
178 
179  /// @brief Equality operator.
180  /// @param Other The other Sphere to compare with.
181  /// @return Returns true if this Sphere is the same as the other provided Sphere, false otherwise.
182  Boole operator==(const Sphere& Other) const;
183  /// @brief Inequality operator.
184  /// @param Other The other Sphere to compare with.
185  /// @return Returns true if this Sphere is not the same as the other provided Sphere, false otherwise.
186  Boole operator!=(const Sphere& Other) const;
187  };//Sphere
188 }//Mezzanine
189 
190 #endif
This is a generic sphere class used for spacial queries.
Definition: sphere.h:62
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Real Radius
The radius of the sphere.
Definition: sphere.h:76
This is used to represent a flat infinite slice of the game world.
Definition: plane.h:65
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
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...
Vector3 Center
The point in world space that is the center of the sphere.
Definition: sphere.h:74
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
std::pair< Boole, Ray > RayTestResult
This is a type used for the return of a ray intersection test.
Definition: sphere.h:68
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...