TravellingSystem uses EMove. EMove and ERotate copied from Returngeance into TransportSystem.

This commit is contained in:
PlatinumSkink
2015-10-15 13:44:16 +02:00
parent 4abce7b17f
commit 927c96d863
14 changed files with 347 additions and 25 deletions
+113
View File
@@ -20,12 +20,125 @@
#include "Transform/TransformSystem.h"
#include "Core/World.h"
void dd::Systems::TransformSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EMove, &Systems::TransformSystem::OnMove);
EVENT_SUBSCRIBE_MEMBER(m_ERotate, &Systems::TransformSystem::OnRotate);
}
void dd::Systems::TransformSystem::Update(double dt)
{
return;
}
void dd::Systems::TransformSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
if (m_MoveItems.find(entity) != m_MoveItems.end())
{
auto transform = m_World->GetComponent<Components::Transform>(entity);
glm::vec3 direction = glm::normalize(m_MoveItems[entity].GoalPosition - transform->Position);
glm::vec3 movement = direction * m_MoveItems[entity].Speed * (float)dt;
glm::vec3 v1 = m_MoveItems[entity].GoalPosition - transform->Position;
glm::vec3 v2 = movement;
if (glm::length(v2) >= glm::length(v1))
{
transform->Position = m_MoveItems[entity].GoalPosition;
//transform->Velocity = glm::vec3(0, 0, 0);
m_MoveItems.erase(entity);
if (m_QueuedMoveItems.find(entity) != m_QueuedMoveItems.end())
{
auto it = m_QueuedMoveItems.find(entity);
m_MoveItems[entity] = it->second;
m_QueuedMoveItems.erase(it->first);
}
}
else
{
transform->Position += movement;
//transform->Velocity = movement;
}
}
if (m_RotationItems.find(entity) != m_RotationItems.end())
{
auto transform = m_World->GetComponent<Components::Transform>(entity);
auto absolutetransform = AbsoluteTransform(entity);
float percentage = dt / m_RotationItems[entity].Time;
m_RotationItems[entity].Time -= dt;
glm::clamp(percentage, 0.f, 1.0f);
transform->Orientation = glm::slerp(transform->Orientation, m_RotationItems[entity].GoalRotation, percentage);
if (m_RotationItems[entity].Time <= 0)
{
m_RotationItems.erase(entity);
if (m_QueuedRotationItems.find(entity) != m_QueuedRotationItems.end())
{
auto it = m_QueuedRotationItems.find(entity);
m_RotationItems[entity] = it->second;
m_QueuedRotationItems.erase(it->first);
}
}
}
}
bool dd::Systems::TransformSystem::OnRotate(const Events::Rotate &event)
{
RotationItems item;
item.Entity = event.Entity;
item.GoalRotation = event.GoalRotation;
item.Time = event.Time;
if (event.Queue)
{
if (m_RotationItems.find(event.Entity) != m_RotationItems.end())
{
m_QueuedRotationItems.insert(std::make_pair(event.Entity, item));
}
else
{
m_RotationItems[event.Entity] = item;
}
}
else
{
m_RotationItems[event.Entity] = item;
}
return true;
}
bool dd::Systems::TransformSystem::OnMove(const Events::Move &event)
{
MoveItems item;
item.Entity = event.Entity;
item.GoalPosition = event.GoalPosition;
item.Speed = event.Speed;
if (event.Queue)
{
if (m_MoveItems.find(event.Entity) != m_MoveItems.end())
{
m_QueuedMoveItems.insert(std::make_pair(event.Entity, item));
}
else
{
m_MoveItems[event.Entity] = item;
}
}
else
{
m_MoveItems[event.Entity] = item;
}
return true;
}
glm::vec3 dd::Systems::TransformSystem::AbsolutePosition(EntityID entity)
{
glm::vec3 absPosition;