Bullet Collision Detection & Physics Library
btTransform.h
Go to the documentation of this file.
1/*
2Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/
3
4This software is provided 'as-is', without any express or implied warranty.
5In no event will the authors be held liable for any damages arising from the use of this software.
6Permission is granted to anyone to use this software for any purpose,
7including commercial applications, and to alter it and redistribute it freely,
8subject to the following restrictions:
9
101. 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.
112. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
123. This notice may not be removed or altered from any source distribution.
13*/
14
15
16
17#ifndef BT_TRANSFORM_H
18#define BT_TRANSFORM_H
19
20
21#include "btMatrix3x3.h"
22
23#ifdef BT_USE_DOUBLE_PRECISION
24#define btTransformData btTransformDoubleData
25#else
26#define btTransformData btTransformFloatData
27#endif
28
29
30
31
35
40
41public:
42
49 const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0)))
50 : m_basis(q),
51 m_origin(c)
52 {}
53
58 const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0)))
59 : m_basis(b),
60 m_origin(c)
61 {}
64 : m_basis(other.m_basis),
65 m_origin(other.m_origin)
66 {
67 }
70 {
71 m_basis = other.m_basis;
72 m_origin = other.m_origin;
73 return *this;
74 }
75
76
81 SIMD_FORCE_INLINE void mult(const btTransform& t1, const btTransform& t2) {
82 m_basis = t1.m_basis * t2.m_basis;
83 m_origin = t1(t2.m_origin);
84 }
85
86/* void multInverseLeft(const btTransform& t1, const btTransform& t2) {
87 btVector3 v = t2.m_origin - t1.m_origin;
88 m_basis = btMultTransposeLeft(t1.m_basis, t2.m_basis);
89 m_origin = v * t1.m_basis;
90 }
91 */
92
95 {
96 return x.dot3(m_basis[0], m_basis[1], m_basis[2]) + m_origin;
97 }
98
101 {
102 return (*this)(x);
103 }
104
107 {
108 return getRotation() * q;
109 }
110
114 SIMD_FORCE_INLINE const btMatrix3x3& getBasis() const { return m_basis; }
115
117 SIMD_FORCE_INLINE btVector3& getOrigin() { return m_origin; }
119 SIMD_FORCE_INLINE const btVector3& getOrigin() const { return m_origin; }
120
123 btQuaternion q;
124 m_basis.getRotation(q);
125 return q;
126 }
127
128
132 {
133 m_basis.setFromOpenGLSubMatrix(m);
134 m_origin.setValue(m[12],m[13],m[14]);
135 }
136
139 void getOpenGLMatrix(btScalar *m) const
140 {
141 m_basis.getOpenGLSubMatrix(m);
142 m[12] = m_origin.x();
143 m[13] = m_origin.y();
144 m[14] = m_origin.z();
145 m[15] = btScalar(1.0);
146 }
147
151 {
152 m_origin = origin;
153 }
154
155 SIMD_FORCE_INLINE btVector3 invXform(const btVector3& inVec) const;
156
157
160 {
161 m_basis = basis;
162 }
163
166 {
167 m_basis.setRotation(q);
168 }
169
170
173 {
174 m_basis.setIdentity();
175 m_origin.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));
176 }
177
181 {
182 m_origin += m_basis * t.m_origin;
183 m_basis *= t.m_basis;
184 return *this;
185 }
186
189 {
190 btMatrix3x3 inv = m_basis.transpose();
191 return btTransform(inv, inv * -m_origin);
192 }
193
197 btTransform inverseTimes(const btTransform& t) const;
198
200 btTransform operator*(const btTransform& t) const;
201
203 static const btTransform& getIdentity()
204 {
205 static const btTransform identityTransform(btMatrix3x3::getIdentity());
206 return identityTransform;
207 }
208
209 void serialize(struct btTransformData& dataOut) const;
210
211 void serializeFloat(struct btTransformFloatData& dataOut) const;
212
213 void deSerialize(const struct btTransformData& dataIn);
214
215 void deSerializeDouble(const struct btTransformDoubleData& dataIn);
216
217 void deSerializeFloat(const struct btTransformFloatData& dataIn);
218
219};
220
221
224{
225 btVector3 v = inVec - m_origin;
226 return (m_basis.transpose() * v);
227}
228
231{
232 btVector3 v = t.getOrigin() - m_origin;
234 v * m_basis);
235}
236
239{
240 return btTransform(m_basis * t.m_basis,
241 (*this)(t.m_origin));
242}
243
246{
247 return ( t1.getBasis() == t2.getBasis() &&
248 t1.getOrigin() == t2.getOrigin() );
249}
250
251
254{
257};
258
260{
263};
264
265
266
268{
269 m_basis.serialize(dataOut.m_basis);
270 m_origin.serialize(dataOut.m_origin);
271}
272
274{
277}
278
279
281{
282 m_basis.deSerialize(dataIn.m_basis);
283 m_origin.deSerialize(dataIn.m_origin);
284}
285
287{
290}
291
293{
296}
297
298
299#endif //BT_TRANSFORM_H
300
301
302
303
304
305
btMatrix3x3 operator*(const btMatrix3x3 &m, const btScalar &k)
Definition: btMatrix3x3.h:836
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:82
#define SIMD_FORCE_INLINE
Definition: btScalar.h:81
#define btTransformData
Definition: btTransform.h:26
bool operator==(const btTransform &t1, const btTransform &t2)
Test if two transforms have all elements equal.
Definition: btTransform.h:245
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:48
void setFromOpenGLSubMatrix(const btScalar *m)
Set from the rotational part of a 4x4 OpenGL matrix.
Definition: btMatrix3x3.h:181
btMatrix3x3 transpose() const
Return the transpose of the matrix.
Definition: btMatrix3x3.h:958
void getRotation(btQuaternion &q) const
Get the matrix represented as a quaternion.
Definition: btMatrix3x3.h:400
void deSerializeFloat(const struct btMatrix3x3FloatData &dataIn)
Definition: btMatrix3x3.h:1335
static const btMatrix3x3 & getIdentity()
Definition: btMatrix3x3.h:330
void setIdentity()
Set the matrix to the identity.
Definition: btMatrix3x3.h:317
void getOpenGLSubMatrix(btScalar *m) const
Fill the rotational part of an OpenGL matrix and clear the shear/perspective.
Definition: btMatrix3x3.h:347
btMatrix3x3 transposeTimes(const btMatrix3x3 &m) const
Definition: btMatrix3x3.h:1016
void deSerializeDouble(const struct btMatrix3x3DoubleData &dataIn)
Definition: btMatrix3x3.h:1341
void serialize(struct btMatrix3x3Data &dataOut) const
Definition: btMatrix3x3.h:1316
void serializeFloat(struct btMatrix3x3FloatData &dataOut) const
Definition: btMatrix3x3.h:1322
void deSerialize(const struct btMatrix3x3Data &dataIn)
Definition: btMatrix3x3.h:1329
void setRotation(const btQuaternion &q)
Set the matrix from a quaternion.
Definition: btMatrix3x3.h:209
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
Definition: btQuaternion.h:55
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
const btVector3 & getOrigin() const
Return the origin vector translation.
Definition: btTransform.h:119
btTransform inverse() const
Return the inverse of this transform.
Definition: btTransform.h:188
btMatrix3x3 m_basis
Storage for the rotation.
Definition: btTransform.h:37
void serialize(struct btTransformData &dataOut) const
Definition: btTransform.h:267
void serializeFloat(struct btTransformFloatData &dataOut) const
Definition: btTransform.h:273
btVector3 operator*(const btVector3 &x) const
Return the transform of the vector.
Definition: btTransform.h:100
btTransform & operator=(const btTransform &other)
Assignment Operator.
Definition: btTransform.h:69
btVector3 invXform(const btVector3 &inVec) const
Definition: btTransform.h:223
void deSerialize(const struct btTransformData &dataIn)
Definition: btTransform.h:280
void deSerializeFloat(const struct btTransformFloatData &dataIn)
Definition: btTransform.h:286
btTransform()
No initialization constructor.
Definition: btTransform.h:44
void setFromOpenGLMatrix(const btScalar *m)
Set from an array.
Definition: btTransform.h:131
void getOpenGLMatrix(btScalar *m) const
Fill an array representation.
Definition: btTransform.h:139
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:112
static const btTransform & getIdentity()
Return an identity transform.
Definition: btTransform.h:203
void setRotation(const btQuaternion &q)
Set the rotational element by btQuaternion.
Definition: btTransform.h:165
void deSerializeDouble(const struct btTransformDoubleData &dataIn)
Definition: btTransform.h:292
btTransform(const btMatrix3x3 &b, const btVector3 &c=btVector3(btScalar(0), btScalar(0), btScalar(0)))
Constructor from btMatrix3x3 (optional btVector3)
Definition: btTransform.h:57
btTransform & operator*=(const btTransform &t)
Multiply this Transform by another(this = this * another)
Definition: btTransform.h:180
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:172
btQuaternion getRotation() const
Return a quaternion representing the rotation.
Definition: btTransform.h:122
btVector3 & getOrigin()
Return the origin vector translation.
Definition: btTransform.h:117
void setOrigin(const btVector3 &origin)
Set the translational element.
Definition: btTransform.h:150
btQuaternion operator*(const btQuaternion &q) const
Return the transform of the btQuaternion.
Definition: btTransform.h:106
void setBasis(const btMatrix3x3 &basis)
Set the rotational element by btMatrix3x3.
Definition: btTransform.h:159
btTransform(const btTransform &other)
Copy constructor.
Definition: btTransform.h:63
void mult(const btTransform &t1, const btTransform &t2)
Set the current transform as the value of the product of two transforms.
Definition: btTransform.h:81
btVector3 m_origin
Storage for the translation.
Definition: btTransform.h:39
const btMatrix3x3 & getBasis() const
Return the basis matrix for the rotation.
Definition: btTransform.h:114
btTransform inverseTimes(const btTransform &t) const
Return the inverse of this transform times the other transform.
Definition: btTransform.h:230
btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition: btTransform.h:94
btTransform(const btQuaternion &q, const btVector3 &c=btVector3(btScalar(0), btScalar(0), btScalar(0)))
Constructor from btQuaternion (optional btVector3 )
Definition: btTransform.h:48
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:84
const btScalar & z() const
Return the z value.
Definition: btVector3.h:591
void deSerializeFloat(const struct btVector3FloatData &dataIn)
Definition: btVector3.h:1330
void deSerialize(const struct btVector3Data &dataIn)
Definition: btVector3.h:1358
btVector3 dot3(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2) const
Definition: btVector3.h:731
void serializeFloat(struct btVector3FloatData &dataOut) const
Definition: btVector3.h:1323
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:652
void deSerializeDouble(const struct btVector3DoubleData &dataIn)
Definition: btVector3.h:1344
const btScalar & x() const
Return the x value.
Definition: btVector3.h:587
void serialize(struct btVector3Data &dataOut) const
Definition: btVector3.h:1351
const btScalar & y() const
Return the y value.
Definition: btVector3.h:589
for serialization
Definition: btMatrix3x3.h:1309
for serialization
Definition: btMatrix3x3.h:1303
btVector3DoubleData m_origin
Definition: btTransform.h:262
btMatrix3x3DoubleData m_basis
Definition: btTransform.h:261
for serialization
Definition: btTransform.h:254
btMatrix3x3FloatData m_basis
Definition: btTransform.h:255
btVector3FloatData m_origin
Definition: btTransform.h:256