Transform.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 tfTransform_H
00018 #define tfTransform_H
00019 
00020 
00021 #include "Matrix3x3.h"
00022 
00023 namespace tf
00024 {
00025 
00026 #define TransformData TransformDoubleData
00027 
00028 
00031 class Transform {
00032         
00034         Matrix3x3 m_basis;
00036         Vector3   m_origin;
00037 
00038 public:
00039         
00041         Transform() {}
00045         explicit TFSIMD_FORCE_INLINE Transform(const Quaternion& q, 
00046                 const Vector3& c = Vector3(tfScalar(0), tfScalar(0), tfScalar(0))) 
00047                 : m_basis(q),
00048                 m_origin(c)
00049         {}
00050 
00054         explicit TFSIMD_FORCE_INLINE Transform(const Matrix3x3& b, 
00055                 const Vector3& c = Vector3(tfScalar(0), tfScalar(0), tfScalar(0)))
00056                 : m_basis(b),
00057                 m_origin(c)
00058         {}
00060         TFSIMD_FORCE_INLINE Transform (const Transform& other)
00061                 : m_basis(other.m_basis),
00062                 m_origin(other.m_origin)
00063         {
00064         }
00066         TFSIMD_FORCE_INLINE Transform& operator=(const Transform& other)
00067         {
00068                 m_basis = other.m_basis;
00069                 m_origin = other.m_origin;
00070                 return *this;
00071         }
00072 
00077                 TFSIMD_FORCE_INLINE void mult(const Transform& t1, const Transform& t2) {
00078                         m_basis = t1.m_basis * t2.m_basis;
00079                         m_origin = t1(t2.m_origin);
00080                 }
00081 
00082 /*              void multInverseLeft(const Transform& t1, const Transform& t2) {
00083                         Vector3 v = t2.m_origin - t1.m_origin;
00084                         m_basis = tfMultTransposeLeft(t1.m_basis, t2.m_basis);
00085                         m_origin = v * t1.m_basis;
00086                 }
00087                 */
00088 
00090         TFSIMD_FORCE_INLINE Vector3 operator()(const Vector3& x) const
00091         {
00092                 return Vector3(m_basis[0].dot(x) + m_origin.x(), 
00093                         m_basis[1].dot(x) + m_origin.y(), 
00094                         m_basis[2].dot(x) + m_origin.z());
00095         }
00096 
00098         TFSIMD_FORCE_INLINE Vector3 operator*(const Vector3& x) const
00099         {
00100                 return (*this)(x);
00101         }
00102 
00104         TFSIMD_FORCE_INLINE Quaternion operator*(const Quaternion& q) const
00105         {
00106                 return getRotation() * q;
00107         }
00108 
00110         TFSIMD_FORCE_INLINE Matrix3x3&       getBasis()          { return m_basis; }
00112         TFSIMD_FORCE_INLINE const Matrix3x3& getBasis()    const { return m_basis; }
00113 
00115         TFSIMD_FORCE_INLINE Vector3&         getOrigin()         { return m_origin; }
00117         TFSIMD_FORCE_INLINE const Vector3&   getOrigin()   const { return m_origin; }
00118 
00120         Quaternion getRotation() const { 
00121                 Quaternion q;
00122                 m_basis.getRotation(q);
00123                 return q;
00124         }
00125         
00126         
00129         void setFromOpenGLMatrix(const tfScalar *m)
00130         {
00131                 m_basis.setFromOpenGLSubMatrix(m);
00132                 m_origin.setValue(m[12],m[13],m[14]);
00133         }
00134 
00137         void getOpenGLMatrix(tfScalar *m) const 
00138         {
00139                 m_basis.getOpenGLSubMatrix(m);
00140                 m[12] = m_origin.x();
00141                 m[13] = m_origin.y();
00142                 m[14] = m_origin.z();
00143                 m[15] = tfScalar(1.0);
00144         }
00145 
00148         TFSIMD_FORCE_INLINE void setOrigin(const Vector3& origin) 
00149         { 
00150                 m_origin = origin;
00151         }
00152 
00153         TFSIMD_FORCE_INLINE Vector3 invXform(const Vector3& inVec) const;
00154 
00155 
00157         TFSIMD_FORCE_INLINE void setBasis(const Matrix3x3& basis)
00158         { 
00159                 m_basis = basis;
00160         }
00161 
00163         TFSIMD_FORCE_INLINE void setRotation(const Quaternion& q)
00164         {
00165                 m_basis.setRotation(q);
00166         }
00167 
00168 
00170         void setIdentity()
00171         {
00172                 m_basis.setIdentity();
00173                 m_origin.setValue(tfScalar(0.0), tfScalar(0.0), tfScalar(0.0));
00174         }
00175 
00178         Transform& operator*=(const Transform& t) 
00179         {
00180                 m_origin += m_basis * t.m_origin;
00181                 m_basis *= t.m_basis;
00182                 return *this;
00183         }
00184 
00186         Transform inverse() const
00187         { 
00188                 Matrix3x3 inv = m_basis.transpose();
00189                 return Transform(inv, inv * -m_origin);
00190         }
00191 
00195         Transform inverseTimes(const Transform& t) const;  
00196 
00198         Transform operator*(const Transform& t) const;
00199 
00201         static const Transform& getIdentity()
00202         {
00203                 static const Transform identityTransform(Matrix3x3::getIdentity());
00204                 return identityTransform;
00205         }
00206 
00207         void    serialize(struct        TransformData& dataOut) const;
00208 
00209         void    serializeFloat(struct   TransformFloatData& dataOut) const;
00210 
00211         void    deSerialize(const struct        TransformData& dataIn);
00212 
00213         void    deSerializeDouble(const struct  TransformDoubleData& dataIn);
00214 
00215         void    deSerializeFloat(const struct   TransformFloatData& dataIn);
00216 
00217 };
00218 
00219 
00220 TFSIMD_FORCE_INLINE Vector3
00221 Transform::invXform(const Vector3& inVec) const
00222 {
00223         Vector3 v = inVec - m_origin;
00224         return (m_basis.transpose() * v);
00225 }
00226 
00227 TFSIMD_FORCE_INLINE Transform 
00228 Transform::inverseTimes(const Transform& t) const  
00229 {
00230         Vector3 v = t.getOrigin() - m_origin;
00231                 return Transform(m_basis.transposeTimes(t.m_basis),
00232                         v * m_basis);
00233 }
00234 
00235 TFSIMD_FORCE_INLINE Transform 
00236 Transform::operator*(const Transform& t) const
00237 {
00238         return Transform(m_basis * t.m_basis, 
00239                 (*this)(t.m_origin));
00240 }
00241 
00243 TFSIMD_FORCE_INLINE bool operator==(const Transform& t1, const Transform& t2)
00244 {
00245    return ( t1.getBasis()  == t2.getBasis() &&
00246             t1.getOrigin() == t2.getOrigin() );
00247 }
00248 
00249 
00251 struct  TransformFloatData
00252 {
00253         Matrix3x3FloatData      m_basis;
00254         Vector3FloatData        m_origin;
00255 };
00256 
00257 struct  TransformDoubleData
00258 {
00259         Matrix3x3DoubleData     m_basis;
00260         Vector3DoubleData       m_origin;
00261 };
00262 
00263 
00264 
00265 TFSIMD_FORCE_INLINE     void    Transform::serialize(TransformData& dataOut) const
00266 {
00267         m_basis.serialize(dataOut.m_basis);
00268         m_origin.serialize(dataOut.m_origin);
00269 }
00270 
00271 TFSIMD_FORCE_INLINE     void    Transform::serializeFloat(TransformFloatData& dataOut) const
00272 {
00273         m_basis.serializeFloat(dataOut.m_basis);
00274         m_origin.serializeFloat(dataOut.m_origin);
00275 }
00276 
00277 
00278 TFSIMD_FORCE_INLINE     void    Transform::deSerialize(const TransformData& dataIn)
00279 {
00280         m_basis.deSerialize(dataIn.m_basis);
00281         m_origin.deSerialize(dataIn.m_origin);
00282 }
00283 
00284 TFSIMD_FORCE_INLINE     void    Transform::deSerializeFloat(const TransformFloatData& dataIn)
00285 {
00286         m_basis.deSerializeFloat(dataIn.m_basis);
00287         m_origin.deSerializeFloat(dataIn.m_origin);
00288 }
00289 
00290 TFSIMD_FORCE_INLINE     void    Transform::deSerializeDouble(const TransformDoubleData& dataIn)
00291 {
00292         m_basis.deSerializeDouble(dataIn.m_basis);
00293         m_origin.deSerializeDouble(dataIn.m_origin);
00294 }
00295 
00296 }
00297 
00298 #endif
00299 
00300 
00301 
00302 
00303 
00304 


tf
Author(s): Tully Foote, Eitan Marder-Eppstein, Wim Meeussen
autogenerated on Sat Feb 24 2018 03:56:42