Blender V2.61 - r43446
|
00001 /* 00002 Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/ 00003 00004 This software is provided 'as-is', without any express or implied warranty. 00005 In no event will the authors be held liable for any damages arising from the use of this software. 00006 Permission is granted to anyone to use this software for any purpose, 00007 including commercial applications, and to alter it and redistribute it freely, 00008 subject to the following restrictions: 00009 00010 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. 00011 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 00012 3. This notice may not be removed or altered from any source distribution. 00013 */ 00014 00015 00016 00017 #ifndef btTransform_H 00018 #define btTransform_H 00019 00020 00021 #include "btMatrix3x3.h" 00022 00023 #ifdef BT_USE_DOUBLE_PRECISION 00024 #define btTransformData btTransformDoubleData 00025 #else 00026 #define btTransformData btTransformFloatData 00027 #endif 00028 00029 00030 00031 00034 class btTransform { 00035 00037 btMatrix3x3 m_basis; 00039 btVector3 m_origin; 00040 00041 public: 00042 00044 btTransform() {} 00048 explicit SIMD_FORCE_INLINE btTransform(const btQuaternion& q, 00049 const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0))) 00050 : m_basis(q), 00051 m_origin(c) 00052 {} 00053 00057 explicit SIMD_FORCE_INLINE btTransform(const btMatrix3x3& b, 00058 const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0))) 00059 : m_basis(b), 00060 m_origin(c) 00061 {} 00063 SIMD_FORCE_INLINE btTransform (const btTransform& other) 00064 : m_basis(other.m_basis), 00065 m_origin(other.m_origin) 00066 { 00067 } 00069 SIMD_FORCE_INLINE btTransform& operator=(const btTransform& other) 00070 { 00071 m_basis = other.m_basis; 00072 m_origin = other.m_origin; 00073 return *this; 00074 } 00075 00076 00081 SIMD_FORCE_INLINE void mult(const btTransform& t1, const btTransform& t2) { 00082 m_basis = t1.m_basis * t2.m_basis; 00083 m_origin = t1(t2.m_origin); 00084 } 00085 00086 /* void multInverseLeft(const btTransform& t1, const btTransform& t2) { 00087 btVector3 v = t2.m_origin - t1.m_origin; 00088 m_basis = btMultTransposeLeft(t1.m_basis, t2.m_basis); 00089 m_origin = v * t1.m_basis; 00090 } 00091 */ 00092 00094 SIMD_FORCE_INLINE btVector3 operator()(const btVector3& x) const 00095 { 00096 return btVector3(m_basis[0].dot(x) + m_origin.x(), 00097 m_basis[1].dot(x) + m_origin.y(), 00098 m_basis[2].dot(x) + m_origin.z()); 00099 } 00100 00102 SIMD_FORCE_INLINE btVector3 operator*(const btVector3& x) const 00103 { 00104 return (*this)(x); 00105 } 00106 00108 SIMD_FORCE_INLINE btQuaternion operator*(const btQuaternion& q) const 00109 { 00110 return getRotation() * q; 00111 } 00112 00114 SIMD_FORCE_INLINE btMatrix3x3& getBasis() { return m_basis; } 00116 SIMD_FORCE_INLINE const btMatrix3x3& getBasis() const { return m_basis; } 00117 00119 SIMD_FORCE_INLINE btVector3& getOrigin() { return m_origin; } 00121 SIMD_FORCE_INLINE const btVector3& getOrigin() const { return m_origin; } 00122 00124 btQuaternion getRotation() const { 00125 btQuaternion q; 00126 m_basis.getRotation(q); 00127 return q; 00128 } 00129 00130 00133 void setFromOpenGLMatrix(const btScalar *m) 00134 { 00135 m_basis.setFromOpenGLSubMatrix(m); 00136 m_origin.setValue(m[12],m[13],m[14]); 00137 } 00138 00141 void getOpenGLMatrix(btScalar *m) const 00142 { 00143 m_basis.getOpenGLSubMatrix(m); 00144 m[12] = m_origin.x(); 00145 m[13] = m_origin.y(); 00146 m[14] = m_origin.z(); 00147 m[15] = btScalar(1.0); 00148 } 00149 00152 SIMD_FORCE_INLINE void setOrigin(const btVector3& origin) 00153 { 00154 m_origin = origin; 00155 } 00156 00157 SIMD_FORCE_INLINE btVector3 invXform(const btVector3& inVec) const; 00158 00159 00161 SIMD_FORCE_INLINE void setBasis(const btMatrix3x3& basis) 00162 { 00163 m_basis = basis; 00164 } 00165 00167 SIMD_FORCE_INLINE void setRotation(const btQuaternion& q) 00168 { 00169 m_basis.setRotation(q); 00170 } 00171 00172 00174 void setIdentity() 00175 { 00176 m_basis.setIdentity(); 00177 m_origin.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); 00178 } 00179 00182 btTransform& operator*=(const btTransform& t) 00183 { 00184 m_origin += m_basis * t.m_origin; 00185 m_basis *= t.m_basis; 00186 return *this; 00187 } 00188 00190 btTransform inverse() const 00191 { 00192 btMatrix3x3 inv = m_basis.transpose(); 00193 return btTransform(inv, inv * -m_origin); 00194 } 00195 00199 btTransform inverseTimes(const btTransform& t) const; 00200 00202 btTransform operator*(const btTransform& t) const; 00203 00205 static const btTransform& getIdentity() 00206 { 00207 static const btTransform identityTransform(btMatrix3x3::getIdentity()); 00208 return identityTransform; 00209 } 00210 00211 void serialize(struct btTransformData& dataOut) const; 00212 00213 void serializeFloat(struct btTransformFloatData& dataOut) const; 00214 00215 void deSerialize(const struct btTransformData& dataIn); 00216 00217 void deSerializeDouble(const struct btTransformDoubleData& dataIn); 00218 00219 void deSerializeFloat(const struct btTransformFloatData& dataIn); 00220 00221 }; 00222 00223 00224 SIMD_FORCE_INLINE btVector3 00225 btTransform::invXform(const btVector3& inVec) const 00226 { 00227 btVector3 v = inVec - m_origin; 00228 return (m_basis.transpose() * v); 00229 } 00230 00231 SIMD_FORCE_INLINE btTransform 00232 btTransform::inverseTimes(const btTransform& t) const 00233 { 00234 btVector3 v = t.getOrigin() - m_origin; 00235 return btTransform(m_basis.transposeTimes(t.m_basis), 00236 v * m_basis); 00237 } 00238 00239 SIMD_FORCE_INLINE btTransform 00240 btTransform::operator*(const btTransform& t) const 00241 { 00242 return btTransform(m_basis * t.m_basis, 00243 (*this)(t.m_origin)); 00244 } 00245 00247 SIMD_FORCE_INLINE bool operator==(const btTransform& t1, const btTransform& t2) 00248 { 00249 return ( t1.getBasis() == t2.getBasis() && 00250 t1.getOrigin() == t2.getOrigin() ); 00251 } 00252 00253 00255 struct btTransformFloatData 00256 { 00257 btMatrix3x3FloatData m_basis; 00258 btVector3FloatData m_origin; 00259 }; 00260 00261 struct btTransformDoubleData 00262 { 00263 btMatrix3x3DoubleData m_basis; 00264 btVector3DoubleData m_origin; 00265 }; 00266 00267 00268 00269 SIMD_FORCE_INLINE void btTransform::serialize(btTransformData& dataOut) const 00270 { 00271 m_basis.serialize(dataOut.m_basis); 00272 m_origin.serialize(dataOut.m_origin); 00273 } 00274 00275 SIMD_FORCE_INLINE void btTransform::serializeFloat(btTransformFloatData& dataOut) const 00276 { 00277 m_basis.serializeFloat(dataOut.m_basis); 00278 m_origin.serializeFloat(dataOut.m_origin); 00279 } 00280 00281 00282 SIMD_FORCE_INLINE void btTransform::deSerialize(const btTransformData& dataIn) 00283 { 00284 m_basis.deSerialize(dataIn.m_basis); 00285 m_origin.deSerialize(dataIn.m_origin); 00286 } 00287 00288 SIMD_FORCE_INLINE void btTransform::deSerializeFloat(const btTransformFloatData& dataIn) 00289 { 00290 m_basis.deSerializeFloat(dataIn.m_basis); 00291 m_origin.deSerializeFloat(dataIn.m_origin); 00292 } 00293 00294 SIMD_FORCE_INLINE void btTransform::deSerializeDouble(const btTransformDoubleData& dataIn) 00295 { 00296 m_basis.deSerializeDouble(dataIn.m_basis); 00297 m_origin.deSerializeDouble(dataIn.m_origin); 00298 } 00299 00300 00301 #endif 00302 00303 00304 00305 00306 00307