Beispiel #1
0
    void ProcessInput(const Input& input)
    {
        if (input.IsKeyPressed(Key::ESCAPE))
        {
            input.SetCursorVisible(true);
            m_isMouseGrabbed = false;
        }

        if (input.IsKeyDown(Key::W))
        {
            m_cameraTransform->position += m_cameraTransform->GetForward() * m_speed;
        }

        if (input.IsKeyDown(Key::S))
        {
            m_cameraTransform->position += m_cameraTransform->GetBack() * m_speed;
        }

        if (input.IsKeyDown(Key::A))
        {
            m_cameraTransform->position += m_cameraTransform->GetLeft() * m_speed;
        }

        if (input.IsKeyDown(Key::D))
        {
            m_cameraTransform->position += m_cameraTransform->GetRight() * m_speed;
        }

        if (m_isMouseGrabbed)
        {
            glm::vec2 deltaPos = input.GetMousePosition() - m_centerPosition;

            bool rotY = deltaPos.x != 0;
            bool rotX = deltaPos.y != 0;

            if (rotY)
            {
                m_cameraTransform->rotation *= glm::normalize(glm::angleAxis(glm::radians(deltaPos.x * m_sensitivity), m_cameraTransform->GetUp()));
            }

            if (rotX)
            {
                m_cameraTransform->rotation *= glm::normalize(glm::angleAxis(glm::radians(deltaPos.y * m_sensitivity), m_cameraTransform->GetRight()));
            }

            if (rotY || rotX)
            {
                input.SetMousePosition(m_centerPosition);
            }
        }

        if (input.IsMouseButtonPressed(Mouse::BUTTON_LEFT))
        {
            input.SetCursorVisible(false);
            input.SetMousePosition(m_centerPosition);
            m_isMouseGrabbed = true;
        }
    }
Beispiel #2
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;
	}
}