@@ -23,10 +23,11 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile);
|
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile);
|
||||||
if (model != nullptr)
|
if (model != nullptr)
|
||||||
{
|
{
|
||||||
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
/*glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||||
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
|
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
|
||||||
glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity);
|
glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity);*/
|
||||||
m_Renderer->AddModelToDraw(model, position, orientation, scale, modelComponent->Visible, modelComponent->ShadowCaster);
|
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||||
|
m_Renderer->AddModelToDraw(model, absoluteTransform.Position, absoluteTransform.Orientation, absoluteTransform.Scale, modelComponent->Visible, modelComponent->ShadowCaster);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,3 +60,34 @@ glm::vec3 Systems::TransformSystem::AbsoluteScale(EntityID entity)
|
|||||||
|
|
||||||
return absScale;
|
return absScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Components::Transform Systems::TransformSystem::AbsoluteTransform(EntityID entity)
|
||||||
|
{
|
||||||
|
glm::vec3 absPosition;
|
||||||
|
glm::quat absOrientation;
|
||||||
|
glm::vec3 absScale(1);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
entity = m_World->GetEntityParent(entity);
|
||||||
|
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
|
||||||
|
// Position
|
||||||
|
if (entity != 0)
|
||||||
|
absPosition += transform2->Orientation * transform->Position;
|
||||||
|
else
|
||||||
|
absPosition += transform->Position;
|
||||||
|
// Orientation
|
||||||
|
absOrientation = transform->Orientation * absOrientation;
|
||||||
|
// Scale
|
||||||
|
absScale *= transform->Scale;
|
||||||
|
} while (entity != 0);
|
||||||
|
|
||||||
|
Components::Transform transform;
|
||||||
|
transform.Position = absPosition;
|
||||||
|
transform.Orientation = absOrientation;
|
||||||
|
transform.Scale = absScale;
|
||||||
|
|
||||||
|
return transform;
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ public:
|
|||||||
|
|
||||||
//void Update(double dt) override;
|
//void Update(double dt) override;
|
||||||
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
|
||||||
|
Components::Transform AbsoluteTransform(EntityID entity);
|
||||||
glm::vec3 AbsolutePosition(EntityID entity);
|
glm::vec3 AbsolutePosition(EntityID entity);
|
||||||
glm::quat AbsoluteOrientation(EntityID entity);
|
glm::quat AbsoluteOrientation(EntityID entity);
|
||||||
glm::vec3 AbsoluteScale(EntityID entity);
|
glm::vec3 AbsoluteScale(EntityID entity);
|
||||||
|
|||||||
+3
-6
@@ -22,16 +22,13 @@ EntityID World::GenerateEntityID()
|
|||||||
|
|
||||||
void World::RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID parentEntity)
|
void World::RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID parentEntity)
|
||||||
{
|
{
|
||||||
for (auto pair : m_EntityParents)
|
for (auto &pair : m_EntityParents)
|
||||||
{
|
{
|
||||||
EntityID child = pair.first;
|
EntityID child = pair.first;
|
||||||
EntityID parent = pair.second;
|
EntityID parent = pair.second;
|
||||||
|
|
||||||
if (parent == parentEntity)
|
system->UpdateEntity(dt, child, parent);
|
||||||
{
|
//RecursiveUpdate(system, dt, child);
|
||||||
system->UpdateEntity(dt, child, parent);
|
|
||||||
RecursiveUpdate(system, dt, child);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user