FreeSteeringSystem updated to allow for controller input
This commit is contained in:
@@ -24,95 +24,85 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
|||||||
{
|
{
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
|
||||||
glm::vec3 cameraRight = glm::vec3(m_InputController->Orientation * glm::vec4(1, 0, 0, 0));
|
glm::vec3 cameraRight = glm::vec3(transform->Orientation * glm::vec4(1, 0, 0, 0));
|
||||||
glm::vec3 cameraForward = glm::vec3(m_InputController->Orientation * glm::vec4(0, 0, -1, 0));
|
glm::vec3 cameraForward = glm::vec3(transform->Orientation * glm::vec4(0, 0, -1, 0));
|
||||||
glm::vec3 movement;
|
glm::vec3 movement;
|
||||||
movement += cameraRight * m_InputController->Movement.x;
|
movement += cameraRight * m_InputController->Movement.x;
|
||||||
movement.y += m_InputController->Movement.y;
|
movement.y += m_InputController->Movement.y;
|
||||||
movement += cameraForward * -m_InputController->Movement.z;
|
movement += cameraForward * -m_InputController->Movement.z;
|
||||||
transform->Position += movement * steering->Speed * m_InputController->SpeedMultiplier * (float)dt;
|
float speedMultiplier = 1.f;
|
||||||
transform->Orientation = m_InputController->Orientation;
|
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)
|
bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||||
{
|
{
|
||||||
// Movement
|
// 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;
|
Movement.y = event.Value;
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Speed
|
// Speed
|
||||||
else if (event.Command == "+fast")
|
else if (event.Command == "speed")
|
||||||
{
|
{
|
||||||
SpeedMultiplier *= 4.f;
|
SpeedMultiplier = event.Value;
|
||||||
}
|
|
||||||
else if (event.Command == "-fast")
|
|
||||||
{
|
|
||||||
SpeedMultiplier /= 4.f;
|
|
||||||
}
|
|
||||||
else if (event.Command == "+slow")
|
|
||||||
{
|
|
||||||
SpeedMultiplier /= 4.f;
|
|
||||||
}
|
|
||||||
else if (event.Command == "-slow")
|
|
||||||
{
|
|
||||||
SpeedMultiplier *= 4.f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mouse click
|
// 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;
|
return true;
|
||||||
@@ -122,11 +112,7 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnMouseMove(const
|
|||||||
{
|
{
|
||||||
if (OrientationActive)
|
if (OrientationActive)
|
||||||
{
|
{
|
||||||
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
MouseOrientation = -glm::vec3(event.DeltaY / 300.f, event.DeltaX / 300.f, 0.f);
|
||||||
//---------------------------------------------------------------------
|
|
||||||
Orientation = glm::angleAxis<float>(event.DeltaX / 300.f, glm::vec3(0, -1, 0)) * Orientation * glm::angleAxis<float>(event.DeltaY / 300.f, glm::vec3(-1, 0, 0));
|
|
||||||
//---------------------------------------------------------------------
|
|
||||||
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "Components/Transform.h"
|
#include "Components/Transform.h"
|
||||||
#include "Components/FreeSteering.h"
|
#include "Components/FreeSteering.h"
|
||||||
#include "InputController.h"
|
#include "InputController.h"
|
||||||
|
#include "Events/LockMouse.h"
|
||||||
|
|
||||||
namespace Systems
|
namespace Systems
|
||||||
{
|
{
|
||||||
@@ -31,11 +32,12 @@ class FreeSteeringSystem::FreeSteeringInputController : InputController
|
|||||||
public:
|
public:
|
||||||
FreeSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
|
FreeSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
|
||||||
: InputController(eventBroker)
|
: InputController(eventBroker)
|
||||||
, SpeedMultiplier(1.f)
|
, SpeedMultiplier(0.f)
|
||||||
, OrientationActive(false) { }
|
, OrientationActive(false) { }
|
||||||
|
|
||||||
glm::vec3 Movement;
|
glm::vec3 Movement;
|
||||||
glm::quat Orientation;
|
glm::vec3 MouseOrientation;
|
||||||
|
glm::vec3 ControllerOrientation;
|
||||||
float SpeedMultiplier;
|
float SpeedMultiplier;
|
||||||
bool OrientationActive;
|
bool OrientationActive;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user