• Advertisement


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

Camera Troubles

This topic is 5248 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm new to 3D with the camera. I am using The Zen of Direct3D by Peter Walsh as a guide (pretty good book) and have a textured mesh (ie wall) and some 2D rendering thru the GDI. The camera moves nicely, pitches, rolls, and all that jazz. The only problem I am having with the camera is when I move my mouse in a circle to the left making many circles, my scene rolls left. When I move my mouse in a circle to the right making many circles, my scene rolls to the right. Any ideas? The camera roll property is always set to 0 for no rolling. Same with the frame containing the mesh. I'm using the camera as a first person view for a Quake style game. Here's the update routine for the camera: // Updates the Direct3D view matrix void CCamera::Update() { // Update the x position m_Position.x += m_Velocity.x * m_Right.x; m_Position.y += m_Velocity.x * m_Right.y; m_Position.z += m_Velocity.x * m_Right.z; // Update the y position m_Position.x += m_Velocity.y * m_Up.x; m_Position.y += m_Velocity.y * m_Up.y; m_Position.z += m_Velocity.y * m_Up.z; // Update the z position m_Position.x += m_Velocity.z * m_LookAt.x; m_Position.y += m_Velocity.z * m_LookAt.y; m_Position.z += m_Velocity.z * m_LookAt.z; // Normalize and Regenerate the Look, Right, and Up Vectors D3DXVec3Normalize( &m_LookAt, &m_LookAt ); D3DXVec3Cross( &m_Right, &m_Up, &m_LookAt ); D3DXVec3Normalize( &m_Right, &m_Right ); D3DXVec3Cross( &m_Up, &m_LookAt, &m_Right ); D3DXVec3Normalize( &m_Up, &m_Up ); // Set up the y-axis rotation D3DXMatrixRotationAxis( &mYaw, &m_Up, m_Yaw ); D3DXVec3TransformCoord( &m_LookAt, &m_LookAt, &mYaw ); D3DXVec3TransformCoord( &m_Right, &m_Right, &mYaw ); // Set up the x-axis rotation D3DXMatrixRotationAxis( &mPitch, &m_Right, m_Pitch ); D3DXVec3TransformCoord( &m_LookAt, &m_LookAt, &mPitch ); D3DXVec3TransformCoord( &m_Up, &m_Up, &mPitch ); // Set up the z-axis rotation D3DXMatrixRotationAxis( &mRoll, &m_LookAt, m_Roll ); D3DXVec3TransformCoord( &m_Right, &m_Right, &mRoll ); D3DXVec3TransformCoord( &m_Up, &m_Up, &mRoll ); // Init the view matrix to an identity D3DXMatrixIdentity( &mView ); // Fill in the view matrix mView(0,0) = m_Right.x; mView(0,1) = m_Up.x; mView(0,2) = m_LookAt.x; mView(1,0) = m_Right.y; mView(1,1) = m_Up.y; mView(1,2) = m_LookAt.y; mView(2,0) = m_Right.z; mView(2,1) = m_Up.z; mView(2,2) = m_LookAt.z; mView(3,0) = - D3DXVec3Dot( &m_Position, &m_Right ); mView(3,1) = - D3DXVec3Dot( &m_Position, &m_Up ); mView(3,2) = - D3DXVec3Dot( &m_Position, &m_LookAt ); // Set the view matrix g_pDevice->SetTransform( D3DTS_VIEW, &mView ); } [edited by - SteveK on October 9, 2003 8:53:21 PM]

Share this post

Link to post
Share on other sites

  • Advertisement