mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 04:19:19 +02:00
WIP
This commit is contained in:
27
entitysystem/systems/HierarchySystem.cpp
Normal file
27
entitysystem/systems/HierarchySystem.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "stdafx.h"
|
||||
#include "HierarchySystem.h"
|
||||
|
||||
#include "entitysystem/ECWorld.h"
|
||||
#include "entitysystem/components/BasicComponents.h"
|
||||
|
||||
void HierarchySystem::Update(ECWorld& world, float dt)
|
||||
{
|
||||
world.Each<ECSComponent::Parent, ECSComponent::Transform>(
|
||||
entt::exclude<ECSComponent::Disabled>,
|
||||
[&](entt::entity, ECSComponent::Parent& parent, ECSComponent::Transform& childTransform)
|
||||
{
|
||||
if (parent.value == entt::null || !world.IsAlive(parent.value))
|
||||
return;
|
||||
|
||||
const auto* parentTransform = world.GetComponent<ECSComponent::Transform>(parent.value);
|
||||
if (!parentTransform)
|
||||
return;
|
||||
|
||||
// Rotate local offset by parent rotation then add parent world position.
|
||||
glm::dvec3 rotatedOffset = glm::dvec3(parentTransform->Rotation * glm::vec3(parent.localOffset));
|
||||
childTransform.Position = parentTransform->Position + rotatedOffset;
|
||||
|
||||
// Compose rotations: child world = parent world * child local.
|
||||
childTransform.Rotation = parentTransform->Rotation * parent.localRotation;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user