diff --git a/src/Systems/FreeSteeringSystem.cpp b/src/Systems/FreeSteeringSystem.cpp index d59b475..edf24d0 100755 --- a/src/Systems/FreeSteeringSystem.cpp +++ b/src/Systems/FreeSteeringSystem.cpp @@ -24,95 +24,85 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit { auto transform = m_World->GetComponent(entity, "Transform"); - glm::vec3 cameraRight = glm::vec3(m_InputController->Orientation * glm::vec4(1, 0, 0, 0)); - glm::vec3 cameraForward = glm::vec3(m_InputController->Orientation * glm::vec4(0, 0, -1, 0)); + glm::vec3 cameraRight = glm::vec3(transform->Orientation * glm::vec4(1, 0, 0, 0)); + glm::vec3 cameraForward = glm::vec3(transform->Orientation * glm::vec4(0, 0, -1, 0)); glm::vec3 movement; movement += cameraRight * m_InputController->Movement.x; movement.y += m_InputController->Movement.y; movement += cameraForward * -m_InputController->Movement.z; - transform->Position += movement * steering->Speed * m_InputController->SpeedMultiplier * (float)dt; - transform->Orientation = m_InputController->Orientation; + float speedMultiplier = 1.f; + if (m_InputController->SpeedMultiplier > 0) + speedMultiplier *= 4; + else if (m_InputController->SpeedMultiplier < 0) + speedMultiplier /= 4; + + transform->Position += movement * steering->Speed * speedMultiplier * (float)dt; + + glm::quat mouseOrientationPitch = glm::quat(m_InputController->MouseOrientation * glm::vec3(1, 0, 0)); + glm::quat mouseOrientationYaw = glm::quat(m_InputController->MouseOrientation * glm::vec3(0, 1, 0)); + + glm::vec3 controllerOrientationEuler = m_InputController->ControllerOrientation * (float)dt; + glm::quat controllerOrientationPitch = glm::quat(controllerOrientationEuler * glm::vec3(1, 0, 0)); + glm::quat controllerOrientationYaw = glm::quat(controllerOrientationEuler * glm::vec3(0, 1, 0)); + + // TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS + //--------------------------------------------------------------------- + transform->Orientation = (mouseOrientationYaw * controllerOrientationYaw) + * transform->Orientation + * (mouseOrientationPitch * controllerOrientationPitch); + //--------------------------------------------------------------------- + // TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS } + + m_InputController->MouseOrientation = glm::vec3(0); } bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event) { // Movement - if (event.Command == "+cam_forward") + if (event.Command == "vertical") { - Movement.z += -1.f; + Movement.z = -event.Value; } - else if (event.Command == "-cam_forward") + else if (event.Command == "horizontal") { - Movement.z -= -1.f; + Movement.x = event.Value; } - else if (event.Command == "+cam_backward") + else if (event.Command == "normal") { - Movement.z += 1.f; - } - else if (event.Command == "-cam_backward") - { - Movement.z -= 1.f; - } - else if (event.Command == "+cam_right") - { - Movement.x -= 1.f; - } - else if (event.Command == "-cam_right") - { - Movement.x += 1.f; - } - else if (event.Command == "+cam_left") - { - Movement.x -= -1.f; - } - else if (event.Command == "-cam_left") - { - Movement.x += -1.f; - } - else if (event.Command == "+up") - { - Movement.y += 1.f; - } - else if (event.Command == "-up") - { - Movement.y -= 1.f; - } - else if (event.Command == "+down") - { - Movement.y += -1.f; - } - else if (event.Command == "-down") - { - Movement.y -= -1.f; + Movement.y = event.Value; } // Speed - else if (event.Command == "+fast") + else if (event.Command == "speed") { - SpeedMultiplier *= 4.f; - } - else if (event.Command == "-fast") - { - SpeedMultiplier /= 4.f; - } - else if (event.Command == "+slow") - { - SpeedMultiplier /= 4.f; - } - else if (event.Command == "-slow") - { - SpeedMultiplier *= 4.f; + SpeedMultiplier = event.Value; } // Mouse click - else if (event.Command == "+attack") + else if (event.Command == "attack") { - OrientationActive = true; + OrientationActive = event.Value > 0; + + if (OrientationActive) + { + Events::LockMouse e; + EventBroker->Publish(e); + } + else + { + Events::UnlockMouse e; + EventBroker->Publish(e); + } } - else if (event.Command == "-attack") + + else if (event.Command == "vertical2") { - OrientationActive = false; + ControllerOrientation.x = event.Value; + } + else if (event.Command == "horizontal2") + { + ControllerOrientation.y = -event.Value; } return true; @@ -122,11 +112,7 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnMouseMove(const { if (OrientationActive) { - // TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS - //--------------------------------------------------------------------- - Orientation = glm::angleAxis(event.DeltaX / 300.f, glm::vec3(0, -1, 0)) * Orientation * glm::angleAxis(event.DeltaY / 300.f, glm::vec3(-1, 0, 0)); - //--------------------------------------------------------------------- - // TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS + MouseOrientation = -glm::vec3(event.DeltaY / 300.f, event.DeltaX / 300.f, 0.f); } return true; diff --git a/src/Systems/FreeSteeringSystem.h b/src/Systems/FreeSteeringSystem.h index 4535cbb..b94466b 100755 --- a/src/Systems/FreeSteeringSystem.h +++ b/src/Systems/FreeSteeringSystem.h @@ -4,6 +4,7 @@ #include "Components/Transform.h" #include "Components/FreeSteering.h" #include "InputController.h" +#include "Events/LockMouse.h" namespace Systems { @@ -31,11 +32,12 @@ class FreeSteeringSystem::FreeSteeringInputController : InputController public: FreeSteeringInputController(std::shared_ptr<::EventBroker> eventBroker) : InputController(eventBroker) - , SpeedMultiplier(1.f) + , SpeedMultiplier(0.f) , OrientationActive(false) { } glm::vec3 Movement; - glm::quat Orientation; + glm::vec3 MouseOrientation; + glm::vec3 ControllerOrientation; float SpeedMultiplier; bool OrientationActive;