Spinning Topp Logo BlackTopp Studios
inc
vector3.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 _vector3_h
41 #define _vector3_h
42 
43 #ifndef SWIG
44  #include <limits>
45 #endif
46 
47 #include "crossplatformexport.h"
48 #include "datatypes.h"
49 #include "enumerations.h"
50 #include "interpolator.h"
51 #include "swig.h"
52 
53 #ifndef SWIG
54  #include "XML/xml.h"
55 #endif
56 
57 //Forward Declarations for wierd compatibility functions
58 class btVector3;
59 namespace Ogre
60 {
61  class Vector3;
62 }
63 
64 
65 
66 namespace Mezzanine
67 {
68  class Quaternion;
69  ///////////////////////////////////////////////////////////////////////////////
70  /// @class Vector3
71  /// @headerfile vector3.h
72  /// @brief This is used to represent a point in space, or a vector through space
73  /// @details This contains an X, Y and a Z value used to represent coordinates.
74  /// This also has a number of facilities to make converting from Physics subsystem
75  /// vectors or graphics subsystems as easy as possible
76  /// @note No operator<< existing in any scripting interface for this class
78  {
79  public:
80 
81  ///////////////////////////////////////////////////////////////////////////////
82  // The Essentials
83 
84  /// @brief Coordinate on the X vector.
86  /// @brief Coordinate on the Y vector.
88  /// @brief Coordinate on the Z vector.
90 
91 #if !(defined(SWIG) && defined(MEZZLUA51)) // Stop Swig from making lua bindings but allow other languages
92  /// @brief Get The value associate with a certain Axis.
93  /// @param Axis Which axis to retrieve.
94  /// @note Despite the multiple scripting overloads of this Method, only Real GetAxisValue(const Whole& Axis) const; exists in the scripting interface
95  /// @return Either X, Y or Z as indicated by the value passed in.
96  Real GetAxisValue(const StandardAxis& Axis) const;
97 #endif // \SWIG
98 
99  /// @copydoc GetAxisValue(const StandardAxis& Axis) const
100  Real GetAxisValue(const Whole& Axis) const;
101 
102 #ifndef SWIG // Since these functions differ only by constness, they make no sense to most(all?) scripting languages
103  /// @brief Get The value associate with a certain Axis in such a way that it can readily be assigned in this Vector3.
104  /// @param Axis Which axis to retrieve.
105  /// @return Either X, Y or Z as indicated by the value passed in.
106  Real& GetAxisValue(const StandardAxis& Axis);
107  /// @copydoc GetAxisValue(const StandardAxis& Axis)
108  Real& GetAxisValue(const Whole& Axis);
109 #endif // \SWIG
110 
111  /// @copydoc GetAxisValue(const StandardAxis& Axis) const
112  Real operator[] (const StandardAxis& Axis) const;
113  /// @copydoc GetAxisValue(const StandardAxis& Axis) const
114  Real operator[] (const Whole& Axis) const;
115  /// @copydoc GetAxisValue(const StandardAxis& Axis)
116  Real& operator[] (const StandardAxis& Axis);
117  /// @copydoc GetAxisValue(const StandardAxis& Axis)
118  Real& operator[] (const Whole& Axis);
119 
120  /// @brief What are the X, Y and Z channels implmented with
121  typedef Real ChannelType;
122 
123  ///////////////////////////////////////////////////////////////////////////////
124  // Constructors
125 
126  /// @brief Default Constructor.
127  /// @details Basic all zero initialization constructor.
128  Vector3();
129  /// @brief Real value Constructor.
130  /// @details Constructor that sets all three vectors.
131  /// @param X Coordinate on the X vector.
132  /// @param Y Coordinate on the Y vector.
133  /// @param Z Coordinate on the Z vector.
134  Vector3(const Real& X, const Real& Y, const Real& Z);
135  /// @brief Ogre Value Constructor.
136  /// @details Constructor that sets all values to match the Ogre vector.
137  /// @param Vec The vector to be copied to make this vector.
138  explicit Vector3(const Ogre::Vector3& Vec);
139  /// @brief Bullet Value Constructor.
140  /// @details Constructor that sets all values to match the Bullet vector.
141  /// @param Vec The vector to be copied to make this vector.
142  explicit Vector3(const btVector3& Vec);
143  /// @brief Copy Constructor
144  /// @param Vec The other Mezzanine::Vector3 to copy to make this one.
145  Vector3(const Mezzanine::Vector3& Vec);
146  /// @brief Deserializing constructor
147  /// @param OneNode The XML node to deserialize from.
148  explicit Vector3(XML::Node OneNode);
149 
150  ///////////////////////////////////////////////////////////////////////////////
151  // Prebuilt Vectors
152 
153  /// @brief Gets a vector representing the X unit of a Vector3.
154  /// @return A Vector3(1,0,0).
155  static Vector3 Unit_X();
156  /// @brief Gets a vector representing the Y unit of a Vector3.
157  /// @return A Vector3(0,1,0).
158  static Vector3 Unit_Y();
159  /// @brief Gets a vector representing the Z unit of a Vector3.
160  /// @return A Vector3(0,0,1).
161  static Vector3 Unit_Z();
162  /// @brief Gets a vector representing the negative X unit of a Vector3.
163  /// @return A Vector3(-1,0,0).
164  static Vector3 Neg_Unit_X();
165  /// @brief Gets a vector representing the negative Y unit of a Vector3.
166  /// @return A Vector3(0,-1,0).
167  static Vector3 Neg_Unit_Y();
168  /// @brief Gets a vector representing the negative Z unit of a Vector3.
169  /// @return A Vector3(0,0,-1).
170  static Vector3 Neg_Unit_Z();
171 
172  /// @brief Get a Unit Vector along the given Axis
173  /// @param Axis The StandardAxis correlating to the Unit Vector you are retrieving
174  /// @return A vector one unit in length along the Axis specified.
175  static Vector3 UnitOnAxis(StandardAxis Axis);
176  /// @brief Get a Unit Vector along the given Axis
177  /// @return The Corresponding StandardAxis if a Vector equal to Unit_X, Unit_Y or Unit_Z is passed in.
178  StandardAxis IsStandardUnitAxis() const;
179 
180  ///////////////////////////////////////////////////////////////////////////////
181  // Assignment Operators
182 
183  /// @brief Assignment operator to convert from Bullet Vectors
184  /// @details This copies the x,y and z values from the bullet into this vector
185  /// @param Vec This is a btVector3 that will be copied
186  /// @return A reference to the assigned Vector3 to allow chained expresions
187  Vector3& operator= (const btVector3 &Vec);
188  /// @brief Assignment operator to convert from Ogre Vectors
189  /// @details This copies the x,y and z values from the bullet into this vector
190  /// @param Vec This is a Ogre::Vector3 that will be copied.
191  /// @return A reference to the assigned Vector3 to allow chained expresions
192  Vector3& operator= (const Ogre::Vector3 &Vec);
193 
194  ///////////////////////////////////////////////////////////////////////////////
195  // Unary Operators
196 
197  /// @brief Additive Inverse Operator
198  /// @details Returns the opposite Vector3 relative to 0,0,0
199  /// @return A copy of Vector3 with the signs on each value flipped
201 
202  ///////////////////////////////////////////////////////////////////////////////
203  // Vector3 Arithmetic with Real
204 
205  /// @brief Scaling by multiplication.
206  /// @details This Multiplies X, Y and Z by scalar.
207  /// @return This returns a Vector3 that has been scaled.
208  /// @param scalar This is the amount to scale the Vector3 by.
209  /// @return A copy of Vector3 scaled by the amount passed.
210  Vector3 operator* (const Real &scalar) const;
211  /// @brief Scaling by Division.
212  /// @details This Diisionn X, Y and Z by scalar.
213  /// @return This returns a Vector3 that has been scaled.
214  /// @param scalar This is the amount to scale the Vector3 by.
215  /// @return A copy of Vector3 scaled by the amount passed.
216  Vector3 operator/ (const Real &scalar) const;
217 
218  ///////////////////////////////////////////////////////////////////////////////
219  // Vector3 Arithmetic and assignment with Real
220 
221  /// @brief Scaling by multiplication.
222  /// @details This Multiplies X, Y and Z by scalar and stores the changes in this Vector3.
223  /// @param scalar This is the amount to scale the Vector3 by.
224  /// @return A reference to the assigned Vector3 to allow chained expresions.
225  Vector3& operator*= (const Real &scalar);
226  /// @brief Scaling by Division
227  /// @details This Division X, Y and Z by scalar and and stores the changes in this Vector3.
228  /// @param scalar This is the amount to scale the Vector3 by.
229  /// @return A reference to the assigned Vector3 to allow chained expresions.
230  Vector3& operator/= (const Real &scalar);
231 
232  ///////////////////////////////////////////////////////////////////////////////
233  // Equality Comparison operators
234 
235  /// @brief Equality Comparison Operator.
236  /// @return Returns true if X==X, Y==Y and Z==Z. If any of those do not match this returns false.
237  /// @param Vec This is the other Mezzanine::Vector3.
238  Boole operator== (const Mezzanine::Vector3 &Vec) const;
239  /// @brief Equality Comparison Operator.
240  /// @return Returns true if X==getX(), Y==getY() and Z==getZ(). If any of those do not match this returns false.
241  /// @param Vec This is an btVector3 that needs to be compared with this.
242  Boole operator== (const btVector3 &Vec) const;
243  /// @brief Equality Comparison Operator.
244  /// @return Returns true if X==x, Y==y and Z==z. If any of those do not match this returns false.
245  /// @param Vec This is an Ogre::Vector3 that needs to be compared with this.
246  Boole operator== (const Ogre::Vector3 &Vec) const;
247 
248  /// @brief Inequality Comparison Operator.
249  /// @return Returns true if X!=X, Y!=Y or Z!=Z. If all of those match this returns false.
250  /// @param Vec This is the other Mezzanine::Vector3.
251  Boole operator!= (const Mezzanine::Vector3 &Vec) const;
252  /// @brief Inequality Comparison Operator.
253  /// @return Returns true if X!=getX(), Y!=getY() or Z!=getZ(). If all of those match this returns false.
254  /// @param Vec This is an btVector3 that needs to be compared with this.
255  Boole operator!= (const btVector3 &Vec) const;
256  /// @brief Inequality Comparison Operator.
257  /// @return Returns true if X!=x, Y!=y or Z!=z. If all of those match this returns false.
258  /// @param Vec This is an Ogre::Vector3 that needs to be compared with this.
259  Boole operator!= (const Ogre::Vector3 &Vec) const;
260 
261  /// @brief Less or Equal Comparison Operator.
262  /// @return Returns true if X<=X, Y<=Y and Z<=Z. If any of those do not hold this returns false.
263  /// @param Vec This is the other Mezzanine::Vector3.
264  /// @note Used primarily for testing. This is not implement for use with other kinds of Vector3 implementations as it is widely considered useless.
265  Boole operator<= (const Mezzanine::Vector3 &Vec) const;
266  /// @brief Greater than or Equal Comparison Operator.
267  /// @return Returns true if X>=X, Y>=Y and Z>=Z. If any of those do not hold this returns false.
268  /// @param Vec This is the other Mezzanine::Vector3.
269  /// @note Used primarily for testing. This is not implement for use with other kinds of Vector3 implementations as it is widely considered useless.
270  Boole operator>= (const Mezzanine::Vector3 &Vec) const;
271 
272  ///////////////////////////////////////////////////////////////////////////////
273  // Arithmetic Operators
274 
275  /// @brief Addition Operator
276  /// @details Allows for addition from a Mezzanine::Vector3
277  /// @param Vec This is the other Mezzanine::Vector3
278  /// @return A copy of the calculated Vector3 to allow chained expresions.
279  Vector3 operator+ (const Vector3& Vec) const;
280  /// @brief Subraction Operator
281  /// @details Allows for subtraction from a Mezzanine::Vector3
282  /// @param Vec This is the other Mezzanine::Vector3
283  /// @return A copy of the calculated Vector3 to allow chained expresions.
284  Vector3 operator- (const Vector3& Vec) const;
285  /// @brief Multiplaction Operator
286  /// @details Allows for multiplaction from a Mezzanine::Vector3
287  /// @param Vec This is the other Mezzanine::Vector3
288  /// @return A copy of the calculated Vector3 to allow chained expresions.
289  Vector3 operator* (const Vector3& Vec) const;
290  /// @brief Division Operator
291  /// @details Allows for division from a Mezzanine::Vector3
292  /// @param Vec This is the other Mezzanine::Vector3
293  /// @return A copy of the calculated Vector3 to allow chained expresions.
294  Vector3 operator/ (const Vector3& Vec) const;
295 
296  /// @brief Addition Assignment Operator.
297  /// @param Vec The other Vector3 to be added.
298  /// @return Returns a reference to this.
299  Vector3& operator+= (const Vector3& Vec);
300  /// @brief Subraction Assignment Operator.
301  /// @param Vec The other Vector3 to be subtracted.
302  /// @return Returns a reference to this.
303  Vector3& operator-= (const Vector3& Vec);
304  /// @brief Multiplaction Assignment Operator.
305  /// @param Vec The other Vector3 to be multiplied.
306  /// @return Returns a reference to this.
307  Vector3& operator*= (const Vector3& Vec);
308  /// @brief Division Assignment Operator.
309  /// @param Vec The other Vector3 to be divided.
310  /// @return Returns a reference to this.
311  Vector3& operator/= (const Vector3& Vec);
312 
313  /////////////////////////////////////////////////////////////////////
314  // Arithmetic Operators with btVector3
315 
316  /// @brief Bullet Addition Operator
317  /// @details Allows for addition between a Mezzanine::Vector3 and a btVector3
318  /// @param Vec This is the btVector3 to be added
319  /// @return A copy of the calculated Vector3 to allow chained expresions.
320  Vector3 operator+ (const btVector3 &Vec) const;
321  /// @brief Bullet Subtraction Operator
322  /// @details Allows for subtraction between a Mezzanine::Vector3 and a btVector3
323  /// @param Vec This is the btVector3 to be subtracted
324  /// @return A copy of the calculated Vector3 to allow chained expresions.
325  Vector3 operator- (const btVector3 &Vec) const;
326  /// @brief Bullet Multiplication Operator
327  /// @details Allows for multiplication between a Mezzanine::Vector3 and a btVector3
328  /// @param Vec This is the btVector3 to be multiplied
329  /// @return A copy of the calculated Vector3 to allow chained expresions.
330  Vector3 operator* (const btVector3 &Vec) const;
331  /// @brief Bullet Division Operator
332  /// @details Allows for division between a Mezzanine::Vector3 and a btVector3
333  /// @param Vec This is the btVector3 to be divided
334  /// @return A copy of the calculated Vector3 to allow chained expresions.
335  Vector3 operator/ (const btVector3 &Vec) const;
336 
337  ///////////////////////////////////////////////////////////////////////////////
338  // Arithmetic Operators with Ogre::Vector3
339 
340  /// @brief Ogre Addition Operator
341  /// @details Allows for addition between a Mezzanine::Vector3 and a Ogre::Vector3
342  /// @param Vec This is the Ogre::Vector3 to be added
343  /// @return A copy of the calculated Vector3 to allow chained expresions.
344  Vector3 operator+ (const Ogre::Vector3 &Vec) const;
345  /// @brief Ogre Subtraction Operator
346  /// @details Allows for subtraction between a Mezzanine::Vector3 and a Ogre::Vector3
347  /// @param Vec This is the Ogre::Vector3 to be subtracted
348  /// @return A copy of the calculated Vector3 to allow chained expresions.
349  Vector3 operator- (const Ogre::Vector3 &Vec) const;
350  /// @brief Ogre Multiplication Operator
351  /// @details Allows for multiplying between a Mezzanine::Vector3 and a Ogre::Vector3
352  /// @param Vec This is the Ogre::Vector3 to be multiplied.
353  /// @return A copy of the calculated Vector3 to allow chained expresions.
354  Vector3 operator* (const Ogre::Vector3 &Vec) const;
355  /// @brief Ogre Division Operator.
356  /// @details Allows for division between a Mezzanine::Vector3 and a Ogre::Vector3
357  /// @param Vec This is the Ogre::Vector3 to be divided.
358  /// @return A copy of the calculated Vector3 to allow chained expresions.
359  Vector3 operator/ (const Ogre::Vector3 &Vec) const;
360 
361  ///////////////////////////////////////////////////////////////////////////////
362  // Fancy Math
363 
364  /// @brief This is used to calculate the crossproduct of this and another vector
365  /// @details This creates a third vector, which should be on a line perpendicular
366  /// to the line that contains the origin and the other vector \n\n
367  /// Thanks to the guys at Ogre3d for the well written version of this function
368  /// that we based this on.
369  /// @param Vec the Vector to work with to create the cross product
370  /// @return A Vector3 containing crossproduct of this vector and Vec
371  Vector3 CrossProduct(const Vector3& Vec) const;
372  /// @brief This is used to calculate the dotproduct of this and another vector
373  /// @details This calculates the sum of the products of X, Y and Z. \n\n
374  /// Thanks to the guys at Ogre3d for the well written version of this function
375  /// that we based this on.
376  /// @param Vec The vector to work with to create the cross product
377  /// @return This is the dotproduct of this vector and vec
378  Real DotProduct(const Vector3& Vec) const;
379  /// @brief This will change this point into it's own normal relative to the origin
380  /// @details This will change this vector into one that is the same direction from the origin, but only one unit a away.
381  /// @return Returns a reference to this after being altered.
382  Vector3& Normalize();
383  /// @brief This returns the normal for this relative to the origin
384  /// @details This will return a vector that is 1 unit in away from the origin, if a line were starting and the origin it would pass through
385  /// both the normal and the original point.
386  /// @return At a vector3 that is the normal of this Vector3 or 0,0,0 if the current Vector is all 0s
387  Vector3 GetNormal() const;
388  /// @brief Gets the angle between this and another vector assuming both are directional vectors.
389  /// @note The vectors provided do not need to be normalized.
390  /// @param Direction The other directional vector to get the angular distance from.
391  /// @return Returns the angle between both directional vectors.
392  Real AngleBetween(const Vector3& Direction) const;
393  /// @brief Shifts all of the components to the right.
394  /// @details This assigns the Z component to X, the X component to Y, and the Y component to Z.
395  /// @return Returns a reference to this after being altered.
396  Vector3& Permute();
397  /// @brief Gets a permuted copy of this vector.
398  /// @return Returns a new Vector3 that has the values this vector would have if it were permuted.
399  Vector3 GetPermute() const;
400  /// @brief Shifts all of the components to the left.
401  /// @details This assigns the Y component to X, the Z component to Y, and the X component to Z.
402  /// @return Returns a reference to this after being altered.
403  Vector3& AntiPermute();
404  /// @brief Gets a anti-permuted copy of this vector.
405  /// @return Returns a new Vector3 that has the values this vector would have if it were anti-permuted.
406  Vector3 GetAntiPermute() const;
407  /// @brief This will get the direction between two points.
408  /// @details This returns the direction expressed as a vector between this vector
409  /// and another provided vector.
410  /// @param Destination The point in space to determine the direction for.
411  /// @return A normalized Vector3 that indicates the direction from this vector to another.
412  Vector3 GetDirection(const Vector3& Destination) const;
413  /// @brief Gets a vector that is perpendicular to this one.
414  /// @remarks There are an infinite number of possibilities for 3 dimensions but this method will guarantee to generate one of them.
415  /// @return Returns a Vector3 that is guarenteed to be perpendicular to this vector.
416  Vector3 Perpendicular() const;
417  /// @brief Gets whether or not a vector is perpendicular to this one.
418  /// @remarks This simply checks if the dot product between these two vectors is zero.
419  /// @param Perp The other Vector3 to compare with.
420  /// @return Returns true if the provided vector is perpendicular to this one.
421  Boole IsPerpendicular(const Vector3& Perp) const;
422  /// @brief This will inverse the reals in the vector.
423  /// @details This function will inverse all the reals in the vector.
424  /// @return A copy of of the current Vector3.
425  Vector3 Inverse();
426  /// @brief Gets a reflection vector to the plane with the given normal.
427  /// @param Normal The normal of the plane being reflected off of.
428  /// @return Returns a Vector3 containing the reflection vector.
429  Vector3 Reflect(const Vector3& Normal);
430  /// @brief Gets the distance between this and another vector.
431  /// @details This uses a 3d extension of pythagoras thereom to calculate the distance between
432  /// this Vector3 and another.
433  /// @param OtherVec This is the other point to measure the distance to.
434  /// @return Returns a Real representing the distance.
435  Real Distance(const Vector3& OtherVec) const;
436  /// @brief Gets the squared distance between this and another vector.
437  /// @param OtherVec This is the other point to measure the distance to.
438  /// @return Returns a Real representing the distance squared.
439  Real SquaredDistance(const Vector3& OtherVec) const;
440  /// @brief Gets the length of this vector.
441  /// @return Returns a real representing the length of this vector.
442  Real Length() const;
443  /// @brief Gets the length of this vector squared.
444  /// @return Returns a real representing the squared length of this vector.
445  Real SquaredLength() const;
446  /// @brief Checks to see if the length of this vector is zero.
447  /// @return Returns true if this vector has zero length, false otherwise.
448  Boole IsZeroLength() const;
449  /// @brief Gets the rotation needed to rotate this vector as an axis to another axis.
450  /// @param Axis The target axis to rotate to.
451  /// @param FallBackAxis If the Dot produt of this and Axis are invalid FallBackAxis will be used instead otherwise, the rotation is calculated the hard way.
452  /// @return Returns a Quaternion representing the needed rotation to the specified axis.
453  Quaternion GetRotationToAxis(const Vector3& Axis, const Vector3& FallBackAxis = Vector3()) const;
454 
455  ///////////////////////////////////////////////////////////////////////////////
456  // Utility Functions
457 
458  /// @brief Sets all the members of this vector3 to zero.
459  void Zero();
460  /// @brief Manually sets all the members of this vector3.
461  /// @param X Value to set for X.
462  /// @param Y Value to set for Y.
463  /// @param Z Value to set for Z.
464  void SetValues(const Real& X, const Real& Y, const Real& Z);
465  /// @brief Checks to see if the values of this vector are all zero.
466  /// @return Returns true if all components of this vector are zero, false otherwise.
467  Boole IsZero() const;
468 
469  /// @brief Sets each member of this Vector3 to the higher value between the two vector3s.
470  /// @param Other The other Vector to compare with.
471  /// @return Returns a reference to this.
472  Vector3& Ceil(const Vector3& Other);
473  /// @brief Sets each member of this Vector3 to the lower value between the two vector3s.
474  /// @param Other The other Vector to compare with.
475  /// @return Returns a reference to this.
476  Vector3& Floor(const Vector3& Other);
477 
478  ///////////////////////////////////////////////////////////////////////////////
479  // Manual Conversions
480 
481  /// @brief Gets a Bullet vector3.
482  /// @details Creates a Bullet vector3 with values equal to this class and returns it.
483  /// @return A Bullet Vector3 containing the same value as the Mezzanine::Vector3
484  btVector3 GetBulletVector3() const;
485  /// @brief Copies an existing Bullet vector3.
486  /// @details This function will copy the values stored in an existing Bullet vector3
487  /// and set the values of this class to be the same.
488  /// @param temp The vector3 to be extracted.
489  void ExtractBulletVector3(const btVector3& temp);
490  /// @brief Gets a Ogre vector3.
491  /// @details Creates a Ogre vector3 with values equal to this class and returns it.
492  /// @return A Ogre Vector3 containing the same value as the Mezzanine::Vector3
493  Ogre::Vector3 GetOgreVector3() const;
494  /// @brief Copies an existing Ogre vector3.
495  /// @details This function will copy the values stored in an existing Ogre vector3
496  /// and set the values of this class to be the same.
497  /// @param temp The vector3 to be extracted.
498  void ExtractOgreVector3(const Ogre::Vector3& temp);
499 
500  ///////////////////////////////////////////////////////////////////////////////
501  // Serialization
502 
503  // void DeSerializableClass::ProtoDeSerialize(const XML::Node&);
504  // static String DeSerializableClass::GetSerializableName();
505  /// @brief Convert this class to an XML::Node ready for serialization
506  /// @param CurrentRoot The point in the XML hierarchy that all this vector3 should be appended to.
507  void ProtoSerialize(XML::Node& CurrentRoot) const;
508  /// @brief Take the data stored in an XML and overwrite this instance of this object with it
509  /// @param OneNode and XML::Node containing the data.
510  void ProtoDeSerialize(const XML::Node& OneNode);
511  /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
512  /// @return A string containing "Vector3"
513  static String GetSerializableName();
514 
515  /// @brief
516  const char* __str__();
517 
518  };//Vector3
519 
520  ///////////////////////////////////////////////////////////////////////////////
521  /// @brief A compare fuctor that uses vector length.
522  /// @details
523  ///////////////////////////////////////
525  {
526  public:
527  /// @brief Compares two Vector3's to determine which has the greater length/magnitude.
528  /// @param First The first Vector3 to compare with.
529  /// @param Second The second Vector3 to compare with.
530  /// @return Returns true if the first Vector3 has a smaller length/magnitude than the second, false otherwise.
531  Boole operator()(const Vector3& First, const Vector3& Second) const;
532  };//Vector3LengthCompare
533 }//Mezzanine
534 
535 namespace std
536 {
537  #ifndef SWIG
538  /// @brief Get Numeric details on Vector3
539  template<>
540  class numeric_limits<Mezzanine::Vector3>
541  {
542  public:
543  /// @brief Does this class (numeric_limits<Mezzanine::Vector3>) exist
544  static const bool is_specialized = true;
545  /// @brief Does this support negative values?
546  static const bool is_signed = true;
547  /// @brief Can this only store integer types.
548  static const bool is_integer = false;
549  /// @brief The Vector3 uses Real, which is typically a machine dependedant which can be inexact
550  static const bool is_exact = std::numeric_limits<Mezzanine::Real>::is_exact;
551  /// @brief Can This represent an infinitely large value in X, Y or Z?
552  static const bool has_infinity = std::numeric_limits<Mezzanine::Real>::has_infinity;
553  /// @brief ??? Required by std::numeric to be compliant
554  /// @todo Learn why this exists and document it.
555  static const bool has_quiet_NaN = std::numeric_limits<Mezzanine::Real>::has_quiet_NaN;
556  /// @brief ??? Required by std::numeric to be compliant
557  /// @todo Learn why this exists and document it.
558  static const bool has_signaling_NaN = std::numeric_limits<Mezzanine::Real>::has_signaling_NaN;
559  /// @brief Does this support exceptionally small numbers near 0?
560  static const std::float_denorm_style has_denorm = std::numeric_limits<Mezzanine::Real>::has_denorm;
561  /// @brief When extra precision near 0 is lost, can this type distinguish that from other imprecision.
562  static const bool has_denorm_loss = std::numeric_limits<Mezzanine::Real>::has_denorm_loss;
563  /// @brief How items that fit between the precise amount a Real can represent will be adapted.
564  static const std::float_round_style round_style = std::numeric_limits<Mezzanine::Real>::round_style;
565  /// @brief Do X, Y and Z adhere to iec 559?
566  static const bool is_iec559 = std::numeric_limits<Mezzanine::Real>::is_iec559;
567  /// @brief Is overflow of this type handle by modulo overflow?
568  static const bool is_modulo = std::numeric_limits<Mezzanine::Real>::is_modulo;
569  /// @brief How many integer digits(in machine base) of precision can this handle in each X, Y or Z without floating point component or error?
570  static const int digits = std::numeric_limits<Mezzanine::Real>::digits;
571  /// @brief How many integer digits in base 10 of precision can this handle in each X, Y or Z without floating point component or error?
572  static const int digits10 = std::numeric_limits<Mezzanine::Real>::digits10;
573  /// @brief The base of the number system that this is implemented in
574  static const int radix = std::numeric_limits<Mezzanine::Real>::radix;
575  /// @brief The smallest power of the radix that is valid floating point value
576  static const int min_exponent = std::numeric_limits<Mezzanine::Real>::min_exponent;
577  /// @brief The smallest power of 10 that is valid floating point value
578  static const int min_exponent10 = std::numeric_limits<Mezzanine::Real>::min_exponent10;
579  /// @brief The largest power of the radix that is valid floating point value
580  static const int max_exponent = std::numeric_limits<Mezzanine::Real>::max_exponent;
581  /// @brief The largest power of 10 that is valid floating point value
582  static const int max_exponent10 = std::numeric_limits<Mezzanine::Real>::max_exponent10;
583  /// @brief Can this generate a trap?
584  static const bool traps = std::numeric_limits<Mezzanine::Real>::traps;
585  /// @brief Are tiny values respected during rounding?
586  static const bool tinyness_before = std::numeric_limits<Mezzanine::Real>::tinyness_before;
587 
588  /// @brief Get the lowest positive finite value this can represent
589  /// @return A vector with 3 very small numbers
591  {
592  return Mezzanine::Vector3(std::numeric_limits<Mezzanine::Real>::min(),
593  std::numeric_limits<Mezzanine::Real>::min(),
594  std::numeric_limits<Mezzanine::Real>::min()
595  );
596  }
597 
598  /// @brief Get the highest positive finite value this can represent
599  /// @return A vector with 3 very large numbers
601  {
602  return Mezzanine::Vector3(std::numeric_limits<Mezzanine::Real>::max(),
603  std::numeric_limits<Mezzanine::Real>::max(),
604  std::numeric_limits<Mezzanine::Real>::max()
605  );
606  }
607 
608  /// @brief The smallest value representable from 1.0,1.0,1.0 to the next value
609  /// @return A vector with a very small number
611  {
612  return Mezzanine::Vector3(std::numeric_limits<Mezzanine::Real>::epsilon(),
613  std::numeric_limits<Mezzanine::Real>::epsilon(),
614  std::numeric_limits<Mezzanine::Real>::epsilon()
615  );
616  }
617 
618  /// @brief Get the largest possible rounding error
619  /// @return A vector containing 3 values indicating how much they could be rounded.
621  {
622  return Mezzanine::Vector3(std::numeric_limits<Mezzanine::Real>::round_error(),
623  std::numeric_limits<Mezzanine::Real>::round_error(),
624  std::numeric_limits<Mezzanine::Real>::round_error()
625  );
626  }
627 
628  /// @brief Get the special value "Positive infinity"
629  /// @return A vector containing 3 values.
631  {
632  return Mezzanine::Vector3(std::numeric_limits<Mezzanine::Real>::infinity(),
633  std::numeric_limits<Mezzanine::Real>::infinity(),
634  std::numeric_limits<Mezzanine::Real>::infinity()
635  );
636  }
637 
638  /// @brief Get the special value "Quiet Not actual Number"
639  /// @return A vector containing 3 values.
641  {
642  return Mezzanine::Vector3(std::numeric_limits<Mezzanine::Real>::quiet_NaN(),
643  std::numeric_limits<Mezzanine::Real>::quiet_NaN(),
644  std::numeric_limits<Mezzanine::Real>::quiet_NaN()
645  );
646  }
647 
648  /// @brief Get the special value "Signaling Not actual Number"
649  /// @return A vector containing 3 values.
651  {
652  return Mezzanine::Vector3(std::numeric_limits<Mezzanine::Real>::signaling_NaN(),
653  std::numeric_limits<Mezzanine::Real>::signaling_NaN(),
654  std::numeric_limits<Mezzanine::Real>::signaling_NaN()
655  );
656  }
657 
658  /// @brief Get the closest value to 0 that is not 0 this can represent, including extra precision for being close to 0 if supported.
659  /// @return A vector containing 3 very small values.
661  {
662  return Mezzanine::Vector3(std::numeric_limits<Mezzanine::Real>::denorm_min(),
663  std::numeric_limits<Mezzanine::Real>::denorm_min(),
664  std::numeric_limits<Mezzanine::Real>::denorm_min()
665  );
666  }
667 
668  }; //Numeric Limits
669  #endif // \SWIG
670 
671 } // std
672 
673 namespace Mezzanine
674 {
675  ///////////////////////////////////////////////////////////////////////////////
676  // Right Hand Arithmetic Operators
677 
678  /// @brief Right Hand Addition Operator for Bullet Vectors with a Mezzanine::Vector3.
679  /// @param Vec The Bullet Vector to be added.
680  /// @param lhs The Mezzanine::Vector3 to be added.
681  /// @return A Mezzanine::Vector3 with the Sum.
682  Mezzanine::Vector3 MEZZ_LIB operator+ (const btVector3 &Vec, const Mezzanine::Vector3& lhs);
683 
684  /// @brief Right Hand Subtraction Operator for Bullet Vectors with a Mezzanine::Vector3.
685  /// @param Vec The Bullet Vector to be subtracted from.
686  /// @param lhs The Mezzanine::Vector3 to be subtracted.
687  /// @return A Mezzanine::Vector3 with the difference.
688  Mezzanine::Vector3 MEZZ_LIB operator- (const btVector3 &Vec, const Mezzanine::Vector3& lhs);
689 
690  /// @brief Right Hand Multiplication Operator for Bullet Vectors with a Mezzanine::Vector3.
691  /// @param Vec The Bullet Vector to be multiplied.
692  /// @param lhs The Mezzanine::Vector3 to be multiplied.
693  /// @return A Mezzanine::Vector3 with the product.
694  Mezzanine::Vector3 MEZZ_LIB operator* (const btVector3 &Vec, const Mezzanine::Vector3& lhs);
695 
696  /// @brief Right Hand Division Operator for Bullet Vectors with a Mezzanine::Vector3.
697  /// @param Vec The Bullet Vector to be divided by.
698  /// @param lhs The Mezzanine::Vector3 to be divided.
699  /// @return A Mezzanine::Vector3 with the results
700  Mezzanine::Vector3 MEZZ_LIB operator/ (const btVector3 &Vec, const Mezzanine::Vector3& lhs);
701 
702  /// @brief Right Hand Addition Operator for Ogre Vectors with a Mezzanine::Vector3.
703  /// @param Vec The Ogre Vector to be added.
704  /// @param lhs The Mezzanine::Vector3 to be added.
705  /// @return A Mezzanine::Vector3 with the Sum.
706  Mezzanine::Vector3 MEZZ_LIB operator+ (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs);
707 
708  /// @brief Right Hand Subtraction Operator for Ogre Vectors with a Mezzanine::Vector3.
709  /// @param Vec The Ogre Vector to be subtracted from.
710  /// @param lhs The Mezzanine::Vector3 to be subtracted.
711  /// @return A Mezzanine::Vector3 with the difference.
712  Mezzanine::Vector3 MEZZ_LIB operator- (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs);
713 
714  /// @brief Right Hand Multiplication Operator for Ogre Vectors with a Mezzanine::Vector3.
715  /// @param Vec The Ogre Vector to be multiplied.
716  /// @param lhs The Mezzanine::Vector3 to be multiplied.
717  /// @return A Mezzanine::Vector3 with the product.
718  Mezzanine::Vector3 MEZZ_LIB operator* (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs);
719 
720  /// @brief Right Hand Division Operator for Ogre Vectors with a Mezzanine::Vector3.
721  /// @param Vec The Ogre Vector to be divided by.
722  /// @param lhs The Mezzanine::Vector3 to be divided.
723  /// @return A Mezzanine::Vector3 with the results
724  Mezzanine::Vector3 MEZZ_LIB operator/ (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs);
725 
726  ///////////////////////////////////////////////////////////////////////////////
727  // Class External << Operators for streaming or assignment
728 
729  // We can skip these operators when creating bindings with swig
730  #ifndef SWIG
731 
732  /// @brief Used to Serialize an Mezzanine::Vector3 to a human readable stream
733  /// @details The current XML format
734  /// will create one node with no child nodes. The name of the xml node will be "Vector3". It will have 4 attributes.
735  /// "Version", will be set to a value of 1, indicating if came from version 1 compatible Vector3. It will also have an "X", "Y" and
736  /// "Z" attributes will values set appropriately. For example '<Vector3 Version="1" X="1" Y="2" Z="3" />'.
737  /// @param x The Mezzanine::Vector3 to be converted to characters.
738  /// @param stream The place to send the characters, that define the Mezzanine::Vector3.
739  /// @return Get an std::ostream that was written to, this allow chaining of the << operators.
740  std::ostream& MEZZ_LIB operator << (std::ostream& stream, const Mezzanine::Vector3& x);
741 
742  /// @brief Used to de-serialize an Mezzanine::Vector3 from a stream
743  /// @details This reads in the xml and sets the target vector according to values
744  /// from the stream.
745  /// @param Vec The Mezzanine::Vector3 that will accept the values from the xml
746  /// @param stream The place to get the characters from, that define the Mezzanine::Vector3.
747  /// @return Get an std::ostream that was read from, this allow chaining of the >> operators.
748  /// @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.
749  std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::Vector3& Vec);
750 
751  /// @brief Converts an XML node into a Mezzanine::Vector3
752  /// @details This will convert an XML::Node will a valid serialized Mezzanine::Vector3 into a Mezzanine::Vector3
753  /// @param OneNode An XML Node containing the the text of a Vector3
754  /// @param Vec the Mezzanine::Vector3 to store the deserialized Vector3
755  /// @return This returns a reference to the XML::Node for operator chaining or whatever.
756  /// @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.
758 
759  /// @brief Conversion Assignment Operator to Ogre::Vector3.
760  /// @param VecTo The left hand side vector, is an Ogre::Vector3. The values of VecFrom will be copied here.
761  /// @param VecFrom The right hand side, is a\ Mezzanine::Vector3, this vector will be copied and unchanged.
762  /// @return An Ogre::Vector3 in case multiple operators are chainged together (not usually a good idea).
763  Ogre::Vector3& MEZZ_LIB operator << (Ogre::Vector3& VecTo, const Mezzanine::Vector3& VecFrom);
764 
765  /// @brief Conversion Assignment Operator to Ogre::Vector3.
766  /// @param VecTo The left hand side vector, is an Ogre::Vector3. The values of VecFrom will be copied here.
767  /// @param VecFrom The right hand side, is a btVector3, this vector will be copied and unchanged.
768  /// @return An Ogre::Vector3 in case multiple operators are chainged together (not usually a good idea).
769  Ogre::Vector3& MEZZ_LIB operator << (Ogre::Vector3& VecTo, const btVector3& VecFrom);
770 
771  /// @brief Conversion Assignment Operator to btVector3.
772  /// @param VecTo The left hand side vector, is an btVector3. The values of VecFrom will be copied here.
773  /// @param VecFrom The right hand side, is a Ogre::Vector3, this vector will be copied and unchanged.
774  /// @return An btVector3 in case multiple operators are chainged together (not usually a good idea).
775  btVector3& MEZZ_LIB operator << (btVector3& VecTo, const Ogre::Vector3& VecFrom);
776 
777  /// @brief Conversion Assignment Operator to btVector3.
778  /// @param VecTo The left hand side vector, is an btVector3. The values of VecFrom will be copied here.
779  /// @param VecFrom The right hand side, is a Mezzanine::Vector3, this vector will be copied and unchanged.
780  /// @return An btVector3 in case multiple operators are chainged together (not usually a good idea).
781  btVector3& MEZZ_LIB operator << (btVector3& VecTo, const Mezzanine::Vector3& VecFrom);
782 
783  /// @brief Conversion Assignment Operator to Mezzanine::Vector3.
784  /// @param VecTo The left hand side vector, is an Mezzanine::Vector3. The values of VecFrom will be copied here.
785  /// @param VecFrom The right hand side, is a Ogre::Vector3, this vector will be copied and unchanged.
786  /// @return An Mezzanine::Vector3 in case multiple operators are chainged together (not usually a good idea).
787  Mezzanine::Vector3& MEZZ_LIB operator << (Mezzanine::Vector3& VecTo, const Ogre::Vector3& VecFrom);
788 
789  /// @brief Conversion Assignment Operator to Mezzanine::Vector3.
790  /// @param VecTo The left hand side vector, is an Mezzanine::Vector3. The values of VecFrom will be copied here.
791  /// @param VecFrom The right hand side, is a btVector3, this vector will be copied and unchanged.
792  /// @return An Mezzanine::Vector3 in case multiple operators are chainged together (not usually a good idea).
793  Mezzanine::Vector3& MEZZ_LIB operator << (Mezzanine::Vector3& VecTo, const btVector3& VecFrom);
794 #endif // \SWIG
795 }
796 
797 #endif // \include gaurd
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
This file is used on some platforms to determine what data should be read and written to and from a s...
Real X
Coordinate on the X vector.
Definition: vector3.h:85
Real Z
Coordinate on the Z vector.
Definition: vector3.h:89
StandardAxis
Used to identify different Axis in a 3d coordinate system.
Definition: enumerations.h:119
All the definitions for datatypes as well as some basic conversion functions are defined here...
STL namespace.
SmoothTrackIterator< InterpolatableType > & operator+(Integer Steps, SmoothTrackIterator< InterpolatableType > &Iter)
This allows for addition with and an Integer on the Left hand side, such as: 2 + Iter.
static Mezzanine::Vector3 quiet_NaN()
Get the special value "Quiet Not actual Number".
Definition: vector3.h:640
Any global enumerations shared between multiple classes is to be declared here.
Mezzanine::Vector3 operator/(const btVector3 &Vec, const Mezzanine::Vector3 &lhs)
Right Hand Division Operator for Bullet Vectors with a Mezzanine::Vector3.
Definition: vector3.cpp:653
A compare fuctor that uses vector length.
Definition: vector3.h:524
std::ostream & operator<<(std::ostream &stream, const Mezzanine::HashedString32 &x)
Send a HashedString32 down a stream serialized.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
SmoothTrackIterator< InterpolatableType > & operator-(Integer Steps, SmoothTrackIterator< InterpolatableType > &Iter)
This allows for subtraction with and an Integer on the Left hand side, such as: 2 + Iter...
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
Mezzanine::Vector3 operator*(const btVector3 &Vec, const Mezzanine::Vector3 &lhs)
Right Hand Multiplication Operator for Bullet Vectors with a Mezzanine::Vector3.
Definition: vector3.cpp:651
static Mezzanine::Vector3 min()
Get the lowest positive finite value this can represent.
Definition: vector3.h:590
Real Y
Coordinate on the Y vector.
Definition: vector3.h:87
std::istream & operator>>(std::istream &stream, Mezzanine::Vector3 &Vec)
Used to de-serialize an Mezzanine::Vector3 from a stream.
Definition: vector3.cpp:689
static Mezzanine::Vector3 signaling_NaN()
Get the special value "Signaling Not actual Number".
Definition: vector3.h:650
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...
static Mezzanine::Vector3 denorm_min()
Get the closest value to 0 that is not 0 this can represent, including extra precision for being clos...
Definition: vector3.h:660
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
Used to give commands specifically to the SWIG preprocessor.
static Mezzanine::Vector3 infinity()
Get the special value "Positive infinity".
Definition: vector3.h:630
static Mezzanine::Vector3 epsilon()
The smallest value representable from 1.0,1.0,1.0 to the next value.
Definition: vector3.h:610
Real ChannelType
What are the X, Y and Z channels implmented with.
Definition: vector3.h:121
This is used to store information about rotation in 3d space.
Definition: quaternion.h:68
static Mezzanine::Vector3 max()
Get the highest positive finite value this can represent.
Definition: vector3.h:600
Helper classes to assist in generating data points between two other data points. ...
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
static Mezzanine::Vector3 round_error()
Get the largest possible rounding error.
Definition: vector3.h:620