Fixed absolute positions once and for all (maybe?)

This commit is contained in:
2015-12-13 23:39:22 +01:00
parent 2f3843e595
commit 7c1182c28f
2 changed files with 20 additions and 16 deletions
@@ -13,8 +13,12 @@ public:
RenderQueueFactory(); RenderQueueFactory();
void Update(World* world); void Update(World* world);
RenderQueueCollection RenderQueues() const { return m_RenderQueues; } RenderQueueCollection RenderQueues() const { return m_RenderQueues; }
static glm::vec3 AbsolutePosition(World* world, EntityID entity);
static glm::quat AbsoluteOrientation(World* world, EntityID entity);
static glm::vec3 AbsoluteScale(World* world, EntityID entity);
private: private:
RenderQueueCollection m_RenderQueues; RenderQueueCollection m_RenderQueues;
@@ -22,10 +26,6 @@ private:
void FillLights(World* world, RenderQueue* renderQueue); void FillLights(World* world, RenderQueue* renderQueue);
glm::mat4 ModelMatrix(World* world, EntityID entity); glm::mat4 ModelMatrix(World* world, EntityID entity);
glm::vec3 AbsolutePosition(World* world, EntityID entity);
glm::quat AbsoluteOrientation(World* world, EntityID entity);
glm::vec3 AbsoluteScale(World* world, EntityID entity);
}; };
#endif #endif
+15 -11
View File
@@ -23,15 +23,19 @@ glm::mat4 RenderQueueFactory::ModelMatrix(World* world, EntityID entity)
return modelMatrix; return modelMatrix;
} }
glm::vec3 RenderQueueFactory::AbsolutePosition(World* world, EntityID entity) glm::vec3 RenderQueueFactory::AbsolutePosition(World* world, EntityID entity)
{ {
glm::vec3 position; glm::vec3 position;
do { do {
ComponentWrapper transform = world->GetComponent(entity, "Transform"); ComponentWrapper transform = world->GetComponent(entity, "Transform");
position += (glm::vec3)transform["Position"]; EntityID parent = world->GetParent(entity);
entity = world->GetParent(entity); if (parent != 0) {
position += AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
} else {
position += (glm::vec3)transform["Position"];
}
entity = parent;
} while (entity != 0); } while (entity != 0);
return position; return position;
@@ -52,15 +56,15 @@ glm::quat RenderQueueFactory::AbsoluteOrientation(World* world, EntityID entity)
glm::vec3 RenderQueueFactory::AbsoluteScale(World* world, EntityID entity) glm::vec3 RenderQueueFactory::AbsoluteScale(World* world, EntityID entity)
{ {
ComponentWrapper transform = world->GetComponent(entity, "Transform"); glm::vec3 scale(1.f);
glm::vec3 scale = (glm::vec3)transform["Scale"];
EntityID parent = world->GetParent(entity); do {
if (parent != 0) { ComponentWrapper transform = world->GetComponent(entity, "Transform");
return AbsoluteScale(world, parent) * scale; scale *= (glm::vec3)transform["Scale"];
} else { entity = world->GetParent(entity);
return scale; } while (entity != 0);
}
return scale;
} }
void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)