Search code examples
c#matrixxna

rotation matrix to facing direction vector


I have a position of a character as xyz coordinates x= 102, y= 0.75, z= -105.7 for example. And i have the rotation matrix for the character as

M11 = -0.14
M12 = 0
M13 = -0.99
M21 = 0
M22 = 1
M23 = 0
M31 = 0.99
M32 =0
M33 = 0.14

I don't have much understanding about graphics and how these data can correlate to the facing direction of the character. I want to find a vector such that i can use that vector to aim at a direction that the character is facing. How do i do that?


Solution

  • The direction your character is facing is the 3rd row of the rotation matrix. So that would be:

    Vector3 facingDirection = new Vector3(0.99f, 0f, 0.14f);//(m31,m32,m33)
    

    this vector appears to be normalized, but if it weren't, you would do:

    Vector3 facingDirection = Vector3.Normalize(new Vector3(0.99f, 0f, 0.14f));
    

    If the matrix is an XNA Matrix, then you would simply use the Matrix.Forward property of the Matrix structure and get the same result.