Building View Matrix in Direct3D11

Posted by Balls on Game Development See other posts from Game Development or by Balls
Published on 2012-10-14T06:53:34Z Indexed on 2012/10/14 9:52 UTC
Read the original article Hit count: 264

Filed under:
|
|

Am I doing it right? I converted this.

m_ViewMatrix = XMMatrixLookAtLH(XMLoadFloat3(&m_Position), lookAtVector, upVector);

to this one.

XMVECTOR vz = XMVector3Normalize( lookAtVector - XMLoadFloat3(&m_Position) );
XMVECTOR vx = XMVector3Normalize( XMVector3Cross( upVector, vz ) );
XMVECTOR vy = XMVector3Cross( vz, vx );

m_ViewMatrix.r[0] = vx;
m_ViewMatrix.r[1] = vy;
m_ViewMatrix.r[2] = vz;
m_ViewMatrix.r[3] = XMLoadFloat3(&m_Position);

m_ViewMatrix.r[0].m128_f32[3] = 0.0f;
m_ViewMatrix.r[1].m128_f32[3] = 0.0f;
m_ViewMatrix.r[2].m128_f32[3] = 0.0f;
m_ViewMatrix.r[3].m128_f32[3] = 1.0f;

m_ViewMatrix = XMMatrixInverse( &XMMatrixDeterminant(m_ViewMatrix), m_ViewMatrix );

Everything looks fine when I run it. Another question is, I saw on this site(http://webglfactory.blogspot.com/2011/06/how-to-create-view-matrix.html) that he subtracted lookat from position in his vector vz. I tried it but gave me wrong view matrix. Can anyone check my code. I'm studying linear algebra right now. Sucks my course doesn't have one.

Thank you, Balls

© Game Development or respective owner

Related posts about math

Related posts about matrix