#pragma once #include "ecs_system.hpp" #include "components/transform.hpp" #include "scene.hpp" #include "log.hpp" #include #include #include #include #include namespace engine { class TransformSystem : public System { public: TransformSystem(Scene* scene) : System(scene, { typeid(TransformComponent).hash_code() }) { } void onUpdate(float ts) override { for (uint32_t entity : m_entities) { auto t = m_scene->getComponent(entity); TRACE("tag is {}", t->tag); glm::mat4 transform; // rotation transform = glm::mat4_cast(t->rotation); // position reinterpret_cast(transform[3]) = t->position; // scale (effectively applied first) transform = glm::scale(transform, t->scale); if (t->parent != 0) { transform = m_scene->getComponent(t->parent)->worldMatrix * transform; } t->worldMatrix = transform; } } uint32_t getChildEntity(uint32_t parent, const std::string& tag) { for (uint32_t entity : m_entities) { auto t = m_scene->getComponent(entity); if (t->parent == parent) { if (t->tag == tag) { return entity; } } } return 0; } }; }