2
Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/
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:
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.
17
#ifndef SimdTransform_H
18
#define SimdTransform_H
20
#include "SimdVector3.h"
21
#include "SimdMatrix3x3.h"
29
RIGID = TRANSLATION | ROTATION,
31
LINEAR = ROTATION | SCALING,
32
AFFINE = TRANSLATION | LINEAR
38
// template <typename Scalar2>
39
// explicit Transform(const Scalar2 *m) { setValue(m); }
41
explicit SIMD_FORCE_INLINE SimdTransform(const SimdQuaternion& q,
42
const SimdVector3& c = SimdVector3(SimdScalar(0), SimdScalar(0), SimdScalar(0)))
48
explicit SIMD_FORCE_INLINE SimdTransform(const SimdMatrix3x3& b,
49
const SimdVector3& c = SimdVector3(SimdScalar(0), SimdScalar(0), SimdScalar(0)),
50
unsigned int type = AFFINE)
57
SIMD_FORCE_INLINE void mult(const SimdTransform& t1, const SimdTransform& t2) {
58
m_basis = t1.m_basis * t2.m_basis;
59
m_origin = t1(t2.m_origin);
60
m_type = t1.m_type | t2.m_type;
63
void multInverseLeft(const SimdTransform& t1, const SimdTransform& t2) {
64
SimdVector3 v = t2.m_origin - t1.m_origin;
65
if (t1.m_type & SCALING) {
66
SimdMatrix3x3 inv = t1.m_basis.inverse();
67
m_basis = inv * t2.m_basis;
71
m_basis = SimdMultTransposeLeft(t1.m_basis, t2.m_basis);
72
m_origin = v * t1.m_basis;
74
m_type = t1.m_type | t2.m_type;
77
SIMD_FORCE_INLINE SimdVector3 operator()(const SimdVector3& x) const
79
return SimdVector3(m_basis[0].dot(x) + m_origin[0],
80
m_basis[1].dot(x) + m_origin[1],
81
m_basis[2].dot(x) + m_origin[2]);
84
SIMD_FORCE_INLINE SimdVector3 operator*(const SimdVector3& x) const
89
SIMD_FORCE_INLINE SimdMatrix3x3& getBasis() { return m_basis; }
90
SIMD_FORCE_INLINE const SimdMatrix3x3& getBasis() const { return m_basis; }
92
SIMD_FORCE_INLINE SimdVector3& getOrigin() { return m_origin; }
93
SIMD_FORCE_INLINE const SimdVector3& getOrigin() const { return m_origin; }
95
SimdQuaternion getRotation() const {
97
m_basis.getRotation(q);
100
template <typename Scalar2>
101
void setValue(const Scalar2 *m)
104
m_origin.setValue(&m[12]);
109
void setFromOpenGLMatrix(const SimdScalar *m)
111
m_basis.setFromOpenGLSubMatrix(m);
117
void getOpenGLMatrix(SimdScalar *m) const
119
m_basis.getOpenGLSubMatrix(m);
123
m[15] = SimdScalar(1.0f);
126
SIMD_FORCE_INLINE void setOrigin(const SimdVector3& origin)
129
m_type |= TRANSLATION;
132
SIMD_FORCE_INLINE SimdVector3 invXform(const SimdVector3& inVec) const;
136
SIMD_FORCE_INLINE void setBasis(const SimdMatrix3x3& basis)
142
SIMD_FORCE_INLINE void setRotation(const SimdQuaternion& q)
144
m_basis.setRotation(q);
145
m_type = (m_type & ~LINEAR) | ROTATION;
148
SIMD_FORCE_INLINE void scale(const SimdVector3& scaling)
150
m_basis = m_basis.scaled(scaling);
156
m_basis.setIdentity();
157
m_origin.setValue(SimdScalar(0.0), SimdScalar(0.0), SimdScalar(0.0));
161
SIMD_FORCE_INLINE bool isIdentity() const { return m_type == 0x0; }
163
SimdTransform& operator*=(const SimdTransform& t)
165
m_origin += m_basis * t.m_origin;
166
m_basis *= t.m_basis;
171
SimdTransform inverse() const
175
SimdMatrix3x3 inv = (m_type & SCALING) ?
179
return SimdTransform(inv, inv * -m_origin, m_type);
185
SimdTransform inverseTimes(const SimdTransform& t) const;
187
SimdTransform operator*(const SimdTransform& t) const;
191
SimdMatrix3x3 m_basis;
192
SimdVector3 m_origin;
197
SIMD_FORCE_INLINE SimdVector3
198
SimdTransform::invXform(const SimdVector3& inVec) const
200
SimdVector3 v = inVec - m_origin;
201
return (m_basis.transpose() * v);
204
SIMD_FORCE_INLINE SimdTransform
205
SimdTransform::inverseTimes(const SimdTransform& t) const
207
SimdVector3 v = t.getOrigin() - m_origin;
208
if (m_type & SCALING)
210
SimdMatrix3x3 inv = m_basis.inverse();
211
return SimdTransform(inv * t.getBasis(), inv * v,
216
return SimdTransform(m_basis.transposeTimes(t.m_basis),
217
v * m_basis, m_type | t.m_type);
221
SIMD_FORCE_INLINE SimdTransform
222
SimdTransform::operator*(const SimdTransform& t) const
224
return SimdTransform(m_basis * t.m_basis,