FPS Camera Move Up/Down

Started by
0 comments, last by Medo Mex 11 years, 4 months ago
I have First-Person Shooter camera setup, it's working perfectly, the only problem is that I couldn't get it to move up/down using the cursor.

I'm not sure how I should insert m_vRight into the view matrix without messing up with my camera.

Default camera settings:
D3DXVECTOR3 m_vEye(0.0f, 40.0f, 1.0f);
D3DXVECTOR3 m_vLookAt(0.0f, 40.0f, 0.0f)
D3DXVECTOR3 m_vUp(0.0f, 1.0f, 0.0f);
D3DXVECTOR3 m_vRight(1.0f, 0.0f, 0.0f);


void FPSCameraMouseControl()
{
POINT mousePosit;
GetCursorPos( &mousePosit );
ScreenToClient( hWnd, &mousePosit );
g_ptCurrentMousePosit.x = mousePosit.x;
g_ptCurrentMousePosit.y = mousePosit.y;
D3DXMATRIX matRotation;

int nXDiff = (g_ptCurrentMousePosit.x - g_ptLastMousePosit.x);
int nYDiff = (g_ptCurrentMousePosit.y - g_ptLastMousePosit.y);

if( nYDiff != 0 )
{
// Up/Down: This part DOESN'T work because m_vRight is not set to the view matrix and I am not sure how to set it
D3DXMatrixRotationAxis( &matRotation, &camera->m_vRight, D3DXToRadian((float)nYDiff / 3.0f));
D3DXVec3TransformCoord( &camera->target, &camera->target, &matRotation );
D3DXVec3TransformCoord( &camera->m_vUp, &camera->m_vUp, &matRotation );
}

if( nXDiff != 0 )
{
// Right/Left: This part is working perfectly
D3DXMatrixRotationAxis( &matRotation, &D3DXVECTOR3(0,1,0), D3DXToRadian((float)nXDiff / 3.0f) );
D3DXVec3TransformCoord( &camera->target, &camera->target, &matRotation );
D3DXVec3TransformCoord( &camera->m_vUp, &camera->m_vUp, &matRotation );
}

g_ptLastMousePosit.x = g_ptCurrentMousePosit.x;
g_ptLastMousePosit.y = g_ptCurrentMousePosit.y;
}

void UpdateCamera()
{
// ***************** I'm not sure how should I add m_vRight to the view D3DXMATRIX without messing up with my camera *****************
D3DXMATRIX view;
D3DXMatrixLookAtLH(&matView,
&m_position,
&m_lookAt,
&m_vUp);
device->SetTransform(D3DTS_VIEW, &view);
}


Since this is FPS game, the up/down mouse rotation should be restricted to 90 degree.
Advertisement
I have updated the thread to focus on the main issue.

This topic is closed to new replies.

Advertisement