I need to get rotation matrix from direction vector (vForward) I also have vRight and vUp vectors. All those vectors are unit vectors.
I just need to get rotation matrix.
To get rotation matrix for rotation in only one plane (xy) parallel to ground, I do this: XMMATRIX xmResult;
Vec3f vFwd = pPlayer->VForward;
vFwd.z = 0;
vFwd.Normalize();
xmResult = XMMatrixSet( vFwd.y, -vFwd.x, 0, 0,
vFwd.x, vFwd.y, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
Above code only get rotation matrix to rotate around Z axis:
I would like to get the code to rotate around all axis. This is coordinate system I'm forced to use. I know it is strange:
This is how I'm using my matrix later in code:
XMStoreFloat3((XMFLOAT3*)&vStart, XMVector3Transform(XMLoadFloat3((XMFLOAT3*)&vStart), xmTransformation));
XMStoreFloat3((XMFLOAT3*)&vEnd, XMVector3Transform(XMLoadFloat3((XMFLOAT3*)&vEnd), xmTransformation));
rotationMatrix = rotationVectorToMatrix( rotationVector ) returns a 3-D rotation matrix that corresponds to the input axis-angle rotation vector. The function uses the Rodrigues formula for the computation.
A rotation matrix can be defined as a transformation matrix that operates on a vector and produces a rotated vector such that the coordinate axes always remain fixed. These matrices rotate a vector in the counterclockwise direction by an angle θ. A rotation matrix is always a square matrix with real entities.
Depending on how you use your matrices, Right, Up and Forward should correspond to the rows or columns of your matrix.
xmResult = XMMatrixSet( vRight.x, vRight.y, vRight.z, 0, vFwd.x, vFwd.y, vFwd.z, 0, vUp.x, vUp.y, vUp.z, 0, 0, 0, 0, 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With