我最終通過更多的網上衝浪來解決我的問題。爲了將來的參考,繼承人如何做到這一點。
變換組件被存儲在4×4矩陣是這樣的:
r r r t
r r r t
r r r t
0 0 0 1
其中r是旋轉分量和t是平移分量。因此,我們可以將翻譯組件表示爲一個向量。 2矢量可以線性插值,所以我們插入這兩個矢量,然後在旋轉矩陣完成後將它們推回到旋轉矩陣中。繼承人的最終代碼,但它有點混亂:
float total = (orderedBones[i]->Animation->keyFrames[nextKeyFrame] - orderedBones[i]->Animation->keyFrames[nextKeyFrame - 1])*ANIMATION_MULTIPLICATION_CONST;
float progress = orderedBones[i]->Animation->accumTime - (orderedBones[i]->Animation->keyFrames[nextKeyFrame - 1]*ANIMATION_MULTIPLICATION_CONST);
float interpolation = progress/total;
glm::quat firstQuat = glm::quat_cast(orderedBones[i]->Animation->Matrices[nextKeyFrame - 1]);
glm::quat secondQuat = glm::quat_cast(orderedBones[i]->Animation->Matrices[nextKeyFrame]);
glm::quat finalQuat = glm::slerp(firstQuat, secondQuat, interpolation);
orderedBones[i]->Animation->interpoltaedMatrix = glm::mat4_cast(finalQuat);
glm::vec4 transformComp1 = glm::vec4(orderedBones[i]->Animation->Matrices[nextKeyFrame - 1][0][3],orderedBones[i]->Animation->Matrices[nextKeyFrame - 1][1][3],orderedBones[i]->Animation->Matrices[nextKeyFrame - 1][2][3],orderedBones[i]->Animation->Matrices[nextKeyFrame - 1][3][3]);
glm::vec4 transformComp2 = glm::vec4(orderedBones[i]->Animation->Matrices[nextKeyFrame][0][3],orderedBones[i]->Animation->Matrices[nextKeyFrame][1][3],orderedBones[i]->Animation->Matrices[nextKeyFrame][2][3],orderedBones[i]->Animation->Matrices[nextKeyFrame][3][3]);
glm::vec4 finalTrans = (float)(1.0-interpolation)*transformComp1+transformComp2*interpolation;
//good for now, although in future the 2 transformation components need to be interpolated
orderedBones[i]->Animation->interpoltaedMatrix[0][3] = finalTrans.x;
orderedBones[i]->Animation->interpoltaedMatrix[1][3] = finalTrans.y;
orderedBones[i]->Animation->interpoltaedMatrix[2][3] = finalTrans.z;
orderedBones[i]->Animation->interpoltaedMatrix[3][3] = finalTrans.w;
希望這能回答別人的問題:)
我會建議加標籤'quaternion'(單數) –
@SeverinPappadeux新增:) – BlueSpud
是什麼啥東東? –