Now caching resulting absolute model matrices as well

This commit is contained in:
2016-03-12 04:10:14 +01:00
parent 01db8e0615
commit df7b4faf24
+10 -1
View File
@@ -145,7 +145,16 @@ glm::mat4 Transform::ModelMatrix(EntityID entityID, World* world)
glm::mat4 Transform::ModelMatrix(EntityWrapper entity)
{
return glm::translate(AbsolutePosition(entity)) * glm::toMat4(AbsoluteOrientation(entity)) * glm::scale(AbsoluteScale(entity));
auto cacheIt = MatrixCache.find(entity);
ComponentWrapper cTransform = entity["Transform"];
bool isDirty = cTransform["Position"].Dirty(DirtySetType::Transform) || cTransform["Orientation"].Dirty(DirtySetType::Transform) || cTransform["Scale"].Dirty(DirtySetType::Transform);
if (cacheIt != MatrixCache.end() && !isDirty) {
return cacheIt->second;
} else {
glm::mat4 matrix = glm::translate(AbsolutePosition(entity)) * glm::toMat4(AbsoluteOrientation(entity)) * glm::scale(AbsoluteScale(entity));
MatrixCache[entity] = matrix;
return matrix;
}
}
glm::vec3 Transform::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)