Example #1
0
/*
 *	Update the position of the DebugCamera based on user input.
 *	@param	dt		The deltaTime value this frame.
 */
void DebugCamera::Update(float dt)
{
	InputManager* pManager = InputManager::Instance();

	// Current speed
	float moveSpeed = m_moveSpeed * dt;
    float rotSpeed = m_rotationSpeed * dt;

	// Speed up when shift is pressed
	if (pManager->IsKeyDown(VK_SHIFT)) { moveSpeed *= 5; }

	// Movement
	if (pManager->IsKeyDown('W')) { MoveRelative(0, 0, moveSpeed); }
	if (pManager->IsKeyDown('S')) { MoveRelative(0, 0, -moveSpeed); }
	if (pManager->IsKeyDown('A')) { MoveRelative(-moveSpeed, 0, 0); }
	if (pManager->IsKeyDown('D')) { MoveRelative(moveSpeed, 0, 0); }
	if (pManager->IsKeyDown('X')) { MoveAbsolute(0, -moveSpeed, 0); }
	if (pManager->IsKeyDown(' ')) { MoveAbsolute(0, moveSpeed, 0); }
	if (pManager->IsKeyDown('Q')) { Rotate(0.0f, -rotSpeed); }
	if (pManager->IsKeyDown('E')) { Rotate(0.0f, rotSpeed); }

	// Handle rotation
	if (pManager->IsMouseDown(MouseButton::LMB))
	{
		POINT   prevMousePos = pManager->GetPreviousMousePos(),
				currMousePos = pManager->GetCurrentMousePos();

		float xDiff = (currMousePos.x - prevMousePos.x) * 0.005f;
		float yDiff = (currMousePos.y - prevMousePos.y) * 0.005f;

		Rotate(yDiff, xDiff);
	}
}
void CObject::MoveForward(const float fDistance)
{
	D3DXVECTOR3 d3dxvPosition = *GetPosition();
	D3DXVECTOR3 d3dxvLookAt = *GetLookAt();
	d3dxvPosition += fDistance * d3dxvLookAt;
	MoveAbsolute(&d3dxvPosition);
}
void CObject::MoveRelative(const D3DXVECTOR3 *d3dxVec)
{
	D3DXVECTOR3 d3dxvPosition = *GetPosition();

	D3DXVECTOR3 d3dxvRight = *GetRight();
	D3DXVECTOR3 d3dxvUp = *GetUp();
	D3DXVECTOR3 d3dxvLookAt = *GetLookAt();

	d3dxvPosition += d3dxVec->x * d3dxvRight;
	d3dxvPosition += d3dxVec->y * d3dxvUp;
	d3dxvPosition += d3dxVec->z * d3dxvLookAt;

	MoveAbsolute(&d3dxvPosition);
}
void CObject::MoveRelative(const float fx, const float fy, const float fz)
{
	D3DXVECTOR3 d3dxvPosition = *GetPosition();

	D3DXVECTOR3 d3dxvRight = *GetRight();
	D3DXVECTOR3 d3dxvUp = *GetUp();
	D3DXVECTOR3 d3dxvLookAt = *GetLookAt();

	d3dxvPosition += fx * d3dxvRight;
	d3dxvPosition += fy * d3dxvUp;
	d3dxvPosition += fz * d3dxvLookAt;

	MoveAbsolute(&d3dxvPosition);
}
Example #5
0
void
MergeMouse::MoveAbsolute(int new_x, int new_y,
                         int min_x, int max_x, int min_y, int max_y)
{
  /* scale touschreen coordinates to screen size */

  if (new_x < min_x)
    new_x = 0;
  else if (max_x > min_x)
    new_x = new_x * int(rotate.GetWidth()) / (max_x - min_x);

  if (new_y < min_y)
    new_y = 0;
  else if (max_y > min_y)
    new_y = new_y * int(rotate.GetHeight()) / (max_y - min_y);

  /* now call the "real" MoveAbsolute() */
  MoveAbsolute(PixelPoint(new_x, new_y));
}
Example #6
0
void
MergeMouse::MoveRelative(PixelPoint d)
{
  MoveAbsolute(GetPosition() + rotate.DoRelative(d));
}