Ejemplo n.º 1
0
void Camera::UpdateRotation(float delta)
{
	float m_sensitivity = 0.5f;

	if (Input::GetMouseDown(Input::RIGHT_MOUSE))
	{
		Input::SetCursor(true);
		mouseLocked = false;
	}

	if (mouseLocked)
	{
		Vector2f centerPosition = Vector2f((float)Window::GetWidth() / 2.0f, (float)Window::GetHeight() / 2.0f);
		Vector2f deltaPos = Input::GetMousePosition() - centerPosition;

		bool rotY = deltaPos.GetX() != 0;
		bool rotX = deltaPos.GetY() != 0;

		if (rotY)
			m_transform.Rotate(Vector3f(0, 1, 0), ToRadians(deltaPos.GetX() * m_sensitivity));
		if (rotX)
			m_transform.Rotate(m_transform.GetRot().GetRight(), ToRadians(deltaPos.GetY() * m_sensitivity));

		if (rotY || rotX)
			Input::SetMousePosition(centerPosition);
	}

	if (Input::GetMouseDown(Input::LEFT_MOUSE))
	{
		Vector2f centerPosition = Vector2f((float)Window::GetWidth() / 2.0f, (float)Window::GetHeight() / 2.0f);
		Input::SetCursor(false);
		Input::SetMousePosition(centerPosition);
		mouseLocked = true;
	}
}
const Vector2f Vector2f::operator-(const Vector2f &other) const
{
	Vector2f result;
	result.SetX(_x - other.GetX());
	result.SetY(_y - other.GetY());
	return result;
}
Ejemplo n.º 3
0
void line::setup(float x1,float y1,float x2,float y2)
{
	P1 = Vector2f(x1,y1);
	P2 = Vector2f(x2,y2);

	
	Vector2f v = P2 - P1;
	Normal = Vector2f(-v.GetY(),v.GetX());
	/*float length = N.length();
	Normal = Vector2f(N.GetX()/length,N.GetY()/length);*/

	Normal = Normal.normalise();
}
Ejemplo n.º 4
0
void Game::OnInput()
{
	if(_input->IsKeyDown(Keys::KEY_A))
		printf("Button %d pressed! \n", Keys::KEY_A);
	if(_input->IsKeyDown(Keys::KEY_B))
		printf("Button %d pressed! \n", Keys::KEY_B);
	if(_input->IsMouseClicked())
	{
		Vector2f mousePosition = _input->GetMousePosition();
		int x = mousePosition.GetX();
		int y = mousePosition.GetY();
		printf("Mouse clicked on x : %d, y : %d \n", x, y);	
	}
}
Ejemplo n.º 5
0
void FreeLook::ProcessInput(const Input& input, float delta)
{
	if(input.GetKey(m_unlockMouseKey))
	{
		input.SetCursor(true);
		m_mouseLocked = false;
	}

	if(m_mouseLocked)
	{
		Vector2f deltaPos = input.GetMousePosition() - m_windowCenter;
		
		bool rotY = deltaPos.GetX() != 0;
		bool rotX = deltaPos.GetY() != 0;
			
		if(rotY)
		{
			GetTransform()->Rotate(Vector3f(0,1,0), ToRadians(deltaPos.GetX() * m_sensitivity));
		}
		if(rotX)
		{
			GetTransform()->Rotate(GetTransform()->GetRot()->GetRight(), ToRadians(deltaPos.GetY() * m_sensitivity));
		}
			
		if(rotY || rotX)
		{
			input.SetMousePosition(m_windowCenter);
		}
	}

	if(input.GetMouseDown(Input::MOUSE_LEFT_BUTTON))
	{
		input.SetCursor(false);
		input.SetMousePosition(m_windowCenter);
		m_mouseLocked = true;
	}
}
void Vector2f::Copy(const Vector2f& v)
{
	_x = v.GetX();
	_y = v.GetY();
}