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  {
133  m_origin.setValue(m[12],m[13],m[14]);
134  }
135 
138  void getOpenGLMatrix(tf2Scalar *m) const
139  {
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  {
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;
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 {
288  m_origin.deSerializeFloat(dataIn.m_origin);
289 }
290 
292 {
294  m_origin.deSerializeDouble(dataIn.m_origin);
295 }
296 
297 }
298 
299 #endif
300 
301 
302 
303 
304 
305 
tf2::Transform::m_origin
Vector3 m_origin
Storage for the translation.
Definition: Transform.h:37
tf2::Transform::serializeFloat
void serializeFloat(struct TransformFloatData &dataOut) const
Definition: Transform.h:272
tf2::dot
TF2SIMD_FORCE_INLINE tf2Scalar dot(const Quaternion &q1, const Quaternion &q2)
Calculate the dot product between two quaternions.
Definition: Quaternion.h:392
tf2::TransformFloatData::m_origin
Vector3FloatData m_origin
Definition: Transform.h:255
tf2::Transform::Transform
TF2SIMD_FORCE_INLINE Transform(const Transform &other)
Copy constructor.
Definition: Transform.h:61
Matrix3x3.h
tf2::Transform::getOpenGLMatrix
void getOpenGLMatrix(tf2Scalar *m) const
Fill an array representation.
Definition: Transform.h:138
tf2::Transform::deSerializeFloat
void deSerializeFloat(const struct TransformFloatData &dataIn)
Definition: Transform.h:285
tf2::Transform::serialize
void serialize(struct TransformData &dataOut) const
Definition: Transform.h:266
tf2::Transform::inverse
Transform inverse() const
Return the inverse of this transform.
Definition: Transform.h:187
tf2::Matrix3x3::deSerializeFloat
void deSerializeFloat(const struct Matrix3x3FloatData &dataIn)
Definition: Matrix3x3.h:682
tf2::Transform::operator*
TF2SIMD_FORCE_INLINE Vector3 operator*(const Vector3 &x) const
Return the transform of the vector.
Definition: Transform.h:99
tf2::Matrix3x3::getRotation
void getRotation(Quaternion &q) const
Get the matrix represented as a quaternion.
Definition: Matrix3x3.h:245
tf2::Transform::Transform
Transform()
No initialization constructor.
Definition: Transform.h:42
tf2::Transform::setRotation
TF2SIMD_FORCE_INLINE void setRotation(const Quaternion &q)
Set the rotational element by Quaternion.
Definition: Transform.h:164
tf2::Transform::Transform
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
tf2::Transform::m_basis
Matrix3x3 m_basis
Storage for the rotation.
Definition: Transform.h:35
tf2::Transform::operator*
TF2SIMD_FORCE_INLINE Quaternion operator*(const Quaternion &q) const
Return the transform of the Quaternion.
Definition: Transform.h:105
tf2::Transform::getOrigin
TF2SIMD_FORCE_INLINE Vector3 & getOrigin()
Return the origin vector translation.
Definition: Transform.h:116
tf2::Transform::operator*=
Transform & operator*=(const Transform &t)
Multiply this Transform by another(this = this * another)
Definition: Transform.h:179
tf2::Vector3DoubleData
Definition: Vector3.h:682
tf2::Transform::invXform
TF2SIMD_FORCE_INLINE Vector3 invXform(const Vector3 &inVec) const
Definition: Transform.h:222
tf2::Matrix3x3::getIdentity
static const Matrix3x3 & getIdentity()
Definition: Matrix3x3.h:217
tf2::Matrix3x3::getOpenGLSubMatrix
void getOpenGLSubMatrix(tf2Scalar *m) const
Fill the values of the matrix into a 9 element array.
Definition: Matrix3x3.h:227
tf2::Matrix3x3::setRotation
void setRotation(const Quaternion &q)
Set the matrix from a quaternion.
Definition: Matrix3x3.h:148
tf2::Matrix3x3::transposeTimes
Matrix3x3 transposeTimes(const Matrix3x3 &m) const
Definition: Matrix3x3.h:578
tf2::Vector3FloatData
Definition: Vector3.h:677
tf2::Matrix3x3FloatData
for serialization
Definition: Matrix3x3.h:649
tf2::TransformDoubleData::m_origin
Vector3DoubleData m_origin
Definition: Transform.h:261
tf2::Transform::operator()
TF2SIMD_FORCE_INLINE Vector3 operator()(const Vector3 &x) const
Return the transform of the vector.
Definition: Transform.h:91
tf2::Matrix3x3::deSerialize
void deSerialize(const struct Matrix3x3Data &dataIn)
Definition: Matrix3x3.h:676
tf2::Transform::operator=
TF2SIMD_FORCE_INLINE Transform & operator=(const Transform &other)
Assignment Operator.
Definition: Transform.h:67
tf2::Transform::getIdentity
static const Transform & getIdentity()
Return an identity transform.
Definition: Transform.h:202
tf2::operator==
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
tf2::Matrix3x3::deSerializeDouble
void deSerializeDouble(const struct Matrix3x3DoubleData &dataIn)
Definition: Matrix3x3.h:688
tf2::Transform::deSerialize
void deSerialize(const struct TransformData &dataIn)
Definition: Transform.h:279
tf2::TransformFloatData
for serialization
Definition: Transform.h:252
tf2::Transform::setOrigin
TF2SIMD_FORCE_INLINE void setOrigin(const Vector3 &origin)
Set the translational element.
Definition: Transform.h:149
tf2::TransformDoubleData::m_basis
Matrix3x3DoubleData m_basis
Definition: Transform.h:260
tf2::Transform::setBasis
TF2SIMD_FORCE_INLINE void setBasis(const Matrix3x3 &basis)
Set the rotational element by Matrix3x3.
Definition: Transform.h:158
tf2::Transform::setFromOpenGLMatrix
void setFromOpenGLMatrix(const tf2Scalar *m)
Set from an array.
Definition: Transform.h:130
tf2::Transform
The Transform class supports rigid transforms with only translation and rotation and no scaling/shear...
Definition: Transform.h:32
tf2::Transform::getRotation
Quaternion getRotation() const
Return a quaternion representing the rotation.
Definition: Transform.h:121
TF2SIMD_FORCE_INLINE
#define TF2SIMD_FORCE_INLINE
Definition: Scalar.h:129
tf2::Transform::Transform
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
tf2::Matrix3x3DoubleData
for serialization
Definition: Matrix3x3.h:655
tf2::Transform::inverseTimes
Transform inverseTimes(const Transform &t) const
Return the inverse of this transform times the other transform.
Definition: Transform.h:229
tf2::Matrix3x3::setIdentity
void setIdentity()
Set the matrix to the identity.
Definition: Matrix3x3.h:210
tf2::Transform::getBasis
const TF2SIMD_FORCE_INLINE Matrix3x3 & getBasis() const
Return the basis matrix for the rotation.
Definition: Transform.h:113
tf2
Definition: buffer_core.h:54
tf2::Matrix3x3::setFromOpenGLSubMatrix
void setFromOpenGLSubMatrix(const tf2Scalar *m)
Set from a carray of tf2Scalars.
Definition: Matrix3x3.h:120
tf2::Matrix3x3::serializeFloat
void serializeFloat(struct Matrix3x3FloatData &dataOut) const
Definition: Matrix3x3.h:669
tf2::Quaternion
The Quaternion implements quaternion to perform linear algebra rotations in combination with Matrix3x...
Definition: Quaternion.h:30
tf2::Transform::deSerializeDouble
void deSerializeDouble(const struct TransformDoubleData &dataIn)
Definition: Transform.h:291
tf2::Matrix3x3::serialize
void serialize(struct Matrix3x3Data &dataOut) const
Definition: Matrix3x3.h:663
tf2::Matrix3x3::transpose
Matrix3x3 transpose() const
Return the transpose of the matrix.
Definition: Matrix3x3.h:550
tf2Scalar
double tf2Scalar
The tf2Scalar type abstracts floating point numbers, to easily switch between double and single float...
Definition: Scalar.h:159
tf2::Transform::getOrigin
const TF2SIMD_FORCE_INLINE Vector3 & getOrigin() const
Return the origin vector translation.
Definition: Transform.h:118
TransformData
#define TransformData
Definition: Transform.h:27
tf2::Matrix3x3
The Matrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with Q...
Definition: Matrix3x3.h:33
tf2::TransformFloatData::m_basis
Matrix3x3FloatData m_basis
Definition: Transform.h:254
tf2::Transform::mult
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
tf2::TransformDoubleData
Definition: Transform.h:258
tf2::Transform::getBasis
TF2SIMD_FORCE_INLINE Matrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: Transform.h:111
tf2::Transform::setIdentity
void setIdentity()
Set this transformation to the identity.
Definition: Transform.h:171


tf2
Author(s): Tully Foote, Eitan Marder-Eppstein, Wim Meeussen
autogenerated on Sun Feb 4 2024 03:18:11