MouseInputHandler
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "Rendering/Renderer.h"
|
||||
#include "Rendering/DebugCameraInputController.h"
|
||||
|
||||
void Renderer::Initialize()
|
||||
{
|
||||
@@ -83,6 +84,8 @@ void Renderer::InitializeShaders()
|
||||
|
||||
void Renderer::InputUpdate(double dt)
|
||||
{
|
||||
static DebugCameraInputController<Renderer> firstPersonInputController(m_EventBroker, -1);
|
||||
|
||||
glm::vec3 m_Position = m_Camera->Position();
|
||||
if (glfwGetKey(m_Window, GLFW_KEY_O) == GLFW_PRESS)
|
||||
{
|
||||
@@ -112,37 +115,15 @@ void Renderer::InputUpdate(double dt)
|
||||
m_CameraMoveSpeed = 0.5f;
|
||||
}
|
||||
|
||||
|
||||
static double mousePosX, mousePosY;
|
||||
glfwGetCursorPos(m_Window, &mousePosX, &mousePosY);
|
||||
|
||||
if (glfwGetKey(m_Window, GLFW_KEY_SPACE) == GLFW_PRESS) {
|
||||
|
||||
|
||||
double deltaX, deltaY;
|
||||
deltaX = mousePosX - (float)Resolution().Width / 2;
|
||||
deltaY = mousePosY - (float)Resolution().Height / 2;
|
||||
|
||||
float rotationY = -deltaY / 300.f;
|
||||
float rotationX = -deltaX / 300.f;
|
||||
glm::quat orientation = m_Camera->Orientation();
|
||||
|
||||
|
||||
orientation = orientation * glm::angleAxis<float>(rotationY, glm::vec3(1, 0, 0));
|
||||
orientation = glm::angleAxis<float>(rotationX, glm::vec3(0, 1, 0)) * orientation;
|
||||
|
||||
m_Camera->SetOrientation(orientation);
|
||||
|
||||
glfwSetCursorPos(m_Window, Resolution().Width / 2, Resolution().Height / 2);
|
||||
}
|
||||
m_Camera->SetPosition(m_Position);
|
||||
firstPersonInputController.Update(dt);
|
||||
m_Camera->SetOrientation(firstPersonInputController.Orientation());
|
||||
m_Camera->SetPosition(firstPersonInputController.Position());
|
||||
}
|
||||
|
||||
void Renderer::Update(double dt)
|
||||
{
|
||||
m_EventBroker->Process<Renderer>();
|
||||
InputUpdate(dt);
|
||||
|
||||
}
|
||||
|
||||
void Renderer::Draw(RenderQueueCollection& rq)
|
||||
|
||||
Reference in New Issue
Block a user