Merge remote-tracking branch 'origin/master' into particles
Conflicts: src/GameWorld.cpp src/Systems/ParticleSystem.cpp
This commit is contained in:
@@ -19,7 +19,7 @@ public:
|
||||
|
||||
void Update(double dt) override;
|
||||
|
||||
EventRelay<Events::KeyDown> m_EKeyDown;
|
||||
EventRelay<DebugSystem, Events::KeyDown> m_EKeyDown;
|
||||
bool OnKeyDown(const Events::KeyDown &event);
|
||||
|
||||
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
void Systems::FreeSteeringSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("FreeSteering", []() { return new Components::FreeSteering(); });
|
||||
cf->Register<Components::FreeSteering>([]() { return new Components::FreeSteering(); });
|
||||
}
|
||||
|
||||
void Systems::FreeSteeringSystem::Initialize()
|
||||
@@ -19,100 +19,90 @@ void Systems::FreeSteeringSystem::Update(double dt)
|
||||
|
||||
void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto steering = m_World->GetComponent<Components::FreeSteering>(entity, "FreeSteering");
|
||||
auto steering = m_World->GetComponent<Components::FreeSteering>(entity);
|
||||
if (steering)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
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 == "cam_vertical")
|
||||
{
|
||||
Movement.z += -1.f;
|
||||
Movement.z = -event.Value;
|
||||
}
|
||||
else if (event.Command == "-cam_forward")
|
||||
else if (event.Command == "cam_horizontal")
|
||||
{
|
||||
Movement.z -= -1.f;
|
||||
Movement.x = event.Value;
|
||||
}
|
||||
else if (event.Command == "+cam_backward")
|
||||
else if (event.Command == "cam_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 == "cam_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 == "cam_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 == "cam_vertical2")
|
||||
{
|
||||
OrientationActive = false;
|
||||
ControllerOrientation.x = event.Value;
|
||||
}
|
||||
else if (event.Command == "cam_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,6 +4,7 @@
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/FreeSteering.h"
|
||||
#include "InputController.h"
|
||||
#include "Events/LockMouse.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -26,16 +27,17 @@ private:
|
||||
std::unique_ptr<FreeSteeringInputController> m_InputController;
|
||||
};
|
||||
|
||||
class FreeSteeringSystem::FreeSteeringInputController : InputController
|
||||
class FreeSteeringSystem::FreeSteeringInputController : InputController<FreeSteeringSystem>
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "HelicopterSteeringSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::HelicopterSteeringSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register<Components::HelicopterSteering>([]() { return new Components::HelicopterSteering(); });
|
||||
}
|
||||
|
||||
void Systems::HelicopterSteeringSystem::Initialize()
|
||||
{
|
||||
m_InputController = std::unique_ptr<HelicopterSteeringInputController>(new HelicopterSteeringInputController(EventBroker));
|
||||
}
|
||||
|
||||
void Systems::HelicopterSteeringSystem::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::HelicopterSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transform)
|
||||
return;
|
||||
|
||||
auto helicopterComponent = m_World->GetComponent<Components::HelicopterSteering>(entity);
|
||||
if (helicopterComponent)
|
||||
{
|
||||
glm::vec3 controllerRotationEuler = m_InputController->Rotation * (float)dt;
|
||||
transform->Orientation *= glm::quat(controllerRotationEuler);
|
||||
|
||||
Events::ApplyForce e;
|
||||
e.Entity = entity;
|
||||
e.DeltaTime = dt;
|
||||
e.Force = glm::normalize(transform->Orientation * glm::vec3(0, 1, 0)) * (m_InputController->Power * 3000.f * 9.82f * 8.f);
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
|
||||
bool Systems::HelicopterSteeringSystem::HelicopterSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
{
|
||||
if (event.Command == "horizontal")
|
||||
{
|
||||
Rotation.z = -event.Value;
|
||||
}
|
||||
else if (event.Command == "vertical")
|
||||
{
|
||||
Rotation.x = -event.Value;
|
||||
}
|
||||
|
||||
else if (event.Command == "normal")
|
||||
{
|
||||
Power = event.Value;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::HelicopterSteeringSystem::HelicopterSteeringInputController::OnMouseMove(const Events::MouseMove &event)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Systems::HelicopterSteeringSystem::HelicopterSteeringInputController::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "System.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/HelicopterSteering.h"
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "InputController.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class HelicopterSteeringSystem : public System
|
||||
{
|
||||
public:
|
||||
HelicopterSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Initialize() override;
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
private:
|
||||
class HelicopterSteeringInputController;
|
||||
std::unique_ptr<HelicopterSteeringInputController> m_InputController;
|
||||
|
||||
std::map<EntityID, double> m_TimeSinceLastShot;
|
||||
};
|
||||
|
||||
class HelicopterSteeringSystem::HelicopterSteeringInputController : InputController<HelicopterSteeringSystem>
|
||||
{
|
||||
public:
|
||||
HelicopterSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
|
||||
: InputController(eventBroker)
|
||||
, Power(0.f)
|
||||
{ }
|
||||
|
||||
float Power;
|
||||
glm::vec3 Rotation;
|
||||
|
||||
void Update(double dt);
|
||||
|
||||
protected:
|
||||
bool OnCommand(const Events::InputCommand &event) override;
|
||||
bool OnMouseMove(const Events::MouseMove &event) override;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+152
-17
@@ -4,18 +4,23 @@
|
||||
|
||||
void Systems::InputSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("Input", []() { return new Components::Input(); });
|
||||
cf->Register<Components::Input>([]() { return new Components::Input(); });
|
||||
}
|
||||
|
||||
void Systems::InputSystem::Initialize()
|
||||
{
|
||||
// Subscribe to events
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Systems::InputSystem::OnKeyDown)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Systems::InputSystem::OnKeyUp)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Systems::InputSystem::OnMousePress)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Systems::InputSystem::OnMouseRelease)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindKey, &Systems::InputSystem::OnBindKey)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindMouseButton, &Systems::InputSystem::OnBindMouseButton)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Systems::InputSystem::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Systems::InputSystem::OnKeyUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Systems::InputSystem::OnMousePress);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Systems::InputSystem::OnMouseRelease);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGamepadAxis, &Systems::InputSystem::OnGamepadAxis);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGamepadButtonDown, &Systems::InputSystem::OnGamepadButtonDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGamepadButtonUp, &Systems::InputSystem::OnGamepadButtonUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindKey, &Systems::InputSystem::OnBindKey);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindMouseButton, &Systems::InputSystem::OnBindMouseButton);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindGamepadAxis, &Systems::InputSystem::OnBindGamepadAxis);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindGamepadButton, &Systems::InputSystem::OnBindGamepadButton);
|
||||
}
|
||||
|
||||
void Systems::InputSystem::Update(double dt)
|
||||
@@ -44,7 +49,11 @@ bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event)
|
||||
auto bindingIt = m_KeyBindings.find(event.KeyCode);
|
||||
if (bindingIt != m_KeyBindings.end())
|
||||
{
|
||||
PublishCommand(0, bindingIt->second, 1.f, false);
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandKeyboardValues[command][event.KeyCode] = value;
|
||||
PublishCommand(1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -55,7 +64,11 @@ bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event)
|
||||
auto bindingIt = m_KeyBindings.find(event.KeyCode);
|
||||
if (bindingIt != m_KeyBindings.end())
|
||||
{
|
||||
PublishCommand(0, bindingIt->second, 1.f, true);
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandKeyboardValues[command][event.KeyCode] = 0;
|
||||
PublishCommand(1, command, GetCommandTotalValue(command));;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -66,7 +79,11 @@ bool Systems::InputSystem::OnMousePress(const Events::MousePress &event)
|
||||
auto bindingIt = m_MouseButtonBindings.find(event.Button);
|
||||
if (bindingIt != m_MouseButtonBindings.end())
|
||||
{
|
||||
PublishCommand(0, bindingIt->second, 1.f, false);
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandMouseButtonValues[command][event.Button] = value;
|
||||
PublishCommand(1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -77,12 +94,62 @@ bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event)
|
||||
auto bindingIt = m_MouseButtonBindings.find(event.Button);
|
||||
if (bindingIt != m_MouseButtonBindings.end())
|
||||
{
|
||||
PublishCommand(0, bindingIt->second, 1.f, true);
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandMouseButtonValues[command][event.Button] = 0;
|
||||
PublishCommand(1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnGamepadAxis(const Events::GamepadAxis &event)
|
||||
{
|
||||
auto bindingIt = m_GamepadAxisBindings.find(event.Axis);
|
||||
if (bindingIt != m_GamepadAxisBindings.end())
|
||||
{
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandGamepadAxisValues[command][event.Axis] = event.Value * value;
|
||||
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnGamepadButtonDown(const Events::GamepadButtonDown &event)
|
||||
{
|
||||
auto bindingIt = m_GamepadButtonBindings.find(event.Button);
|
||||
if (bindingIt != m_GamepadButtonBindings.end())
|
||||
{
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandGamepadButtonValues[command][event.Button] = value;
|
||||
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnGamepadButtonUp(const Events::GamepadButtonUp &event)
|
||||
{
|
||||
auto bindingIt = m_GamepadButtonBindings.find(event.Button);
|
||||
if (bindingIt != m_GamepadButtonBindings.end())
|
||||
{
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandGamepadButtonValues[command][event.Button] = 0;
|
||||
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Systems::InputSystem::OnBindKey(const Events::BindKey &event)
|
||||
{
|
||||
if (event.Command.empty())
|
||||
@@ -91,7 +158,7 @@ bool Systems::InputSystem::OnBindKey(const Events::BindKey &event)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_KeyBindings[event.KeyCode] = event.Command;
|
||||
m_KeyBindings[event.KeyCode] = std::make_tuple(event.Command, event.Value);
|
||||
LOG_DEBUG("Input: Bound key %c to %s", (char)event.KeyCode, event.Command.c_str());
|
||||
}
|
||||
|
||||
@@ -106,25 +173,93 @@ bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &even
|
||||
}
|
||||
else
|
||||
{
|
||||
m_MouseButtonBindings[event.Button] = event.Command;
|
||||
m_MouseButtonBindings[event.Button] = std::make_tuple(event.Command, event.Value);
|
||||
LOG_DEBUG("Input: Bound mouse button %i to %s", event.Button, event.Command.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Systems::InputSystem::PublishCommand(int playerID, std::string command, float value, bool release /*= false*/)
|
||||
bool Systems::InputSystem::OnBindGamepadAxis(const Events::BindGamepadAxis &event)
|
||||
{
|
||||
if (release && command.at(0) == '+')
|
||||
if (event.Command.empty())
|
||||
{
|
||||
command[0] = '-';
|
||||
m_GamepadAxisBindings.erase(event.Axis);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_GamepadAxisBindings[event.Axis] = std::make_tuple(event.Command, event.Value);
|
||||
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Axis, event.Command.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnBindGamepadButton(const Events::BindGamepadButton &event)
|
||||
{
|
||||
if (event.Command.empty())
|
||||
{
|
||||
m_GamepadButtonBindings.erase(event.Button);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_GamepadButtonBindings[event.Button] = std::make_tuple(event.Command, event.Value);
|
||||
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Button, event.Command.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float Systems::InputSystem::GetCommandTotalValue(std::string command)
|
||||
{
|
||||
float value = 0.f;
|
||||
|
||||
auto keyboardIt = m_CommandKeyboardValues.find(command);
|
||||
if (keyboardIt != m_CommandKeyboardValues.end())
|
||||
{
|
||||
for (auto &key : keyboardIt->second)
|
||||
{
|
||||
value += key.second;
|
||||
}
|
||||
}
|
||||
|
||||
auto mouseButtonIt = m_CommandMouseButtonValues.find(command);
|
||||
if (mouseButtonIt != m_CommandMouseButtonValues.end())
|
||||
{
|
||||
for (auto &button : mouseButtonIt->second)
|
||||
{
|
||||
value += button.second;
|
||||
}
|
||||
}
|
||||
|
||||
auto gamepadAxisIt = m_CommandGamepadAxisValues.find(command);
|
||||
if (gamepadAxisIt != m_CommandGamepadAxisValues.end())
|
||||
{
|
||||
for (auto &axis : gamepadAxisIt->second)
|
||||
{
|
||||
value += axis.second;
|
||||
}
|
||||
}
|
||||
|
||||
auto gamepadButtonIt = m_CommandGamepadButtonValues.find(command);
|
||||
if (gamepadButtonIt != m_CommandGamepadButtonValues.end())
|
||||
{
|
||||
for (auto &button : gamepadButtonIt->second)
|
||||
{
|
||||
value += button.second;
|
||||
}
|
||||
}
|
||||
|
||||
return std::max(-1.f, std::min(value, 1.f));
|
||||
}
|
||||
|
||||
void Systems::InputSystem::PublishCommand(int playerID, std::string command, float value)
|
||||
{
|
||||
Events::InputCommand e;
|
||||
e.PlayerID = playerID;
|
||||
e.Command = command;
|
||||
e.Value = value;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
LOG_DEBUG("Input: Published command %s for player %i", e.Command.c_str(), playerID);
|
||||
LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, playerID);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <unordered_map>
|
||||
#include <boost/any.hpp>
|
||||
|
||||
#include "System.h"
|
||||
#include "Components/Input.h"
|
||||
@@ -10,8 +11,12 @@
|
||||
#include "Events/KeyDown.h"
|
||||
#include "Events/MousePress.h"
|
||||
#include "Events/MouseRelease.h"
|
||||
#include "Events/GamepadAxis.h"
|
||||
#include "Events/GamepadButton.h"
|
||||
#include "Events/BindKey.h"
|
||||
#include "Events/BindMouseButton.h"
|
||||
#include "Events/BindGamepadAxis.h"
|
||||
#include "Events/BindGamepadButton.h"
|
||||
#include "Events/InputCommand.h"
|
||||
|
||||
namespace Systems
|
||||
@@ -29,26 +34,43 @@ public:
|
||||
void Update(double dt) override;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::unordered_map<int, float>> m_CommandKeyboardValues; // command string -> keyboard key value for command
|
||||
std::unordered_map<std::string, std::unordered_map<int, float>> m_CommandMouseButtonValues; // command string -> mouse button value for command
|
||||
std::unordered_map<std::string, std::unordered_map<Gamepad::Axis, float>> m_CommandGamepadAxisValues; // command string -> gamepad axis value for command
|
||||
std::unordered_map<std::string, std::unordered_map<Gamepad::Button, float>> m_CommandGamepadButtonValues; // command string -> gamepad button value for command
|
||||
// Input binding tables
|
||||
std::unordered_map<int, std::string> m_KeyBindings; // GLFW_KEY... -> command string
|
||||
std::unordered_map<int, std::string> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
|
||||
std::unordered_map<int, std::tuple<std::string, float>> m_KeyBindings; // GLFW_KEY... -> command string & value
|
||||
std::unordered_map<int, std::tuple<std::string, float>> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
|
||||
std::unordered_map<Gamepad::Axis, std::tuple<std::string, float>> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value
|
||||
std::unordered_map<Gamepad::Button, std::tuple<std::string, float>> m_GamepadButtonBindings; // Gamepad::Button -> command string
|
||||
|
||||
// Input events
|
||||
EventRelay<Events::KeyDown> m_EKeyDown;
|
||||
EventRelay<InputSystem, Events::KeyDown> m_EKeyDown;
|
||||
bool OnKeyDown(const Events::KeyDown &event);
|
||||
EventRelay<Events::KeyUp> m_EKeyUp;
|
||||
EventRelay<InputSystem, Events::KeyUp> m_EKeyUp;
|
||||
bool OnKeyUp(const Events::KeyUp &event);
|
||||
EventRelay<Events::MousePress> m_EMousePress;
|
||||
EventRelay<InputSystem, Events::MousePress> m_EMousePress;
|
||||
bool OnMousePress(const Events::MousePress &event);
|
||||
EventRelay<Events::MouseRelease> m_EMouseRelease;
|
||||
EventRelay<InputSystem, Events::MouseRelease> m_EMouseRelease;
|
||||
bool OnMouseRelease(const Events::MouseRelease &event);
|
||||
EventRelay<InputSystem, Events::GamepadAxis> m_EGamepadAxis;
|
||||
bool OnGamepadAxis(const Events::GamepadAxis &event);
|
||||
EventRelay<InputSystem, Events::GamepadButtonDown> m_EGamepadButtonDown;
|
||||
bool OnGamepadButtonDown(const Events::GamepadButtonDown &event);
|
||||
EventRelay<InputSystem, Events::GamepadButtonUp> m_EGamepadButtonUp;
|
||||
bool OnGamepadButtonUp(const Events::GamepadButtonUp &event);
|
||||
// Input binding events
|
||||
EventRelay<Events::BindKey> m_EBindKey;
|
||||
EventRelay<InputSystem, Events::BindKey> m_EBindKey;
|
||||
bool OnBindKey(const Events::BindKey &event);
|
||||
EventRelay<Events::BindMouseButton> m_EBindMouseButton;
|
||||
EventRelay<InputSystem, Events::BindMouseButton> m_EBindMouseButton;
|
||||
bool OnBindMouseButton(const Events::BindMouseButton &event);
|
||||
EventRelay<InputSystem, Events::BindGamepadAxis> m_EBindGamepadAxis;
|
||||
bool OnBindGamepadAxis(const Events::BindGamepadAxis &event);
|
||||
EventRelay<InputSystem, Events::BindGamepadButton> m_EBindGamepadButton;
|
||||
bool OnBindGamepadButton(const Events::BindGamepadButton &event);
|
||||
|
||||
void PublishCommand(int playerID, std::string command, float value, bool release = false);
|
||||
float GetCommandTotalValue(std::string command);
|
||||
void PublishCommand(int playerID, std::string command, float value);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
void Systems::ParticleSystem::Initialize()
|
||||
{
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||
tempSpawnedExplosions = false;
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Systems::ParticleSystem::OnKeyUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &ParticleSystem::OnKeyUp);
|
||||
}
|
||||
|
||||
void Systems::ParticleSystem::Update(double dt)
|
||||
@@ -20,7 +20,7 @@ void Systems::ParticleSystem::Update(double dt)
|
||||
double spawnTime = it->second;
|
||||
|
||||
double timeLived = glfwGetTime() - spawnTime;
|
||||
auto eComp = m_World->GetComponent<Components::ParticleEmitter>(explosionID, "ParticleEmitter");
|
||||
auto eComp = m_World->GetComponent<Components::ParticleEmitter>(explosionID);
|
||||
|
||||
if(timeLived > eComp->LifeTime)
|
||||
{
|
||||
@@ -37,15 +37,15 @@ void Systems::ParticleSystem::Update(double dt)
|
||||
|
||||
void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if(!transformComponent)
|
||||
return;
|
||||
|
||||
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(entity, "ParticleEmitter");
|
||||
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(entity);
|
||||
if(emitterComponent)
|
||||
{
|
||||
emitterComponent->TimeSinceLastSpawn += dt;
|
||||
auto emitterTransformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto emitterTransformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
|
||||
{
|
||||
SpawnParticles(entity);
|
||||
@@ -56,8 +56,8 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end();)
|
||||
{
|
||||
EntityID particleID = (it)->ParticleID;
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(particleID, "Transform");
|
||||
auto particleComponent = m_World->GetComponent<Components::Particle>(particleID, "Particle");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(particleID);
|
||||
auto particleComponent = m_World->GetComponent<Components::Particle>(particleID);
|
||||
|
||||
double timeLived = glfwGetTime() - it->SpawnTime;
|
||||
if(timeLived > particleComponent->LifeTime)
|
||||
@@ -115,24 +115,24 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
|
||||
void Systems::ParticleSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); });
|
||||
cf->Register("Particle", []() { return new Components::Particle(); });
|
||||
cf->Register<Components::ParticleEmitter>([]() { return new Components::ParticleEmitter(); });
|
||||
cf->Register<Components::Particle>([]() { return new Components::Particle(); });
|
||||
}
|
||||
|
||||
|
||||
void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
||||
{
|
||||
auto eComponent = m_World->GetComponent<Components::ParticleEmitter>(emitterID, "ParticleEmitter");
|
||||
auto eTransform = m_World->GetComponent<Components::Transform>(emitterID, "Transform");
|
||||
auto eComponent = m_World->GetComponent<Components::ParticleEmitter>(emitterID);
|
||||
auto eTransform = m_World->GetComponent<Components::Transform>(emitterID);
|
||||
glm::vec3 ePosition = m_TransformSystem->AbsolutePosition(emitterID);
|
||||
glm::quat eOrientation = eTransform->Orientation;
|
||||
glm::vec3 paticleSpeed = glm::vec3(eComponent->Speed);
|
||||
|
||||
for(int i = 0; i < eComponent->SpawnCount; i++)
|
||||
{
|
||||
auto particleEntity = m_World->CloneEntity(eComponent->ParticleTemplate);
|
||||
auto ent = m_World->CloneEntity(eComponent->ParticleTemplate);
|
||||
|
||||
auto particleTransform = m_World->GetComponent<Components::Transform>(particleEntity, "Transform");
|
||||
auto particleTransform = m_World->GetComponent<Components::Transform>(ent);
|
||||
particleTransform->Position = ePosition;
|
||||
|
||||
particleTransform->Orientation = eOrientation;
|
||||
@@ -143,16 +143,16 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
||||
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 1, 0))) *
|
||||
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 0, 1)));
|
||||
|
||||
auto particleComponent = m_World->AddComponent<Components::Particle>(particleEntity, "Particle");
|
||||
particleComponent->LifeTime = eComponent->LifeTime;
|
||||
particleComponent->ScaleSpectrum = eComponent->ScaleSpectrum;
|
||||
particleComponent->VelocitySpectrum.push_back(particleTransform->Velocity);
|
||||
auto particle = m_World->AddComponent<Components::Particle>(ent);
|
||||
particle->LifeTime = eComponent->LifeTime;
|
||||
particle->ScaleSpectrum = eComponent->ScaleSpectrum;
|
||||
particle->VelocitySpectrum.push_back(particleTransform->Velocity);
|
||||
|
||||
if (eComponent->ScaleSpectrum.size() > 0)
|
||||
{
|
||||
if (eComponent->ScaleSpectrum.size() > 1)
|
||||
{
|
||||
particleComponent->ScaleSpectrum = eComponent->ScaleSpectrum;
|
||||
particle->ScaleSpectrum = eComponent->ScaleSpectrum;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -165,20 +165,20 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
||||
}
|
||||
|
||||
if(eComponent->UseGoalVelocity)
|
||||
particleComponent->VelocitySpectrum.push_back(eComponent->GoalVelocity);
|
||||
particleComponent->OrientationSpectrum = eComponent->OrientationSpectrum;
|
||||
if(particleComponent->OrientationSpectrum.size() != 0)
|
||||
particleTransform->Orientation = glm::angleAxis(0.f, particleComponent->OrientationSpectrum[0]);
|
||||
particleComponent->AngularVelocitySpectrum = eComponent->AngularVelocitySpectrum;
|
||||
particle->VelocitySpectrum.push_back(eComponent->GoalVelocity);
|
||||
particle->OrientationSpectrum = eComponent->OrientationSpectrum;
|
||||
if(particle->OrientationSpectrum.size() != 0)
|
||||
particleTransform->Orientation = glm::angleAxis(0.f, particle->OrientationSpectrum[0]);
|
||||
particle->AngularVelocitySpectrum = eComponent->AngularVelocitySpectrum;
|
||||
|
||||
|
||||
ParticleData data;
|
||||
data.ParticleID = particleEntity;
|
||||
data.ParticleID = ent;
|
||||
data.SpawnTime = glfwGetTime();
|
||||
if (particleComponent->AngularVelocitySpectrum.size() != 0)
|
||||
data.AngularVelocity = particleComponent->AngularVelocitySpectrum[0];
|
||||
if (particleComponent->OrientationSpectrum.size() != 0)
|
||||
data.Orientation = particleComponent->OrientationSpectrum[0];
|
||||
if (particle->AngularVelocitySpectrum.size() != 0)
|
||||
data.AngularVelocity = particle->AngularVelocitySpectrum[0];
|
||||
if (particle->OrientationSpectrum.size() != 0)
|
||||
data.Orientation = particle->OrientationSpectrum[0];
|
||||
else data.Orientation = eOrientation * glm::vec3(0,0,-1);
|
||||
m_ParticleEmitter[emitterID].push_back(data);
|
||||
}
|
||||
@@ -228,7 +228,7 @@ void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vect
|
||||
void Systems::ParticleSystem::CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale)
|
||||
{
|
||||
auto explosion = m_World->CreateEntity();
|
||||
auto emitter = m_World->AddComponent<Components::ParticleEmitter>(explosion, "ParticleEmitter");
|
||||
auto emitter = m_World->AddComponent<Components::ParticleEmitter>(explosion);
|
||||
emitter->LifeTime = _lifeTime;
|
||||
emitter->SpawnCount = _particlesToSpawn;
|
||||
emitter->Speed = _speed;
|
||||
@@ -239,14 +239,14 @@ void Systems::ParticleSystem::CreateExplosion(glm::vec3 _pos, double _lifeTime,
|
||||
m_World->CommitEntity(explosion);
|
||||
|
||||
auto particleEnt = m_World->CreateEntity();
|
||||
auto TEMP = m_World->AddComponent<Components::Transform>(particleEnt, "Transform");
|
||||
auto TEMP = m_World->AddComponent<Components::Transform>(particleEnt);
|
||||
TEMP->Scale = glm::vec3(0);
|
||||
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEnt, "Sprite");
|
||||
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEnt);
|
||||
spriteComponent->SpriteFile = _spritePath;
|
||||
m_World->CommitEntity(particleEnt);
|
||||
emitter->ParticleTemplate = particleEnt;
|
||||
|
||||
auto transform = m_World->AddComponent<Components::Transform>(explosion, "Transform");
|
||||
auto transform = m_World->AddComponent<Components::Transform>(explosion);
|
||||
transform->Position = _pos;
|
||||
transform->Orientation = _relativeUpOri;
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ private:
|
||||
|
||||
bool tempSpawnedExplosions;
|
||||
|
||||
EventRelay<Events::KeyUp> m_EKeyUp;
|
||||
EventRelay<ParticleSystem, Events::KeyUp> m_EKeyUp;
|
||||
bool OnKeyUp(const Events::KeyUp &e);
|
||||
|
||||
};
|
||||
|
||||
@@ -27,10 +27,15 @@
|
||||
|
||||
void Systems::PhysicsSystem::Initialize()
|
||||
{
|
||||
|
||||
|
||||
m_Accumulator = 0;
|
||||
|
||||
// Events
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EApplyForce, &Systems::PhysicsSystem::OnApplyForce);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EApplyPointImpulse, &Systems::PhysicsSystem::OnApplyPointImpulse);
|
||||
|
||||
hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer
|
||||
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
|
||||
@@ -70,7 +75,7 @@ void Systems::PhysicsSystem::Initialize()
|
||||
|
||||
worldInfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);
|
||||
worldInfo.m_gravity = hkVector4(0.0f, -9.82f, 0.0f);
|
||||
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // just fix the entity if the object falls off too far
|
||||
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_DO_NOTHING;
|
||||
|
||||
// You must specify the size of the broad phase - objects should not be simulated outside this region
|
||||
worldInfo.setBroadPhaseWorldSize(1000.0f);
|
||||
@@ -101,21 +106,22 @@ void Systems::PhysicsSystem::Initialize()
|
||||
SetupVisualDebugger(m_Context);
|
||||
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
m_collisionResolution = new MyCollisionResolution;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("Physics", []() { return new Components::Physics(); });
|
||||
cf->Register("BoxShape", []() { return new Components::BoxShape(); });
|
||||
cf->Register("SphereShape", []() { return new Components::SphereShape(); });
|
||||
cf->Register("Vehicle", []() { return new Components::Vehicle(); });
|
||||
cf->Register("Wheel", []() { return new Components::Wheel(); });
|
||||
cf->Register("MeshShape", []() { return new Components::MeshShape(); });
|
||||
cf->Register("HingeConstraint", []() { return new Components::HingeConstraint(); });
|
||||
cf->Register("WheelPair", []() { return new Components::WheelPair(); });
|
||||
|
||||
cf->Register<Components::Physics>([]() { return new Components::Physics(); });
|
||||
cf->Register<Components::BoxShape>([]() { return new Components::BoxShape(); });
|
||||
cf->Register<Components::SphereShape>([]() { return new Components::SphereShape(); });
|
||||
cf->Register<Components::Vehicle>([]() { return new Components::Vehicle(); });
|
||||
cf->Register<Components::Wheel>([]() { return new Components::Wheel(); });
|
||||
cf->Register<Components::MeshShape>([]() { return new Components::MeshShape(); });
|
||||
cf->Register<Components::HingeConstraint>([]() { return new Components::HingeConstraint(); });
|
||||
cf->Register<Components::WheelPair>([]() { return new Components::WheelPair(); });
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::Update(double dt)
|
||||
@@ -128,7 +134,7 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
if (m_RigidBodies.find(entity) == m_RigidBodies.end())
|
||||
continue;
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transformComponent)
|
||||
continue;
|
||||
|
||||
@@ -139,14 +145,14 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
|
||||
if (parent)
|
||||
{
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||
position = ConvertPosition(absoluteTransform.Position);
|
||||
rotation = ConvertRotation(absoluteTransform.Orientation);
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
||||
position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
|
||||
rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
|
||||
}
|
||||
else
|
||||
{
|
||||
position = ConvertPosition(transformComponent->Position);
|
||||
rotation = ConvertRotation(transformComponent->Orientation);
|
||||
position = GLMVEC3_TO_HKVECTOR4(transformComponent->Position);
|
||||
rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation);
|
||||
}
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[entity]->setPositionAndRotation(position, rotation);
|
||||
@@ -172,19 +178,16 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
// Clear accumulated timer data in this thread and all slave threads
|
||||
hkMonitorStream::getInstance().reset();
|
||||
m_ThreadPool->clearTimerData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transformComponent)
|
||||
return;
|
||||
|
||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity, "Wheel");
|
||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity);
|
||||
if (wheelComponent)
|
||||
{
|
||||
EntityID car = m_World->GetEntityParent(entity);
|
||||
@@ -201,17 +204,17 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
|
||||
hkQuaternion steeringOrientation = m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_steeringOrientationChassisSpace;
|
||||
hkReal spinAngle = -m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_spinAngle;
|
||||
glm::quat orientation = ConvertRotation(steeringOrientation) * glm::angleAxis<float>(spinAngle, glm::vec3(1, 0, 0));
|
||||
glm::quat orientation = HKQUATERNION_TO_GLMQUAT(steeringOrientation) * glm::angleAxis<float>(spinAngle, glm::vec3(1, 0, 0));
|
||||
transformComponent->Orientation = orientation * wheelComponent->OriginalOrientation;
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
}
|
||||
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
|
||||
{
|
||||
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent, "Transform");
|
||||
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent);
|
||||
|
||||
transformComponent->Position = ConvertPosition(m_RigidBodies[entity]->getPosition());
|
||||
transformComponent->Orientation = ConvertRotation(m_RigidBodies[entity]->getRotation());
|
||||
transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition());
|
||||
transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation());
|
||||
// TODO: No support for Scale, MIGHT be possible
|
||||
|
||||
if (transformComponentParent)
|
||||
@@ -227,11 +230,11 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
|
||||
void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transformComponent)
|
||||
return;
|
||||
|
||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity, "Wheel");
|
||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity);
|
||||
if (wheelComponent)
|
||||
{
|
||||
wheelComponent->ID = m_Wheels.size();
|
||||
@@ -241,9 +244,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
|
||||
EntityID entityParent = m_World->GetEntityBaseParent(entity);
|
||||
|
||||
auto sphereComponent = m_World->GetComponent<Components::SphereShape>(entity, "SphereShape");
|
||||
auto boxComponent = m_World->GetComponent<Components::BoxShape>(entity, "BoxShape");
|
||||
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape >(entity, "MeshShape");
|
||||
auto sphereComponent = m_World->GetComponent<Components::SphereShape>(entity);
|
||||
auto boxComponent = m_World->GetComponent<Components::BoxShape>(entity);
|
||||
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape >(entity);
|
||||
|
||||
if(entityParent == entity && (sphereComponent || boxComponent || meshShapeComponent))
|
||||
{
|
||||
@@ -251,7 +254,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
return;
|
||||
}
|
||||
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity, "Physics");
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||
if (physicsComponent)
|
||||
{
|
||||
hkpShape* shape;
|
||||
@@ -274,13 +277,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT);
|
||||
// Save the listShape for further use
|
||||
m_ListShapes[entity] = listShape;
|
||||
shape = listShape;
|
||||
|
||||
//////////////////////////////////
|
||||
//******************************//
|
||||
// Add a hkpBvShape //
|
||||
//******************************//
|
||||
//////////////////////////////////
|
||||
//shape = listShape;
|
||||
hkpBoxShape* box = new hkpBoxShape(listShape->m_aabbHalfExtents, 0.0f);
|
||||
shape = new hkpBvShape(listShape, box);
|
||||
|
||||
// Clean up for less memory usage
|
||||
m_Shapes.erase(entity);
|
||||
@@ -292,9 +291,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
{
|
||||
rigidBodyInfo.m_shape = shape;
|
||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_DYNAMIC;
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||
hkVector4 position = ConvertPosition(absoluteTransform.Position);
|
||||
hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation);
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
||||
hkVector4 position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
|
||||
hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
|
||||
rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3));
|
||||
rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3));
|
||||
|
||||
@@ -305,7 +304,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
// Create RigidBody
|
||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
||||
|
||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity, "Vehicle");
|
||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity);
|
||||
if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end())
|
||||
{
|
||||
for (int i = 0; i < m_Wheels.size(); i++)
|
||||
@@ -324,9 +323,11 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
m_PhysicsWorld->markForWrite();
|
||||
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
|
||||
// Add the vehicle's entities and phantoms to the world
|
||||
rigidBody->addContactListener( m_collisionResolution );
|
||||
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
||||
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||
|
||||
|
||||
// The vehicle is an action
|
||||
m_PhysicsWorld->addAction(m_Vehicles[entity]);
|
||||
@@ -340,8 +341,10 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
else
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
rigidBody->addContactListener( m_collisionResolution );
|
||||
m_PhysicsWorld->addEntity(rigidBody);
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
shape->removeReference();
|
||||
@@ -357,11 +360,11 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
for (auto &shapeData : m_Shapes[entity])
|
||||
{
|
||||
|
||||
auto childTransformComponent = m_World->GetComponent<Components::Transform>(shapeData.Entity, "Transform");
|
||||
auto childTransformComponent = m_World->GetComponent<Components::Transform>(shapeData.Entity);
|
||||
|
||||
hkVector4 position = ConvertPosition(childTransformComponent->Position);
|
||||
hkQuaternion rotation = ConvertRotation(childTransformComponent->Orientation);
|
||||
hkVector4 scale = ConvertScale(childTransformComponent->Scale);
|
||||
hkVector4 position = GLMVEC3_TO_HKVECTOR4(childTransformComponent->Position);
|
||||
hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(childTransformComponent->Orientation);
|
||||
hkVector4 scale = GLMVEC3_TO_HKVECTOR4(childTransformComponent->Scale);
|
||||
hkQsTransform transform(position, rotation, scale);
|
||||
|
||||
staticCompoundShape->addInstance(shapeData.Shape, transform);
|
||||
@@ -378,9 +381,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
{
|
||||
rigidBodyInfo.m_shape = shape;
|
||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||
hkVector4 position = ConvertPosition(absoluteTransform.Position);
|
||||
hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation);
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
||||
hkVector4 position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
|
||||
hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
|
||||
rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3));
|
||||
rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3));
|
||||
|
||||
@@ -394,6 +397,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_PhysicsWorld->addEntity(rigidBody);
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
shape->removeReference();
|
||||
@@ -411,7 +415,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
{
|
||||
hkpSphereShape* sphereShape = new hkpSphereShape(sphereComponent->Radius);
|
||||
|
||||
hkQsTransform transform( ConvertPosition(transformComponent->Position), ConvertRotation(transformComponent->Orientation), ConvertScale(transformComponent->Scale));
|
||||
hkQsTransform transform( GLMVEC3_TO_HKVECTOR4(transformComponent->Position), GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation), GLMVEC3_TO_HKVECTOR4(transformComponent->Scale));
|
||||
hkpConvexTransformShape* transformedSphereShape = new hkpConvexTransformShape( sphereShape, transform );
|
||||
|
||||
m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedSphereShape));
|
||||
@@ -424,7 +428,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
hkReal thickness = 0.05;
|
||||
hkpBoxShape* boxShape = new hkpBoxShape(hkVector4(boxComponent->Width- thickness, boxComponent->Height -thickness, boxComponent->Depth - thickness), thickness);
|
||||
|
||||
hkQsTransform transform( ConvertPosition(transformComponent->Position), ConvertRotation(transformComponent->Orientation), ConvertScale(transformComponent->Scale));
|
||||
hkQsTransform transform( GLMVEC3_TO_HKVECTOR4(transformComponent->Position), GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation), GLMVEC3_TO_HKVECTOR4(transformComponent->Scale));
|
||||
hkpConvexTransformShape* transformedBoxShape = new hkpConvexTransformShape( boxShape, transform );
|
||||
m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedBoxShape));
|
||||
boxShape->removeReference();
|
||||
@@ -532,51 +536,44 @@ void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*)
|
||||
LOG_INFO("%s", msg);
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 Systems::PhysicsSystem::ConvertPosition(const hkVector4 &hkPosition)
|
||||
{
|
||||
return glm::vec3(hkPosition(0), hkPosition(1), hkPosition(2));
|
||||
}
|
||||
|
||||
const hkVector4& Systems::PhysicsSystem::ConvertPosition(glm::vec3 glmPosition)
|
||||
{
|
||||
return hkVector4( glmPosition.x, glmPosition.y, glmPosition.z);
|
||||
}
|
||||
|
||||
glm::quat Systems::PhysicsSystem::ConvertRotation(const hkQuaternion &hkRotation)
|
||||
{
|
||||
return glm::quat(hkRotation(3), hkRotation(0), hkRotation(1), hkRotation(2));
|
||||
}
|
||||
|
||||
const hkQuaternion& Systems::PhysicsSystem::ConvertRotation(glm::quat glmRotation)
|
||||
{
|
||||
return hkQuaternion(glmRotation.x, glmRotation.y, glmRotation.z, glmRotation.w);
|
||||
}
|
||||
|
||||
glm::vec3 Systems::PhysicsSystem::ConvertScale(const hkVector4 &hkScale)
|
||||
{
|
||||
return glm::vec3(hkScale(0), hkScale(1), hkScale(2));
|
||||
}
|
||||
|
||||
const hkVector4& Systems::PhysicsSystem::ConvertScale(glm::vec3 glmScale)
|
||||
{
|
||||
return hkVector4(glmScale.x, glmScale.y, glmScale.z);
|
||||
}
|
||||
|
||||
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
|
||||
{
|
||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity, "Vehicle");
|
||||
auto inputComponent = m_World->GetComponent<Components::Input>(event.Entity, "Input");
|
||||
if (vehicleComponent && inputComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
|
||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
|
||||
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
|
||||
deviceStatus->m_positionX = event.PositionX;
|
||||
deviceStatus->m_positionY = event.PositionY;
|
||||
if(event.PositionY > 0)
|
||||
{
|
||||
deviceStatus->m_reverseButtonPressed = true;
|
||||
}
|
||||
deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity));
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::PhysicsSystem::OnApplyForce(const Events::ApplyForce &event)
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->applyForce(event.DeltaTime, GLMVEC3_TO_HKVECTOR4(event.Force));
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::PhysicsSystem::OnApplyPointImpulse( const Events::ApplyPointImpulse &event )
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->applyPointImpulse(GLMVEC3_TO_HKVECTOR4(event.Impulse), GLMVEC3_TO_HKVECTOR4(event.Position));
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
return true;
|
||||
}
|
||||
|
||||
+43
-14
@@ -1,6 +1,16 @@
|
||||
#ifndef PhysicsSystem_h__
|
||||
#define PhysicsSystem_h__
|
||||
|
||||
#define HKVECTOR4_TO_GLMVEC3(hkvec) \
|
||||
glm::vec3(hkvec(0), hkvec(1), hkvec(2))
|
||||
#define GLMVEC3_TO_HKVECTOR4(glmvec) \
|
||||
hkVector4(glmvec.x, glmvec.y, glmvec.z)
|
||||
|
||||
#define HKQUATERNION_TO_GLMQUAT(gkquat) \
|
||||
glm::quat(gkquat(3), gkquat(0), gkquat(1), gkquat(2))
|
||||
#define GLMQUAT_TO_HKQUATERNION(glmquat) \
|
||||
hkQuaternion(glmquat.x, glmquat.y, glmquat.z, glmquat.w)
|
||||
|
||||
#include "System.h"
|
||||
#include "Systems/TransformSystem.h"
|
||||
#include "Components/Transform.h"
|
||||
@@ -12,7 +22,11 @@
|
||||
#include "Components/MeshShape.h"
|
||||
#include "Components/HingeConstraint.h"
|
||||
#include "Components/WheelPair.h"
|
||||
#include "Components/TowerSteering.h"
|
||||
#include "Events/TankSteer.h"
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "Events/ApplyPointImpulse.h"
|
||||
#include "OBJ.h"
|
||||
|
||||
// Math and base include
|
||||
@@ -58,9 +72,27 @@
|
||||
#include "Physics/VehicleSetup.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include <Physics2012/Dynamics/Collide/ContactListener/hkpContactListener.h>
|
||||
|
||||
class MyCollisionResolution: public hkReferencedObject, public hkpContactListener
|
||||
{
|
||||
public:
|
||||
std::unordered_map<hkpRigidBody*, EntityID> m_RigidBodies;
|
||||
|
||||
virtual void contactPointCallback( const hkpContactPointEvent& event )
|
||||
{
|
||||
|
||||
EntityID entity1 = m_RigidBodies[event.getBody(0)];
|
||||
EntityID entity2 = m_RigidBodies[event.getBody(1)];
|
||||
//LOG_INFO("Entities colliding: %i, %i ", entity1, entity2);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class PhysicsSystem : public System
|
||||
{
|
||||
public:
|
||||
@@ -75,14 +107,20 @@ public:
|
||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||
void OnComponentRemoved(std::string type, Component* component) override;
|
||||
void OnEntityCommit(EntityID entity) override;
|
||||
|
||||
|
||||
private:
|
||||
double m_Accumulator;
|
||||
hkpWorld* m_PhysicsWorld;
|
||||
|
||||
// Events
|
||||
EventRelay<Events::TankSteer> m_ETankSteer;
|
||||
EventRelay<PhysicsSystem, Events::TankSteer> m_ETankSteer;
|
||||
bool OnTankSteer(const Events::TankSteer &event);
|
||||
EventRelay<PhysicsSystem, Events::SetVelocity> m_ESetVelocity;
|
||||
bool OnSetVelocity(const Events::SetVelocity &event);
|
||||
EventRelay<PhysicsSystem, Events::ApplyForce> m_EApplyForce;
|
||||
bool OnApplyForce(const Events::ApplyForce &event);
|
||||
EventRelay<PhysicsSystem, Events::ApplyPointImpulse> m_EApplyPointImpulse;
|
||||
bool OnApplyPointImpulse(const Events::ApplyPointImpulse &event);
|
||||
|
||||
void SetUpPhysicsState(EntityID entity, EntityID parent);
|
||||
void TearDownPhysicsState(EntityID entity, EntityID parent);
|
||||
@@ -93,16 +131,6 @@ private:
|
||||
static void HK_CALL HavokErrorReport(const char* msg, void*);
|
||||
void SetupPhysics(hkpWorld* physicsWorld);
|
||||
|
||||
// Converterfunctions
|
||||
glm::vec3 ConvertPosition(const hkVector4 &hkPosition);
|
||||
const hkVector4& ConvertPosition(glm::vec3 glmPosition);
|
||||
|
||||
glm::quat ConvertRotation(const hkQuaternion &hkRotation);
|
||||
const hkQuaternion& ConvertRotation(glm::quat glmRotation);
|
||||
|
||||
glm::vec3 ConvertScale(const hkVector4 &hkScale);
|
||||
const hkVector4&ConvertScale(glm::vec3 glmScale);
|
||||
|
||||
std::unordered_map<EntityID, hkpRigidBody*> m_RigidBodies;
|
||||
|
||||
hkJobThreadPool* m_ThreadPool;
|
||||
@@ -140,8 +168,9 @@ private:
|
||||
hkpMoppBvTreeShape* MoppShape;
|
||||
};
|
||||
std::unordered_map<EntityID, ExtendedShapeData > m_ExtendedMeshShapes;
|
||||
|
||||
MyCollisionResolution* m_collisionResolution;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // PhysicsSystem_h__
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "RaySystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::RaySystem::Initialize()
|
||||
{
|
||||
// Subscribe to events
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ECastRay, &Systems::RaySystem::OnCastRay);
|
||||
}
|
||||
|
||||
void Systems::RaySystem::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::RaySystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Systems::RaySystem::OnCastRay(const Events::CastRay &event)
|
||||
{
|
||||
Ray r;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef DebugSystem_h__
|
||||
#define DebugSystem_h__
|
||||
|
||||
#include "System.h"
|
||||
#include "Events/CastRay.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class RaySystem : public System
|
||||
{
|
||||
public:
|
||||
RaySystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
private:
|
||||
struct Ray
|
||||
{
|
||||
glm::vec3 Direction;
|
||||
};
|
||||
|
||||
EventRelay<Events::CastRay> m_ECastRay;
|
||||
bool OnCastRay(const Events::CastRay &event);
|
||||
|
||||
std::list<Ray> m_UnresolvedRays;
|
||||
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // DebugSystem_h__
|
||||
@@ -2,26 +2,59 @@
|
||||
#include "RenderSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::RenderSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
||||
void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm)
|
||||
{
|
||||
if(type == "Model")
|
||||
rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName)); });
|
||||
rm->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); });
|
||||
rm->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register<Components::Camera>([]() { return new Components::Camera(); });
|
||||
cf->Register<Components::Model>([]() { return new Components::Model(); });
|
||||
cf->Register<Components::Sprite>([]() { return new Components::Sprite(); });
|
||||
cf->Register<Components::PointLight>([]() { return new Components::PointLight(); });
|
||||
cf->Register<Components::DirectionalLight>([]() { return new Components::DirectionalLight(); });
|
||||
cf->Register<Components::Viewport>([]() { return new Components::Viewport(); });
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::OnEntityCommit(EntityID entity)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
auto camera = m_World->GetComponent<Components::Camera>(entity);
|
||||
if (transform && camera)
|
||||
{
|
||||
auto modelComponent = std::static_pointer_cast<Components::Model>(component);
|
||||
m_Renderer->RegisterCamera(entity, camera->FOV, camera->NearClip, camera->FarClip);
|
||||
m_Renderer->UpdateCamera(entity, m_TransformSystem->AbsolutePosition(entity), m_TransformSystem->AbsoluteOrientation(entity), camera->FOV, camera->NearClip, camera->FarClip);
|
||||
}
|
||||
|
||||
auto viewport = m_World->GetComponent<Components::Viewport>(entity);
|
||||
if (viewport)
|
||||
{
|
||||
m_Renderer->RegisterViewport(entity, viewport->Left, viewport->Top, viewport->Right, viewport->Bottom);
|
||||
if (viewport->Camera != 0)
|
||||
{
|
||||
m_Renderer->UpdateViewport(entity, viewport->Camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
if (transformComponent == nullptr)
|
||||
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
|
||||
if (templateComponent)
|
||||
return;
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
// Draw models
|
||||
auto modelComponent = m_World->GetComponent<Components::Model>(entity, "Model");
|
||||
if (modelComponent != nullptr)
|
||||
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
|
||||
if (transformComponent && modelComponent)
|
||||
{
|
||||
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile);
|
||||
if (model != nullptr)
|
||||
if (model)
|
||||
{
|
||||
/*glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
|
||||
@@ -31,38 +64,48 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
}
|
||||
}
|
||||
|
||||
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
|
||||
if (pointLightComponent != nullptr)
|
||||
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
|
||||
if (transformComponent && pointLightComponent)
|
||||
{
|
||||
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
m_Renderer->AddPointLightToDraw(
|
||||
position,
|
||||
pointLightComponent->Specular,
|
||||
pointLightComponent->Diffuse,
|
||||
pointLightComponent->constantAttenuation,
|
||||
pointLightComponent->linearAttenuation,
|
||||
pointLightComponent->quadraticAttenuation,
|
||||
pointLightComponent->spotExponent);
|
||||
pointLightComponent->specularExponent,
|
||||
pointLightComponent->ConstantAttenuation,
|
||||
pointLightComponent->LinearAttenuation,
|
||||
pointLightComponent->QuadraticAttenuation
|
||||
);
|
||||
}
|
||||
|
||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
|
||||
if (cameraComponent != nullptr)
|
||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity);
|
||||
if (transformComponent && cameraComponent)
|
||||
{
|
||||
m_Renderer->GetCamera()->Position(m_TransformSystem->AbsolutePosition(entity));
|
||||
m_Renderer->GetCamera()->Orientation(m_TransformSystem->AbsoluteOrientation(entity));
|
||||
|
||||
m_Renderer->GetCamera()->FOV(cameraComponent->FOV);
|
||||
m_Renderer->GetCamera()->NearClip(cameraComponent->NearClip);
|
||||
m_Renderer->GetCamera()->FarClip(cameraComponent->FarClip);
|
||||
m_Renderer->UpdateCamera(entity
|
||||
, m_TransformSystem->AbsolutePosition(entity)
|
||||
, m_TransformSystem->AbsoluteOrientation(entity)
|
||||
, cameraComponent->FOV
|
||||
, cameraComponent->NearClip
|
||||
, cameraComponent->FarClip);
|
||||
}
|
||||
|
||||
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity, "Sprite");
|
||||
if(spriteComponent != nullptr)
|
||||
auto viewportComponent = m_World->GetComponent<Components::Viewport>(entity);
|
||||
if (viewportComponent)
|
||||
{
|
||||
if (viewportComponent->Camera != 0)
|
||||
{
|
||||
m_Renderer->UpdateViewport(entity, viewportComponent->Camera);
|
||||
}
|
||||
}
|
||||
|
||||
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
||||
if (transformComponent && spriteComponent)
|
||||
{
|
||||
//TEMP
|
||||
Texture* texture = m_World->GetResourceManager()->Load<Texture>("Texture", spriteComponent->SpriteFile);
|
||||
//glBindTexture(GL_TEXTURE_2D, texture);
|
||||
auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity);
|
||||
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1));
|
||||
m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale);
|
||||
}
|
||||
@@ -70,26 +113,8 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
|
||||
void Systems::RenderSystem::Initialize()
|
||||
{
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||
|
||||
m_Renderer->SetSphereModel(m_World->GetResourceManager()->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"));
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("Camera", []() { return new Components::Camera(); });
|
||||
cf->Register("Model", []() { return new Components::Model(); });
|
||||
cf->Register("Sprite", []() { return new Components::Sprite(); });
|
||||
cf->Register("PointLight", []() { return new Components::PointLight(); });
|
||||
cf->Register("DirectionalLight", []() { return new Components::DirectionalLight(); });
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm)
|
||||
{
|
||||
rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName)); });
|
||||
rm->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); });
|
||||
rm->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "Components/Sprite.h"
|
||||
#include "Components/PointLight.h"
|
||||
#include "Components/DirectionalLight.h"
|
||||
#include "Components/Viewport.h"
|
||||
|
||||
#include "Components/Template.h"
|
||||
#include "Components/Transform.h"
|
||||
@@ -34,7 +35,7 @@ public:
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
|
||||
|
||||
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
|
||||
void OnEntityCommit(EntityID entity) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ void Systems::SoundSystem::Initialize()
|
||||
|
||||
void Systems::SoundSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("SoundEmitter", []() { return new Components::SoundEmitter(); });
|
||||
cf->Register<Components::SoundEmitter>([]() { return new Components::SoundEmitter(); });
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::RegisterResourceTypes(ResourceManager* rm)
|
||||
@@ -44,7 +44,7 @@ void Systems::SoundSystem::Update(double dt)
|
||||
|
||||
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (transformComponent == nullptr)
|
||||
return;
|
||||
|
||||
@@ -68,7 +68,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
||||
alListenerfv(AL_ORIENTATION, listenerOri);
|
||||
}
|
||||
|
||||
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
||||
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity);
|
||||
if(soundEmitter != nullptr)
|
||||
{
|
||||
ALuint source = m_Sources[soundEmitter];
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
//unsigned long dataSize;
|
||||
|
||||
// Events
|
||||
EventRelay<Events::PlaySound> m_EPlaySound;
|
||||
EventRelay<SoundSystem, Events::PlaySound> m_EPlaySound;
|
||||
bool OnPlaySound(const Events::PlaySound &event);
|
||||
|
||||
std::map<Component*, ALuint> m_Sources;
|
||||
|
||||
@@ -4,84 +4,145 @@
|
||||
|
||||
void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf )
|
||||
{
|
||||
cf->Register("TankSteering", []() { return new Components::TankSteering(); });
|
||||
cf->Register<Components::TankSteering>([]() { return new Components::TankSteering(); });
|
||||
cf->Register<Components::TowerSteering>([]() { return new Components::TowerSteering(); });
|
||||
cf->Register<Components::BarrelSteering>([]() { return new Components::BarrelSteering(); });
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::Initialize()
|
||||
{
|
||||
m_InputController = std::unique_ptr<TankSteeringInputController>(new TankSteeringInputController(EventBroker));
|
||||
m_InputController->PositionX = 0;
|
||||
m_InputController->PositionY = 0;
|
||||
m_InputController->Handbrake = false;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
m_TankInputControllers[i] = std::shared_ptr<TankSteeringInputController>(new TankSteeringInputController(EventBroker, i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::Update(double dt)
|
||||
{
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
m_TankInputControllers[i]->Update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity, "TankSteering");
|
||||
if(tankSteeringComponent)
|
||||
auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity);
|
||||
if(!tankSteeringComponent)
|
||||
return;
|
||||
|
||||
auto playerComponent = m_World->GetComponent<Components::Player>(tankSteeringComponent->Player);
|
||||
if (!playerComponent)
|
||||
return;
|
||||
|
||||
if (playerComponent->ID == 0)
|
||||
return;
|
||||
|
||||
auto inputController = m_TankInputControllers[playerComponent->ID - 1];
|
||||
|
||||
Events::TankSteer eSteering;
|
||||
eSteering.Entity = entity;
|
||||
eSteering.PositionX = inputController->PositionX;
|
||||
eSteering.PositionY = inputController->PositionY;
|
||||
eSteering.Handbrake = inputController->Handbrake;
|
||||
EventBroker->Publish(eSteering);
|
||||
|
||||
|
||||
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(tankSteeringComponent->Turret);
|
||||
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(tankSteeringComponent->Barrel);
|
||||
|
||||
if(towerSteeringComponent)
|
||||
{
|
||||
Events::TankSteer e;
|
||||
e.Entity = entity;
|
||||
e.PositionX = m_InputController->PositionX;
|
||||
e.PositionY = m_InputController->PositionY;
|
||||
e.Handbrake = m_InputController->Handbrake;
|
||||
EventBroker->Publish(e);
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(tankSteeringComponent->Turret);
|
||||
glm::quat orientation = glm::angleAxis(towerSteeringComponent->TurnSpeed * inputController->TowerDirection * (float)dt, towerSteeringComponent->Axis);
|
||||
transformComponent->Orientation *= orientation;
|
||||
}
|
||||
|
||||
if(barrelSteeringComponent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(tankSteeringComponent->Barrel);
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(tankSteeringComponent->Barrel);
|
||||
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * inputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
|
||||
transformComponent->Orientation *= orientation;
|
||||
|
||||
if(inputController->Shoot && m_TimeSinceLastShot[tankSteeringComponent->Barrel] > 0.5)
|
||||
{
|
||||
EntityID clone = m_World->CloneEntity(barrelSteeringComponent->ShotTemplate);
|
||||
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(barrelSteeringComponent->ShotTemplate);
|
||||
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone);
|
||||
cloneTransform->Position = templateAbsoluteTransform.Position;
|
||||
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
|
||||
Events::SetVelocity eSetVelocity;
|
||||
eSetVelocity.Entity = clone;
|
||||
eSetVelocity.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
|
||||
EventBroker->Publish(eSetVelocity);
|
||||
m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0;
|
||||
|
||||
|
||||
auto clonePhysicsComponent = m_World->GetComponent<Components::Physics>(clone);
|
||||
//1,670m/s
|
||||
//25kg
|
||||
Events::ApplyPointImpulse ePointImpulse ;
|
||||
ePointImpulse.Entity = entity;
|
||||
ePointImpulse.Position = absoluteTransform.Position;
|
||||
ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 1670.f;
|
||||
EventBroker->Publish(ePointImpulse);
|
||||
}
|
||||
|
||||
m_TimeSinceLastShot[tankSteeringComponent->Barrel] += dt;
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt )
|
||||
{
|
||||
PositionX = m_Horizontal;
|
||||
PositionY = m_Vertical;
|
||||
|
||||
TowerDirection = m_TowerDirection;
|
||||
BarrelDirection = m_BarrelDirection;
|
||||
Shoot = m_Shoot;
|
||||
}
|
||||
|
||||
bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
{
|
||||
float val = boost::any_cast<float>(event.Value);
|
||||
if (event.Command == "+right")
|
||||
if (event.PlayerID != this->PlayerID)
|
||||
return false;
|
||||
|
||||
float val = event.Value;
|
||||
|
||||
// Tank
|
||||
if (event.Command == "horizontal")
|
||||
{
|
||||
PositionX += val;
|
||||
m_Horizontal = val;
|
||||
m_Vertical = -0.4f;
|
||||
}
|
||||
else if (event.Command == "-right")
|
||||
else if (event.Command == "vertical")
|
||||
{
|
||||
PositionX -= val;
|
||||
m_Vertical = -val;
|
||||
}
|
||||
else if (event.Command == "+left")
|
||||
|
||||
else if (event.Command == "handbrake")
|
||||
{
|
||||
PositionX += -val;
|
||||
}
|
||||
else if (event.Command == "-left")
|
||||
{
|
||||
PositionX -= -val;
|
||||
}
|
||||
else if (event.Command == "+forward")
|
||||
{
|
||||
PositionY += -val;
|
||||
}
|
||||
else if (event.Command == "-forward")
|
||||
{
|
||||
PositionY -= -val;
|
||||
}
|
||||
else if (event.Command == "+backward")
|
||||
{
|
||||
PositionY += val;
|
||||
}
|
||||
else if (event.Command == "-backward")
|
||||
{
|
||||
PositionY -= val;
|
||||
Handbrake = val > 0;
|
||||
}
|
||||
|
||||
else if (event.Command == "+handbrake")
|
||||
// Turret
|
||||
if(event.Command == "tower_rotation")
|
||||
{
|
||||
Handbrake = true;
|
||||
m_TowerDirection = -val;
|
||||
}
|
||||
else if (event.Command == "-handbrake")
|
||||
else if(event.Command == "barrel_rotation")
|
||||
{
|
||||
Handbrake = false;
|
||||
m_BarrelDirection = val;
|
||||
}
|
||||
|
||||
else if (event.Command == "shoot")
|
||||
{
|
||||
m_Shoot = val > 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::TankSteeringSystem::TankSteeringInputController::OnMouseMove( const Events::MouseMove &event )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,9 +2,17 @@
|
||||
|
||||
#include "System.h"
|
||||
#include "Events/TankSteer.h"
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "Events/ApplyPointImpulse.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/TankSteering.h"
|
||||
#include "Components/TowerSteering.h"
|
||||
#include "Components/BarrelSteering.h"
|
||||
#include "Components/Physics.h"
|
||||
#include "Components/Vehicle.h"
|
||||
#include "Components/Player.h"
|
||||
#include "Systems/TransformSystem.h"
|
||||
#include "InputController.h"
|
||||
|
||||
namespace Systems
|
||||
@@ -24,22 +32,55 @@ namespace Systems
|
||||
|
||||
private:
|
||||
class TankSteeringInputController;
|
||||
std::unique_ptr<TankSteeringInputController> m_InputController;
|
||||
std::array<std::shared_ptr<TankSteeringInputController>, 4> m_TankInputControllers;
|
||||
|
||||
std::map<EntityID, double> m_TimeSinceLastShot;
|
||||
};
|
||||
|
||||
class TankSteeringSystem::TankSteeringInputController : InputController
|
||||
class TankSteeringSystem::TankSteeringInputController : InputController<TankSteeringSystem>
|
||||
{
|
||||
public:
|
||||
TankSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
|
||||
: InputController(eventBroker) { }
|
||||
TankSteeringInputController(std::shared_ptr<::EventBroker> eventBroker, int playerID)
|
||||
: InputController(eventBroker)
|
||||
{
|
||||
PlayerID = playerID;
|
||||
|
||||
m_Horizontal = 0.f;
|
||||
m_Vertical = 0.f;
|
||||
PositionX = 0;
|
||||
PositionY = 0;
|
||||
Handbrake = false;
|
||||
|
||||
m_TowerDirection = 0.f;
|
||||
m_BarrelDirection = 0.f;
|
||||
TowerDirection = 0.f;
|
||||
BarrelDirection = 0.f;
|
||||
|
||||
m_Shoot = false;
|
||||
}
|
||||
|
||||
int PlayerID;
|
||||
|
||||
float PositionY;
|
||||
float PositionX;
|
||||
bool Handbrake;
|
||||
|
||||
float TowerDirection;
|
||||
float BarrelDirection;
|
||||
bool Shoot;
|
||||
|
||||
void Update(double dt);
|
||||
protected:
|
||||
virtual bool OnCommand(const Events::InputCommand &event);
|
||||
virtual bool OnMouseMove(const Events::MouseMove &event);
|
||||
};
|
||||
//virtual bool OnMouseMove(const Events::MouseMove &event);
|
||||
|
||||
private:
|
||||
float m_Horizontal;
|
||||
float m_Vertical;
|
||||
|
||||
float m_TowerDirection;
|
||||
float m_BarrelDirection;
|
||||
|
||||
bool m_Shoot;
|
||||
};
|
||||
}
|
||||
@@ -7,8 +7,8 @@
|
||||
// if (parent == 0)
|
||||
// return;
|
||||
//
|
||||
// auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
// auto parentTransform = m_World->GetComponent<Components::Transform>(parent, "Transform");
|
||||
// auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
// auto parentTransform = m_World->GetComponent<Components::Transform>(parent);
|
||||
//
|
||||
// transform->Position = parentTransform->Position + transform->RelativePosition;
|
||||
//}
|
||||
@@ -20,14 +20,14 @@ glm::vec3 Systems::TransformSystem::AbsolutePosition(EntityID entity)
|
||||
|
||||
do
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
//absPosition += transform->Position;
|
||||
entity = m_World->GetEntityParent(entity);
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
if (entity != 0)
|
||||
absPosition += transform2->Orientation * transform->Position;
|
||||
else
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (entity == 0)
|
||||
absPosition += transform->Position;
|
||||
else
|
||||
absPosition = transform2->Orientation * (absPosition + transform->Position);
|
||||
} while (entity != 0);
|
||||
|
||||
return absPosition * accumulativeOrientation;
|
||||
@@ -39,7 +39,7 @@ glm::quat Systems::TransformSystem::AbsoluteOrientation(EntityID entity)
|
||||
|
||||
do
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
absOrientation = transform->Orientation * absOrientation;
|
||||
entity = m_World->GetEntityParent(entity);
|
||||
} while (entity != 0);
|
||||
@@ -53,7 +53,7 @@ glm::vec3 Systems::TransformSystem::AbsoluteScale(EntityID entity)
|
||||
|
||||
do
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
absScale *= transform->Scale;
|
||||
entity = m_World->GetEntityParent(entity);
|
||||
} while (entity != 0);
|
||||
@@ -69,15 +69,15 @@ Components::Transform Systems::TransformSystem::AbsoluteTransform(EntityID entit
|
||||
|
||||
do
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
entity = m_World->GetEntityParent(entity);
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
// Position
|
||||
if (entity != 0)
|
||||
absPosition += transform2->Orientation * transform->Position;
|
||||
else
|
||||
if (entity == 0)
|
||||
absPosition += transform->Position;
|
||||
else
|
||||
absPosition = transform2->Orientation * (absPosition + transform->Position);
|
||||
// Orientation
|
||||
absOrientation = transform->Orientation * absOrientation;
|
||||
// Scale
|
||||
|
||||
Reference in New Issue
Block a user