如何在DirectX11中简化矩阵乘法?

时间:2014-11-25 20:00:49

标签: c++ directx-11 directxmath

我可以简化以下声明,使其更具人性化吗?关于调整要求,我可以逐步进行乘法运算吗?

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 个答案:

答案 0 :(得分:1)

使用XMVECTORXMMATRIX局部变量。生成的代码在优化构建中应该相同。

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);