Spinning Topp Logo BlackTopp Studios
inc
quaternion.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 _quaternion_h
41 #define _quaternion_h
42 
43 #include "crossplatformexport.h"
44 #include "datatypes.h"
45 
46 #ifndef SWIG
47  #include "XML/xml.h"
48  #include <limits>
49 #endif
50 
51 class btQuaternion;
52 namespace Ogre
53 {
54  class Quaternion;
55 }
56 
57 namespace Mezzanine
58 {
59  class Vector3;
60  class Matrix3x3;
61  ///////////////////////////////////////////////////////////////////////////////
62  /// @class Quaternion
63  /// @headerfile quaternion.h
64  /// @brief This is used to store information about rotation in 3d space
65  /// @details This is used to store information about rotation in 3d space. The
66  /// X, Y and Z are used to identify a ray from the origin (0,0,0), about which
67  /// W represents an amount of rotation.
69  {
70  public:
71  ///////////////////////////////////////////////////////////////////////////////
72  // Data Members
73 
74  /// @brief The X component of the Axis.
76  /// @brief The Y component of the Axis.
78  /// @brief The Z component of the Axis.
80  /// @brief Rotation on the Axis X, Y and Z defined.
82 
83  ///////////////////////////////////////////////////////////////////////////////
84  // Constructors
85 
86  /// @brief Blank Constructor.
87  /// @details Basic no-initialization constructor.
88  Quaternion();
89  /// @brief Constructor.
90  /// @details Constructor that sets all four axis' of rotation.
91  /// @param X The X component of the Axis.
92  /// @param Y The Y component of the Axis.
93  /// @param Z The Z component of the Axis.
94  /// @param W Rotation on the Axis X, Y and Z defined.
95  Quaternion(const Real& X, const Real& Y, const Real& Z, const Real& W);
96  /// @brief Axis and Rotation Constructor.
97  /// @details This assembles a quaternion based on an axis and a rotation in radians.
98  /// @param Angle Real representing the angle to be applied along the axis in radians.
99  /// @param Axis Vector3 representing the axis to apply the rotation.
100  Quaternion(const Real& Angle, const Vector3& Axis);
101  /// @brief Rotation Matrix Constructor.
102  /// @param Mat The matrix to set this quaternion from.
103  Quaternion(const Matrix3x3& Mat);
104  /// @brief Axes Constructor.
105  /// @param AxisX The vector expressing the X axis.
106  /// @param AxisY The vector expressing the Y axis.
107  /// @param AxisZ The vector expressing the Z axis.
108  Quaternion(const Vector3& AxisX, const Vector3& AxisY, const Vector3& AxisZ);
109  /// @brief Rotation To Z constructor.
110  /// @param DirectionAxis The axis to get the rotation to Z for.
111  /// @param UpAxis The up axis in local space.
112  Quaternion(const Vector3& DirectionAxis, const Vector3& UpAxis);
113  /// @brief Bullet Quaternion constructor.
114  /// @details Constructor that sets all values to match the Bullet quaternion.
115  /// @param Theirs The quaternion to be copied to make this quaternion.
116  explicit Quaternion(const btQuaternion& Theirs);
117  /// @brief Ogre Quaternion constructor.
118  /// @details Constructor that sets all values to match the Ogre quaternion.
119  /// @param Theirs The quaternion to be copied to make this quaternion.
120  explicit Quaternion(const Ogre::Quaternion& Theirs);
121  /// @brief Copy Constructor.
122  /// @param Other The Quaternion to copy.
123  Quaternion(const Mezzanine::Quaternion& Other);
124  /// @brief XML Constructor.
125  /// @param OneNode The XML node to deserialize from.
126  explicit Quaternion(const XML::Node& OneNode);
127 
128  ///////////////////////////////////////////////////////////////////////////////
129  // Fancy Math and Utilities
130 
131  /// @brief Sets default/identity values to the members of this quaternion.
132  void SetIdentity();
133  /// @brief Sets the individual values of this quaterion directly.
134  /// @param X The X component of the Axis.
135  /// @param Y The Y component of the Axis.
136  /// @param Z The Z component of the Axis.
137  /// @param W Rotation on the Axis X, Y and Z defined.
138  void SetValues(const Real& X, const Real& Y, const Real& Z, const Real& W);
139  /// @brief Generates and sets the values of this quaternion to describe a rotation from an axis and angle on that axis.
140  /// @param Angle Real representing the angle to be applied along the axis in radians.
141  /// @param Axis Vector3 representing the axis to apply the rotation.
142  void SetFromAxisAngle(const Real& Angle, const Vector3& Axis);
143  /// @brief Sets this quaternions values to express the same rotation as a Matrix3x3.
144  /// @param Mat The matrix to set this quaternion from.
145  void SetFromMatrix3x3(const Matrix3x3& Mat);
146  /// @brief Generates and sets the values of this quaternion from 3 Axis vectors.
147  /// @param AxisX The vector expressing the X axis.
148  /// @param AxisY The vector expressing the Y axis.
149  /// @param AxisZ The vector expressing the Z axis.
150  void SetFromAxes(const Vector3& AxisX, const Vector3& AxisY, const Vector3& AxisZ);
151  /// @brief Generates and sets the values of this quaternion to describe a rotation from the direction axis to the Z axis.
152  /// @param DirectionAxis The axis to get the rotation to Z for.
153  /// @param UpAxis The up axis in local space.
154  void SetFromAxisToZ(const Vector3& DirectionAxis, const Vector3& UpAxis);
155 
156  /// @brief Converts the rotation expressed by this Quaternion into it's individual rotation and axis components.
157  /// @param Angle The amount of rotation to apply to the axis.
158  /// @param Axis The Axis this quaternions rotation is on.
159  void ConvertToAngleAxis(Real& Angle, Vector3& Axis) const;
160 
161  /// @brief Gets the Dot Product of this quaternion and another quaternion.
162  /// @param Other The other quaternion to calculate the dot product from.
163  /// @return Returns a Real that is the Dot Product of the two quaternions.
164  Real DotProduct(const Quaternion& Other) const;
165  /// @brief Gets the length of the quaternion.
166  /// @return Returns a Real representing the length of the quaternion.
167  Real Length() const;
168  /// @brief Gets the squared length(len^2) of the quaternion.
169  /// @return Returns a Real representing the squared length(len^2) of the quaternion.
170  Real LengthSqrd() const;
171  /// @brief Normalizes this Quaternion.
172  /// @return Returns a normalized reference of this quaternion.
173  Quaternion& Normalize();
174  /// @brief Get a normalized copy of this Quaternion without changing this one.
175  /// @return A Copy of this Quaternion after the copy has been normalized.
176  Quaternion GetNormalizedCopy() const;
177  /// @brief Inverses this Quaternion.
178  /// @return Returns a quaternion that is a copy of this one after it has been inversed.
179  Quaternion GetInverse() const;
180 
181  ///////////////////////////////////////////////////////////////////////////////
182  // Explicit Conversion
183 
184  /// @brief Gets a Bullet quaternion.
185  /// @details Creates a Bullet quaternion with values equal to this class and returns it.
186  /// @param normalize Whether or not you want this function to normalize the quaternion for you.
187  /// @return A btQuaternion that has the same contents as this Mezzanine::Quaternion.
188  btQuaternion GetBulletQuaternion(Boole normalize=false) const;
189 
190  /// @brief Copies an existing Bullet quaternion.
191  /// @details This function will copy the values stored in an existing Bullet quaternion
192  /// and set the values of this class to be the same.
193  /// @param Ours The quaternion to be extracted.
194  void ExtractBulletQuaternion(const btQuaternion &Ours);
195 
196  /// @brief Gets a Ogre quaternion.
197  /// @details Creates a Ogre quaternion with values equal to this class and returns it.
198  /// @param normalize Whether or not you want this function to normalize the quaternion for you.
199  Ogre::Quaternion GetOgreQuaternion(Boole normalize=false) const;
200 
201  /// @brief Copies an existing Ogre quaternion.
202  /// @details This function will copy the values stored in an existing Ogre quaternion
203  /// and set the values of this class to be the same.
204  /// @param Ours The quaternion to be extracted.
205  void ExtractOgreQuaternion(const Ogre::Quaternion &Ours);
206 
207  ///////////////////////////////////////////////////////////////////////////////
208  // Access Operators
209 
210  /// @brief Allows Array style access to the members of this class.
211  /// @param Index The number corresponding to the Index you want. 0 = X, 1 = Y, 2 = Z, 3 = W.
212  /// @return Returns a copy of the number at the index requested.
213  Real operator[](const Whole& Index) const;
214 
215  /// @brief Allows Array style access to the members of this class.
216  /// @param Index The number corresponding to the Index you want. 0 = X, 1 = Y, 2 = Z, 3 = W.
217  /// @return Returns a writable reference to the number at the index requested.
218  Real& operator[](const Whole& Index);
219 
220  ///////////////////////////////////////////////////////////////////////////////
221  // Arithmetic By Real Operators
222 
223  /// @brief Scaling by multiplication.
224  /// @param Scalar This is the amount to scale the quaternion by.
225  /// @return Returns a scaled quaternion.
226  Quaternion operator* (const Real& Scalar) const;
227 
228  /// @brief Scaling by division.
229  /// @param Scalar This is the amount to scale the quaternion by.
230  /// @return Returns a scaled quaternion.
231  Quaternion operator/ (const Real& Scalar) const;
232 
233  ///////////////////////////////////////////////////////////////////////////////
234  // Left Hand Basic Arithmetic Operators
235 
236  /// @brief Addition operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
237  /// @param Other The other Quaternion to add to this one.
238  /// @return A Mezzanine::Quaternion with the sum.
239  Quaternion operator+ (const Mezzanine::Quaternion& Other) const;
240 
241  /// @brief Addition operator with Mezzanine::Quaternion and Ogre::Quaternion.
242  /// @param Other The other Quaternion to add to this one.
243  /// @return A Mezzanine::Quaternion with the sum.
244  Quaternion operator+ (const Ogre::Quaternion& Other) const;
245 
246  /// @brief Addition operator with Mezzanine::Quaternion and btQuaternion.
247  /// @param Other The other Quaternion to add to this one.
248  /// @return A Mezzanine::Quaternion with the sum.
249  Quaternion operator+ (const btQuaternion& Other) const;
250 
251  /// @brief Subtraction operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
252  /// @param Other The other Quaternion to subtract from this one.
253  /// @return A Mezzanine::Quaternion with the difference.
254  Quaternion operator- (const Mezzanine::Quaternion& Other) const;
255 
256  /// @brief Subtraction operator with Mezzanine::Quaternion and Ogre::Quaternion.
257  /// @param Other The other Quaternion to subtract from this one.
258  /// @return A Mezzanine::Quaternion with the difference.
259  Quaternion operator- (const Ogre::Quaternion& Other) const;
260 
261  /// @brief Subtraction operator with Mezzanine::Quaternion and btQuaternion.
262  /// @param Other The other Quaternion to subtract from this one.
263  /// @return A Mezzanine::Quaternion with the difference.
264  Quaternion operator- (const btQuaternion& Other) const;
265 
266  /// @brief Multiplication operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
267  /// @param Other The other Quaternion to multiply from this one.
268  /// @return A Mezzanine::Quaternion with the result.
269  Quaternion operator* (const Mezzanine::Quaternion& Other) const;
270 
271  /// @brief Multiplication operator with Mezzanine::Quaternion and Ogre::Quaternion.
272  /// @param Other The other Quaternion to multiply from this one.
273  /// @return A Mezzanine::Quaternion with the result.
274  Quaternion operator* (const Ogre::Quaternion& Other) const;
275 
276  /// @brief Multiplication operator with Mezzanine::Quaternion and btQuaternion.
277  /// @param Other The other Quaternion to multiply from this one.
278  /// @return A Mezzanine::Quaternion with the result.
279  Quaternion operator* (const btQuaternion& Other) const;
280 
281  ///////////////////////////////////////////////////////////////////////////////
282  // Vector Rotation Operators
283 
284  /// @brief Rotates a vector by the provided quaternion.
285  /// @param Other The vector to rotate.
286  /// @return Returns a rotated version of the provided vector.
287  Vector3 operator* (const Vector3& Other) const;
288 
289  ///////////////////////////////////////////////////////////////////////////////
290  // Increment and Decrement Operators
291 
292  /// @brief Incrementing operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
293  /// @param Other The other Quaternion to add to this one.
294  /// @return This Mezzanine::Quaternion with the sum.
295  Quaternion& operator+= (const Mezzanine::Quaternion& Other);
296 
297  /// @brief Incrementing operator with Mezzanine::Quaternion and Ogre::Quaternion.
298  /// @param Other The other Quaternion to add to this one.
299  /// @return This Mezzanine::Quaternion with the sum.
300  Quaternion& operator+= (const Ogre::Quaternion& Other);
301 
302  /// @brief Incrementing operator with Mezzanine::Quaternion and btQuaternion.
303  /// @param Other The other Quaternion to add to this one.
304  /// @return This Mezzanine::Quaternion with the sum.
305  Quaternion& operator+= (const btQuaternion& Other);
306 
307  /// @brief Decrementing operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
308  /// @param Other The other Quaternion to subtract from this one.
309  /// @return This Mezzanine::Quaternion with the difference.
310  Quaternion& operator-= (const Mezzanine::Quaternion& Other);
311 
312  /// @brief Decrementing operator with Mezzanine::Quaternion and Ogre::Quaternion.
313  /// @param Other The other Quaternion to subtract from this one.
314  /// @return This Mezzanine::Quaternion with the difference.
315  Quaternion& operator-= (const Ogre::Quaternion& Other);
316 
317  /// @brief Decrementing operator with Mezzanine::Quaternion and btQuaternion.
318  /// @param Other The other Quaternion to subtract from this one.
319  /// @return This Mezzanine::Quaternion with the difference.
320  Quaternion& operator-= (const btQuaternion& Other);
321 
322  ///////////////////////////////////////////////////////////////////////////////
323  // Assignment Operators
324 
325  /// @brief Assignment Operator from Mezzanine::Quaternion.
326  /// @param Other The other quaternion to overwrite this one.
327  /// @return This Quaternion after being assigned fresh values.
328  Quaternion& operator= (const Mezzanine::Quaternion& Other);
329 
330  /// @brief Assignment Operator from Ogre::Quaternion.
331  /// @param Other The other quaternion to overwrite this one.
332  /// @return This Quaternion after being assigned fresh values.
333  Quaternion& operator= (const Ogre::Quaternion& Other);
334 
335  /// @brief Assignment Operator from btQuaternion.
336  /// @param Other The other quaternion to overwrite this one.
337  /// @return This Quaternion after being assigned fresh values.
338  Quaternion& operator= (const btQuaternion& Other);
339 
340  ///////////////////////////////////////////////////////////////////////////////
341  // Equality Comparison Operators
342 
343  /// @brief Equality Comparison Operator from Mezzanine::Quaternion.
344  /// @param Other The other quaternion to compare with.
345  /// @return True if the Quaternions are semantically equal, false otherwise.
346  Boole operator==(const Mezzanine::Quaternion& Other) const;
347  /// @brief Equality Comparison Operator from Ogre::Quaternion.
348  /// @param Other The other quaternion to compare with.
349  /// @return True if the Quaternions are semantically equal, false otherwise.
350  Boole operator==(const Ogre::Quaternion& Other) const;
351  /// @brief Equality Comparison Operator from btQuaternion.
352  /// @param Other The other quaternion to compare with.
353  /// @return True if the Quaternions are semantically equal, false otherwise.
354  Boole operator==(const btQuaternion& Other) const;
355 
356  /// @brief Inequality Comparison Operator from Mezzanine::Quaternion.
357  /// @param Other The other quaternion to compare with.
358  /// @return True if the Quaternions are not semantically equal, false otherwise.
359  Boole operator!=(const Mezzanine::Quaternion& Other) const;
360  /// @brief Inequality Comparison Operator from Ogre::Quaternion.
361  /// @param Other The other quaternion to compare with.
362  /// @return True if the Quaternions are not semantically equal, false otherwise.
363  Boole operator!=(const Ogre::Quaternion& Other) const;
364  /// @brief Inequality Comparison Operator from btQuaternion.
365  /// @param Other The other quaternion to compare with.
366  /// @return True if the Quaternions are not semantically equal, false otherwise.
367  Boole operator!=(const btQuaternion& Other) const;
368 
369  /// @brief Is every value in this Quaternion less than or equal to its corresponding value in another.
370  /// @param Other The Quaternion on the right hand side of the sign.
371  /// @note Used primarily for testing. This is not implemented for use with other kinds of Quaternion implementations as it is widely considered useless.
372  Boole operator<= (const Mezzanine::Quaternion& Other) const;
373  /// @brief Is every value in this Quaternion greater than or equal to its corresponding value in another.
374  /// @param Other The Quaternion on the right hand side of the sign.
375  /// @note Used primarily for testing. This is not implemented for use with other kinds of Quaternion implementations as it is widely considered useless.
376  Boole operator>= (const Mezzanine::Quaternion& Other) const;
377 
378  ///////////////////////////////////////////////////////////////////////////////
379  // Serialization
380 
381  // Serializable
382  /// @brief Convert this class to an XML::Node ready for serialization
383  /// @param CurrentRoot The point in the XML hierarchy that all this quaternion should be appended to.
384  void ProtoSerialize(XML::Node& CurrentRoot) const;
385 
386  // DeSerializable
387  /// @brief Take the data stored in an XML and overwrite this instance of this object with it
388  /// @param OneNode and XML::Node containing the data.
389  void ProtoDeSerialize(const XML::Node& OneNode);
390 
391  /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
392  /// @return A string containing "Quaternion"
393  static String GetSerializableName();
394 
395  };//Quaternion
396 }//Mezzanine
397 
398 ///////////////////////////////////////////////////////////////////////////////
399 // Right Hand Arithmetic Operators
400 
401 /// @brief Addition operator with Mezzanine::Quaternion and Ogre::Quaternion.
402 /// @param Other The first Quaternion to add.
403 /// @param Other2 The Mezzanine::Quaternion to add.
404 /// @return A Mezzanine::Quaternion with the sum.
405 Mezzanine::Quaternion MEZZ_LIB operator+ (const Ogre::Quaternion& Other, const Mezzanine::Quaternion& Other2);
406 
407 /// @brief Addition operator with Mezzanine::Quaternion and btQuaternion.
408 /// @param Other The first Quaternion to add.
409 /// @param Other2 The Mezzanine::Quaternion to add.
410 /// @return A Mezzanine::Quaternion with the sum.
411 Mezzanine::Quaternion MEZZ_LIB operator+ (const btQuaternion& Other, const Mezzanine::Quaternion& Other2);
412 
413 /// @brief Subtraction operator with Mezzanine::Quaternion and Ogre::Quaternion.
414 /// @param Other The first Quaternion to subtract from.
415 /// @param Other2 The Mezzanine::Quaternion to subtract.
416 /// @return A Mezzanine::Quaternion with the sum.
417 Mezzanine::Quaternion MEZZ_LIB operator- (const Ogre::Quaternion& Other, const Mezzanine::Quaternion& Other2);
418 
419 /// @brief Subtraction operator with Mezzanine::Quaternion and btQuaternion.
420 /// @param Other The first Quaternion to subtract from.
421 /// @param Other2 The Mezzanine::Quaternion to subtract.
422 /// @return A Mezzanine::Quaternion with the sum.
423 Mezzanine::Quaternion MEZZ_LIB operator- (const btQuaternion& Other, const Mezzanine::Quaternion& Other2);
424 
425 
426 ///////////////////////////////////////////////////////////////////////////////
427 // Class External << Operators for streaming or assignment
428 
429 #ifndef SWIG
430 /// @brief Conversion operator to btQuaternion.
431 /// @param Other The Quaternion to store the fresh contents.
432 /// @param Other2 The Quaternion to be converted.
433 /// @return A btQuaternion containing the contents of the converted Quaternion.
434 btQuaternion& MEZZ_LIB operator<< ( btQuaternion& Other, const Mezzanine::Quaternion& Other2);
435 
436 /// @brief Conversion operator to btQuaternion.
437 /// @param Other The Quaternion to store the fresh contents.
438 /// @param Other2 The Quaternion to be converted.
439 /// @return A btQuaternion containing the contents of the converted Quaternion.
440 btQuaternion& MEZZ_LIB operator<< ( btQuaternion& Other, const Ogre::Quaternion& Other2);
441 
442 /// @brief Conversion operator to Mezzanine::Quaternion.
443 /// @param Other The Quaternion to store the fresh contents.
444 /// @param Other2 The Quaternion to be converted.
445 /// @return A Mezzanine::Quaternion containing the contents of the converted Quaternion.
446 Mezzanine::Quaternion& MEZZ_LIB operator<< ( Mezzanine::Quaternion& Other, const Ogre::Quaternion& Other2);
447 
448 /// @brief Conversion operator to btQuaternion.
449 /// @param Other The Quaternion to store the fresh contents.
450 /// @param Other2 The Quaternion to be converted.
451 /// @return A btQuaternion containing the contents of the converted Quaternion.
452 Mezzanine::Quaternion& MEZZ_LIB operator<< ( Mezzanine::Quaternion& Other, const btQuaternion& Other2);
453 
454 /// @brief Conversion operator to Ogre::Quaternion.
455 /// @param Other The Quaternion to store the fresh contents.
456 /// @param Other2 The Quaternion to be converted.
457 /// @return A Ogre::Quaternion containing the contents of the converted Quaternion.
458 Ogre::Quaternion& MEZZ_LIB operator<< ( Ogre::Quaternion& Other, const Mezzanine::Quaternion& Other2);
459 
460 /// @brief Conversion operator to Ogre::Quaternion.
461 /// @param Other The Quaternion to store the fresh contents.
462 /// @param Other2 The Quaternion to be converted.
463 /// @return A Ogre::Quaternion containing the contents of the converted Quaternion.
464 Ogre::Quaternion& MEZZ_LIB operator<< ( Ogre::Quaternion& Other, const btQuaternion& Other2);
465 
466 /// @brief Used to Serialize an Mezzanine::Quaternion to a human readable stream
467 /// @details This puts proper XML output to the output stream,
468 /// including versioning information which will be used to maintain backwards compatibility. The current XML format
469 /// will create one node with no child nodes. The name of the xml node will be "Quaternion". It will have 5 attributes.
470 /// "Version", will be set to a value of 1, indicating if came from version 1 compatible Quaternion. It will also have an "X", "Y",
471 /// "Z" and "W" attributes will values set appropriately. For example '<Quaternion Version="1" X="1" Y="2" Z="3" W="0" />'.
472 /// @param x The Mezzanine::Quaternion to be converted to characters.
473 /// @param stream The place to send the characters, that define the Mezzanine::Quaternion.
474 /// @return Get an std::ostream that was written to, this allow chaining of the << operators.
475 std::ostream& MEZZ_LIB operator << (std::ostream& stream, const Mezzanine::Quaternion& x);
476 
477 /// @brief Used to de-serialize an Mezzanine::Quaternion from a stream
478 /// @details This reads in the xml and sets the target vector according to values
479 /// from the stream.
480 /// @param Vec The Mezzanine::Quaternion that will accept the values from the xml
481 /// @param stream The place to get the characters from, that define the Mezzanine::Quaternion.
482 /// @return Get an std::ostream that was read from, this allow chaining of the >> operators.
483 /// @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.
484 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::Quaternion& Vec);
485 
486 /// @brief Converts an XML node into a Mezzanine::Quaternion
487 /// @details This will convert an XML::Node will a valid serialized Mezzanine::Quaternion into a Mezzanine::Quaternion
488 /// @param OneNode An XML Node containing the the text of a Quaternion
489 /// @param Vec the Mezzanine::Quaternion to store the deserialized Quaternion
490 /// @return This returns a reference to the XML::Node for operator chaining or whatever.
491 /// @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.
493 #endif // \ SWIG
494 
495 namespace std
496 {
497  #ifndef SWIG
498  /// @brief Get Numeric details on Quaternion
499  template<>
500  class numeric_limits<Mezzanine::Quaternion>
501  {
502  public:
503  /// @brief Does this class (numeric_limits<Mezzanine::Quaternion>) exist
504  static const bool is_specialized = true;
505  /// @brief Does this support negative values?
506  static const bool is_signed = true;
507  /// @brief Can this only store integer types.
508  static const bool is_integer = false;
509  /// @brief The Quaternion uses Real, which is typically a machine dependedant which can be inexact
510  static const bool is_exact = std::numeric_limits<Mezzanine::Real>::is_exact;
511  /// @brief Can This represent an infinitely large value in X, Y or Z?
512  static const bool has_infinity = std::numeric_limits<Mezzanine::Real>::has_infinity;
513  /// @brief ??? Required by std::numeric to be compliant
514  /// @todo Learn why this exists and document it.
515  static const bool has_quiet_NaN = std::numeric_limits<Mezzanine::Real>::has_quiet_NaN;
516  /// @brief ??? Required by std::numeric to be compliant
517  /// @todo Learn why this exists and document it.
518  static const bool has_signaling_NaN = std::numeric_limits<Mezzanine::Real>::has_signaling_NaN;
519  /// @brief Does this support exceptionally small numbers near 0?
520  static const std::float_denorm_style has_denorm = std::numeric_limits<Mezzanine::Real>::has_denorm;
521  /// @brief When extra precision near 0 is lost, can this type distinguish that from other imprecision.
522  static const bool has_denorm_loss = std::numeric_limits<Mezzanine::Real>::has_denorm_loss;
523  /// @brief How items that fit between the precise amount a Real can represent will be adapted.
524  static const std::float_round_style round_style = std::numeric_limits<Mezzanine::Real>::round_style;
525  /// @brief Do X, Y and Z adhere to iec 559?
526  static const bool is_iec559 = std::numeric_limits<Mezzanine::Real>::is_iec559;
527  /// @brief Is overflow of this type handle by modulo overflow?
528  static const bool is_modulo = std::numeric_limits<Mezzanine::Real>::is_modulo;
529  /// @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?
530  static const int digits = std::numeric_limits<Mezzanine::Real>::digits;
531  /// @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?
532  static const int digits10 = std::numeric_limits<Mezzanine::Real>::digits10;
533  /// @brief The base of the number system that this is implemented in
534  static const int radix = std::numeric_limits<Mezzanine::Real>::radix;
535  /// @brief The smallest power of the radix that is valid floating point value
536  static const int min_exponent = std::numeric_limits<Mezzanine::Real>::min_exponent;
537  /// @brief The smallest power of 10 that is valid floating point value
538  static const int min_exponent10 = std::numeric_limits<Mezzanine::Real>::min_exponent10;
539  /// @brief The largest power of the radix that is valid floating point value
540  static const int max_exponent = std::numeric_limits<Mezzanine::Real>::max_exponent;
541  /// @brief The largest power of 10 that is valid floating point value
542  static const int max_exponent10 = std::numeric_limits<Mezzanine::Real>::max_exponent10;
543  /// @brief Can this generate a trap?
544  static const bool traps = std::numeric_limits<Mezzanine::Real>::traps;
545  /// @brief Are tiny values respected during rounding?
546  static const bool tinyness_before = std::numeric_limits<Mezzanine::Real>::tinyness_before;
547 
548  /// @brief Get the lowest positive finite value this can represent
549  /// @return A Quaternion with 4 very small numbers
551  {
552  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::min(),
553  std::numeric_limits<Mezzanine::Real>::min(),
554  std::numeric_limits<Mezzanine::Real>::min(),
555  std::numeric_limits<Mezzanine::Real>::min()
556  );
557  }
558 
559  /// @brief Get the highest positive finite value this can represent
560  /// @return A Quaternion with 4 very large numbers
562  {
563  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::max(),
564  std::numeric_limits<Mezzanine::Real>::max(),
565  std::numeric_limits<Mezzanine::Real>::max(),
566  std::numeric_limits<Mezzanine::Real>::max()
567  );
568  }
569 
570  /// @brief The smallest value representable from 1.0,1.0,1.0 to the next value
571  /// @return A Quaternion with very small numbers
573  {
574  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::epsilon(),
575  std::numeric_limits<Mezzanine::Real>::epsilon(),
576  std::numeric_limits<Mezzanine::Real>::epsilon(),
577  std::numeric_limits<Mezzanine::Real>::epsilon()
578  );
579  }
580 
581  /// @brief Get the largest possible rounding error
582  /// @return A Quaternion containing 4 values indicating how much they could be rounded.
584  {
585  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::round_error(),
586  std::numeric_limits<Mezzanine::Real>::round_error(),
587  std::numeric_limits<Mezzanine::Real>::round_error(),
588  std::numeric_limits<Mezzanine::Real>::round_error()
589  );
590  }
591 
592  /// @brief Get the special value "Positive infinity"
593  /// @return A Quaternion containing 4 values.
595  {
596  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::infinity(),
597  std::numeric_limits<Mezzanine::Real>::infinity(),
598  std::numeric_limits<Mezzanine::Real>::infinity(),
599  std::numeric_limits<Mezzanine::Real>::infinity()
600  );
601  }
602 
603  /// @brief Get the special value "Quiet Not actual Number"
604  /// @return A Quaternion containing 4 values.
606  {
607  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::quiet_NaN(),
608  std::numeric_limits<Mezzanine::Real>::quiet_NaN(),
609  std::numeric_limits<Mezzanine::Real>::quiet_NaN(),
610  std::numeric_limits<Mezzanine::Real>::quiet_NaN()
611  );
612  }
613 
614  /// @brief Get the special value "Signaling Not actual Number"
615  /// @return A Quaternion containing 4 special values.
617  {
618  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::signaling_NaN(),
619  std::numeric_limits<Mezzanine::Real>::signaling_NaN(),
620  std::numeric_limits<Mezzanine::Real>::signaling_NaN(),
621  std::numeric_limits<Mezzanine::Real>::signaling_NaN()
622  );
623  }
624 
625  /// @brief Get the closest value to 0 that is not 0 this can represent, including extra precision for being close to 0 if supported.
626  /// @return A vector containing 3 very small values.
628  {
629  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::denorm_min(),
630  std::numeric_limits<Mezzanine::Real>::denorm_min(),
631  std::numeric_limits<Mezzanine::Real>::denorm_min(),
632  std::numeric_limits<Mezzanine::Real>::denorm_min()
633  );
634  }
635  }; //Numeric Limits
636  #endif // \SWIG
637 
638 } // std
639 
640 
641 #endif
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
This is a 3x3 Matrix class used for representing rotations and scaling in an object.
Definition: matrix3x3.h:62
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...
All the definitions for datatypes as well as some basic conversion functions are defined here...
Real Y
The Y component of the Axis.
Definition: quaternion.h:77
STL namespace.
static Mezzanine::Quaternion denorm_min()
Get the closest value to 0 that is not 0 this can represent, including extra precision for being clos...
Definition: quaternion.h:627
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.
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
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
static Mezzanine::Quaternion max()
Get the highest positive finite value this can represent.
Definition: quaternion.h:561
static Mezzanine::Quaternion epsilon()
The smallest value representable from 1.0,1.0,1.0 to the next value.
Definition: quaternion.h:572
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
Real W
Rotation on the Axis X, Y and Z defined.
Definition: quaternion.h:81
static Mezzanine::Quaternion infinity()
Get the special value "Positive infinity".
Definition: quaternion.h:594
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
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
std::istream & operator>>(std::istream &stream, Mezzanine::LinearInterpolator< T > &Lint)
Used to de-serialize an Mezzanine::LinearInterpolator from a stream.
Definition: interpolator.h:448
Real X
The X component of the Axis.
Definition: quaternion.h:75
This is used to store information about rotation in 3d space.
Definition: quaternion.h:68
static Mezzanine::Quaternion signaling_NaN()
Get the special value "Signaling Not actual Number".
Definition: quaternion.h:616
Real Z
The Z component of the Axis.
Definition: quaternion.h:79
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
static Mezzanine::Quaternion quiet_NaN()
Get the special value "Quiet Not actual Number".
Definition: quaternion.h:605
static Mezzanine::Quaternion min()
Get the lowest positive finite value this can represent.
Definition: quaternion.h:550
static Mezzanine::Quaternion round_error()
Get the largest possible rounding error.
Definition: quaternion.h:583