Finality Engine
Toggle main menu visibility
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
17
namespace
FINALITY
18
{
20
class
WorldTransforms
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
}
Components.h
Defines authored entity components shared by scene and rendering systems.
Entity.h
Provides a scene-bound handle for component and hierarchy operations.
FINALITY::WorldTransforms::Get
glm::mat4 Get(entt::entity entity)
Definition
WorldTransforms.h:28
FINALITY::WorldTransforms::WorldTransforms
WorldTransforms(const entt::registry ®istry)
Definition
WorldTransforms.h:26
FINALITY
Definition
Asset.h:12
FINALITY::RelationshipComponent
Intrusive hierarchy links using EnTT handles; entt::null denotes a missing link.
Definition
Entity.h:84
FINALITY::RelationshipComponent::Parent
entt::entity Parent
Definition
Entity.h:85
FINALITY::TransformComponent
Definition
Components.h:38
FINALITY::TransformComponent::GetTransformMatrix
glm::mat4 GetTransformMatrix() const
Definition
Components.h:56
FinalityEngine
src
Scene
WorldTransforms.h
Generated by
1.18.0