Added crude absolute positioning when rendering

This commit is contained in:
sippeangelo
2015-12-09 15:26:49 +01:00
parent 578018607a
commit 90a79c702f
8 changed files with 73 additions and 14 deletions
+1 -1
Submodule assets updated: 5a207bbb3e...8a7ecf53f7
+2
View File
@@ -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;
@@ -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
+1 -1
View File
@@ -12,7 +12,7 @@
<xs:element name="Position" type="t:Vector" minOccurs="0">
<xs:annotation><xs:documentation>The position vector</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Orientation" type="t:Quaternion" minOccurs="0"/>
<xs:element name="Orientation" type="t:Vector" minOccurs="0"/>
<xs:element name="Scale" type="t:Vector" minOccurs="0"/>
</xs:all>
</xs:complexType>
+54 -1
View File
@@ -2,7 +2,9 @@
<Entity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd" xmlns:c="components">
<Components>
<c:Transform></c:Transform>
<c:Transform>
<Orientation X="0" Y="0" Z="0"/>
</c:Transform>
<c:Model>
<Resource>Models/DummyScene.obj</Resource>
</c:Model>
@@ -37,8 +39,59 @@
</c:Transform>
<c:Model>
<Resource>Models/Core/UnitRaptor.obj</Resource>
<Color R="1" G="0.4" B="0.8"/>
</c:Model>
</Components>
<Children>
<Entity>
<Components>
<c:Transform>
<Position X="-0.2" Y="0"/>
<Orientation X="0" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Transform>
<Position X="0" Y="0.4"/>
<Scale X="0.1" Y="0.4" Z="0.1"/>
</c:Transform>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
<Color R="1" G="0.4" B="0.8"/>
</c:Model>
</Components>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="0" Y="0.6"/>
<Scale X="1.7" Y="0.03" Z="0.1"/>
<Orientation X="0" Y="0" Z="0"/>
</c:Transform>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
<Color R="1" G="0.4" B="0.8"/>
</c:Model>
</Components>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="0" Y="0.6"/>
<Scale X="1.7" Y="0.03" Z="0.1"/>
<Orientation X="0" Y="1.57" Z="0"/>
</c:Transform>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
<Color R="1" G="0.4" B="0.8"/>
</c:Model>
</Components>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
+6
View File
@@ -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
+8 -9
View File
@@ -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)
+1 -1
View File
@@ -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();