#ifndef __JOINTTRANSFORM_H__ #define __JOINTTRANSFORM_H__ /* =============================================================================== Joint Quaternion =============================================================================== */ class idJointQuat { public: idQuat q; idVec3 t; float w; }; // offsets for SIMD code #define JOINTQUAT_SIZE (8*4) // sizeof( idJointQuat ) #define JOINTQUAT_SIZE_SHIFT 5 // log2( sizeof( idJointQuat ) ) #define JOINTQUAT_Q_OFFSET (0*4) // offsetof( idJointQuat, q ) #define JOINTQUAT_T_OFFSET (4*4) // offsetof( idJointQuat, t ) assert_sizeof( idJointQuat, JOINTQUAT_SIZE ); assert_sizeof( idJointQuat, (1< epsilon ) { return false; } } return true; } ID_INLINE bool idJointMat::operator==( const idJointMat &a ) const { return Compare( a ); } ID_INLINE bool idJointMat::operator!=( const idJointMat &a ) const { return !Compare( a ); } ID_INLINE idMat3 idJointMat::ToMat3( void ) const { return idMat3( mat[0 * 4 + 0], mat[1 * 4 + 0], mat[2 * 4 + 0], mat[0 * 4 + 1], mat[1 * 4 + 1], mat[2 * 4 + 1], mat[0 * 4 + 2], mat[1 * 4 + 2], mat[2 * 4 + 2] ); } ID_INLINE idVec3 idJointMat::ToVec3( void ) const { return idVec3( mat[0 * 4 + 3], mat[1 * 4 + 3], mat[2 * 4 + 3] ); } ID_INLINE const float *idJointMat::ToFloatPtr( void ) const { return mat; } ID_INLINE float *idJointMat::ToFloatPtr( void ) { return mat; } ID_INLINE void idJointMat::Mul( idJointMat &result, const idJointMat &mat, const float s ) { result.mat[0 * 4 + 0] = s * mat.mat[0 * 4 + 0]; result.mat[0 * 4 + 1] = s * mat.mat[0 * 4 + 1]; result.mat[0 * 4 + 2] = s * mat.mat[0 * 4 + 2]; result.mat[0 * 4 + 3] = s * mat.mat[0 * 4 + 3]; result.mat[1 * 4 + 0] = s * mat.mat[1 * 4 + 0]; result.mat[1 * 4 + 1] = s * mat.mat[1 * 4 + 1]; result.mat[1 * 4 + 2] = s * mat.mat[1 * 4 + 2]; result.mat[1 * 4 + 3] = s * mat.mat[1 * 4 + 3]; result.mat[2 * 4 + 0] = s * mat.mat[2 * 4 + 0]; result.mat[2 * 4 + 1] = s * mat.mat[2 * 4 + 1]; result.mat[2 * 4 + 2] = s * mat.mat[2 * 4 + 2]; result.mat[2 * 4 + 3] = s * mat.mat[2 * 4 + 3]; } ID_INLINE void idJointMat::Mad( idJointMat &result, const idJointMat &mat, const float s ) { result.mat[0 * 4 + 0] += s * mat.mat[0 * 4 + 0]; result.mat[0 * 4 + 1] += s * mat.mat[0 * 4 + 1]; result.mat[0 * 4 + 2] += s * mat.mat[0 * 4 + 2]; result.mat[0 * 4 + 3] += s * mat.mat[0 * 4 + 3]; result.mat[1 * 4 + 0] += s * mat.mat[1 * 4 + 0]; result.mat[1 * 4 + 1] += s * mat.mat[1 * 4 + 1]; result.mat[1 * 4 + 2] += s * mat.mat[1 * 4 + 2]; result.mat[1 * 4 + 3] += s * mat.mat[1 * 4 + 3]; result.mat[2 * 4 + 0] += s * mat.mat[2 * 4 + 0]; result.mat[2 * 4 + 1] += s * mat.mat[2 * 4 + 1]; result.mat[2 * 4 + 2] += s * mat.mat[2 * 4 + 2]; result.mat[2 * 4 + 3] += s * mat.mat[2 * 4 + 3]; } ID_INLINE void idJointMat::Multiply( idJointMat &result, const idJointMat &m1, const idJointMat &m2 ) { result.mat[0 * 4 + 0] = m1.mat[0 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[0 * 4 + 1] * m2.mat[1 * 4 + 0] + m1.mat[0 * 4 + 2] * m2.mat[2 * 4 + 0]; result.mat[0 * 4 + 1] = m1.mat[0 * 4 + 0] * m2.mat[0 * 4 + 1] + m1.mat[0 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[0 * 4 + 2] * m2.mat[2 * 4 + 1]; result.mat[0 * 4 + 2] = m1.mat[0 * 4 + 0] * m2.mat[0 * 4 + 2] + m1.mat[0 * 4 + 1] * m2.mat[1 * 4 + 2] + m1.mat[0 * 4 + 2] * m2.mat[2 * 4 + 2]; result.mat[0 * 4 + 3] = m1.mat[0 * 4 + 0] * m2.mat[0 * 4 + 3] + m1.mat[0 * 4 + 1] * m2.mat[1 * 4 + 3] + m1.mat[0 * 4 + 2] * m2.mat[2 * 4 + 3] + m1.mat[0 * 4 + 3]; result.mat[1 * 4 + 0] = m1.mat[1 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[1 * 4 + 1] * m2.mat[1 * 4 + 0] + m1.mat[1 * 4 + 2] * m2.mat[2 * 4 + 0]; result.mat[1 * 4 + 1] = m1.mat[1 * 4 + 0] * m2.mat[0 * 4 + 1] + m1.mat[1 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[1 * 4 + 2] * m2.mat[2 * 4 + 1]; result.mat[1 * 4 + 2] = m1.mat[1 * 4 + 0] * m2.mat[0 * 4 + 2] + m1.mat[1 * 4 + 1] * m2.mat[1 * 4 + 2] + m1.mat[1 * 4 + 2] * m2.mat[2 * 4 + 2]; result.mat[1 * 4 + 3] = m1.mat[1 * 4 + 0] * m2.mat[0 * 4 + 3] + m1.mat[1 * 4 + 1] * m2.mat[1 * 4 + 3] + m1.mat[1 * 4 + 2] * m2.mat[2 * 4 + 3] + m1.mat[1 * 4 + 3]; result.mat[2 * 4 + 0] = m1.mat[2 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[2 * 4 + 1] * m2.mat[1 * 4 + 0] + m1.mat[2 * 4 + 2] * m2.mat[2 * 4 + 0]; result.mat[2 * 4 + 1] = m1.mat[2 * 4 + 0] * m2.mat[0 * 4 + 1] + m1.mat[2 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[2 * 4 + 2] * m2.mat[2 * 4 + 1]; result.mat[2 * 4 + 2] = m1.mat[2 * 4 + 0] * m2.mat[0 * 4 + 2] + m1.mat[2 * 4 + 1] * m2.mat[1 * 4 + 2] + m1.mat[2 * 4 + 2] * m2.mat[2 * 4 + 2]; result.mat[2 * 4 + 3] = m1.mat[2 * 4 + 0] * m2.mat[0 * 4 + 3] + m1.mat[2 * 4 + 1] * m2.mat[1 * 4 + 3] + m1.mat[2 * 4 + 2] * m2.mat[2 * 4 + 3] + m1.mat[2 * 4 + 3]; } ID_INLINE void idJointMat::InverseMultiply( idJointMat &result, const idJointMat &m1, const idJointMat &m2 ) { float dst[3]; result.mat[0 * 4 + 0] = m1.mat[0 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[0 * 4 + 1] * m2.mat[0 * 4 + 1] + m1.mat[0 * 4 + 2] * m2.mat[0 * 4 + 2]; result.mat[0 * 4 + 1] = m1.mat[0 * 4 + 0] * m2.mat[1 * 4 + 0] + m1.mat[0 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[0 * 4 + 2] * m2.mat[1 * 4 + 2]; result.mat[0 * 4 + 2] = m1.mat[0 * 4 + 0] * m2.mat[2 * 4 + 0] + m1.mat[0 * 4 + 1] * m2.mat[2 * 4 + 1] + m1.mat[0 * 4 + 2] * m2.mat[2 * 4 + 2]; result.mat[1 * 4 + 0] = m1.mat[1 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[1 * 4 + 1] * m2.mat[0 * 4 + 1] + m1.mat[1 * 4 + 2] * m2.mat[0 * 4 + 2]; result.mat[1 * 4 + 1] = m1.mat[1 * 4 + 0] * m2.mat[1 * 4 + 0] + m1.mat[1 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[1 * 4 + 2] * m2.mat[1 * 4 + 2]; result.mat[1 * 4 + 2] = m1.mat[1 * 4 + 0] * m2.mat[2 * 4 + 0] + m1.mat[1 * 4 + 1] * m2.mat[2 * 4 + 1] + m1.mat[1 * 4 + 2] * m2.mat[2 * 4 + 2]; result.mat[2 * 4 + 0] = m1.mat[2 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[2 * 4 + 1] * m2.mat[0 * 4 + 1] + m1.mat[2 * 4 + 2] * m2.mat[0 * 4 + 2]; result.mat[2 * 4 + 1] = m1.mat[2 * 4 + 0] * m2.mat[1 * 4 + 0] + m1.mat[2 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[2 * 4 + 2] * m2.mat[1 * 4 + 2]; result.mat[2 * 4 + 2] = m1.mat[2 * 4 + 0] * m2.mat[2 * 4 + 0] + m1.mat[2 * 4 + 1] * m2.mat[2 * 4 + 1] + m1.mat[2 * 4 + 2] * m2.mat[2 * 4 + 2]; dst[0] = - ( m2.mat[0 * 4 + 0] * m2.mat[0 * 4 + 3] + m2.mat[1 * 4 + 0] * m2.mat[1 * 4 + 3] + m2.mat[2 * 4 + 0] * m2.mat[2 * 4 + 3] ); dst[1] = - ( m2.mat[0 * 4 + 1] * m2.mat[0 * 4 + 3] + m2.mat[1 * 4 + 1] * m2.mat[1 * 4 + 3] + m2.mat[2 * 4 + 1] * m2.mat[2 * 4 + 3] ); dst[2] = - ( m2.mat[0 * 4 + 2] * m2.mat[0 * 4 + 3] + m2.mat[1 * 4 + 2] * m2.mat[1 * 4 + 3] + m2.mat[2 * 4 + 2] * m2.mat[2 * 4 + 3] ); result.mat[0 * 4 + 3] = m1.mat[0 * 4 + 0] * dst[0] + m1.mat[0 * 4 + 1] * dst[1] + m1.mat[0 * 4 + 2] * dst[2] + m1.mat[0 * 4 + 3]; result.mat[1 * 4 + 3] = m1.mat[1 * 4 + 0] * dst[0] + m1.mat[1 * 4 + 1] * dst[1] + m1.mat[1 * 4 + 2] * dst[2] + m1.mat[1 * 4 + 3]; result.mat[2 * 4 + 3] = m1.mat[2 * 4 + 0] * dst[0] + m1.mat[2 * 4 + 1] * dst[1] + m1.mat[2 * 4 + 2] * dst[2] + m1.mat[2 * 4 + 3]; } // RAVEN BEGIN // dluetscher: added function to quickly invert an idJointMat - assumes rotation-translation only ID_INLINE void idJointMat::Invert( ) { float m01, m02, m12, tx, ty; tx = mat[0 * 4 + 3]; ty = mat[1 * 4 + 3]; mat[0 * 4 + 3] = -(tx*mat[0 * 4 + 0] + ty*mat[1 * 4 + 0] + mat[2 * 4 + 3]*mat[2 * 4 + 0]); mat[1 * 4 + 3] = -(tx*mat[0 * 4 + 1] + ty*mat[1 * 4 + 1] + mat[2 * 4 + 3]*mat[2 * 4 + 1]); mat[2 * 4 + 3] = -(tx*mat[0 * 4 + 2] + ty*mat[1 * 4 + 2] + mat[2 * 4 + 3]*mat[2 * 4 + 2]); m01 = mat[0 * 4 + 1]; m02 = mat[0 * 4 + 2]; m12 = mat[1 * 4 + 2]; mat[0 * 4 + 1] = mat[1 * 4 + 0]; mat[0 * 4 + 2] = mat[2 * 4 + 0]; mat[1 * 4 + 0] = m01; mat[1 * 4 + 2] = mat[2 * 4 + 1]; mat[2 * 4 + 0] = m02; mat[2 * 4 + 1] = m12; } // RAVEN END #endif /* !__JOINTTRANSFORM_H__ */