Archived

This topic is now archived and is closed to further replies.

scottdewald

Create Matrix from Vectors

Recommended Posts

I have an airplane that contains four vectors, m_pos, m_lookAt, m_right, and m_up. I am pretty sure that I am doing the rotations correctly when the user moves the joystick, but the plane is not rendering w/ the correct orientation. I read somewhere else that I could create a rotation/translation matrix from my vectors, but is is not working correctly. Here is my render method: void CPlayer::render(CCamera *p_cam) { float m[16]; m[0] = m_right.x; m[4] = m_up.x; m[8] = m_lookAt.x; m[12] = 0.0f; m[1] = m_right.y; m[5] = m_up.y; m[9] = m_lookAt.y; m[13] = 0.0f; m[2] = m_right.z; m[6] = m_up.z; m[10]= m_lookAt.z; m[14] = 0.0f; m[3] = m_pos.x; m[7] = m_pos.y;m[11]= m_pos.z; m[15] = 1.0f; glPushMatrix(); glLoadIdentity(); glMultMatrixf(m); CObjModel::render(p_cam); glPopMatrix(); }

Share this post


Link to post
Share on other sites
There is a notation difference between D3D and OpenGL:

OpenGL: v'' = M * v

M[ 0] = right.x; M[ 4] = up.x; M[ 8] = at.x; M[12] = pos.x;
M[ 1] = right.y; M[ 5] = up.y; M[ 9] = at.y; M[13] = pos.y;
M[ 2] = right.z; M[ 6] = up.z; M[10] = at.z; M[14] = pos.z;
M[ 3] = 0.0f; M[ 7] = 0.0f; M[11] = 0.0f; M[15] = 1.0f;
D3D: v'' = v * M

M[ 0] = right.x; M[ 1] = right.y; M[ 2] = right.z; M[ 3] = 0.0f;
M[ 4] = up.x; M[ 5] = up.y; M[ 6] = up.z; M[ 7] = 0.0f;
M[ 8] = at.x; M[ 9] = at.y; M[10] = at.z; M[11] = 0.0f;
M[12] = pos.x; M[13] = pos.x; M[14] = pos.x; M[15] = 1.0f;
Notice that the layout of the matrix in memory is the same for both.

Share this post


Link to post
Share on other sites