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 btTransform_H |
---|
18 | #define btTransform_H |
---|
19 | |
---|
20 | #include "btVector3.h" |
---|
21 | #include "btMatrix3x3.h" |
---|
22 | |
---|
23 | |
---|
24 | ///The btTransform class supports rigid transforms with only translation and rotation and no scaling/shear. |
---|
25 | ///It can be used in combination with btVector3, btQuaternion and btMatrix3x3 linear algebra classes. |
---|
26 | class btTransform { |
---|
27 | |
---|
28 | |
---|
29 | public: |
---|
30 | |
---|
31 | |
---|
32 | btTransform() {} |
---|
33 | |
---|
34 | explicit SIMD_FORCE_INLINE btTransform(const btQuaternion& q, |
---|
35 | const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0))) |
---|
36 | : m_basis(q), |
---|
37 | m_origin(c) |
---|
38 | {} |
---|
39 | |
---|
40 | explicit SIMD_FORCE_INLINE btTransform(const btMatrix3x3& b, |
---|
41 | const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0))) |
---|
42 | : m_basis(b), |
---|
43 | m_origin(c) |
---|
44 | {} |
---|
45 | |
---|
46 | SIMD_FORCE_INLINE btTransform (const btTransform& other) |
---|
47 | : m_basis(other.m_basis), |
---|
48 | m_origin(other.m_origin) |
---|
49 | { |
---|
50 | } |
---|
51 | |
---|
52 | SIMD_FORCE_INLINE btTransform& operator=(const btTransform& other) |
---|
53 | { |
---|
54 | m_basis = other.m_basis; |
---|
55 | m_origin = other.m_origin; |
---|
56 | return *this; |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | SIMD_FORCE_INLINE void mult(const btTransform& t1, const btTransform& t2) { |
---|
61 | m_basis = t1.m_basis * t2.m_basis; |
---|
62 | m_origin = t1(t2.m_origin); |
---|
63 | } |
---|
64 | |
---|
65 | /* void multInverseLeft(const btTransform& t1, const btTransform& t2) { |
---|
66 | btVector3 v = t2.m_origin - t1.m_origin; |
---|
67 | m_basis = btMultTransposeLeft(t1.m_basis, t2.m_basis); |
---|
68 | m_origin = v * t1.m_basis; |
---|
69 | } |
---|
70 | */ |
---|
71 | |
---|
72 | |
---|
73 | SIMD_FORCE_INLINE btVector3 operator()(const btVector3& x) const |
---|
74 | { |
---|
75 | return btVector3(m_basis[0].dot(x) + m_origin.x(), |
---|
76 | m_basis[1].dot(x) + m_origin.y(), |
---|
77 | m_basis[2].dot(x) + m_origin.z()); |
---|
78 | } |
---|
79 | |
---|
80 | SIMD_FORCE_INLINE btVector3 operator*(const btVector3& x) const |
---|
81 | { |
---|
82 | return (*this)(x); |
---|
83 | } |
---|
84 | |
---|
85 | SIMD_FORCE_INLINE btMatrix3x3& getBasis() { return m_basis; } |
---|
86 | SIMD_FORCE_INLINE const btMatrix3x3& getBasis() const { return m_basis; } |
---|
87 | |
---|
88 | SIMD_FORCE_INLINE btVector3& getOrigin() { return m_origin; } |
---|
89 | SIMD_FORCE_INLINE const btVector3& getOrigin() const { return m_origin; } |
---|
90 | |
---|
91 | btQuaternion getRotation() const { |
---|
92 | btQuaternion q; |
---|
93 | m_basis.getRotation(q); |
---|
94 | return q; |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | void setFromOpenGLMatrix(const btScalar *m) |
---|
99 | { |
---|
100 | m_basis.setFromOpenGLSubMatrix(m); |
---|
101 | m_origin.setValue(m[12],m[13],m[14]); |
---|
102 | } |
---|
103 | |
---|
104 | void getOpenGLMatrix(btScalar *m) const |
---|
105 | { |
---|
106 | m_basis.getOpenGLSubMatrix(m); |
---|
107 | m[12] = m_origin.x(); |
---|
108 | m[13] = m_origin.y(); |
---|
109 | m[14] = m_origin.z(); |
---|
110 | m[15] = btScalar(1.0); |
---|
111 | } |
---|
112 | |
---|
113 | SIMD_FORCE_INLINE void setOrigin(const btVector3& origin) |
---|
114 | { |
---|
115 | m_origin = origin; |
---|
116 | } |
---|
117 | |
---|
118 | SIMD_FORCE_INLINE btVector3 invXform(const btVector3& inVec) const; |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | SIMD_FORCE_INLINE void setBasis(const btMatrix3x3& basis) |
---|
123 | { |
---|
124 | m_basis = basis; |
---|
125 | } |
---|
126 | |
---|
127 | SIMD_FORCE_INLINE void setRotation(const btQuaternion& q) |
---|
128 | { |
---|
129 | m_basis.setRotation(q); |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | |
---|
134 | void setIdentity() |
---|
135 | { |
---|
136 | m_basis.setIdentity(); |
---|
137 | m_origin.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | btTransform& operator*=(const btTransform& t) |
---|
142 | { |
---|
143 | m_origin += m_basis * t.m_origin; |
---|
144 | m_basis *= t.m_basis; |
---|
145 | return *this; |
---|
146 | } |
---|
147 | |
---|
148 | btTransform inverse() const |
---|
149 | { |
---|
150 | btMatrix3x3 inv = m_basis.transpose(); |
---|
151 | return btTransform(inv, inv * -m_origin); |
---|
152 | } |
---|
153 | |
---|
154 | btTransform inverseTimes(const btTransform& t) const; |
---|
155 | |
---|
156 | btTransform operator*(const btTransform& t) const; |
---|
157 | |
---|
158 | static btTransform getIdentity() |
---|
159 | { |
---|
160 | btTransform tr; |
---|
161 | tr.setIdentity(); |
---|
162 | return tr; |
---|
163 | } |
---|
164 | |
---|
165 | private: |
---|
166 | |
---|
167 | btMatrix3x3 m_basis; |
---|
168 | btVector3 m_origin; |
---|
169 | }; |
---|
170 | |
---|
171 | |
---|
172 | SIMD_FORCE_INLINE btVector3 |
---|
173 | btTransform::invXform(const btVector3& inVec) const |
---|
174 | { |
---|
175 | btVector3 v = inVec - m_origin; |
---|
176 | return (m_basis.transpose() * v); |
---|
177 | } |
---|
178 | |
---|
179 | SIMD_FORCE_INLINE btTransform |
---|
180 | btTransform::inverseTimes(const btTransform& t) const |
---|
181 | { |
---|
182 | btVector3 v = t.getOrigin() - m_origin; |
---|
183 | return btTransform(m_basis.transposeTimes(t.m_basis), |
---|
184 | v * m_basis); |
---|
185 | } |
---|
186 | |
---|
187 | SIMD_FORCE_INLINE btTransform |
---|
188 | btTransform::operator*(const btTransform& t) const |
---|
189 | { |
---|
190 | return btTransform(m_basis * t.m_basis, |
---|
191 | (*this)(t.m_origin)); |
---|
192 | } |
---|
193 | |
---|
194 | SIMD_FORCE_INLINE bool operator==(const btTransform& t1, const btTransform& t2) |
---|
195 | { |
---|
196 | return ( t1.getBasis() == t2.getBasis() && |
---|
197 | t1.getOrigin() == t2.getOrigin() ); |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | #endif |
---|
202 | |
---|
203 | |
---|
204 | |
---|
205 | |
---|
206 | |
---|
207 | |
---|