MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
transform.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2014 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 SerializableName();
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  bool 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  bool 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  /// @brief Get Numeric details on Transform
183  template<>
184  class numeric_limits<Mezzanine::Transform>
185  {
186  public:
187  /// @brief Does this class (numeric_limits<Mezzanine::Transform>) exist
188  static const bool is_specialized = true;
189  /// @brief Does this support negative values?
190  static const bool is_signed = true;
191  /// @brief Can this only store integer types.
192  static const bool is_integer = false;
193  /// @brief The Transform uses Real, which is typically a machine dependedant which can be inexact
194  static const bool is_exact = std::numeric_limits<Mezzanine::Real>::is_exact;
195  /// @brief Can This represent an infinitely large value in subvalues?
196  static const bool has_infinity = std::numeric_limits<Mezzanine::Real>::has_infinity;
197  /// @brief ??? Required by std::numeric to be compliant
198  /// @todo Learn why this exists and document it.
199  static const bool has_quiet_NaN = std::numeric_limits<Mezzanine::Real>::has_quiet_NaN;
200  /// @brief ??? Required by std::numeric to be compliant
201  /// @todo Learn why this exists and document it.
202  static const bool has_signaling_NaN = std::numeric_limits<Mezzanine::Real>::has_signaling_NaN;
203  /// @brief Does this support exceptionally small numbers near 0?
204  static const std::float_denorm_style has_denorm = std::numeric_limits<Mezzanine::Real>::has_denorm;
205  /// @brief When extra precision near 0 is lost, can this type distinguish that from other imprecision.
206  static const bool has_denorm_loss = std::numeric_limits<Mezzanine::Real>::has_denorm_loss;
207  /// @brief How items that fit between the precise amount a Real can represent will be adapted.
208  static const std::float_round_style round_style = std::numeric_limits<Mezzanine::Real>::round_style;
209  /// @brief Do subvalues adhere to iec 559?
210  static const bool is_iec559 = std::numeric_limits<Mezzanine::Real>::is_iec559;
211  /// @brief Is overflow of this type handle by modulo overflow?
212  static const bool is_modulo = std::numeric_limits<Mezzanine::Real>::is_modulo;
213  /// @brief How many integer digits(in machine base) of precision can this handle in each subvalue without floating point component or error?
214  static const int digits = std::numeric_limits<Mezzanine::Real>::digits;
215  /// @brief How many integer digits in base 10 of precision can this handle in each subvalue without floating point component or error?
216  static const int digits10 = std::numeric_limits<Mezzanine::Real>::digits10;
217  /// @brief The base of the number system that this is implemented in
218  static const int radix = std::numeric_limits<Mezzanine::Real>::radix;
219  /// @brief The smallest power of the radix that is valid floating point value
220  static const int min_exponent = std::numeric_limits<Mezzanine::Real>::min_exponent;
221  /// @brief The smallest power of 10 that is valid floating point value
222  static const int min_exponent10 = std::numeric_limits<Mezzanine::Real>::min_exponent10;
223  /// @brief The largest power of the radix that is valid floating point value
224  static const int max_exponent = std::numeric_limits<Mezzanine::Real>::max_exponent;
225  /// @brief The largest power of 10 that is valid floating point value
226  static const int max_exponent10 = std::numeric_limits<Mezzanine::Real>::max_exponent10;
227  /// @brief Can this generate a trap?
228  static const bool traps = std::numeric_limits<Mezzanine::Real>::traps;
229  /// @brief Are tiny values respected during rounding?
230  static const bool tinyness_before = std::numeric_limits<Mezzanine::Real>::tinyness_before;
231 
232  /// @brief Get the lowest positive finite value this can represent
233  /// @return A Transform with 3 very small numbers in the location and 4 very small values in the rotation
235  {
238  );
239  }
240 
241  /// @brief Get the highest positive finite value this can represent
242  /// @return A Transform with 3 very large numbers in the location and 4 very large values in the rotation
244  {
247  );
248  }
249 
250  /// @brief The smallest value representable from 1,1,1/1,1,1,1 to the next value
251  /// @return A Transform with values larger than 1, but only just so.
253  {
256  );
257  }
258 
259  /// @brief Get the largest possible rounding error
260  /// @return A Transform containing with each value indicating how much they could be rounded.
262  {
265  );
266  }
267 
268  /// @brief Get the special value "Positive infinity"
269  /// @return A transform containing 7 infinities.
271  {
274  );
275  }
276 
277  /// @brief Get the special value "Quiet Not actual Number"
278  /// @return A Tranform containing 7 values
280  {
283  );
284  }
285 
286  /// @brief Get the special value "Signaling Not actual Number"
287  /// @return A Tranform containing 7 values
289  {
292  );
293  }
294 
295  /// @brief Get the closest value to 0 that is not 0 this can represent, including extra precision for being close to 0 if supported.
296  /// @return A Tranform containing 7 small values
298  {
301  );
302  }
303 
304  }; //Numeric Limits
305 
306 } // std
307 
308 #endif