From 7520986e97ac742ec634bfab102ecc82e21d81cb Mon Sep 17 00:00:00 2001 From: Jakub Domagala Date: Wed, 31 Jan 2024 22:40:36 +0100 Subject: [PATCH] [#187]: Don't recalculate ViewProjection matrix when not needed --- editor/editor.cpp | 2 +- engine/renderer/camera/camera.cpp | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/editor/editor.cpp b/editor/editor.cpp index 74921512..ce99140e 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -748,7 +748,7 @@ Editor::GetObjectsInArea(const std::array< glm::vec2, 4 >& area) const { std::set< Object::ID > objectsList = {}; - if (glm::length(area.at(1) - area.at(3)) < currentLevel_->GetTileSize() / 2) + if (glm::length(area.at(1) - area.at(3)) < currentLevel_->GetTileSize() / 2.0f) { return {}; } diff --git a/engine/renderer/camera/camera.cpp b/engine/renderer/camera/camera.cpp index a8661936..611080c9 100644 --- a/engine/renderer/camera/camera.cpp +++ b/engine/renderer/camera/camera.cpp @@ -89,19 +89,21 @@ Camera::Rotate(float angle, bool cumulative) void Camera::Zoom(float value) { - m_zoomScale += value * m_zoomSpeed; + const auto oldZoom = m_zoomScale; + m_zoomScale = glm::clamp(m_zoomScale + (value * m_zoomSpeed), m_maxZoomOut, m_maxZoomIn); - m_zoomScale = glm::clamp(m_zoomScale, m_maxZoomOut, m_maxZoomIn); - - const auto left = -m_windowSize.x / (2.0f + m_zoomScale); - const auto right = m_windowSize.x / (2.0f + m_zoomScale); - const auto top = m_windowSize.y / (2.0f + m_zoomScale); - const auto bottom = -m_windowSize.y / (2.0f + m_zoomScale); + if (oldZoom != m_zoomScale) + { + const auto left = -m_windowSize.x / (2.0f + m_zoomScale); + const auto right = m_windowSize.x / (2.0f + m_zoomScale); + const auto top = m_windowSize.y / (2.0f + m_zoomScale); + const auto bottom = -m_windowSize.y / (2.0f + m_zoomScale); - // NOLINTNEXTLINE top and bottom swapped intentionally - m_projectionMatrix = glm::ortho(left, right, top, bottom, nearPlane_, farPlane_); + // NOLINTNEXTLINE top and bottom swapped intentionally + m_projectionMatrix = glm::ortho(left, right, top, bottom, nearPlane_, farPlane_); - m_viewProjectionMatrix = m_projectionMatrix * m_viewMatrix; + m_viewProjectionMatrix = m_projectionMatrix * m_viewMatrix; + } } float