Jump to content

  • Log In with Google      Sign In   
  • Create Account


FPS Camera Move Up/Down


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 15 December 2012 - 02:58 PM

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.

Sponsor:

#2 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 16 December 2012 - 10:40 AM

I have updated the thread to focus on the main issue.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS