FreeSteeringSystem updated to allow for controller input

This commit is contained in:
2014-05-17 00:50:45 +02:00
parent 33b14b1859
commit 2a28f65c37
2 changed files with 59 additions and 71 deletions
+55 -69
View File
@@ -24,95 +24,85 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
{
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 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<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
MouseOrientation = -glm::vec3(event.DeltaY / 300.f, event.DeltaX / 300.f, 0.f);
}
return true;
+4 -2
View File
@@ -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;