简体   繁体   中英

XMMATRIX Decompose does not give correct scale, rotation and translation

I am making my skinning engine and got it to work for 1 matrix/frame/bone. However that is a huge number of data, so I want to go further and do 1 matrix/keyframe/bone, so I can intepolate the rotation and translation of a bone (scaling is always 1 on each axis, so I am ignoring that). For that I want to decompose a matrix (XMMATRIX structure) for (scaling vector), rotation quaternion and translation vector, interpolate them and reassemble a matrix from them. My code is roughly:

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

In this short code I try to decompose the correct matrix (temp) and then reassemble in the final matrix, but I do not get the original matrix back. (using the temp matrix gives correct results, but using the final matrix does not)

It seems I am missing something very trivial here, could someone point it out please?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM