From df7b4faf24328c061abc858b4cf6f8a30da06e18 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Sat, 12 Mar 2016 04:10:14 +0100 Subject: [PATCH] Now caching resulting absolute model matrices as well --- src/Engine/Core/Transform.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Engine/Core/Transform.cpp b/src/Engine/Core/Transform.cpp index 0a736421..4aed1c18 100644 --- a/src/Engine/Core/Transform.cpp +++ b/src/Engine/Core/Transform.cpp @@ -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)