Spinning Topp Logo BlackTopp Studios
inc
transform.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 _transform_h
41 #define _transform_h
42 
43 #include "vector3.h"
44 #include "quaternion.h"
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 /// @file
48 /// @brief The defintion of the transform is stored in this file.
49 ///////////////////////////////////////
50 
51 class btTransform;
52 
53 namespace Mezzanine
54 {
55  ///////////////////////////////////////////////////////////////////////////////
56  /// @brief Stores information about relative location and rotation in 3d space
57  /// @details This is simple a pair of a vector 3 to store location and a
58  /// quaternion to store rotation. This is communly used to interact with the
59  /// physics system. This also has a few helper functions to make it more
60  /// useful than an std::pair<Vector3,Quaternion>.
61  ///////////////////////////////////////
63  {
64  public:
65  ///////////////////////////////////////////////////////////////////////////////
66  // Data Members
67  /// @brief The location or relative location is stored in a Vector3
69 
70  /// @brief The Rotation or relative rotation is stored in a Quaternion.
72 
73  ///////////////////////////////////////////////////////////////////////////////
74  // Creation
75  /// @brief The multipurpose constructor
76  /// @param Vec The starting Vector#/Location you would like this transform to have. If not passed, a default Vector3 is used.
77  /// @param Quat The starting Quaternion/Rotation you would like this transform to have. If not passed, a default Quaternion is used.
78  Transform(const Vector3& Vec = Vector3(), const Quaternion& Quat = Quaternion());
79 
80  /// @brief The Conversion Constructor
81  /// @param Btt The btTransform from bullet physics.
82  Transform(const btTransform& Btt);
83 
84  /// @brief The copy constructor
85  /// @param TheOther Another Transform to be copied
86  Transform(const Transform& TheOther);
87 
88  ///////////////////////////////////////////////////////////////////////////////
89  // Utilities
90  /// @brief Sets default construction values for all members.
91  void SetIdentity();
92 
93  ///////////////////////////////////////////////////////////////////////////////
94  // Conversion
95  /// @brief Gets a Bullet Transform
96  /// @details Creates a Bullet Transform with values equal to this class instance and returns it.
97  btTransform GetBulletTransform() const;
98  /// @brief Copies an existing Bullet transform
99  /// @details This function will copy the values stored in an existing Bullet transform
100  /// and set the values of this class instance to be the same.
101  /// @param temp The btTransfrom to have its values extracted.
102  void ExtractBulletTransform(const btTransform& temp);
103 
104  /// @brief Set the values of this Transform to match an existing Transform
105  /// @param rhs The item storing the values to copy.
106  /// @return A reference to the freshly overwritten Transform.
107  Transform& operator= (const Transform& rhs);
108  /// @brief Set the values of this Transform to match an existing btTransform.
109  /// @param rhs The item storing the values to copy.
110  /// @return A reference to the freshly overwritten Transform.
111  Transform& operator= (const btTransform& rhs);
112 
113  ///////////////////////////////////////////////////////////////////////////////
114  // Serialization
115 
116  // Serializable
117  /// @brief Convert this class to an XML::Node ready for serialization
118  /// @param CurrentRoot The point in the XML hierarchy that all this vectorw should be appended to.
119  void ProtoSerialize(XML::Node& CurrentRoot) const;
120 
121  // DeSerializable
122  /// @brief Take the data stored in an XML and overwrite this instance of this object with it
123  /// @param OneNode and XML::Node containing the data.
124  /// @warning A precondition of using this is that all of the actors intended for use must already be Deserialized.
125  void ProtoDeSerialize(const XML::Node& OneNode);
126 
127  /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
128  /// @return A string containing "Transform"
129  static String GetSerializableName();
130 
131 
132  ///////////////////////////////////////////////////////////////////////////////
133  // Math and test operations
134  /// @brief Create a Transform with the difference of this and another
135  /// @param rhs The Transform on the right hand side of the sign.
136  /// @return A Transform with
137  Transform operator- (const Transform& rhs) const;
138  /// @brief Create a Transform with the sum of this and another
139  /// @param rhs The Transform on the right hand side of the sign.
140  /// @return A Transform with
141  Transform operator+ (const Transform& rhs) const;
142  /// @brief Multiply all the values of this by a single scalar.
143  /// @param rhs The Transform on the right hand side of the sign.
144  /// @return A Transform with
145  Transform operator* (Real rhs) const;
146  /// @brief Divide all the values of this by a single scalar.
147  /// @param rhs The Transform on the right hand side of the sign.
148  /// @return A Transform with
149  Transform operator/ (Real rhs) const;
150 
151  /// @brief Is every value in this Transform less than or equal to its corresponding value in another.
152  /// @param rhs The Transform on the right hand side of the sign.
153  /// @note Used primarily for testing. This is not implemented for use with other kinds of Transform implementations as it is widely considered useless.
154  Boole operator<= (const Transform& rhs) const;
155  /// @brief Is every value in this Transform greater than or equal to its corresponding value in another.
156  /// @param rhs The Transform on the right hand side of the sign.
157  /// @note Used primarily for testing. This is not implemented for use with other kinds of Transform implementations as it is widely considered useless.
158  Boole operator>= (const Transform& rhs) const;
159 
160 
161  };
162 }
163 
164 #ifndef SWIG
165 std::ostream& MEZZ_LIB operator << (std::ostream& stream, const Mezzanine::Transform& x);
166 
167 /// @brief Overwrite the data in a btTransform with the data in a Mezzanine::Transform using an intelligent assignment operator (in this case we really couldn't code the real assignment operator).
168 /// @param lhs The item on the Left Hand of the Sign, the item to be assigned to.
169 /// @param rhs The item on the Right Hand of the Sign, the item that has the values to be copied.
170 /// @return This returns the original btTransform reference(with the new values) so furhter work can continue to be performed if required
171 btTransform& MEZZ_LIB operator<< (btTransform& lhs, const Mezzanine::Transform& rhs);
172 
173 /// @brief Overwrite the data in a Mezzanine::Transform with the data in a btTransform using an intelligent assignment operator (in this case we really couldn't code the real assignment operator).
174 /// @param lhs The item on the Left Hand of the Sign, the item to be assigned to.
175 /// @param rhs The item on the Right Hand of the Sign, the item that has the values to be copied.
176 /// @return This returns the original Mezzanine::Transform reference(with the new values) so furhter work can continue to be performed if required.
177 Mezzanine::Transform& MEZZ_LIB operator<< (Mezzanine::Transform& lhs, const btTransform& rhs);
178 #endif
179 
180 namespace std
181 {
182  #ifndef SWIG
183  /// @brief Get Numeric details on Transform
184  template<>
185  class numeric_limits<Mezzanine::Transform>
186  {
187  public:
188  /// @brief Does this class (numeric_limits<Mezzanine::Transform>) exist
189  static const bool is_specialized = true;
190  /// @brief Does this support negative values?
191  static const bool is_signed = true;
192  /// @brief Can this only store integer types.
193  static const bool is_integer = false;
194  /// @brief The Transform uses Real, which is typically a machine dependedant which can be inexact
195  static const bool is_exact = std::numeric_limits<Mezzanine::Real>::is_exact;
196  /// @brief Can This represent an infinitely large value in subvalues?
197  static const bool has_infinity = std::numeric_limits<Mezzanine::Real>::has_infinity;
198  /// @brief ??? Required by std::numeric to be compliant
199  /// @todo Learn why this exists and document it.
200  static const bool has_quiet_NaN = std::numeric_limits<Mezzanine::Real>::has_quiet_NaN;
201  /// @brief ??? Required by std::numeric to be compliant
202  /// @todo Learn why this exists and document it.
203  static const bool has_signaling_NaN = std::numeric_limits<Mezzanine::Real>::has_signaling_NaN;
204  /// @brief Does this support exceptionally small numbers near 0?
205  static const std::float_denorm_style has_denorm = std::numeric_limits<Mezzanine::Real>::has_denorm;
206  /// @brief When extra precision near 0 is lost, can this type distinguish that from other imprecision.
207  static const bool has_denorm_loss = std::numeric_limits<Mezzanine::Real>::has_denorm_loss;
208  /// @brief How items that fit between the precise amount a Real can represent will be adapted.
209  static const std::float_round_style round_style = std::numeric_limits<Mezzanine::Real>::round_style;
210  /// @brief Do subvalues adhere to iec 559?
211  static const bool is_iec559 = std::numeric_limits<Mezzanine::Real>::is_iec559;
212  /// @brief Is overflow of this type handle by modulo overflow?
213  static const bool is_modulo = std::numeric_limits<Mezzanine::Real>::is_modulo;
214  /// @brief How many integer digits(in machine base) of precision can this handle in each subvalue without floating point component or error?
215  static const int digits = std::numeric_limits<Mezzanine::Real>::digits;
216  /// @brief How many integer digits in base 10 of precision can this handle in each subvalue without floating point component or error?
217  static const int digits10 = std::numeric_limits<Mezzanine::Real>::digits10;
218  /// @brief The base of the number system that this is implemented in
219  static const int radix = std::numeric_limits<Mezzanine::Real>::radix;
220  /// @brief The smallest power of the radix that is valid floating point value
221  static const int min_exponent = std::numeric_limits<Mezzanine::Real>::min_exponent;
222  /// @brief The smallest power of 10 that is valid floating point value
223  static const int min_exponent10 = std::numeric_limits<Mezzanine::Real>::min_exponent10;
224  /// @brief The largest power of the radix that is valid floating point value
225  static const int max_exponent = std::numeric_limits<Mezzanine::Real>::max_exponent;
226  /// @brief The largest power of 10 that is valid floating point value
227  static const int max_exponent10 = std::numeric_limits<Mezzanine::Real>::max_exponent10;
228  /// @brief Can this generate a trap?
229  static const bool traps = std::numeric_limits<Mezzanine::Real>::traps;
230  /// @brief Are tiny values respected during rounding?
231  static const bool tinyness_before = std::numeric_limits<Mezzanine::Real>::tinyness_before;
232 
233  /// @brief Get the lowest positive finite value this can represent
234  /// @return A Transform with 3 very small numbers in the location and 4 very small values in the rotation
236  {
239  );
240  }
241 
242  /// @brief Get the highest positive finite value this can represent
243  /// @return A Transform with 3 very large numbers in the location and 4 very large values in the rotation
245  {
248  );
249  }
250 
251  /// @brief The smallest value representable from 1,1,1/1,1,1,1 to the next value
252  /// @return A Transform with values larger than 1, but only just so.
254  {
257  );
258  }
259 
260  /// @brief Get the largest possible rounding error
261  /// @return A Transform containing with each value indicating how much they could be rounded.
263  {
266  );
267  }
268 
269  /// @brief Get the special value "Positive infinity"
270  /// @return A transform containing 7 infinities.
272  {
275  );
276  }
277 
278  /// @brief Get the special value "Quiet Not actual Number"
279  /// @return A Tranform containing 7 values
281  {
284  );
285  }
286 
287  /// @brief Get the special value "Signaling Not actual Number"
288  /// @return A Tranform containing 7 values
290  {
293  );
294  }
295 
296  /// @brief Get the closest value to 0 that is not 0 this can represent, including extra precision for being close to 0 if supported.
297  /// @return A Tranform containing 7 small values
299  {
302  );
303  }
304  }; //Numeric Limits
305  #endif // \SWIG
306 
307 
308 } // std
309 
310 #endif
static Mezzanine::Transform quiet_NaN()
Get the special value "Quiet Not actual Number".
Definition: transform.h:280
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
static Mezzanine::Transform min()
Get the lowest positive finite value this can represent.
Definition: transform.h:235
STL namespace.
static Mezzanine::Transform round_error()
Get the largest possible rounding error.
Definition: transform.h:262
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.
static Mezzanine::Vector3 quiet_NaN()
Get the special value "Quiet Not actual Number".
Definition: vector3.h:640
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
static Mezzanine::Transform epsilon()
The smallest value representable from 1,1,1/1,1,1,1 to the next value.
Definition: transform.h:253
static Mezzanine::Transform signaling_NaN()
Get the special value "Signaling Not actual Number".
Definition: transform.h:289
static Mezzanine::Transform infinity()
Get the special value "Positive infinity".
Definition: transform.h:271
btTransform & operator<<(btTransform &lhs, const Mezzanine::Transform &rhs)
Overwrite the data in a btTransform with the data in a Mezzanine::Transform using an intelligent assi...
Definition: transform.cpp:162
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
Quaternion Rotation
The Rotation or relative rotation is stored in a Quaternion.
Definition: transform.h:71
static Mezzanine::Transform max()
Get the highest positive finite value this can represent.
Definition: transform.h:244
static Mezzanine::Quaternion infinity()
Get the special value "Positive infinity".
Definition: quaternion.h:594
static Mezzanine::Vector3 min()
Get the lowest positive finite value this can represent.
Definition: vector3.h:590
static Mezzanine::Transform denorm_min()
Get the closest value to 0 that is not 0 this can represent, including extra precision for being clos...
Definition: transform.h:298
Stores information about relative location and rotation in 3d space.
Definition: transform.h:62
static Mezzanine::Vector3 signaling_NaN()
Get the special value "Signaling Not actual Number".
Definition: vector3.h:650
Vector3 Location
The location or relative location is stored in a Vector3.
Definition: transform.h:68
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
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
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
static Mezzanine::Quaternion signaling_NaN()
Get the special value "Signaling Not actual Number".
Definition: quaternion.h:616
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
static Mezzanine::Vector3 round_error()
Get the largest possible rounding error.
Definition: vector3.h:620