Blender  V3.3
btTransform.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 #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 
30 {
32  btMatrix3x3 m_basis;
35 
36 public:
38  btTransform() {}
43  const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0)))
44  : m_basis(q),
45  m_origin(c)
46  {
47  }
48 
53  const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0)))
54  : m_basis(b),
55  m_origin(c)
56  {
57  }
60  : m_basis(other.m_basis),
61  m_origin(other.m_origin)
62  {
63  }
66  {
67  m_basis = other.m_basis;
68  m_origin = other.m_origin;
69  return *this;
70  }
71 
76  SIMD_FORCE_INLINE void mult(const btTransform& t1, const btTransform& t2)
77  {
78  m_basis = t1.m_basis * t2.m_basis;
79  m_origin = t1(t2.m_origin);
80  }
81 
82  /* void multInverseLeft(const btTransform& t1, const btTransform& t2) {
83  btVector3 v = t2.m_origin - t1.m_origin;
84  m_basis = btMultTransposeLeft(t1.m_basis, t2.m_basis);
85  m_origin = v * t1.m_basis;
86  }
87  */
88 
91  {
92  return x.dot3(m_basis[0], m_basis[1], m_basis[2]) + m_origin;
93  }
94 
97  {
98  return (*this)(x);
99  }
100 
103  {
104  return getRotation() * q;
105  }
106 
108  SIMD_FORCE_INLINE btMatrix3x3& getBasis() { return m_basis; }
110  SIMD_FORCE_INLINE const btMatrix3x3& getBasis() const { return m_basis; }
111 
115  SIMD_FORCE_INLINE const btVector3& getOrigin() const { return m_origin; }
116 
119  {
120  btQuaternion q;
121  m_basis.getRotation(q);
122  return q;
123  }
124 
128  {
129  m_basis.setFromOpenGLSubMatrix(m);
130  m_origin.setValue(m[12], m[13], m[14]);
131  }
132 
135  void getOpenGLMatrix(btScalar * m) const
136  {
137  m_basis.getOpenGLSubMatrix(m);
138  m[12] = m_origin.x();
139  m[13] = m_origin.y();
140  m[14] = m_origin.z();
141  m[15] = btScalar(1.0);
142  }
143 
147  {
148  m_origin = origin;
149  }
150 
151  SIMD_FORCE_INLINE btVector3 invXform(const btVector3& inVec) const;
152 
155  {
156  m_basis = basis;
157  }
158 
161  {
162  m_basis.setRotation(q);
163  }
164 
166  void setIdentity()
167  {
168  m_basis.setIdentity();
169  m_origin.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));
170  }
171 
175  {
176  m_origin += m_basis * t.m_origin;
177  m_basis *= t.m_basis;
178  return *this;
179  }
180 
183  {
184  btMatrix3x3 inv = m_basis.transpose();
185  return btTransform(inv, inv * -m_origin);
186  }
187 
191  btTransform inverseTimes(const btTransform& t) const;
192 
195 
197  static const btTransform& getIdentity()
198  {
199  static const btTransform identityTransform(btMatrix3x3::getIdentity());
200  return identityTransform;
201  }
202 
203  void serialize(struct btTransformData & dataOut) const;
204 
205  void serializeFloat(struct btTransformFloatData & dataOut) const;
206 
207  void deSerialize(const struct btTransformData& dataIn);
208 
209  void deSerializeDouble(const struct btTransformDoubleData& dataIn);
210 
211  void deSerializeFloat(const struct btTransformFloatData& dataIn);
212 };
213 
215 btTransform::invXform(const btVector3& inVec) const
216 {
217  btVector3 v = inVec - m_origin;
218  return (m_basis.transpose() * v);
219 }
220 
223 {
224  btVector3 v = t.getOrigin() - m_origin;
225  return btTransform(m_basis.transposeTimes(t.m_basis),
226  v * m_basis);
227 }
228 
230  btTransform::operator*(const btTransform& t) const
231 {
232  return btTransform(m_basis * t.m_basis,
233  (*this)(t.m_origin));
234 }
235 
238 {
239  return (t1.getBasis() == t2.getBasis() &&
240  t1.getOrigin() == t2.getOrigin());
241 }
242 
245 {
248 };
249 
251 {
254 };
255 
257 {
258  m_basis.serialize(dataOut.m_basis);
259  m_origin.serialize(dataOut.m_origin);
260 }
261 
263 {
264  m_basis.serializeFloat(dataOut.m_basis);
265  m_origin.serializeFloat(dataOut.m_origin);
266 }
267 
269 {
270  m_basis.deSerialize(dataIn.m_basis);
271  m_origin.deSerialize(dataIn.m_origin);
272 }
273 
275 {
276  m_basis.deSerializeFloat(dataIn.m_basis);
277  m_origin.deSerializeFloat(dataIn.m_origin);
278 }
279 
281 {
282  m_basis.deSerializeDouble(dataIn.m_basis);
283  m_origin.deSerializeDouble(dataIn.m_origin);
284 }
285 
286 #endif //BT_TRANSFORM_H
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
ATTR_WARN_UNUSED_RESULT const BMVert * v
btMatrix3x3
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:50
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:285
#define SIMD_FORCE_INLINE
Definition: btScalar.h:280
void serialize(struct btTransformData &dataOut) const
SIMD_FORCE_INLINE void setOrigin(const btVector3 &origin)
Set the translational element.
Definition: btTransform.h:146
btTransform inverse() const
Return the inverse of this transform.
Definition: btTransform.h:182
SIMD_FORCE_INLINE btTransform & operator=(const btTransform &other)
Assignment Operator.
Definition: btTransform.h:65
btTransform inverseTimes(const btTransform &t) const
Return the inverse of this transform times the other transform.
Definition: btTransform.h:222
btVector3 m_origin
Storage for the translation.
Definition: btTransform.h:34
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:166
SIMD_FORCE_INLINE void setRotation(const btQuaternion &q)
Set the rotational element by btQuaternion.
Definition: btTransform.h:160
SIMD_FORCE_INLINE btVector3 invXform(const btVector3 &inVec) const
Definition: btTransform.h:215
btQuaternion getRotation() const
Return a quaternion representing the rotation.
Definition: btTransform.h:118
SIMD_FORCE_INLINE void mult(const btTransform &t1, const btTransform &t2)
Set the current transform as the value of the product of two transforms.
Definition: btTransform.h:76
void setFromOpenGLMatrix(const btScalar *m)
Set from an array.
Definition: btTransform.h:127
SIMD_FORCE_INLINE btVector3 & getOrigin()
Return the origin vector translation.
Definition: btTransform.h:113
SIMD_FORCE_INLINE btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition: btTransform.h:90
void serializeFloat(struct btTransformFloatData &dataOut) const
SIMD_FORCE_INLINE void setBasis(const btMatrix3x3 &basis)
Set the rotational element by btMatrix3x3.
Definition: btTransform.h:154
#define btTransformData
Definition: btTransform.h:23
SIMD_FORCE_INLINE btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:108
void deSerialize(const struct btTransformData &dataIn)
void getOpenGLMatrix(btScalar *m) const
Fill an array representation.
Definition: btTransform.h:135
void deSerializeFloat(const struct btTransformFloatData &dataIn)
btTransform & operator*=(const btTransform &t)
Multiply this Transform by another(this = this * another)
Definition: btTransform.h:174
static const btTransform & getIdentity()
Return an identity transform.
Definition: btTransform.h:197
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
void deSerializeDouble(const struct btTransformDoubleData &dataIn)
SIMD_FORCE_INLINE bool operator==(const btTransform &t1, const btTransform &t2)
Test if two transforms have all elements equal.
Definition: btTransform.h:237
SIMD_FORCE_INLINE btVector3 operator*(const btVector3 &x) const
Return the transform of the vector.
Definition: btTransform.h:96
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
Definition: btQuaternion.h:50
static unsigned c
Definition: RandGen.cpp:83
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
for serialization
Definition: btMatrix3x3.h:1397
for serialization
Definition: btMatrix3x3.h:1391
btVector3DoubleData m_origin
Definition: btTransform.h:253
btMatrix3x3DoubleData m_basis
Definition: btTransform.h:252
for serialization
Definition: btTransform.h:245
btMatrix3x3FloatData m_basis
Definition: btTransform.h:246
btVector3FloatData m_origin
Definition: btTransform.h:247