void updateCamera()
{
if ( D3DXVec3Length( &m_velocity ) > m_maxVelocity )
{
m_velocity = *(D3DXVec3Normalize( &m_velocity, &m_velocity )) * m_maxVelocity;
}
m_position += m_velocity;
m_velocity = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
m_lookAt = m_position + m_look;
// Calculate the new view matrix
D3DXVECTOR3 up = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &m_view, &m_position, &m_lookAt, &up );
// Set the camera axes from the view matrix
m_right.x = m_view._11;
m_right.y = m_view._21;
m_right.z = m_view._31;
m_up.x = m_view._12;
m_up.y = m_view._22;
m_up.z = m_view._32;
m_look.x = m_view._13;
m_look.y = m_view._23;
m_look.z = m_view._33;
// Calculate yaw and pitch
float lookLengthOnXZ = sqrtf( m_look.z * m_look.z + m_look.x * m_look.x );
m_pitch = atan2f( m_look.y, lookLengthOnXZ );
}
The FPS camera is working perfectly, except the little problem that I mentioned (When the up angle is 90 degree and the player try to rotate the mouse up more, right/left start to work which show that the player is rotating around himself).
I have uploaded a video to explain the problem better: