我正在制作蒙皮引擎,并使它能够用于1个矩阵/帧/骨骼。但是,那是大量的数据,所以我想走得更远,并做1个矩阵/关键帧/骨骼,因此我可以内插骨骼的旋转和平移(缩放比例在每个轴上始终为1,因此我忽略了) 。为此,我想为(缩放向量),旋转四元数和平移向量分解矩阵(XMMATRIX结构),对其进行插值并从中重组矩阵。我的代码大致是:

XMMATRIX temp;
{..} //Fill it from a file
temp = XMMatrixTranspose( temp ); //Transposing temp because it was in a shader-readable format
XMVECTOR scal; //for scaling
XMVECTOR quat; //for rotation
XMVECTOR tran; //for translation
XMMatrixDecompose(&scal,&quat,&tran,temp);

XMMATRIX final=XMMatrixIdentity()*XMMatrixScalingFromVector(scal)*XMMatrixRotationQuaternion(quat)*XMMatrixTranslationFromVector(tran);
final = XMMatrixTranspose( final ); //Transposing to get back the shader format


在这段简短的代码中,我尝试分解正确的矩阵(温度),然后在最终的矩阵中重新组合,但我没有得到原始矩阵。 (使用临时矩阵可以得出正确的结果,但是使用最终矩阵则不能)

看来我在这里错过了一些琐碎的事情,有人可以指出吗?

最佳答案

似乎发布了正确的代码,但是在我的程序中它是错误的,因为我错过了其中一个转置。

10-06 10:34