Given the unit vectors of the two axes of the object's rotated coordinate system, find the rotation matrix of the object's rotation. I have seen that many tools have implemented this function.
Take Unreal as an example. The following example is the pseudo-code grabbed from Unreal source to complete the calculation of the rotation matrix from the X-Z axis unit vector.
I would like to ask how this process is done. I hope someone could explain.
FORCEINLINE TVector<T> TVector<T>::operator^(const TVector<T>& V) const
{
return TVector<T>
(
Y * V.Z - Z * V.Y,
Z * V.X - X * V.Z,
X * V.Y - Y * V.X
);
}
// Given X and Z axes
const TVector<T> OldX, OldZ;
const TVector<T> NewX = OldX
const TVector<T> NewZ = OldZ
const TVector<T> NewY = NewZ ^ NewX;
const TVector<T> NewZ = NewX ^ NewY;
// Target Rotation Matrix
TMatrix<T> M(3,3);
M[0][0] = NewX.X; M[0][1] = NewX.Y; M[0][2] = NewX.Z;
M[1][0] = NewY.X; M[1][1] = NewY.Y; M[1][2] = NewY.Z;
M[2][0] = NewZ.X; M[2][1] = NewZ.Y; M[2][2] = NewZ.Z;