Player input properly separated from editor input and server

This commit is contained in:
2016-01-22 21:35:31 +01:00
parent 406b730ef3
commit 55ee2bb3bf
4 changed files with 54 additions and 25 deletions
@@ -23,13 +23,17 @@ public:
m_SpeedMultiplier = m_Config->Get<float>("Editor.CameraSpeed", 3.f);
}
virtual const glm::vec3 Movement() const override
{
return m_Movement * m_SpeedMultiplier;
}
virtual const glm::vec3 Movement() const override { return m_Movement * m_SpeedMultiplier; }
void Enable() { m_Enabled = true; }
void Disable() { m_Enabled = false; }
virtual bool OnCommand(const Events::InputCommand& e) override
{
if (!m_MouseLocked) {
return false;
}
ImGuiIO& io = ImGui::GetIO();
if (glm::abs(e.Value) > 0 && (io.WantCaptureKeyboard || io.WantCaptureMouse)) {
return false;
@@ -64,11 +68,16 @@ public:
protected:
ConfigFile* m_Config;
bool m_Enabled = false;
float m_SpeedMultiplier = 1.f;
EventRelay<EventContext, Events::MousePress> m_EMousePress;
bool OnMousePress(const Events::MousePress& e)
{
if (!m_Enabled) {
return false;
}
if (e.Button == GLFW_MOUSE_BUTTON_2) {
ImGuiIO& io = ImGui::GetIO();
if (!io.WantCaptureMouse) {
@@ -80,6 +89,10 @@ protected:
EventRelay<EventContext, Events::MouseRelease> m_EMouseRelease;
bool OnMouseRelease(const Events::MouseRelease& e)
{
if (!m_Enabled) {
return false;
}
if (e.Button == GLFW_MOUSE_BUTTON_2) {
UnlockMouse();
}
@@ -88,6 +101,10 @@ protected:
EventRelay<EventContext, Events::MouseScroll> m_EMouseScroll;
bool OnMouseScroll(const Events::MouseScroll& e)
{
if (!m_Enabled) {
return false;
}
m_SpeedMultiplier += e.DeltaY * (0.1f * m_SpeedMultiplier);
m_Config->Set("Editor.CameraSpeed", m_SpeedMultiplier);
m_Config->SaveToDisk();
@@ -18,7 +18,7 @@ public:
}
virtual const glm::vec3 Movement() const { return m_Movement; }
virtual const glm::vec3 Orientation() const { return m_Orientation; }
virtual const glm::vec3 Rotation() const { return m_Rotation; }
void LockMouse()
{
@@ -40,21 +40,19 @@ public:
return false;
}
if (m_MouseLocked) {
if (e.Command == "Pitch") {
float val = glm::radians(e.Value);
m_Orientation.x += -val;
m_Orientation.x = glm::clamp(m_Orientation.x, -glm::half_pi<float>(), glm::half_pi<float>());
//m_Orientation = m_Orientation * glm::angleAxis<float>(-val, glm::vec3(1.f, 0, 0));
return true;
}
if (e.Command == "Pitch") {
float val = glm::radians(e.Value);
m_Rotation.x += -val;
m_Rotation.x = glm::clamp(m_Rotation.x, -glm::half_pi<float>(), glm::half_pi<float>());
//m_Rotation = m_Rotation * glm::angleAxis<float>(-val, glm::vec3(1.f, 0, 0));
return true;
}
if (e.Command == "Yaw") {
float val = glm::radians(e.Value);
m_Orientation.y += -val;
//m_Orientation = glm::angleAxis<float>(-val, glm::vec3(0, 1.f, 0)) * m_Orientation;
return true;
}
if (e.Command == "Yaw") {
float val = glm::radians(e.Value);
m_Rotation.y += -val;
//m_Rotation = glm::angleAxis<float>(-val, glm::vec3(0, 1.f, 0)) * m_Rotation;
return true;
}
if (e.Command == "Forward" || e.Command == "Right") {
@@ -75,11 +73,16 @@ public:
return false;
}
virtual void Reset()
{
m_Rotation = glm::vec3(0.f, 0.f, 0.f);
}
protected:
const int m_PlayerID;
bool m_MouseLocked = false;
glm::vec3 m_Orientation;
glm::vec3 m_Rotation;
glm::vec3 m_Movement;
EventRelay<EventContext, Events::LockMouse> m_ELockMouse;