Direct3D Rotation Matrix from Vector and vice-versa
- by Beta Carotin
I need to compute a rotation matrix from a direction vector,
and a direction vector from a rotation matrix.
The up direction should correspond to the z-axis,
forward is y and right is x;
D3DXMATRIX m; // the rotation matrix
D3DXVECTOR3 v; // this is the direction vector wich is given
D3DXVECTOR3 r; // resulting direction vector
float len = D3DXVec3Length(&v); // length of the initial direction vector
// compute matrix
D3DXMatrixLookAtLH(&m, &v, &D3DXVECTOR3(0,0,0), &D3DXVECTOR3(0,0,1));
// use the matrix on a vector { 0, len, 0 }
D3DXVec3TransformCoord(&r, &D3DXVECTOR3(0,len,0), &m);
Now, the vector r should be equal to v, but it isnt.
What exactly do I have to do to get the results I need?