Original Post
having some problems with a first person camera. managed this quite nicely in openGL, but messing around with DirectX now, and i'm getting wierd results. When I point my camera above a certian elevation, it flips, rather than stopping, and after that, my movement goes skew whiff. also, I don't move along the view vector, but on a flat plane. very wierd. also, I don't know how to put code into boxes for the forum, so if you could tell me that, it'd help... here's some of my camera class, if it helps you void cCamera::SetViewByMouse() { D3DXVECTOR3 Moved=m_diControl.CheckForMouseMove(); D3DXMATRIX matRotation; //if no movement occurred, exit function if (Moved==D3DXVECTOR3(0,0,0)) return; else { int nXDiff = (Moved.x); int nYDiff = (Moved.y); if( nYDiff != 0 ) { D3DXMatrixRotationAxis( &matRotation, &m_vRight, D3DXToRadian((float)nYDiff / 3.0f)); D3DXVec3TransformCoord( &m_vTargetPos, &m_vTargetPos, &matRotation ); D3DXVec3TransformCoord( &m_vUpVector, &m_vUpVector, &matRotation ); } if( nXDiff != 0 ) { D3DXMatrixRotationAxis( &matRotation, &m_vUpVector, D3DXToRadian((float)nXDiff / 3.0f) ); D3DXVec3TransformCoord( &m_vTargetPos, &m_vTargetPos, &matRotation ); D3DXVec3TransformCoord( &m_vUpVector, &m_vUpVector, &matRotation ); } } } void cCamera::MoveCamera(float speed) { // Add the strafe vector to our position m_vEyePos.x += m_vTargetPos.x * speed; m_vEyePos.z += m_vTargetPos.z * speed; } void cCamera::StrafeCamera(float speed) { // Add the strafe vector to our position m_vEyePos.x += m_vRight.x * speed; m_vEyePos.z += m_vRight.z * speed; } void cCamera::Update(LPDIRECT3DDEVICE9 p_dx_Device, float fTime) { // Initialize a variable for the cross product result D3DXVECTOR3 vCross = Cross(m_vTargetPos - m_vEyePos, m_vUpVector); // Normalize the strafe vector m_vRight = Normalize(vCross); // Move the camera's view by the mouse SetViewByMouse(); // This checks to see if the keyboard was pressed CheckForMovement(fTime); D3DXMatrixLookAtLH(&m_mView, &m_vEyePos, &m_vTargetPos, &m_vUpVector); //this is truly gammy // UpdateViewMatrix(p_dx_Device); //this function works better -? } void cCamera::UpdateViewMatrix(LPDIRECT3DDEVICE9 p_dx_Device) { D3DXMatrixIdentity( &m_mView ); D3DXVec3Normalize( &m_vTargetPos, &m_vTargetPos ); D3DXVec3Cross( &m_vRight, &m_vUpVector, &m_vTargetPos ); D3DXVec3Normalize( &m_vRight, &m_vRight ); D3DXVec3Cross( &m_vUpVector, &m_vTargetPos, &m_vRight ); D3DXVec3Normalize( &m_vUpVector, &m_vUpVector ); m_mView._11 = m_vRight.x; m_mView._12 = m_vUpVector.x; m_mView._13 = m_vTargetPos.x; m_mView._14 = 0.0f; m_mView._21 = m_vRight.y; m_mView._22 = m_vUpVector.y; m_mView._23 = m_vTargetPos.y; m_mView._24 = 0.0f; m_mView._31 = m_vRight.z; m_mView._32 = m_vUpVector.z; m_mView._33 = m_vTargetPos.z; m_mView._34 = 0.0f; m_mView._41 = -D3DXVec3Dot( &m_vEyePos, &m_vRight ); m_mView._42 = -D3DXVec3Dot( &m_vEyePos, &m_vUpVector ); m_mView._43 = -D3DXVec3Dot( &m_vEyePos, &m_vTargetPos ); m_mView._44 = 1.0f; p_dx_Device->SetTransform( D3DTS_VIEW, &m_mView ); }