diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-04-08 14:34:45 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-04-08 14:34:45 +1000 |
commit | ef3dc1c60e0eb5eeded1ddb96c9a92fc52c71493 (patch) | |
tree | 4a450b1be82b5cfa6ef1bafa65de3247324f3e78 /source/rendering | |
parent | 8a8a0501590e83cbc598c7491fca0b767094466f (diff) |
fix: slightly jittery zoom level transitions
Diffstat (limited to 'source/rendering')
-rw-r--r-- | source/rendering/StarWorldCamera.cpp | 1 | ||||
-rw-r--r-- | source/rendering/StarWorldCamera.hpp | 5 |
2 files changed, 5 insertions, 1 deletions
diff --git a/source/rendering/StarWorldCamera.cpp b/source/rendering/StarWorldCamera.cpp index 81e599f..c0bc645 100644 --- a/source/rendering/StarWorldCamera.cpp +++ b/source/rendering/StarWorldCamera.cpp @@ -3,6 +3,7 @@ namespace Star { void WorldCamera::setCenterWorldPosition(Vec2F const& position, bool force) { + m_rawWorldCenter = position; // Only actually move the world center if a half pixel distance has been // moved in any direction. This is sort of arbitrary, but helps prevent // judder if the camera is at a boundary and floating point inaccuracy is diff --git a/source/rendering/StarWorldCamera.hpp b/source/rendering/StarWorldCamera.hpp index 6354167..aa0713b 100644 --- a/source/rendering/StarWorldCamera.hpp +++ b/source/rendering/StarWorldCamera.hpp @@ -51,6 +51,7 @@ private: float m_pixelRatio = 1.0f; float m_targetPixelRatio = 1.0f; Vec2F m_worldCenter; + Vec2F m_rawWorldCenter; }; inline void WorldCamera::setScreenSize(Vec2U screenSize) { @@ -122,9 +123,11 @@ inline Vec2F WorldCamera::tileMinScreen() const { inline void WorldCamera::update(float dt) { float newPixelRatio = lerp(exp(-20.0f * dt), m_targetPixelRatio, m_pixelRatio); + if (abs(newPixelRatio - m_targetPixelRatio) < 0.0125f) + newPixelRatio = m_targetPixelRatio; if (m_pixelRatio != newPixelRatio) { m_pixelRatio = newPixelRatio; - setCenterWorldPosition(m_worldCenter, true); + setCenterWorldPosition(m_rawWorldCenter, true); } } |