Back to index

supertuxkart  0.5+dfsg1
btTransform.h
Go to the documentation of this file.
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 #include "btVector3.h"
00021 #include "btMatrix3x3.h"
00022 
00023 
00025 class btTransform {
00026        
00027 
00028 public:
00029        
00030        
00031        btTransform() {}
00032 
00033        explicit SIMD_FORCE_INLINE btTransform(const btQuaternion& q, 
00034               const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0))) 
00035               : m_basis(q),
00036               m_origin(c)
00037        {}
00038 
00039        explicit SIMD_FORCE_INLINE btTransform(const btMatrix3x3& b, 
00040               const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0)))
00041               : m_basis(b),
00042               m_origin(c)
00043        {}
00044 
00045        SIMD_FORCE_INLINE btTransform (const btTransform& other)
00046               : m_basis(other.m_basis),
00047               m_origin(other.m_origin)
00048        {
00049        }
00050 
00051        SIMD_FORCE_INLINE btTransform& operator=(const btTransform& other)
00052        {
00053               m_basis = other.m_basis;
00054               m_origin = other.m_origin;
00055               return *this;
00056        }
00057 
00058 
00059               SIMD_FORCE_INLINE void mult(const btTransform& t1, const btTransform& t2) {
00060                      m_basis = t1.m_basis * t2.m_basis;
00061                      m_origin = t1(t2.m_origin);
00062               }
00063 
00064 /*            void multInverseLeft(const btTransform& t1, const btTransform& t2) {
00065                      btVector3 v = t2.m_origin - t1.m_origin;
00066                      m_basis = btMultTransposeLeft(t1.m_basis, t2.m_basis);
00067                      m_origin = v * t1.m_basis;
00068               }
00069               */
00070 
00071 
00072        SIMD_FORCE_INLINE btVector3 operator()(const btVector3& x) const
00073        {
00074               return btVector3(m_basis[0].dot(x) + m_origin.x(), 
00075                      m_basis[1].dot(x) + m_origin.y(), 
00076                      m_basis[2].dot(x) + m_origin.z());
00077        }
00078 
00079        SIMD_FORCE_INLINE btVector3 operator*(const btVector3& x) const
00080        {
00081               return (*this)(x);
00082        }
00083 
00084        SIMD_FORCE_INLINE btMatrix3x3&       getBasis()          { return m_basis; }
00085        SIMD_FORCE_INLINE const btMatrix3x3& getBasis()    const { return m_basis; }
00086 
00087        SIMD_FORCE_INLINE btVector3&         getOrigin()         { return m_origin; }
00088        SIMD_FORCE_INLINE const btVector3&   getOrigin()   const { return m_origin; }
00089 
00090        btQuaternion getRotation() const { 
00091               btQuaternion q;
00092               m_basis.getRotation(q);
00093               return q;
00094        }
00095        
00096        
00097        void setFromOpenGLMatrix(const btScalar *m)
00098        {
00099               m_basis.setFromOpenGLSubMatrix(m);
00100               m_origin.setValue(m[12],m[13],m[14]);
00101        }
00102 
00103        void getOpenGLMatrix(btScalar *m) const 
00104        {
00105               m_basis.getOpenGLSubMatrix(m);
00106               m[12] = m_origin.x();
00107               m[13] = m_origin.y();
00108               m[14] = m_origin.z();
00109               m[15] = btScalar(1.0);
00110        }
00111 
00112        SIMD_FORCE_INLINE void setOrigin(const btVector3& origin) 
00113        { 
00114               m_origin = origin;
00115        }
00116 
00117        SIMD_FORCE_INLINE btVector3 invXform(const btVector3& inVec) const;
00118 
00119 
00120 
00121        SIMD_FORCE_INLINE void setBasis(const btMatrix3x3& basis)
00122        { 
00123               m_basis = basis;
00124        }
00125 
00126        SIMD_FORCE_INLINE void setRotation(const btQuaternion& q)
00127        {
00128               m_basis.setRotation(q);
00129        }
00130 
00131 
00132 
00133        void setIdentity()
00134        {
00135               m_basis.setIdentity();
00136               m_origin.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));
00137        }
00138 
00139        
00140        btTransform& operator*=(const btTransform& t) 
00141        {
00142               m_origin += m_basis * t.m_origin;
00143               m_basis *= t.m_basis;
00144               return *this;
00145        }
00146 
00147        btTransform inverse() const
00148        { 
00149               btMatrix3x3 inv = m_basis.transpose();
00150               return btTransform(inv, inv * -m_origin);
00151        }
00152 
00153        btTransform inverseTimes(const btTransform& t) const;  
00154 
00155        btTransform operator*(const btTransform& t) const;
00156 
00157        static btTransform   getIdentity()
00158        {
00159               btTransform tr;
00160               tr.setIdentity();
00161               return tr;
00162        }
00163        
00164 private:
00165 
00166        btMatrix3x3 m_basis;
00167        btVector3   m_origin;
00168 };
00169 
00170 
00171 SIMD_FORCE_INLINE btVector3
00172 btTransform::invXform(const btVector3& inVec) const
00173 {
00174        btVector3 v = inVec - m_origin;
00175        return (m_basis.transpose() * v);
00176 }
00177 
00178 SIMD_FORCE_INLINE btTransform 
00179 btTransform::inverseTimes(const btTransform& t) const  
00180 {
00181        btVector3 v = t.getOrigin() - m_origin;
00182               return btTransform(m_basis.transposeTimes(t.m_basis),
00183                      v * m_basis);
00184 }
00185 
00186 SIMD_FORCE_INLINE btTransform 
00187 btTransform::operator*(const btTransform& t) const
00188 {
00189        return btTransform(m_basis * t.m_basis, 
00190               (*this)(t.m_origin));
00191 }      
00192 
00193 
00194 
00195 #endif
00196 
00197 
00198 
00199 
00200