Added UniformScale component which keeps an entity's scale at a uniform value relative to the screen.

This commit is contained in:
2016-01-17 06:22:35 +01:00
parent 9f447afbdb
commit 6ec2258758
6 changed files with 68 additions and 0 deletions
+22
View File
@@ -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<UniformScaleSystem, Events::SetCamera> m_ESetCamera;
bool OnSetCamera(const Events::SetCamera& e);
};
#endif
+1
View File
@@ -18,4 +18,5 @@
<xs:include schemaLocation="Components/SpawnPoint.xsd"/>
<xs:include schemaLocation="Components/PlayerSpawn.xsd"/>
<xs:include schemaLocation="Components/Team.xsd"/>
<xs:include schemaLocation="Components/UniformScale.xsd"/>
</xs:schema>
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<UniformScale xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="UniformScale.xsd">
<Scale X="1" Y="1" Z="1"/>
</UniformScale>
+16
View File
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="UniformScale">
<xs:annotation>
<xs:documentation>Keeps an entity at an uniform scale relative to the camera</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="Scale" type="t:Vector" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+1
View File
@@ -27,6 +27,7 @@
<xs:element ref="c:SpawnPoint" minOccurs="0"/>
<xs:element ref="c:PlayerSpawn" minOccurs="0"/>
<xs:element ref="c:Team" minOccurs="0"/>
<xs:element ref="c:UniformScale" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
+24
View File
@@ -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;
}