Finality Engine
Loading...
Searching...
No Matches
WorldTransforms.h
Go to the documentation of this file.
1
11#pragma once
12#include "Components.h"
13#include "Entity.h"
14#include <unordered_map>
15#include <vector>
16
17namespace FINALITY
18{
21 {
22 const entt::registry& m_Registry;
23 std::unordered_map<entt::entity,glm::mat4> m_Values;
24 std::vector<entt::entity> m_Path;
25 public:
26 explicit WorldTransforms(const entt::registry& registry):m_Registry(registry)
27 { m_Path.reserve(32); }
28 glm::mat4 Get(entt::entity entity)
29 {
30 const auto* local=m_Registry.try_get<TransformComponent>(entity);
31 if(!local) return glm::mat4(1);
32 const auto* parent=m_Registry.try_get<RelationshipComponent>(entity);
33 if(!parent || !m_Registry.valid(parent->Parent)) return local->GetTransformMatrix();
34 m_Path.clear(); auto cursor=entity; glm::mat4 value(1);
35 while(m_Registry.valid(cursor) && m_Path.size()<1024)
36 {
37 if(const auto known=m_Values.find(cursor);known!=m_Values.end()) { value=known->second; break; }
38 if(!m_Registry.all_of<TransformComponent>(cursor)) break;
39 m_Path.push_back(cursor);
40 const auto* relationship=m_Registry.try_get<RelationshipComponent>(cursor);
41 cursor=relationship ? relationship->Parent : entt::null;
42 }
43 for(auto it=m_Path.rbegin();it!=m_Path.rend();++it)
44 { value*=m_Registry.get<TransformComponent>(*it).GetTransformMatrix(); m_Values.insert_or_assign(*it,value); }
45 return value;
46 }
47 };
48}
Defines authored entity components shared by scene and rendering systems.
Provides a scene-bound handle for component and hierarchy operations.
glm::mat4 Get(entt::entity entity)
WorldTransforms(const entt::registry &registry)
Intrusive hierarchy links using EnTT handles; entt::null denotes a missing link.
Definition Entity.h:84
glm::mat4 GetTransformMatrix() const
Definition Components.h:56