Skip to content

Commit

Permalink
[#187]: Don't recalculate ViewProjection matrix when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Jan 31, 2024
1 parent ae16eda commit 7520986
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
Expand Down
22 changes: 12 additions & 10 deletions engine/renderer/camera/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7520986

Please sign in to comment.