How can I simplify matrices multiplication at DirectX11?

222 views Asked by At

Can I simplify following statement to make it more human readable? Can I do following multiplication step-by-step regarding aligning requirements?

DirectX::XMStoreFloat4x4(&this->worldTransform, DirectX::XMMatrixMultiply(DirectX::XMMatrixMultiply(DirectX::XMMatrixScalingFromVector(DirectX::XMLoadFloat4(&this->scaling)), DirectX::XMMatrixRotationQuaternion(DirectX::XMLoadFloat4(&this->rotation))), DirectX::XMMatrixTranslationFromVector(DirectX::XMLoadFloat4(&this->translation))));
1

There are 1 answers

0
MooseBoys On BEST ANSWER

Use XMVECTOR and XMMATRIX local variables. The generated code should be identical in an optimized build.

XMVECTOR vTrans = DirectX::XMLoadFloat4(&this->translation);
XMMATRIX mTrans = DirectX::XMMatrixTranslationFromVector(vTrans);
XMVECTOR vScale = DirectX::XMLoadFloat4(&this->scaling);
XMMATRIX mScale = DirectX::XMMatrixScalingFromVector(vScale);
XMVECTOR vRot = DirectX::XMLoadFloat4(&this->rotation);
XMMATRIX mRot = DirectX::XMMatrixRotationQuaternion(rot);
XMMATRIX mTemp = DirectX::XMMatrixMultiply(mScale, mRot);
mTemp = DirectX::XMMatrixMultiply(mTemp, mTrans);
DirectX::XMStoreFloat4x4(&this->worldTransform, mTemp);