diff --git a/include/Engine/Core/Transform.h b/include/Engine/Core/Transform.h index c43e4386..474a7bdb 100644 --- a/include/Engine/Core/Transform.h +++ b/include/Engine/Core/Transform.h @@ -4,59 +4,14 @@ #include "../GLM.h" #include "World.h" -static class Transform +namespace Transform { -public: - static glm::vec3 AbsolutePosition(World* world, EntityID entity) - { - glm::vec3 position; - while (entity != EntityID_Invalid) { - ComponentWrapper transform = world->GetComponent(entity, "Transform"); - EntityID parent = world->GetParent(entity); - position += AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"]; - entity = parent; - } +glm::vec3 AbsolutePosition(World* world, EntityID entity); +glm::quat AbsoluteOrientation(World* world, EntityID entity); +glm::vec3 AbsoluteScale(World* world, EntityID entity); +glm::mat4 ModelMatrix(EntityID entity, World* world); - return position; - }; - - static glm::quat AbsoluteOrientation(World* world, EntityID entity) - { - glm::quat orientation; - - while (entity != EntityID_Invalid) { - ComponentWrapper transform = world->GetComponent(entity, "Transform"); - orientation = glm::quat((glm::vec3)transform["Orientation"]) * orientation; - entity = world->GetParent(entity); - } - - return orientation; - }; - - static glm::vec3 AbsoluteScale(World* world, EntityID entity) - { - glm::vec3 scale(1.f); - - while (entity != EntityID_Invalid) { - ComponentWrapper transform = world->GetComponent(entity, "Transform"); - scale *= (glm::vec3)transform["Scale"]; - entity = world->GetParent(entity); - } - - return scale; - }; - - static glm::mat4 ModelMatrix(EntityID entity, World* world) - { - glm::vec3 position = Transform::AbsolutePosition(world, entity); - glm::quat orientation = Transform::AbsoluteOrientation(world, entity); - glm::vec3 scale = Transform::AbsoluteScale(world, entity); - - glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale); - return modelMatrix; - } - -}; +} #endif \ No newline at end of file diff --git a/src/Engine/Core/Transform.cpp b/src/Engine/Core/Transform.cpp new file mode 100644 index 00000000..cbc405a3 --- /dev/null +++ b/src/Engine/Core/Transform.cpp @@ -0,0 +1,52 @@ +#include "Core/Transform.h" + +glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity) +{ + glm::vec3 position; + + while (entity != EntityID_Invalid) { + ComponentWrapper transform = world->GetComponent(entity, "Transform"); + EntityID parent = world->GetParent(entity); + position += Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"]; + entity = parent; + } + + return position; +} + +glm::quat Transform::AbsoluteOrientation(World* world, EntityID entity) +{ + glm::quat orientation; + + while (entity != EntityID_Invalid) { + ComponentWrapper transform = world->GetComponent(entity, "Transform"); + orientation = glm::quat((glm::vec3)transform["Orientation"]) * orientation; + entity = world->GetParent(entity); + } + + return orientation; +} + +glm::vec3 Transform::AbsoluteScale(World* world, EntityID entity) +{ + glm::vec3 scale(1.f); + + while (entity != EntityID_Invalid) { + ComponentWrapper transform = world->GetComponent(entity, "Transform"); + scale *= (glm::vec3)transform["Scale"]; + entity = world->GetParent(entity); + } + + return scale; +} + +glm::mat4 Transform::ModelMatrix(EntityID entity, World* world) +{ + glm::vec3 position = Transform::AbsolutePosition(world, entity); + glm::quat orientation = Transform::AbsoluteOrientation(world, entity); + glm::vec3 scale = Transform::AbsoluteScale(world, entity); + + glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale); + return modelMatrix; +} + diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 1435e219..943f1a09 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -186,5 +186,4 @@ void RenderSystem::updateCamera(World* world, double dt) } m_Camera->UpdateViewMatrix(); -} - +} \ No newline at end of file diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index a49171bb..a3df754d 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -63,7 +63,6 @@ Game::Game(int argc, char* argv[]) // Create Octrees m_OctreeCollision = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4); m_OctreeFrustrumCulling = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4); - // Create system pipeline m_SystemPipeline = new SystemPipeline(m_EventBroker);