diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 53cc1e40..938b0b57 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -22,6 +22,7 @@ #include "ECS_Base/Managers/SHEntityManager.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Scene/SHSceneManager.h" +#include "Math/Transform/SHTransformSystem.h" #include "Scenes/SBTestScene.h" @@ -45,8 +46,10 @@ namespace Sandbox window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow); // Create Systems - SHADE::SHSystemManager::CreateSystem(); SHADE::SHSystemManager::CreateSystem(); + // TODO(Diren): Create Physics System here + SHADE::SHSystemManager::CreateSystem(); + SHADE::SHSystemManager::CreateSystem(); SHADE::SHGraphicsSystem* graphicsSystem = static_cast(SHADE::SHSystemManager::GetSystem()); // Create Routines @@ -54,6 +57,12 @@ namespace Sandbox SHADE::SHSystemManager::RegisterRoutine(); SHADE::SHSystemManager::RegisterRoutine(); SHADE::SHSystemManager::RegisterRoutine(); + + // TODO(Diren): Register Physics System & Routines here + + SHADE::SHSystemManager::RegisterRoutine(); + SHADE::SHComponentManager::CreateComponentSparseSet(); + SHADE::SHSystemManager::RegisterRoutine(); SHADE::SHSystemManager::RegisterRoutine(); SHADE::SHSystemManager::RegisterRoutine(); diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index c59fa234..751e17a8 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -8,6 +8,7 @@ #include "Scene/SHSceneManager.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h" #include "Scripting/SHScriptEngine.h" +#include "Math/Transform/SHTransformComponent.h" using namespace SHADE; @@ -38,11 +39,15 @@ namespace Sandbox auto matInst = graphicsSystem->AddMaterialInstance(); // Create entity and add mesh - testObj = SHADE::SHEntityManager::CreateEntity(); + testObj = SHADE::SHEntityManager::CreateEntity(); auto& renderable = *SHADE::SHComponentManager::GetComponent_s(testObj); renderable.Mesh = CUBE_MESH; renderable.SetMaterial(matInst); - renderable.TransformMatrix.Translate(0.0f, 0.0f, 2.0f); + // Create transform + auto& transform = *SHADE::SHComponentManager::GetComponent_s(testObj); + transform.SetLocalPosition(SHVec3{ 0.0f, 0.0f, 2.0f }); + + renderable.TransformMatrix = SHMatrix::Translate(0.0f, 0.0f, 2.0f); SHADE::SHScriptEngine* scriptEngine = static_cast(SHADE::SHSystemManager::GetSystem()); scriptEngine->AddScript(*SHADE::SHEntityManager::GetEntityByID(testObj), "TestScript"); } diff --git a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp index adbdf746..f61f3e42 100644 --- a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp +++ b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp @@ -25,14 +25,12 @@ namespace SHADE /* Static Data Member Definitions */ /*-----------------------------------------------------------------------------------*/ - //SHTransformSystem::TransformUpdateRoutine SHTransformSystem::UpdateRoutine; - /*-----------------------------------------------------------------------------------*/ /* Constructors & Destructor Definitions */ /*-----------------------------------------------------------------------------------*/ SHTransformSystem::TransformUpdateRoutine::TransformUpdateRoutine() - : SHSystemRoutine { "Transform Update", false } + : SHSystemRoutine { "Transform Update", true } {} @@ -47,6 +45,16 @@ namespace SHADE UpdateEntity(SCENE_GRAPH.GetRoot()); } + void SHTransformSystem::Init() + { + + } + + void SHTransformSystem::Exit() + { + + } + /*-----------------------------------------------------------------------------------*/ /* Private Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ @@ -66,11 +74,9 @@ namespace SHADE SHASSERT(IS_NODE_ACTIVE == IS_ENTITY_ACTIVE, "Entity and Node active states are not synced!") #endif + // Anything below is inactive if (!IS_NODE_ACTIVE) - { - UpdateEntity(child); - continue; - } + break; const bool HAS_TRANSFORM = SHComponentManager::HasComponent(child->GetEntityID()); if (!HAS_TRANSFORM) @@ -96,7 +102,7 @@ namespace SHADE if (parent) { localToWorld = parent->GetTRS(); - worldToLocal = SHMatrix::Inverse(tf.local.trs); + worldToLocal = SHMatrix::Inverse(localToWorld); } while (!tf.updateQueue.empty()) @@ -140,6 +146,10 @@ namespace SHADE tf.world.scale = tf.local.scale * (parent ? parent->GetLocalScale() : SHVec3::One); tf.world.ComputeTRS(); + + // Transpose TRS to column major + tf.local.trs.Transpose(); + tf.world.trs.Transpose(); } } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Transform/SHTransformSystem.h b/SHADE_Engine/src/Math/Transform/SHTransformSystem.h index c57cbdbd..02c3b6c6 100644 --- a/SHADE_Engine/src/Math/Transform/SHTransformSystem.h +++ b/SHADE_Engine/src/Math/Transform/SHTransformSystem.h @@ -21,7 +21,7 @@ namespace SHADE /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ - class SH_API SHTransformSystem : public SHSystem + class SH_API SHTransformSystem final : public SHSystem { public: /*---------------------------------------------------------------------------------*/ @@ -29,7 +29,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ SHTransformSystem () = default; - ~SHTransformSystem () = default; + ~SHTransformSystem () override = default; SHTransformSystem (const SHTransformSystem&) = delete; SHTransformSystem (SHTransformSystem&&) = delete; @@ -45,7 +45,7 @@ namespace SHADE /* System Routines */ /*---------------------------------------------------------------------------------*/ - class TransformUpdateRoutine : public SHSystemRoutine + class SH_API TransformUpdateRoutine final: public SHSystemRoutine { public: /*-------------------------------------------------------------------------------*/ @@ -72,7 +72,12 @@ namespace SHADE void Execute(double dt) noexcept override; }; - //static TransformUpdateRoutine UpdateRoutine; + /*---------------------------------------------------------------------------------*/ + /* Function Members */ + /*---------------------------------------------------------------------------------*/ + + void Init () override; + void Exit () override; private: /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.cpp b/SHADE_Engine/src/Scene/SHSceneGraph.cpp index 84c7f1c5..da2dcffd 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.cpp +++ b/SHADE_Engine/src/Scene/SHSceneGraph.cpp @@ -497,9 +497,16 @@ namespace SHADE SHSceneNode* newNode = AllocateNode(entityID); if (parent == nullptr) + { + // Specific handling for root to avoid a warning when removing a non-existent child parent = root; - - newNode->SetParent(parent); + newNode->parent = root; + root->children.emplace_back(newNode); + } + else + { + newNode->SetParent(parent); + } return newNode; }