Fixed absoute positioning, I think...

This commit is contained in:
sippeangelo
2015-12-10 10:15:14 +01:00
parent 90a79c702f
commit 53ef749736
2 changed files with 44 additions and 9 deletions
@@ -22,6 +22,10 @@ private:
void FillLights(World* world, RenderQueue* renderQueue);
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
+40 -9
View File
@@ -15,20 +15,51 @@ void RenderQueueFactory::Update(World* world)
glm::mat4 RenderQueueFactory::ModelMatrix(World* world, EntityID entity)
{
//should really return absolute model matrix based on parents position, scale and orientation
//GetAbsolutePosition(World* world, ComponentWrapper transformComponent)
glm::vec3 position = AbsolutePosition(world, entity);
glm::quat orientation = AbsoluteOrientation(world, entity);
glm::vec3 scale = AbsoluteScale(world, entity);
ComponentWrapper transformComponent = world->GetComponent(entity, "Transform");
glm::vec3 position = transformComponent["Position"];
glm::vec3 scale = transformComponent["Scale"];
glm::vec3 oritentation = transformComponent["Orientation"];
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
return modelMatrix;
}
glm::vec3 RenderQueueFactory::AbsolutePosition(World* world, EntityID entity)
{
glm::vec3 position;
do {
ComponentWrapper transform = world->GetComponent(entity, "Transform");
position += AbsoluteOrientation(world, entity) * (glm::vec3)transform["Position"];
entity = world->GetParent(entity);
} while (entity != 0);
return position;
}
glm::quat RenderQueueFactory::AbsoluteOrientation(World* world, EntityID entity)
{
glm::quat orientation;
do {
ComponentWrapper transform = world->GetComponent(entity, "Transform");
orientation = glm::quat((glm::vec3)transform["Orientation"]) * orientation;
entity = world->GetParent(entity);
} while (entity != 0);
return orientation;
}
glm::vec3 RenderQueueFactory::AbsoluteScale(World* world, EntityID entity)
{
ComponentWrapper transform = world->GetComponent(entity, "Transform");
glm::vec3 scale = (glm::vec3)transform["Scale"];
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;
return AbsoluteScale(world, parent) * scale;
} else {
return modelMatrix;
return scale;
}
}