Bullet Collision Detection & Physics Library: btTransform.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btTransform.h
Go to the documentation of this file.
1/*
2Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans https://bulletphysics.org
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#ifndef BT_TRANSFORM_H
16#define BT_TRANSFORM_H
17
18#include "btMatrix3x3.h"
19
20#ifdef BT_USE_DOUBLE_PRECISION
21#define btTransformData btTransformDoubleData
22#else
23#define btTransformData btTransformFloatData
24#endif
25
28 ATTRIBUTE_ALIGNED16(class)
29 btTransform
30{
32 btMatrix3x3 m_basis;
34 btVector3 m_origin;
35
36public:
37 BT_DECLARE_ALIGNED_ALLOCATOR();
39 btTransform() {}
43 explicit SIMD_FORCE_INLINE btTransform(const btQuaternion& q,
44 const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0)))
45 : m_basis(q),
46 m_origin(c)
47 {
48 }
49
53 explicit SIMD_FORCE_INLINE btTransform(const btMatrix3x3& b,
54 const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0)))
55 : m_basis(b),
56 m_origin(c)
57 {
58 }
60 SIMD_FORCE_INLINE btTransform(const btTransform& other)
61 : m_basis(other.m_basis),
62 m_origin(other.m_origin)
63 {
64 }
66 SIMD_FORCE_INLINE btTransform& operator=(const btTransform& other)
67 {
68 m_basis = other.m_basis;
69 m_origin = other.m_origin;
70 return *this;
71 }
72
77 SIMD_FORCE_INLINE void mult(const btTransform& t1, const btTransform& t2)
78 {
79 m_basis = t1.m_basis * t2.m_basis;
80 m_origin = t1(t2.m_origin);
81 }
82
83 /* void multInverseLeft(const btTransform& t1, const btTransform& t2) {
84 btVector3 v = t2.m_origin - t1.m_origin;
85 m_basis = btMultTransposeLeft(t1.m_basis, t2.m_basis);
86 m_origin = v * t1.m_basis;
87 }
88 */
89
91 SIMD_FORCE_INLINE btVector3 operator()(const btVector3& x) const
92 {
93 return x.dot3(m_basis[0], m_basis[1], m_basis[2]) + m_origin;
94 }
95
97 SIMD_FORCE_INLINE btVector3 operator*(const btVector3& x) const
98 {
99 return (*this)(x);
100 }
101
103 SIMD_FORCE_INLINE btQuaternion operator*(const btQuaternion& q) const
104 {
105 return getRotation() * q;
106 }
107
109 SIMD_FORCE_INLINE btMatrix3x3& getBasis() { return m_basis; }
111 SIMD_FORCE_INLINE const btMatrix3x3& getBasis() const { return m_basis; }
112
114 SIMD_FORCE_INLINE btVector3& getOrigin() { return m_origin; }
116 SIMD_FORCE_INLINE const btVector3& getOrigin() const { return m_origin; }
117
119 btQuaternion getRotation() const
120 {
121 btQuaternion q;
122 m_basis.getRotation(q);
123 return q;
124 }
125
128 void setFromOpenGLMatrix(const btScalar* m)
129 {
130 m_basis.setFromOpenGLSubMatrix(m);
131 m_origin.setValue(m[12], m[13], m[14]);
132 }
133
136 void getOpenGLMatrix(btScalar * m) const
137 {
138 m_basis.getOpenGLSubMatrix(m);
139 m[12] = m_origin.x();
140 m[13] = m_origin.y();
141 m[14] = m_origin.z();
142 m[15] = btScalar(1.0);
143 }
144
147 SIMD_FORCE_INLINE void setOrigin(const btVector3& origin)
148 {
149 m_origin = origin;
150 }
151
152 SIMD_FORCE_INLINE btVector3 invXform(const btVector3& inVec) const;
153
155 SIMD_FORCE_INLINE void setBasis(const btMatrix3x3& basis)
156 {
157 m_basis = basis;
158 }
159
161 SIMD_FORCE_INLINE void setRotation(const btQuaternion& q)
162 {
163 m_basis.setRotation(q);
164 }
165
167 void setIdentity()
168 {
169 m_basis.setIdentity();
170 m_origin.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));
171 }
172
175 btTransform& operator*=(const btTransform& t)
176 {
177 m_origin += m_basis * t.m_origin;
178 m_basis *= t.m_basis;
179 return *this;
180 }
181
183 btTransform inverse() const
184 {
185 btMatrix3x3 inv = m_basis.transpose();
186 return btTransform(inv, inv * -m_origin);
187 }
188
192 btTransform inverseTimes(const btTransform& t) const;
193
195 btTransform operator*(const btTransform& t) const;
196
198 static const btTransform& getIdentity()
199 {
200 static const btTransform identityTransform(btMatrix3x3::getIdentity());
201 return identityTransform;
202 }
203
204 void serialize(struct btTransformData & dataOut) const;
205
206 void serializeFloat(struct btTransformFloatData & dataOut) const;
207
208 void deSerialize(const struct btTransformData& dataIn);
209
210 void deSerializeDouble(const struct btTransformDoubleData& dataIn);
211
212 void deSerializeFloat(const struct btTransformFloatData& dataIn);
213};
214
215 SIMD_FORCE_INLINE btVector3
216btTransform::invXform(const btVector3& inVec) const
217{
218 btVector3 v = inVec - m_origin;
219 return (m_basis.transpose() * v);
220}
221
222 SIMD_FORCE_INLINE btTransform
223btTransform::inverseTimes(const btTransform& t) const
224{
225 btVector3 v = t.getOrigin() - m_origin;
226 return btTransform(m_basis.transposeTimes(t.m_basis),
227 v * m_basis);
228}
229
230 SIMD_FORCE_INLINE btTransform
231 btTransform::operator*(const btTransform& t) const
232{
233 return btTransform(m_basis * t.m_basis,
234 (*this)(t.m_origin));
235}
236
238 SIMD_FORCE_INLINE bool operator==(const btTransform& t1, const btTransform& t2)
239{
240 return (t1.getBasis() == t2.getBasis() &&
241 t1.getOrigin() == t2.getOrigin());
242}
243
245 struct btTransformFloatData
246{
247 btMatrix3x3FloatData m_basis;
248 btVector3FloatData m_origin;
249};
250
251 struct btTransformDoubleData
252{
253 btMatrix3x3DoubleData m_basis;
254 btVector3DoubleData m_origin;
255};
256
257 SIMD_FORCE_INLINE void btTransform::serialize(btTransformData& dataOut) const
258{
259 m_basis.serialize(dataOut.m_basis);
260 m_origin.serialize(dataOut.m_origin);
261}
262
263 SIMD_FORCE_INLINE void btTransform::serializeFloat(btTransformFloatData& dataOut) const
264{
265 m_basis.serializeFloat(dataOut.m_basis);
266 m_origin.serializeFloat(dataOut.m_origin);
267}
268
269 SIMD_FORCE_INLINE void btTransform::deSerialize(const btTransformData& dataIn)
270{
271 m_basis.deSerialize(dataIn.m_basis);
272 m_origin.deSerialize(dataIn.m_origin);
273}
274
275 SIMD_FORCE_INLINE void btTransform::deSerializeFloat(const btTransformFloatData& dataIn)
276{
277 m_basis.deSerializeFloat(dataIn.m_basis);
278 m_origin.deSerializeFloat(dataIn.m_origin);
279}
280
281 SIMD_FORCE_INLINE void btTransform::deSerializeDouble(const btTransformDoubleData& dataIn)
282{
283 m_basis.deSerializeDouble(dataIn.m_basis);
284 m_origin.deSerializeDouble(dataIn.m_origin);
285}
286
287#endif //BT_TRANSFORM_H
btMatrix3x3.h
operator*
btMatrix3x3 operator*(const btMatrix3x3 &m, const btScalar &k)
Definition btMatrix3x3.h:930
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition btScalar.h:99
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition btScalar.h:98
btTransformData
#define btTransformData
Definition btTransform.h:23
operator==
bool operator==(const btTransform &t1, const btTransform &t2)
Test if two transforms have all elements equal.
Definition btTransform.h:238
btMatrix3x3
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition btMatrix3x3.h:50
btMatrix3x3::setFromOpenGLSubMatrix
void setFromOpenGLSubMatrix(const btScalar *m)
Set from the rotational part of a 4x4 OpenGL matrix.
Definition btMatrix3x3.h:188
btMatrix3x3::transpose
btMatrix3x3 transpose() const
Return the transpose of the matrix.
Definition btMatrix3x3.h:1049
btMatrix3x3::getRotation
void getRotation(btQuaternion &q) const
Get the matrix represented as a quaternion.
Definition btMatrix3x3.h:420
btMatrix3x3::deSerializeFloat
void deSerializeFloat(const struct btMatrix3x3FloatData &dataIn)
Definition btMatrix3x3.h:1419
btMatrix3x3::getIdentity
static const btMatrix3x3 & getIdentity()
Definition btMatrix3x3.h:350
btMatrix3x3::setIdentity
void setIdentity()
Set the matrix to the identity.
Definition btMatrix3x3.h:323
btMatrix3x3::getOpenGLSubMatrix
void getOpenGLSubMatrix(btScalar *m) const
Fill the rotational part of an OpenGL matrix and clear the shear/perspective.
Definition btMatrix3x3.h:367
btMatrix3x3::transposeTimes
btMatrix3x3 transposeTimes(const btMatrix3x3 &m) const
Definition btMatrix3x3.h:1106
btMatrix3x3::deSerializeDouble
void deSerializeDouble(const struct btMatrix3x3DoubleData &dataIn)
Definition btMatrix3x3.h:1425
btMatrix3x3::serialize
void serialize(struct btMatrix3x3Data &dataOut) const
Definition btMatrix3x3.h:1401
btMatrix3x3::serializeFloat
void serializeFloat(struct btMatrix3x3FloatData &dataOut) const
Definition btMatrix3x3.h:1407
btMatrix3x3::deSerialize
void deSerialize(const struct btMatrix3x3Data &dataIn)
Definition btMatrix3x3.h:1413
btMatrix3x3::setRotation
void setRotation(const btQuaternion &q)
Set the matrix from a quaternion.
Definition btMatrix3x3.h:215
btQuaternion
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
Definition btQuaternion.h:50
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:30
btTransform::getOrigin
const btVector3 & getOrigin() const
Return the origin vector translation.
Definition btTransform.h:116
btTransform::inverse
btTransform inverse() const
Return the inverse of this transform.
Definition btTransform.h:183
btTransform::m_basis
btMatrix3x3 m_basis
Storage for the rotation.
Definition btTransform.h:32
btTransform::serialize
void serialize(struct btTransformData &dataOut) const
Definition btTransform.h:257
btTransform::serializeFloat
void serializeFloat(struct btTransformFloatData &dataOut) const
Definition btTransform.h:263
btTransform::operator*
btVector3 operator*(const btVector3 &x) const
Return the transform of the vector.
Definition btTransform.h:97
btTransform::operator=
btTransform & operator=(const btTransform &other)
Assignment Operator.
Definition btTransform.h:66
btTransform::invXform
btVector3 invXform(const btVector3 &inVec) const
Definition btTransform.h:216
btTransform::deSerialize
void deSerialize(const struct btTransformData &dataIn)
Definition btTransform.h:269
btTransform::deSerializeFloat
void deSerializeFloat(const struct btTransformFloatData &dataIn)
Definition btTransform.h:275
btTransform::btTransform
btTransform()
No initialization constructor.
Definition btTransform.h:39
btTransform::setFromOpenGLMatrix
void setFromOpenGLMatrix(const btScalar *m)
Set from an array.
Definition btTransform.h:128
btTransform::getOpenGLMatrix
void getOpenGLMatrix(btScalar *m) const
Fill an array representation.
Definition btTransform.h:136
btTransform::getBasis
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition btTransform.h:109
btTransform::getIdentity
static const btTransform & getIdentity()
Return an identity transform.
Definition btTransform.h:198
btTransform::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btTransform::setRotation
void setRotation(const btQuaternion &q)
Set the rotational element by btQuaternion.
Definition btTransform.h:161
btTransform::deSerializeDouble
void deSerializeDouble(const struct btTransformDoubleData &dataIn)
Definition btTransform.h:281
btTransform::btTransform
btTransform(const btMatrix3x3 &b, const btVector3 &c=btVector3(btScalar(0), btScalar(0), btScalar(0)))
Constructor from btMatrix3x3 (optional btVector3)
Definition btTransform.h:53
btTransform::operator*=
btTransform & operator*=(const btTransform &t)
Multiply this Transform by another(this = this * another)
Definition btTransform.h:175
btTransform::setIdentity
void setIdentity()
Set this transformation to the identity.
Definition btTransform.h:167
btTransform::getRotation
btQuaternion getRotation() const
Return a quaternion representing the rotation.
Definition btTransform.h:119
btTransform::getOrigin
btVector3 & getOrigin()
Return the origin vector translation.
Definition btTransform.h:114
btTransform::setOrigin
void setOrigin(const btVector3 &origin)
Set the translational element.
Definition btTransform.h:147
btTransform::operator*
btQuaternion operator*(const btQuaternion &q) const
Return the transform of the btQuaternion.
Definition btTransform.h:103
btTransform::setBasis
void setBasis(const btMatrix3x3 &basis)
Set the rotational element by btMatrix3x3.
Definition btTransform.h:155
btTransform::btTransform
btTransform(const btTransform &other)
Copy constructor.
Definition btTransform.h:60
btTransform::mult
void mult(const btTransform &t1, const btTransform &t2)
Set the current transform as the value of the product of two transforms.
Definition btTransform.h:77
btTransform::m_origin
btVector3 m_origin
Storage for the translation.
Definition btTransform.h:34
btTransform::getBasis
const btMatrix3x3 & getBasis() const
Return the basis matrix for the rotation.
Definition btTransform.h:111
btTransform::inverseTimes
btTransform inverseTimes(const btTransform &t) const
Return the inverse of this transform times the other transform.
Definition btTransform.h:223
btTransform::operator()
btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition btTransform.h:91
btTransform::btTransform
btTransform(const btQuaternion &q, const btVector3 &c=btVector3(btScalar(0), btScalar(0), btScalar(0)))
Constructor from btQuaternion (optional btVector3 )
Definition btTransform.h:43
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btVector3::deSerialize
void deSerialize(const struct btVector3DoubleData &dataIn)
Definition btVector3.h:1330
btVector3::z
const btScalar & z() const
Return the z value.
Definition btVector3.h:579
btVector3::deSerializeFloat
void deSerializeFloat(const struct btVector3FloatData &dataIn)
Definition btVector3.h:1298
btVector3::dot3
btVector3 dot3(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2) const
Definition btVector3.h:720
btVector3::serializeFloat
void serializeFloat(struct btVector3FloatData &dataOut) const
Definition btVector3.h:1291
btVector3::setValue
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition btVector3.h:640
btVector3::deSerializeDouble
void deSerializeDouble(const struct btVector3DoubleData &dataIn)
Definition btVector3.h:1311
btVector3::x
const btScalar & x() const
Return the x value.
Definition btVector3.h:575
btVector3::serialize
void serialize(struct btVector3Data &dataOut) const
Definition btVector3.h:1317
btVector3::y
const btScalar & y() const
Return the y value.
Definition btVector3.h:577
btMatrix3x3DoubleData
for serialization
Definition btMatrix3x3.h:1397
btMatrix3x3FloatData
for serialization
Definition btMatrix3x3.h:1391
btTransformDoubleData
Definition btTransform.h:252
btTransformDoubleData::m_origin
btVector3DoubleData m_origin
Definition btTransform.h:254
btTransformDoubleData::m_basis
btMatrix3x3DoubleData m_basis
Definition btTransform.h:253
btTransformFloatData
for serialization
Definition btTransform.h:246
btTransformFloatData::m_basis
btMatrix3x3FloatData m_basis
Definition btTransform.h:247
btTransformFloatData::m_origin
btVector3FloatData m_origin
Definition btTransform.h:248
btVector3DoubleData
Definition btVector3.h:1287
btVector3FloatData
Definition btVector3.h:1282