Transform.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/
3 
4 This software is provided 'as-is', without any express or implied warranty.
5 In no event will the authors be held liable for any damages arising from the use of this software.
6 Permission is granted to anyone to use this software for any purpose,
7 including commercial applications, and to alter it and redistribute it freely,
8 subject to the following restrictions:
9 
10 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
11 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
12 3. This notice may not be removed or altered from any source distribution.
13 */
14 
15 
16 
17 #ifndef tf2_Transform_H
18 #define tf2_Transform_H
19 
20 
21 #include "Matrix3x3.h"
22 
23 
24 namespace tf2
25 {
26 
27 #define TransformData TransformDoubleData
28 
29 
32 class Transform {
33 
37  Vector3 m_origin;
38 
39 public:
40 
42  Transform() {}
47  const Vector3& c = Vector3(tf2Scalar(0), tf2Scalar(0), tf2Scalar(0)))
48  : m_basis(q),
49  m_origin(c)
50  {}
51 
56  const Vector3& c = Vector3(tf2Scalar(0), tf2Scalar(0), tf2Scalar(0)))
57  : m_basis(b),
58  m_origin(c)
59  {}
62  : m_basis(other.m_basis),
63  m_origin(other.m_origin)
64  {
65  }
68  {
69  m_basis = other.m_basis;
70  m_origin = other.m_origin;
71  return *this;
72  }
73 
78  TF2SIMD_FORCE_INLINE void mult(const Transform& t1, const Transform& t2) {
79  m_basis = t1.m_basis * t2.m_basis;
80  m_origin = t1(t2.m_origin);
81  }
82 
83 /* void multInverseLeft(const Transform& t1, const Transform& t2) {
84  Vector3 v = t2.m_origin - t1.m_origin;
85  m_basis = tf2MultTransposeLeft(t1.m_basis, t2.m_basis);
86  m_origin = v * t1.m_basis;
87  }
88  */
89 
91  TF2SIMD_FORCE_INLINE Vector3 operator()(const Vector3& x) const
92  {
93  return Vector3(m_basis[0].dot(x) + m_origin.x(),
94  m_basis[1].dot(x) + m_origin.y(),
95  m_basis[2].dot(x) + m_origin.z());
96  }
97 
99  TF2SIMD_FORCE_INLINE Vector3 operator*(const Vector3& x) const
100  {
101  return (*this)(x);
102  }
103 
106  {
107  return getRotation() * q;
108  }
109 
113  TF2SIMD_FORCE_INLINE const Matrix3x3& getBasis() const { return m_basis; }
114 
116  TF2SIMD_FORCE_INLINE Vector3& getOrigin() { return m_origin; }
118  TF2SIMD_FORCE_INLINE const Vector3& getOrigin() const { return m_origin; }
119 
122  Quaternion q;
123  m_basis.getRotation(q);
124  return q;
125  }
126 
127 
131  {
132  m_basis.setFromOpenGLSubMatrix(m);
133  m_origin.setValue(m[12],m[13],m[14]);
134  }
135 
138  void getOpenGLMatrix(tf2Scalar *m) const
139  {
140  m_basis.getOpenGLSubMatrix(m);
141  m[12] = m_origin.x();
142  m[13] = m_origin.y();
143  m[14] = m_origin.z();
144  m[15] = tf2Scalar(1.0);
145  }
146 
149  TF2SIMD_FORCE_INLINE void setOrigin(const Vector3& origin)
150  {
151  m_origin = origin;
152  }
153 
154  TF2SIMD_FORCE_INLINE Vector3 invXform(const Vector3& inVec) const;
155 
156 
159  {
160  m_basis = basis;
161  }
162 
165  {
166  m_basis.setRotation(q);
167  }
168 
169 
171  void setIdentity()
172  {
173  m_basis.setIdentity();
174  m_origin.setValue(tf2Scalar(0.0), tf2Scalar(0.0), tf2Scalar(0.0));
175  }
176 
180  {
181  m_origin += m_basis * t.m_origin;
182  m_basis *= t.m_basis;
183  return *this;
184  }
185 
188  {
189  Matrix3x3 inv = m_basis.transpose();
190  return Transform(inv, inv * -m_origin);
191  }
192 
196  Transform inverseTimes(const Transform& t) const;
197 
199  Transform operator*(const Transform& t) const;
200 
202  static const Transform& getIdentity()
203  {
204  static const Transform identityTransform(Matrix3x3::getIdentity());
205  return identityTransform;
206  }
207 
208  void serialize(struct TransformData& dataOut) const;
209 
210  void serializeFloat(struct TransformFloatData& dataOut) const;
211 
212  void deSerialize(const struct TransformData& dataIn);
213 
214  void deSerializeDouble(const struct TransformDoubleData& dataIn);
215 
216  void deSerializeFloat(const struct TransformFloatData& dataIn);
217 
218 };
219 
220 
221 TF2SIMD_FORCE_INLINE Vector3
222 Transform::invXform(const Vector3& inVec) const
223 {
224  Vector3 v = inVec - m_origin;
225  return (m_basis.transpose() * v);
226 }
227 
230 {
231  Vector3 v = t.getOrigin() - m_origin;
232  return Transform(m_basis.transposeTimes(t.m_basis),
233  v * m_basis);
234 }
235 
238 {
239  return Transform(m_basis * t.m_basis,
240  (*this)(t.m_origin));
241 }
242 
245 {
246  return ( t1.getBasis() == t2.getBasis() &&
247  t1.getOrigin() == t2.getOrigin() );
248 }
249 
250 
253 {
256 };
257 
259 {
262 };
263 
264 
265 
267 {
268  m_basis.serialize(dataOut.m_basis);
269  m_origin.serialize(dataOut.m_origin);
270 }
271 
273 {
274  m_basis.serializeFloat(dataOut.m_basis);
275  m_origin.serializeFloat(dataOut.m_origin);
276 }
277 
278 
280 {
281  m_basis.deSerialize(dataIn.m_basis);
282  m_origin.deSerialize(dataIn.m_origin);
283 }
284 
286 {
287  m_basis.deSerializeFloat(dataIn.m_basis);
288  m_origin.deSerializeFloat(dataIn.m_origin);
289 }
290 
292 {
293  m_basis.deSerializeDouble(dataIn.m_basis);
294  m_origin.deSerializeDouble(dataIn.m_origin);
295 }
296 
297 }
298 
299 #endif
300 
301 
302 
303 
304 
305 
#define TF2SIMD_FORCE_INLINE
Definition: Scalar.h:129
Transform inverseTimes(const Transform &t) const
Return the inverse of this transform times the other transform.
Definition: Transform.h:229
static const Matrix3x3 & getIdentity()
Definition: Matrix3x3.h:217
TF2SIMD_FORCE_INLINE bool operator==(const Matrix3x3 &m1, const Matrix3x3 &m2)
Equality operator between two matrices It will test all elements are equal.
Definition: Matrix3x3.h:641
TF2SIMD_FORCE_INLINE Vector3 operator()(const Vector3 &x) const
Return the transform of the vector.
Definition: Transform.h:91
Matrix3x3 transposeTimes(const Matrix3x3 &m) const
Definition: Matrix3x3.h:578
TF2SIMD_FORCE_INLINE Matrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: Transform.h:111
#define TransformData
Definition: Transform.h:27
void deSerializeFloat(const struct TransformFloatData &dataIn)
Definition: Transform.h:285
void serialize(struct Matrix3x3Data &dataOut) const
Definition: Matrix3x3.h:663
Matrix3x3 transpose() const
Return the transpose of the matrix.
Definition: Matrix3x3.h:550
void setFromOpenGLSubMatrix(const tf2Scalar *m)
Set from a carray of tf2Scalars.
Definition: Matrix3x3.h:120
TF2SIMD_FORCE_INLINE void setRotation(const Quaternion &q)
Set the rotational element by Quaternion.
Definition: Transform.h:164
TF2SIMD_FORCE_INLINE Transform(const Transform &other)
Copy constructor.
Definition: Transform.h:61
void deSerialize(const struct Matrix3x3Data &dataIn)
Definition: Matrix3x3.h:676
TF2SIMD_FORCE_INLINE Transform(const Matrix3x3 &b, const Vector3 &c=Vector3(tf2Scalar(0), tf2Scalar(0), tf2Scalar(0)))
Constructor from Matrix3x3 (optional Vector3)
Definition: Transform.h:55
void deSerializeDouble(const struct Matrix3x3DoubleData &dataIn)
Definition: Matrix3x3.h:688
double tf2Scalar
The tf2Scalar type abstracts floating point numbers, to easily switch between double and single float...
Definition: Scalar.h:159
void serialize(struct TransformData &dataOut) const
Definition: Transform.h:266
TF2SIMD_FORCE_INLINE Vector3 operator*(const Vector3 &x) const
Return the transform of the vector.
Definition: Transform.h:99
TF2SIMD_FORCE_INLINE tf2Scalar dot(const Quaternion &q1, const Quaternion &q2)
Calculate the dot product between two quaternions.
Definition: Quaternion.h:392
void serializeFloat(struct TransformFloatData &dataOut) const
Definition: Transform.h:272
Matrix3x3 m_basis
Storage for the rotation.
Definition: Transform.h:35
Vector3 m_origin
Storage for the translation.
Definition: Transform.h:37
TF2SIMD_FORCE_INLINE Quaternion operator*(const Quaternion &q) const
Return the transform of the Quaternion.
Definition: Transform.h:105
Vector3FloatData m_origin
Definition: Transform.h:255
The Transform class supports rigid transforms with only translation and rotation and no scaling/shear...
Definition: Transform.h:32
void setIdentity()
Set this transformation to the identity.
Definition: Transform.h:171
void deSerialize(const struct TransformData &dataIn)
Definition: Transform.h:279
Transform inverse() const
Return the inverse of this transform.
Definition: Transform.h:187
Matrix3x3FloatData m_basis
Definition: Transform.h:254
TF2SIMD_FORCE_INLINE void setBasis(const Matrix3x3 &basis)
Set the rotational element by Matrix3x3.
Definition: Transform.h:158
The Matrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with Q...
Definition: Matrix3x3.h:33
TF2SIMD_FORCE_INLINE Transform & operator=(const Transform &other)
Assignment Operator.
Definition: Transform.h:67
void deSerializeFloat(const struct Matrix3x3FloatData &dataIn)
Definition: Matrix3x3.h:682
TF2SIMD_FORCE_INLINE Vector3 & getOrigin()
Return the origin vector translation.
Definition: Transform.h:116
for serialization
Definition: Transform.h:252
void serializeFloat(struct Matrix3x3FloatData &dataOut) const
Definition: Matrix3x3.h:669
Vector3DoubleData m_origin
Definition: Transform.h:261
for serialization
Definition: Matrix3x3.h:649
for serialization
Definition: Matrix3x3.h:655
static const Transform & getIdentity()
Return an identity transform.
Definition: Transform.h:202
void setFromOpenGLMatrix(const tf2Scalar *m)
Set from an array.
Definition: Transform.h:130
Transform & operator*=(const Transform &t)
Multiply this Transform by another(this = this * another)
Definition: Transform.h:179
TF2SIMD_FORCE_INLINE void setOrigin(const Vector3 &origin)
Set the translational element.
Definition: Transform.h:149
TF2SIMD_FORCE_INLINE Vector3 invXform(const Vector3 &inVec) const
Definition: Transform.h:222
TF2SIMD_FORCE_INLINE void mult(const Transform &t1, const Transform &t2)
Set the current transform as the value of the product of two transforms.
Definition: Transform.h:78
Matrix3x3DoubleData m_basis
Definition: Transform.h:260
void setRotation(const Quaternion &q)
Set the matrix from a quaternion.
Definition: Matrix3x3.h:148
TF2SIMD_FORCE_INLINE const Vector3 & getOrigin() const
Return the origin vector translation.
Definition: Transform.h:118
TF2SIMD_FORCE_INLINE const Matrix3x3 & getBasis() const
Return the basis matrix for the rotation.
Definition: Transform.h:113
Transform()
No initialization constructor.
Definition: Transform.h:42
Quaternion getRotation() const
Return a quaternion representing the rotation.
Definition: Transform.h:121
void getRotation(Quaternion &q) const
Get the matrix represented as a quaternion.
Definition: Matrix3x3.h:245
The Quaternion implements quaternion to perform linear algebra rotations in combination with Matrix3x...
Definition: Quaternion.h:30
void getOpenGLMatrix(tf2Scalar *m) const
Fill an array representation.
Definition: Transform.h:138
TF2SIMD_FORCE_INLINE Transform(const Quaternion &q, const Vector3 &c=Vector3(tf2Scalar(0), tf2Scalar(0), tf2Scalar(0)))
Constructor from Quaternion (optional Vector3 )
Definition: Transform.h:46
void getOpenGLSubMatrix(tf2Scalar *m) const
Fill the values of the matrix into a 9 element array.
Definition: Matrix3x3.h:227
void deSerializeDouble(const struct TransformDoubleData &dataIn)
Definition: Transform.h:291
void setIdentity()
Set the matrix to the identity.
Definition: Matrix3x3.h:210


tf2
Author(s): Tully Foote, Eitan Marder-Eppstein, Wim Meeussen
autogenerated on Mon Jun 27 2022 02:43:06