From 90a79c702fb237ebc246427528fafed4b8b3b386 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 9 Dec 2015 15:26:49 +0100 Subject: [PATCH] Added crude absolute positioning when rendering --- assets | 2 +- include/Engine/Core/World.h | 2 + include/Engine/Rendering/RenderQueueFactory.h | 1 - resources/Schema/Components/Transform.xsd | 2 +- resources/Schema/Entities/Test.xml | 55 ++++++++++++++++++- src/Engine/Core/World.cpp | 6 ++ src/Engine/Rendering/RenderQueueFactory.cpp | 17 +++--- src/Game/Game.cpp | 2 +- 8 files changed, 73 insertions(+), 14 deletions(-) diff --git a/assets b/assets index 5a207bbb..8a7ecf53 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 5a207bbb3ee4dcc620a9d2dfe8bfa0190db21a63 +Subproject commit 8a7ecf53f7ad7b8c36d778d0927fd77f7c6f6db0 diff --git a/include/Engine/Core/World.h b/include/Engine/Core/World.h index 932d2a17..65dc3be7 100644 --- a/include/Engine/Core/World.h +++ b/include/Engine/Core/World.h @@ -23,6 +23,8 @@ public: ComponentWrapper GetComponent(EntityID entity, std::string componentType); // Get all components of the specified type const ComponentPool* GetComponents(std::string componentType); + // Get entity parent + EntityID GetParent(EntityID entity); private: EntityID m_CurrentEntityID = 1; diff --git a/include/Engine/Rendering/RenderQueueFactory.h b/include/Engine/Rendering/RenderQueueFactory.h index 918692ac..f1535cdb 100644 --- a/include/Engine/Rendering/RenderQueueFactory.h +++ b/include/Engine/Rendering/RenderQueueFactory.h @@ -22,7 +22,6 @@ private: void FillLights(World* world, RenderQueue* renderQueue); glm::mat4 ModelMatrix(World* world, EntityID entity); - glm::vec3 GetAbsolutePosition(World* world, ComponentWrapper transformComponent); }; #endif \ No newline at end of file diff --git a/resources/Schema/Components/Transform.xsd b/resources/Schema/Components/Transform.xsd index d28ff601..b8d24777 100644 --- a/resources/Schema/Components/Transform.xsd +++ b/resources/Schema/Components/Transform.xsd @@ -12,7 +12,7 @@ The position vector - + diff --git a/resources/Schema/Entities/Test.xml b/resources/Schema/Entities/Test.xml index 2b003aea..4e7eafcf 100644 --- a/resources/Schema/Entities/Test.xml +++ b/resources/Schema/Entities/Test.xml @@ -2,7 +2,9 @@ - + + + Models/DummyScene.obj @@ -37,8 +39,59 @@ Models/Core/UnitRaptor.obj + + + + + + + + + + + + + + + + + + Models/Core/UnitCube.obj + + + + + + + + + + + + + Models/Core/UnitCube.obj + + + + + + + + + + + + + Models/Core/UnitCube.obj + + + + + + + \ No newline at end of file diff --git a/src/Engine/Core/World.cpp b/src/Engine/Core/World.cpp index 4ebf733e..dfab23cd 100644 --- a/src/Engine/Core/World.cpp +++ b/src/Engine/Core/World.cpp @@ -47,6 +47,12 @@ const ComponentPool* World::GetComponents(std::string componentType) return (it != m_ComponentPools.end()) ? it->second : nullptr; } + +EntityID World::GetParent(EntityID entity) +{ + return m_EntityParents.at(entity); +} + EntityID World::generateEntityID() { // TODO: Make EntityID generation smarter diff --git a/src/Engine/Rendering/RenderQueueFactory.cpp b/src/Engine/Rendering/RenderQueueFactory.cpp index 9d001b96..0ada02af 100644 --- a/src/Engine/Rendering/RenderQueueFactory.cpp +++ b/src/Engine/Rendering/RenderQueueFactory.cpp @@ -21,16 +21,15 @@ glm::mat4 RenderQueueFactory::ModelMatrix(World* world, EntityID entity) ComponentWrapper transformComponent = world->GetComponent(entity, "Transform"); glm::vec3 position = transformComponent["Position"]; glm::vec3 scale = transformComponent["Scale"]; - glm::quat oritentation = transformComponent["Orientation"]; + glm::vec3 oritentation = transformComponent["Orientation"]; - glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(oritentation) * glm::scale(scale); - return modelMatrix; -} - -glm::vec3 GetAbsolutePosition(World* world, ComponentWrapper transformComponent) -{ - // positionComponent.EntityID - return glm::vec3(); + glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(glm::quat(oritentation)) * glm::scale(scale); + EntityID parent = world->GetParent(entity); + if (parent != 0) { + return ModelMatrix(world, parent) * modelMatrix; + } else { + return modelMatrix; + } } void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 38660e73..eb62587e 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -65,8 +65,8 @@ void Game::Tick() m_EventBroker->Swap(); testTick(dt); - m_RenderQueueFactory->Update(m_World); + m_RenderQueueFactory->Update(m_World); m_Renderer->Draw(m_RenderQueueFactory->RenderQueues()); m_EventBroker->Swap();