Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef tfTransform_H
00018 #define tfTransform_H
00019
00020
00021 #include "Matrix3x3.h"
00022 #include "LinearMath/btTransform.h"
00023
00024 namespace tf
00025 {
00026
00027 #define TransformData TransformDoubleData
00028
00029
00032 class Transform {
00033
00035 Matrix3x3 m_basis;
00037 Vector3 m_origin;
00038
00039 public:
00040
00042 Transform() {}
00046 explicit TFSIMD_FORCE_INLINE Transform(const Quaternion& q,
00047 const Vector3& c = Vector3(tfScalar(0), tfScalar(0), tfScalar(0)))
00048 : m_basis(q),
00049 m_origin(c)
00050 {}
00051
00055 explicit TFSIMD_FORCE_INLINE Transform(const Matrix3x3& b,
00056 const Vector3& c = Vector3(tfScalar(0), tfScalar(0), tfScalar(0)))
00057 : m_basis(b),
00058 m_origin(c)
00059 {}
00061 TFSIMD_FORCE_INLINE Transform (const Transform& other)
00062 : m_basis(other.m_basis),
00063 m_origin(other.m_origin)
00064 {
00065 }
00067 TFSIMD_FORCE_INLINE Transform (const btTransform& other)
00068 : m_basis(other.getBasis()),
00069 m_origin(other.getOrigin())
00070 {
00071 }
00073 TFSIMD_FORCE_INLINE Transform& operator=(const Transform& other)
00074 {
00075 m_basis = other.m_basis;
00076 m_origin = other.m_origin;
00077 return *this;
00078 }
00079
00081 TFSIMD_FORCE_INLINE Transform& operator=(const btTransform& other)
00082 {
00083 m_basis = other.getBasis();
00084 m_origin = other.getOrigin();
00085 return *this;
00086 }
00087
00088 TFSIMD_FORCE_INLINE btTransform as_bt(void) const __attribute__((deprecated)) { return asBt(); };
00090 TFSIMD_FORCE_INLINE btTransform asBt(void) const
00091 {
00092 return btTransform(m_basis.asBt(), m_origin.asBt());
00093 }
00094
00095
00100 TFSIMD_FORCE_INLINE void mult(const Transform& t1, const Transform& t2) {
00101 m_basis = t1.m_basis * t2.m_basis;
00102 m_origin = t1(t2.m_origin);
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00113 TFSIMD_FORCE_INLINE Vector3 operator()(const Vector3& x) const
00114 {
00115 return Vector3(m_basis[0].dot(x) + m_origin.x(),
00116 m_basis[1].dot(x) + m_origin.y(),
00117 m_basis[2].dot(x) + m_origin.z());
00118 }
00119
00121 TFSIMD_FORCE_INLINE Vector3 operator*(const Vector3& x) const
00122 {
00123 return (*this)(x);
00124 }
00125
00127 TFSIMD_FORCE_INLINE Quaternion operator*(const Quaternion& q) const
00128 {
00129 return getRotation() * q;
00130 }
00131
00133 TFSIMD_FORCE_INLINE Matrix3x3& getBasis() { return m_basis; }
00135 TFSIMD_FORCE_INLINE const Matrix3x3& getBasis() const { return m_basis; }
00136
00138 TFSIMD_FORCE_INLINE Vector3& getOrigin() { return m_origin; }
00140 TFSIMD_FORCE_INLINE const Vector3& getOrigin() const { return m_origin; }
00141
00143 Quaternion getRotation() const {
00144 Quaternion q;
00145 m_basis.getRotation(q);
00146 return q;
00147 }
00148
00149
00152 void setFromOpenGLMatrix(const tfScalar *m)
00153 {
00154 m_basis.setFromOpenGLSubMatrix(m);
00155 m_origin.setValue(m[12],m[13],m[14]);
00156 }
00157
00160 void getOpenGLMatrix(tfScalar *m) const
00161 {
00162 m_basis.getOpenGLSubMatrix(m);
00163 m[12] = m_origin.x();
00164 m[13] = m_origin.y();
00165 m[14] = m_origin.z();
00166 m[15] = tfScalar(1.0);
00167 }
00168
00171 TFSIMD_FORCE_INLINE void setOrigin(const Vector3& origin)
00172 {
00173 m_origin = origin;
00174 }
00175
00176 TFSIMD_FORCE_INLINE Vector3 invXform(const Vector3& inVec) const;
00177
00178
00180 TFSIMD_FORCE_INLINE void setBasis(const Matrix3x3& basis)
00181 {
00182 m_basis = basis;
00183 }
00184
00186 TFSIMD_FORCE_INLINE void setRotation(const Quaternion& q)
00187 {
00188 m_basis.setRotation(q);
00189 }
00190
00191
00193 void setIdentity()
00194 {
00195 m_basis.setIdentity();
00196 m_origin.setValue(tfScalar(0.0), tfScalar(0.0), tfScalar(0.0));
00197 }
00198
00201 Transform& operator*=(const Transform& t)
00202 {
00203 m_origin += m_basis * t.m_origin;
00204 m_basis *= t.m_basis;
00205 return *this;
00206 }
00207
00209 Transform inverse() const
00210 {
00211 Matrix3x3 inv = m_basis.transpose();
00212 return Transform(inv, inv * -m_origin);
00213 }
00214
00218 Transform inverseTimes(const Transform& t) const;
00219
00221 Transform operator*(const Transform& t) const;
00222
00224 static const Transform& getIdentity()
00225 {
00226 static const Transform identityTransform(Matrix3x3::getIdentity());
00227 return identityTransform;
00228 }
00229
00230 void serialize(struct TransformData& dataOut) const;
00231
00232 void serializeFloat(struct TransformFloatData& dataOut) const;
00233
00234 void deSerialize(const struct TransformData& dataIn);
00235
00236 void deSerializeDouble(const struct TransformDoubleData& dataIn);
00237
00238 void deSerializeFloat(const struct TransformFloatData& dataIn);
00239
00240 };
00241
00242
00243 TFSIMD_FORCE_INLINE Vector3
00244 Transform::invXform(const Vector3& inVec) const
00245 {
00246 Vector3 v = inVec - m_origin;
00247 return (m_basis.transpose() * v);
00248 }
00249
00250 TFSIMD_FORCE_INLINE Transform
00251 Transform::inverseTimes(const Transform& t) const
00252 {
00253 Vector3 v = t.getOrigin() - m_origin;
00254 return Transform(m_basis.transposeTimes(t.m_basis),
00255 v * m_basis);
00256 }
00257
00258 TFSIMD_FORCE_INLINE Transform
00259 Transform::operator*(const Transform& t) const
00260 {
00261 return Transform(m_basis * t.m_basis,
00262 (*this)(t.m_origin));
00263 }
00264
00266 TFSIMD_FORCE_INLINE bool operator==(const Transform& t1, const Transform& t2)
00267 {
00268 return ( t1.getBasis() == t2.getBasis() &&
00269 t1.getOrigin() == t2.getOrigin() );
00270 }
00271
00272
00274 struct TransformFloatData
00275 {
00276 Matrix3x3FloatData m_basis;
00277 Vector3FloatData m_origin;
00278 };
00279
00280 struct TransformDoubleData
00281 {
00282 Matrix3x3DoubleData m_basis;
00283 Vector3DoubleData m_origin;
00284 };
00285
00286
00287
00288 TFSIMD_FORCE_INLINE void Transform::serialize(TransformData& dataOut) const
00289 {
00290 m_basis.serialize(dataOut.m_basis);
00291 m_origin.serialize(dataOut.m_origin);
00292 }
00293
00294 TFSIMD_FORCE_INLINE void Transform::serializeFloat(TransformFloatData& dataOut) const
00295 {
00296 m_basis.serializeFloat(dataOut.m_basis);
00297 m_origin.serializeFloat(dataOut.m_origin);
00298 }
00299
00300
00301 TFSIMD_FORCE_INLINE void Transform::deSerialize(const TransformData& dataIn)
00302 {
00303 m_basis.deSerialize(dataIn.m_basis);
00304 m_origin.deSerialize(dataIn.m_origin);
00305 }
00306
00307 TFSIMD_FORCE_INLINE void Transform::deSerializeFloat(const TransformFloatData& dataIn)
00308 {
00309 m_basis.deSerializeFloat(dataIn.m_basis);
00310 m_origin.deSerializeFloat(dataIn.m_origin);
00311 }
00312
00313 TFSIMD_FORCE_INLINE void Transform::deSerializeDouble(const TransformDoubleData& dataIn)
00314 {
00315 m_basis.deSerializeDouble(dataIn.m_basis);
00316 m_origin.deSerializeDouble(dataIn.m_origin);
00317 }
00318
00319 }
00320
00321 #endif
00322
00323
00324
00325
00326
00327