• Advertisement
Sign in to follow this  

FPS Camera Move Up/Down

This topic is 1860 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

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[b] m_vEye(0.0f, 40.0f, 1.0f);[/b]
D3DXVECTOR3[b] m_vLookAt(0.0f, 40.0f, 0.0f)[/b]
D3DXVECTOR3[b] m_vUp(0.0f, 1.0f, 0.0f);[/b]
D3DXVECTOR3[b] m_vRight(1.0f, 0.0f, 0.0f);[/b]

[CODE]
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);
}
[/CODE]

[b]Since this is FPS game, the up/down mouse rotation should be restricted to 90 degree.[/b]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement