Archived

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

gir

Camera rotation problems

Recommended Posts

Hello. I'm trying to write a 3D camera class based on storing the up, right and look-at vectors. The following code, that is supposed to keep the camera stationary while looking around, works ok but as I move the mouse around the camera slowly begins rolling around the z-axis. some code to update the camera based on mouse movement (pitch and yaw): // Regenerate base vectors D3DXVec3Normalize(&m_look, &m_look); D3DXVec3Cross(&m_right, &m_up, &m_look); D3DXVec3Normalize(&m_right, &m_right); D3DXVec3Cross(&m_up, &m_look, &m_right); D3DXVec3Normalize(&m_up, &m_up); // Matrices for pitch and yaw D3DXMATRIX matPitch, matYaw; D3DXMatrixRotationAxis(&matPitch, &m_right, pitch); // rotate the LOOK & UP Vectors about the RIGHT Vector D3DXVec3TransformCoord(&m_look, &m_look, &matPitch); D3DXVec3TransformCoord(&m_up, &m_up, &matPitch); D3DXMatrixRotationAxis(&matYaw, &m_up, yaw); // rotate the LOOK & RIGHT Vectors about the UP Vector D3DXVec3TransformCoord(&m_look, &m_look, &matYaw); D3DXVec3TransformCoord(&m_right, &m_right, &matYaw); // Build the view matrix m_matView._11 = m_right.x; m_matView._12 = m_up.x; m_matView._13 = m_look.x; etc... m_matView._41 = - D3DXVec3Dot( &m_position, &m_right ); m_matView._42 = - D3DXVec3Dot( &m_position, &m_up ); m_matView._43 = - D3DXVec3Dot( &m_position, &m_look ); m_device->SetTransform(D3DTS_VIEW, &m_matView); I'm not rotating around the look-at vector, so I can't see how the camera can be rolling. Thanks for your help! Edited by - gir on January 14, 2002 9:24:47 AM Edited by - gir on January 14, 2002 10:55:27 AM

Share this post


Link to post
Share on other sites
Is it constantly rolling, or just getting "off" from where it was when the program started? Does the z-rotation change only when you move the mouse, or is it always rolling at a constant speed? If so, what direction is it rolling?

Ryan Buhr
Trifinity Interactive, LLC.

Share this post


Link to post
Share on other sites
Well, it was accumulating roll as I moved the mouse, and it would roll in either direction. I ended up fixing the problem by rotating the right and look vectors about the WORLD''s Y axis (0,1,0) instead of the camera''s up vector when I was applying yaw. This method does not introduce roll because we''re always yaw-ing around the fixed Y axis, regardless of where the camerea is looking. The camera''s up vector also needed to be rotated about the Y axis to ensure an orthagonal set of local axis for the camera.



Share this post


Link to post
Share on other sites