From 6ec22587583ff7a7344cab5e5eec536edcb0cc13 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Sun, 17 Jan 2016 06:22:35 +0100 Subject: [PATCH] Added UniformScale component which keeps an entity's scale at a uniform value relative to the screen. --- include/Engine/Core/UniformScaleSystem.h | 22 ++++++++++++++++++ resources/Schema/Components.xsd | 1 + resources/Schema/Components/UniformScale.xml | 4 ++++ resources/Schema/Components/UniformScale.xsd | 16 +++++++++++++ resources/Schema/Types/Entity.xsd | 1 + src/Engine/Core/UniformScaleSystem.cpp | 24 ++++++++++++++++++++ 6 files changed, 68 insertions(+) create mode 100644 include/Engine/Core/UniformScaleSystem.h create mode 100755 resources/Schema/Components/UniformScale.xml create mode 100755 resources/Schema/Components/UniformScale.xsd create mode 100644 src/Engine/Core/UniformScaleSystem.cpp diff --git a/include/Engine/Core/UniformScaleSystem.h b/include/Engine/Core/UniformScaleSystem.h new file mode 100644 index 00000000..f44409f0 --- /dev/null +++ b/include/Engine/Core/UniformScaleSystem.h @@ -0,0 +1,22 @@ +#ifndef UniformScaleSystem_h__ +#define UniformScaleSystem_h__ + +#include "../GLM.h" +#include "System.h" +#include "../Rendering/ESetCamera.h" + +class UniformScaleSystem : public PureSystem +{ +public: + UniformScaleSystem(EventBroker* eventBroker); + + virtual void UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& cUniformScale, double dt) override; + +private: + EntityWrapper m_Camera = EntityWrapper::Invalid; + + EventRelay m_ESetCamera; + bool OnSetCamera(const Events::SetCamera& e); +}; + +#endif \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index 8d837aea..b9c8647c 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -18,4 +18,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/UniformScale.xml b/resources/Schema/Components/UniformScale.xml new file mode 100755 index 00000000..0eed72d4 --- /dev/null +++ b/resources/Schema/Components/UniformScale.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/resources/Schema/Components/UniformScale.xsd b/resources/Schema/Components/UniformScale.xsd new file mode 100755 index 00000000..cbd218ea --- /dev/null +++ b/resources/Schema/Components/UniformScale.xsd @@ -0,0 +1,16 @@ + + + + + + + + Keeps an entity at an uniform scale relative to the camera + + + + + + + + diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 1aaa8497..47c4d614 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -27,6 +27,7 @@ + diff --git a/src/Engine/Core/UniformScaleSystem.cpp b/src/Engine/Core/UniformScaleSystem.cpp new file mode 100644 index 00000000..8cf670fc --- /dev/null +++ b/src/Engine/Core/UniformScaleSystem.cpp @@ -0,0 +1,24 @@ +#include "Core/UniformScaleSystem.h" + +UniformScaleSystem::UniformScaleSystem(EventBroker* eventBroker) + : System(eventBroker) + , PureSystem("UniformScale") +{ + EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &UniformScaleSystem::OnSetCamera); +} + +void UniformScaleSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& cUniformScale, double dt) +{ + if (!m_Camera.Valid()) { + return; + } + + float distance = glm::length((glm::vec3)entity["Transform"]["Position"] - (glm::vec3&)m_Camera["Transform"]["Position"]); + entity["Transform"]["Scale"] = (glm::vec3&)cUniformScale["Scale"] * distance; +} + +bool UniformScaleSystem::OnSetCamera(const Events::SetCamera& e) +{ + m_Camera = e.CameraEntity; + return false; +} \ No newline at end of file