Exemplo n.º 1
0
//------------------------------------------------------------------------
// Purpose  : handle mouse based movements!
//------------------------------------------------------------------------
void Camera::MouseMovCam(int wndWidth, int wndHeight)
{
	POINT mousePos;
	int mid_x = wndWidth  >> 1;		// bit Shift right to get half .. 								
	int mid_y = wndHeight >> 1;		// divide is costly!!
	
	float angle_y = 0.0f;
	float angle_z = 0.0f;

	GetCursorPos(&mousePos);
	if ((mousePos.x == mid_x) && (mousePos.y == mid_y))
		return;

	//SetCursorPos(mid_x, mid_y);		// Set cursor in the center of the screen!
	

	// Get the direction from the mouse cursor & set reasonable speed!
	angle_y = (float)((mid_x - mousePos.x))/CAMERA_ROATION_BALANCE_HORIZ;
	angle_z = (float)((mid_y - mousePos.y))/CAMERA_ROATION_BALANCE_VERT;

	// higher the value, faster the camera looks around!
	m_LookAt.y += angle_z * 100;

	// limit the rotation around X-axis!
	//if((m_LookAt.y - m_Position.y) > 145)  m_LookAt.y = m_Position.y + 50;
	//if((m_LookAt.y - m_Position.y) <-145)  m_LookAt.y = m_Position.y - 50;

	RotateCam(angle_y); // Rotate	
}
Exemplo n.º 2
0
bool WalkTest::WalkHandleEvent (iEvent &Event)
{
  if (Event.Name == CanvasHidden)
  {
    canvas_exposed = false;
#ifdef CS_DEBUG
    Report (CS_REPORTER_SEVERITY_NOTIFY, "canvas hidden");
#endif
  }
  else if (Event.Name == CanvasExposed)
  {
    canvas_exposed = true;
#ifdef CS_DEBUG
    Report (CS_REPORTER_SEVERITY_NOTIFY, "canvas exposed");
#endif
  }
  else if (Event.Name == CanvasResize)
  {
    Sys->FrameWidth = Sys->myG2D->GetWidth();
    Sys->FrameHeight = Sys->myG2D->GetHeight();
  }
  else if (CS_IS_KEYBOARD_EVENT(name_reg, Event))
  {
    eatkeypress (&Event);
  }
  else if (CS_IS_MOUSE_EVENT(name_reg, Event))
  {
    switch(csMouseEventHelper::GetEventType(&Event))
    {
    case csMouseEventTypeDown:
      switch(csMouseEventHelper::GetButton(&Event))
      {
	case csmbLeft:
	  MouseClick1Handler(Event); break;
	case csmbRight:
	  MouseClick2Handler(Event); break;
	case csmbMiddle:
	  MouseClick3Handler(Event); break;
      }
      break;

    case csMouseEventTypeMove:
      {
	// additional command by Leslie Saputra -> freelook mode.
	static bool first_time = true;
	if (do_freelook)
	{
	  int last_x, last_y;
	  last_x = csMouseEventHelper::GetX(&Event);
	  last_y = csMouseEventHelper::GetY(&Event);
	  float speed = 6.0f;
  	
	  myG2D->SetMousePosition (FRAME_WIDTH / 2, FRAME_HEIGHT / 2);
	  if (!first_time)
	  {
	    RotateCam (
		      speed * (-((float)(last_y - (FRAME_HEIGHT / 2) ))
		      		/ (FRAME_HEIGHT*2)*(1-2*(int)inverse_mouse)),
		      speed * (((float)(last_x - (FRAME_WIDTH / 2) ))
		      		/ (FRAME_WIDTH*2)));
	  }
	  else
	    first_time = false;
	}
	else
	  first_time = true;
      }
      break;

    case csMouseEventTypeUp:
      if (csMouseEventHelper::GetButton(&Event) == csmbLeft) 
      {
	move_forward = false;
	Step (0);
      }
      break;

    default:
      // ignore
      break;
    }
  }

  return false;
}