From 0fcca4325f13e00f00889697ac4314b9ae8e2593 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Wed, 6 Sep 2023 20:20:43 -0400 Subject: [PATCH] Transform Optimization --- Nuake/src/Scene/Systems/AnimationSystem.cpp | 1 + Nuake/src/Scene/Systems/TransformSystem.cpp | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Nuake/src/Scene/Systems/AnimationSystem.cpp b/Nuake/src/Scene/Systems/AnimationSystem.cpp index 9242115d..675e92f3 100644 --- a/Nuake/src/Scene/Systems/AnimationSystem.cpp +++ b/Nuake/src/Scene/Systems/AnimationSystem.cpp @@ -67,6 +67,7 @@ namespace Nuake transformComponent.SetLocalRotation(localRotation); transformComponent.SetLocalScale(localScale); transformComponent.SetLocalTransform(finalTransform); + transformComponent.Dirty = false; } for (auto& childBone : bone.Children) diff --git a/Nuake/src/Scene/Systems/TransformSystem.cpp b/Nuake/src/Scene/Systems/TransformSystem.cpp index 8569987b..9986e892 100644 --- a/Nuake/src/Scene/Systems/TransformSystem.cpp +++ b/Nuake/src/Scene/Systems/TransformSystem.cpp @@ -78,20 +78,33 @@ namespace Nuake Quat globalOrientation = transform.GetLocalRotation(); Vector3 globalScale = transform.GetLocalScale(); +#ifndef FRAME_PERFECT_TRANSFORM ParentComponent parentComponent = currentParent.GetComponent(); - while (parentComponent.HasParent) + if (parentComponent.HasParent) { TransformComponent& transformComponent = parentComponent.Parent.GetComponent(); - globalPosition = transformComponent.GetLocalPosition() + (globalPosition); + globalPosition = transformComponent.GetGlobalPosition() + (globalPosition); + globalScale *= transformComponent.GetGlobalScale(); + globalOrientation = transformComponent.GetGlobalRotation() * globalOrientation; + globalTransform = transformComponent.GetGlobalTransform() * globalTransform; + } +#else + while (parentComponent.HasParent) + { + TransformComponent& transformComponent = parentComponent.Parent.GetComponent(); + + globalPosition = transformComponent.GetLocalPosition() + (globalPosition); + globalScale *= transformComponent.GetLocalScale(); globalOrientation = transformComponent.GetLocalRotation() * globalOrientation; globalTransform = transformComponent.GetLocalTransform() * globalTransform; - + NameComponent& nameComponent = parentComponent.Parent.GetComponent(); parentComponent = parentComponent.Parent.GetComponent(); } +#endif // FRAME_PERFECT_TRANSFORM transform.SetGlobalPosition(globalPosition); transform.SetGlobalRotation(globalOrientation);