本文整理汇总了C++中Input::SetMousePosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Input::SetMousePosition方法的具体用法?C++ Input::SetMousePosition怎么用?C++ Input::SetMousePosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Input
的用法示例。
在下文中一共展示了Input::SetMousePosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessInput
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;
}
}
示例2: ProcessInput
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;
}
}