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 tfTransform_H
18 #define tfTransform_H
19 
20 
21 #include "Matrix3x3.h"
22 
23 namespace tf
24 {
25 
26 #define TransformData TransformDoubleData
27 
28 
31 class Transform {
32 
37 
38 public:
39 
41  Transform() {}
46  const Vector3& c = Vector3(tfScalar(0), tfScalar(0), tfScalar(0)))
47  : m_basis(q),
48  m_origin(c)
49  {}
50 
55  const Vector3& c = Vector3(tfScalar(0), tfScalar(0), tfScalar(0)))
56  : m_basis(b),
57  m_origin(c)
58  {}
61  : m_basis(other.m_basis),
62  m_origin(other.m_origin)
63  {
64  }
67  {
68  m_basis = other.m_basis;
69  m_origin = other.m_origin;
70  return *this;
71  }
72 
77  TFSIMD_FORCE_INLINE void mult(const Transform& t1, const Transform& t2) {
78  m_basis = t1.m_basis * t2.m_basis;
79  m_origin = t1(t2.m_origin);
80  }
81 
82 /* void multInverseLeft(const Transform& t1, const Transform& t2) {
83  Vector3 v = t2.m_origin - t1.m_origin;
84  m_basis = tfMultTransposeLeft(t1.m_basis, t2.m_basis);
85  m_origin = v * t1.m_basis;
86  }
87  */
88 
91  {
92  return Vector3(m_basis[0].dot(x) + m_origin.x(),
93  m_basis[1].dot(x) + m_origin.y(),
94  m_basis[2].dot(x) + m_origin.z());
95  }
96 
99  {
100  return (*this)(x);
101  }
102 
105  {
106  return getRotation() * q;
107  }
108 
112  TFSIMD_FORCE_INLINE const Matrix3x3& getBasis() const { return m_basis; }
113 
117  TFSIMD_FORCE_INLINE const Vector3& getOrigin() const { return m_origin; }
118 
121  Quaternion q;
122  m_basis.getRotation(q);
123  return q;
124  }
125 
126 
130  {
131  m_basis.setFromOpenGLSubMatrix(m);
132  m_origin.setValue(m[12],m[13],m[14]);
133  }
134 
137  void getOpenGLMatrix(tfScalar *m) const
138  {
139  m_basis.getOpenGLSubMatrix(m);
140  m[12] = m_origin.x();
141  m[13] = m_origin.y();
142  m[14] = m_origin.z();
143  m[15] = tfScalar(1.0);
144  }
145 
148  TFSIMD_FORCE_INLINE void setOrigin(const Vector3& origin)
149  {
150  m_origin = origin;
151  }
152 
153  TFSIMD_FORCE_INLINE Vector3 invXform(const Vector3& inVec) const;
154 
155 
158  {
159  m_basis = basis;
160  }
161 
164  {
165  m_basis.setRotation(q);
166  }
167 
168 
170  void setIdentity()
171  {
172  m_basis.setIdentity();
173  m_origin.setValue(tfScalar(0.0), tfScalar(0.0), tfScalar(0.0));
174  }
175 
179  {
180  m_origin += m_basis * t.m_origin;
181  m_basis *= t.m_basis;
182  return *this;
183  }
184 
187  {
188  Matrix3x3 inv = m_basis.transpose();
189  return Transform(inv, inv * -m_origin);
190  }
191 
195  Transform inverseTimes(const Transform& t) const;
196 
198  Transform operator*(const Transform& t) const;
199 
201  static const Transform& getIdentity()
202  {
203  static const Transform identityTransform(Matrix3x3::getIdentity());
204  return identityTransform;
205  }
206 
207  void serialize(struct TransformData& dataOut) const;
208 
209  void serializeFloat(struct TransformFloatData& dataOut) const;
210 
211  void deSerialize(const struct TransformData& dataIn);
212 
213  void deSerializeDouble(const struct TransformDoubleData& dataIn);
214 
215  void deSerializeFloat(const struct TransformFloatData& dataIn);
216 
217 };
218 
219 
221 Transform::invXform(const Vector3& inVec) const
222 {
223  Vector3 v = inVec - m_origin;
224  return (m_basis.transpose() * v);
225 }
226 
229 {
230  Vector3 v = t.getOrigin() - m_origin;
231  return Transform(m_basis.transposeTimes(t.m_basis),
232  v * m_basis);
233 }
234 
237 {
238  return Transform(m_basis * t.m_basis,
239  (*this)(t.m_origin));
240 }
241 
244 {
245  return ( t1.getBasis() == t2.getBasis() &&
246  t1.getOrigin() == t2.getOrigin() );
247 }
248 
249 
252 {
255 };
256 
258 {
261 };
262 
263 
264 
266 {
267  m_basis.serialize(dataOut.m_basis);
268  m_origin.serialize(dataOut.m_origin);
269 }
270 
272 {
273  m_basis.serializeFloat(dataOut.m_basis);
274  m_origin.serializeFloat(dataOut.m_origin);
275 }
276 
277 
279 {
280  m_basis.deSerialize(dataIn.m_basis);
281  m_origin.deSerialize(dataIn.m_origin);
282 }
283 
285 {
286  m_basis.deSerializeFloat(dataIn.m_basis);
287  m_origin.deSerializeFloat(dataIn.m_origin);
288 }
289 
291 {
292  m_basis.deSerializeDouble(dataIn.m_basis);
293  m_origin.deSerializeDouble(dataIn.m_origin);
294 }
295 
296 }
297 
298 #endif
299 
300 
301 
302 
303 
304 
TFSIMD_FORCE_INLINE void setRotation(const Quaternion &q)
Set the rotational element by Quaternion.
Definition: Transform.h:163
TFSIMD_FORCE_INLINE const Vector3 & getOrigin() const
Return the origin vector translation.
Definition: Transform.h:117
Matrix3x3 m_basis
Storage for the rotation.
Definition: Transform.h:34
void serializeFloat(struct Matrix3x3FloatData &dataOut) const
Definition: Matrix3x3.h:668
TFSIMD_FORCE_INLINE void serialize(struct Vector3Data &dataOut) const
Definition: Vector3.h:718
The Quaternion implements quaternion to perform linear algebra rotations in combination with Matrix3x...
Definition: Quaternion.h:28
#define TransformData
Definition: Transform.h:26
void deSerializeDouble(const struct Matrix3x3DoubleData &dataIn)
Definition: Matrix3x3.h:687
double tfScalar
The tfScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: Scalar.h:160
TFSIMD_FORCE_INLINE Vector3 operator()(const Vector3 &x) const
Return the transform of the vector.
Definition: Transform.h:90
void serialize(struct TransformData &dataOut) const
Definition: Transform.h:265
TFSIMD_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:640
TFSIMD_FORCE_INLINE Matrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: Transform.h:110
TFSIMD_FORCE_INLINE Transform & operator=(const Transform &other)
Assignment Operator.
Definition: Transform.h:66
Matrix3x3DoubleData m_basis
Definition: Transform.h:259
Transform & operator*=(const Transform &t)
Multiply this Transform by another(this = this * another)
Definition: Transform.h:178
TFSIMD_FORCE_INLINE Vector3 invXform(const Vector3 &inVec) const
Definition: Transform.h:221
void setFromOpenGLMatrix(const tfScalar *m)
Set from an array.
Definition: Transform.h:129
Definition: exceptions.h:38
TFSIMD_FORCE_INLINE Quaternion operator*(const Quaternion &q) const
Return the transform of the Quaternion.
Definition: Transform.h:104
Matrix3x3FloatData m_basis
Definition: Transform.h:253
The Matrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with Q...
Definition: Matrix3x3.h:31
TFSIMD_FORCE_INLINE void setValue(const tfScalar &x, const tfScalar &y, const tfScalar &z)
Definition: Vector3.h:308
for serialization
Definition: Matrix3x3.h:648
void getRotation(Quaternion &q) const
Get the matrix represented as a quaternion.
Definition: Matrix3x3.h:243
void setRotation(const Quaternion &q)
Set the matrix from a quaternion.
Definition: Matrix3x3.h:146
void setIdentity()
Set the matrix to the identity.
Definition: Matrix3x3.h:208
void setIdentity()
Set this transformation to the identity.
Definition: Transform.h:170
void serializeFloat(struct TransformFloatData &dataOut) const
Definition: Transform.h:271
TFSIMD_FORCE_INLINE Transform(const Quaternion &q, const Vector3 &c=Vector3(tfScalar(0), tfScalar(0), tfScalar(0)))
Constructor from Quaternion (optional Vector3 )
Definition: Transform.h:45
Vector3DoubleData m_origin
Definition: Transform.h:260
TFSIMD_FORCE_INLINE const tfScalar & x() const
Return the x value.
Definition: Vector3.h:263
TFSIMD_FORCE_INLINE void serializeFloat(struct Vector3FloatData &dataOut) const
Definition: Vector3.h:690
void getOpenGLMatrix(tfScalar *m) const
Fill an array representation.
Definition: Transform.h:137
void deSerializeFloat(const struct TransformFloatData &dataIn)
for serialization
Definition: Matrix3x3.h:654
TFSIMD_FORCE_INLINE const tfScalar & z() const
Return the z value.
Definition: Vector3.h:267
TFSIMD_FORCE_INLINE void deSerializeDouble(const struct Vector3DoubleData &dataIn)
Definition: Vector3.h:711
TFSIMD_FORCE_INLINE const Matrix3x3 & getBasis() const
Return the basis matrix for the rotation.
Definition: Transform.h:112
TFSIMD_FORCE_INLINE Vector3()
No initialization constructor.
Definition: Vector3.h:293
TFSIMD_FORCE_INLINE Vector3 operator*(const Vector3 &x) const
Return the transform of the vector.
Definition: Transform.h:98
The Transform class supports rigid transforms with only translation and rotation and no scaling/shear...
Definition: Transform.h:31
TFSIMD_FORCE_INLINE const tfScalar & y() const
Return the y value.
Definition: Vector3.h:265
TFSIMD_FORCE_INLINE Transform(const Matrix3x3 &b, const Vector3 &c=Vector3(tfScalar(0), tfScalar(0), tfScalar(0)))
Constructor from Matrix3x3 (optional Vector3)
Definition: Transform.h:54
#define TFSIMD_FORCE_INLINE
Definition: Scalar.h:130
Matrix3x3 transposeTimes(const Matrix3x3 &m) const
Definition: Matrix3x3.h:577
TFSIMD_FORCE_INLINE const tfScalar & x() const
Return the x value.
Definition: Vector3.h:484
Transform inverse() const
Return the inverse of this transform.
Definition: Transform.h:186
TFSIMD_FORCE_INLINE void setBasis(const Matrix3x3 &basis)
Set the rotational element by Matrix3x3.
Definition: Transform.h:157
void deSerializeFloat(const struct Matrix3x3FloatData &dataIn)
Definition: Matrix3x3.h:681
TFSIMD_FORCE_INLINE tfScalar dot(const Quaternion &q1, const Quaternion &q2)
Calculate the dot product between two quaternions.
Definition: Quaternion.h:390
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
Return the origin vector translation.
Definition: Transform.h:115
void deSerializeDouble(const struct TransformDoubleData &dataIn)
TFSIMD_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:77
Vector3 m_origin
Storage for the translation.
Definition: Transform.h:36
Transform()
No initialization constructor.
Definition: Transform.h:41
Quaternion getRotation() const
Return a quaternion representing the rotation.
Definition: Transform.h:120
Vector3FloatData m_origin
Definition: Transform.h:254
void deSerialize(const struct TransformData &dataIn)
void setFromOpenGLSubMatrix(const tfScalar *m)
Set from a carray of tfScalars.
Definition: Matrix3x3.h:118
TFSIMD_FORCE_INLINE void deSerialize(const struct Vector3Data &dataIn)
Definition: Vector3.h:725
static const Transform & getIdentity()
Return an identity transform.
Definition: Transform.h:201
Matrix3x3 transpose() const
Return the transpose of the matrix.
Definition: Matrix3x3.h:549
TFSIMD_FORCE_INLINE Transform(const Transform &other)
Copy constructor.
Definition: Transform.h:60
void deSerialize(const struct Matrix3x3Data &dataIn)
Definition: Matrix3x3.h:675
TFSIMD_FORCE_INLINE void deSerializeFloat(const struct Vector3FloatData &dataIn)
Definition: Vector3.h:697
void getOpenGLSubMatrix(tfScalar *m) const
Fill the values of the matrix into a 9 element array.
Definition: Matrix3x3.h:225
Transform inverseTimes(const Transform &t) const
Return the inverse of this transform times the other transform.
Definition: Transform.h:228
TFSIMD_FORCE_INLINE void setOrigin(const Vector3 &origin)
Set the translational element.
Definition: Transform.h:148
static const Matrix3x3 & getIdentity()
Definition: Matrix3x3.h:215
for serialization
Definition: Transform.h:251
Vector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-byte...
Definition: Vector3.h:38
void serialize(struct Matrix3x3Data &dataOut) const
Definition: Matrix3x3.h:662


tf
Author(s): Tully Foote, Eitan Marder-Eppstein, Wim Meeussen
autogenerated on Mon Jun 10 2019 12:25:26