This question already has an answer here:
Working in DirectX (with DirectXMath objects): If I have the rotation of an object relative to some coordinate space as quaternion Q, and I have a transformation matrix tx from that coordinate space to world space, how do I find the rotation of my object in world space?
My thinking, which has proven inaccurate, was: Use XMMatrixDecompose on tx to get the orientation that is the rotation difference between world space and my local coordinate space (qLocalToWorld), invert it to get the rotation of the local coordinate system relative to the world (qWorldToLocal) and combine it with my local rotation Q.
XMVECTOR scale, qLocalToWorld, translation; XMMatrixDecompose(&scale, &qLocalToWorld, &translation, tx); auto qWorldToLocal = XMQuaternionInverse(qLocalToWorld); auto worldOrientation = q * qWorldToLocal;
I figured for e.g. that if the local coordinate system was rotated 90 degrees with respect to the world, and my object was 5 degrees with respect to local, this would yield the 90 + 5 = 95 in world space. But I was wrong :(
I'd appreciate help in understanding the right way to do this. Thanks in advance!