SP3-16 Quaternions #112

Merged
direnbharwani merged 17 commits from SP3-16-Math into main 2022-10-23 20:07:17 +08:00
4 changed files with 80 additions and 12 deletions
Showing only changes of commit db751bd141 - Show all commits

View File

@ -38,7 +38,7 @@ Collapsed=0
DockId=0x00000002,0 DockId=0x00000002,0
[Docking][Data] [Docking][Data]
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=-227,-1256 Size=1920,1012 Split=X DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,79 Size=1920,1012 Split=X
DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1481,1036 Split=X DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1481,1036 Split=X
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=349,1036 Split=Y Selected=0x1E6EB881 DockNode ID=0x00000001 Parent=0x00000005 SizeRef=349,1036 Split=Y Selected=0x1E6EB881
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,94 Selected=0x1E6EB881 DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,94 Selected=0x1E6EB881

View File

@ -83,11 +83,13 @@ namespace Sandbox
SHSystemManager::RegisterRoutine<SHScriptEngine, SHScriptEngine::LateUpdateRoutine>(); SHSystemManager::RegisterRoutine<SHScriptEngine, SHScriptEngine::LateUpdateRoutine>();
SHSystemManager::RegisterRoutine<SHScriptEngine, SHScriptEngine::FrameCleanUpRoutine>(); SHSystemManager::RegisterRoutine<SHScriptEngine, SHScriptEngine::FrameCleanUpRoutine>();
SHSystemManager::RegisterRoutine<SHTransformSystem, SHTransformSystem::TransformPostLogicUpdate>();
SHSystemManager::RegisterRoutine<SHPhysicsSystem, SHPhysicsSystem::PhysicsPreUpdate>(); SHSystemManager::RegisterRoutine<SHPhysicsSystem, SHPhysicsSystem::PhysicsPreUpdate>();
SHSystemManager::RegisterRoutine<SHPhysicsSystem, SHPhysicsSystem::PhysicsFixedUpdate>(); SHSystemManager::RegisterRoutine<SHPhysicsSystem, SHPhysicsSystem::PhysicsFixedUpdate>();
SHSystemManager::RegisterRoutine<SHPhysicsSystem, SHPhysicsSystem::PhysicsPostUpdate>(); SHSystemManager::RegisterRoutine<SHPhysicsSystem, SHPhysicsSystem::PhysicsPostUpdate>();
SHSystemManager::RegisterRoutine<SHTransformSystem, SHTransformSystem::TransformUpdateRoutine>(); SHSystemManager::RegisterRoutine<SHTransformSystem, SHTransformSystem::TransformPostPhysicsUpdate>();
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BatcherDispatcherRoutine>(); SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BatcherDispatcherRoutine>();
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BeginRoutine>(); SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BeginRoutine>();

View File

@ -28,8 +28,12 @@ namespace SHADE
/* Constructors & Destructor Definitions */ /* Constructors & Destructor Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
SHTransformSystem::TransformUpdateRoutine::TransformUpdateRoutine() SHTransformSystem::TransformPostLogicUpdate::TransformPostLogicUpdate()
: SHSystemRoutine { "Transform Update", true } : SHSystemRoutine { "Transform Post-Logic Update", true }
{}
SHTransformSystem::TransformPostPhysicsUpdate::TransformPostPhysicsUpdate()
: SHSystemRoutine { "Transform Post-Physics Update", false }
{} {}
@ -37,13 +41,20 @@ namespace SHADE
/* Public Function Member Definitions */ /* Public Function Member Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void SHTransformSystem::TransformUpdateRoutine::Execute(double) noexcept void SHTransformSystem::TransformPostLogicUpdate::Execute(double) noexcept
{ {
// Get the current scene graph to traverse and update // Get the current scene graph to traverse and update
const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph();
UpdateEntity(SCENE_GRAPH.GetRoot()); UpdateEntity(SCENE_GRAPH.GetRoot());
} }
void SHTransformSystem::TransformPostPhysicsUpdate::Execute(double dt) noexcept
{
// Get the current scene graph to traverse and update
const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph();
UpdateEntityAndClear(SCENE_GRAPH.GetRoot());
}
void SHTransformSystem::Init() void SHTransformSystem::Init()
{ {
std::shared_ptr thisReceiver { std::make_shared<SHEventReceiverSpec<SHTransformSystem>>(this, &SHTransformSystem::ChangeParent) }; std::shared_ptr thisReceiver { std::make_shared<SHEventReceiverSpec<SHTransformSystem>>(this, &SHTransformSystem::ChangeParent) };
@ -175,6 +186,33 @@ namespace SHADE
} }
UpdateEntity(child); UpdateEntity(child);
}
}
void SHTransformSystem::UpdateEntityAndClear(const SHSceneNode* node)
{
const auto* NODE_TRANSFORM = SHComponentManager::GetComponent_s<SHTransformComponent>(node->GetEntityID());
const bool HAS_PARENT_CHANGED = NODE_TRANSFORM && NODE_TRANSFORM->dirty;
for (const auto* child : node->GetChildren())
{
auto* childTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(child->GetEntityID());
if (childTransform)
{
// Only update if node in hierarchy and component are both active
const bool IS_NODE_ACTIVE = child->IsActive();
if (IS_NODE_ACTIVE && childTransform->isActive)
{
if (childTransform->dirty || HAS_PARENT_CHANGED)
{
UpdateTransform(*childTransform, NODE_TRANSFORM);
childTransform->dirty = true;
}
}
}
UpdateEntityAndClear(child);
// Clear dirty flag after all children are updated // Clear dirty flag after all children are updated
if (childTransform) if (childTransform)

View File

@ -45,25 +45,52 @@ namespace SHADE
/* System Routines */ /* System Routines */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
class SH_API TransformUpdateRoutine final: public SHSystemRoutine class SH_API TransformPostLogicUpdate final: public SHSystemRoutine
{ {
public: public:
/*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/
/* Constructors & Destructor */ /* Constructors & Destructor */
/*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/
TransformUpdateRoutine (); TransformPostLogicUpdate ();
~TransformUpdateRoutine () = default; ~TransformPostLogicUpdate () = default;
TransformUpdateRoutine (const TransformUpdateRoutine&) = delete; TransformPostLogicUpdate (const TransformPostLogicUpdate&) = delete;
TransformUpdateRoutine (TransformUpdateRoutine&&) = delete; TransformPostLogicUpdate (TransformPostLogicUpdate&&) = delete;
/*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/
/* Operator Overloads */ /* Operator Overloads */
/*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/
TransformUpdateRoutine& operator= (const TransformUpdateRoutine&) = delete; TransformPostLogicUpdate& operator= (const TransformPostLogicUpdate&) = delete;
TransformUpdateRoutine& operator= (TransformUpdateRoutine&&) = delete; TransformPostLogicUpdate& operator= (TransformPostLogicUpdate&&) = delete;
/*-------------------------------------------------------------------------------*/
/* Function Members */
/*-------------------------------------------------------------------------------*/
void Execute(double dt) noexcept override;
};
class SH_API TransformPostPhysicsUpdate final: public SHSystemRoutine
{
public:
/*-------------------------------------------------------------------------------*/
/* Constructors & Destructor */
/*-------------------------------------------------------------------------------*/
TransformPostPhysicsUpdate ();
~TransformPostPhysicsUpdate () = default;
TransformPostPhysicsUpdate (const TransformPostPhysicsUpdate&) = delete;
TransformPostPhysicsUpdate (TransformPostPhysicsUpdate&&) = delete;
/*-------------------------------------------------------------------------------*/
/* Operator Overloads */
/*-------------------------------------------------------------------------------*/
TransformPostPhysicsUpdate& operator= (const TransformPostPhysicsUpdate&) = delete;
TransformPostPhysicsUpdate& operator= (TransformPostPhysicsUpdate&&) = delete;
/*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/
/* Function Members */ /* Function Members */
@ -88,6 +115,7 @@ namespace SHADE
static void UpdateChildrenLocalTransforms (SHSceneNode* node); static void UpdateChildrenLocalTransforms (SHSceneNode* node);
static void UpdateEntity (const SHSceneNode* node); static void UpdateEntity (const SHSceneNode* node);
static void UpdateEntityAndClear (const SHSceneNode* node);
static void UpdateTransform (SHTransformComponent& tf, const SHTransformComponent* parent = nullptr); static void UpdateTransform (SHTransformComponent& tf, const SHTransformComponent* parent = nullptr);
}; };