Direct3D Rotation Matrix from Vector and vice-versa

Posted by Beta Carotin on Stack Overflow See other posts from Stack Overflow or by Beta Carotin
Published on 2012-10-13T14:33:07Z Indexed on 2012/10/13 15:38 UTC
Read the original article Hit count: 163

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c++

Related posts about vector