From 8c2e9755082fd30d6b146471d58bc21cf3622779 Mon Sep 17 00:00:00 2001 From: wxyu <157348532@qq.com> Date: Thu, 29 Nov 2018 10:48:13 +0800 Subject: [PATCH] Fix smd animation mess aiMatrix4x4t::FromEulerAnglesXYZ modified to row order --- code/MS3DLoader.cpp | 10 +++------- code/SMDLoader.cpp | 5 +++-- include/assimp/matrix4x4.inl | 34 ++++++++++++++++------------------ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/code/MS3DLoader.cpp b/code/MS3DLoader.cpp index b06bea31c..c659d2ec7 100644 --- a/code/MS3DLoader.cpp +++ b/code/MS3DLoader.cpp @@ -181,8 +181,7 @@ void MS3DImporter :: CollectChildJoints(const std::vector& joints, ch->mParent = nd; ch->mTransformation = aiMatrix4x4::Translation(joints[i].position,aiMatrix4x4()=aiMatrix4x4())* - // XXX actually, I don't *know* why we need the inverse here. Probably column vs. row order? - aiMatrix4x4().FromEulerAnglesXYZ(joints[i].rotation).Transpose(); + aiMatrix4x4().FromEulerAnglesXYZ(joints[i].rotation); const aiMatrix4x4 abs = absTrafo*ch->mTransformation; for(unsigned int a = 0; a < mScene->mNumMeshes; ++a) { @@ -639,11 +638,8 @@ void MS3DImporter::InternReadFile( const std::string& pFile, aiQuatKey& q = nd->mRotationKeys[nd->mNumRotationKeys++]; q.mTime = (*rot).time*animfps; - - // XXX it seems our matrix&quaternion code has faults in its conversion routines -- - // aiQuaternion(x,y,z) seems to besomething different as quat(matrix.fromeuler(x,y,z)). - q.mValue = aiQuaternion(aiMatrix3x3(aiMatrix4x4().FromEulerAnglesXYZ((*rot).value)* - aiMatrix4x4().FromEulerAnglesXYZ((*it).rotation)).Transpose()); + q.mValue = aiQuaternion(aiMatrix3x3(aiMatrix4x4().FromEulerAnglesXYZ((*it).rotation)* + aiMatrix4x4().FromEulerAnglesXYZ((*rot).value))); } } diff --git a/code/SMDLoader.cpp b/code/SMDLoader.cpp index 4668da0f1..5a0f4e87c 100644 --- a/code/SMDLoader.cpp +++ b/code/SMDLoader.cpp @@ -558,7 +558,8 @@ void SMDImporter::CreateOutputAnimations() pRotKeys->mTime = pVecKeys->mTime = (*qq).dTime; // compute the rotation quaternion from the euler angles - pRotKeys->mValue = aiQuaternion( (*qq).vRot.x, (*qq).vRot.y, (*qq).vRot.z ); + // aiQuaternion: The order of the parameters is yzx? + pRotKeys->mValue = aiQuaternion( (*qq).vRot.y, (*qq).vRot.z, (*qq).vRot.x ); pVecKeys->mValue = (*qq).vPos; ++pVecKeys; ++pRotKeys; @@ -987,7 +988,7 @@ void SMDImporter::ParseSkeletonElement(const char* szCurrent, mTemp.a4 = vPos.x; mTemp.b4 = vPos.y; mTemp.c4 = vPos.z; - key.matrix = key.matrix * mTemp; + key.matrix = mTemp * key.matrix; } key.vPos = vPos; key.vRot = vRot; diff --git a/include/assimp/matrix4x4.inl b/include/assimp/matrix4x4.inl index 9920f0059..680d7666d 100644 --- a/include/assimp/matrix4x4.inl +++ b/include/assimp/matrix4x4.inl @@ -527,27 +527,25 @@ inline aiMatrix4x4t& aiMatrix4x4t::FromEulerAnglesXYZ(TReal x, TRe { aiMatrix4x4t& _this = *this; - TReal cr = std::cos( x ); - TReal sr = std::sin( x ); - TReal cp = std::cos( y ); - TReal sp = std::sin( y ); - TReal cy = std::cos( z ); - TReal sy = std::sin( z ); + TReal cx = std::cos(x); + TReal sx = std::sin(x); + TReal cy = std::cos(y); + TReal sy = std::sin(y); + TReal cz = std::cos(z); + TReal sz = std::sin(z); - _this.a1 = cp*cy ; - _this.a2 = cp*sy; - _this.a3 = -sp ; + // mz*my*mx + _this.a1 = cz * cy; + _this.a2 = cz * sy * sx - sz * cx; + _this.a3 = sz * sx + cz * sy * cx; - TReal srsp = sr*sp; - TReal crsp = cr*sp; + _this.b1 = sz * cy; + _this.b2 = cz * cx + sz * sy * sx; + _this.b3 = sz * sy * cx - cz * sx; - _this.b1 = srsp*cy-cr*sy ; - _this.b2 = srsp*sy+cr*cy ; - _this.b3 = sr*cp ; - - _this.c1 = crsp*cy+sr*sy ; - _this.c2 = crsp*sy-sr*cy ; - _this.c3 = cr*cp ; + _this.c1 = -sy; + _this.c2 = cy * sx; + _this.c3 = cy * cx; return *this; }