fix: slightly jittery zoom level transitions
This commit is contained in:
parent
8a8a050159
commit
ef3dc1c60e
@ -3,6 +3,7 @@
|
|||||||
namespace Star {
|
namespace Star {
|
||||||
|
|
||||||
void WorldCamera::setCenterWorldPosition(Vec2F const& position, bool force) {
|
void WorldCamera::setCenterWorldPosition(Vec2F const& position, bool force) {
|
||||||
|
m_rawWorldCenter = position;
|
||||||
// Only actually move the world center if a half pixel distance has been
|
// 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
|
// 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
|
// judder if the camera is at a boundary and floating point inaccuracy is
|
||||||
|
@ -51,6 +51,7 @@ private:
|
|||||||
float m_pixelRatio = 1.0f;
|
float m_pixelRatio = 1.0f;
|
||||||
float m_targetPixelRatio = 1.0f;
|
float m_targetPixelRatio = 1.0f;
|
||||||
Vec2F m_worldCenter;
|
Vec2F m_worldCenter;
|
||||||
|
Vec2F m_rawWorldCenter;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void WorldCamera::setScreenSize(Vec2U screenSize) {
|
inline void WorldCamera::setScreenSize(Vec2U screenSize) {
|
||||||
@ -122,9 +123,11 @@ inline Vec2F WorldCamera::tileMinScreen() const {
|
|||||||
|
|
||||||
inline void WorldCamera::update(float dt) {
|
inline void WorldCamera::update(float dt) {
|
||||||
float newPixelRatio = lerp(exp(-20.0f * dt), m_targetPixelRatio, m_pixelRatio);
|
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) {
|
if (m_pixelRatio != newPixelRatio) {
|
||||||
m_pixelRatio = newPixelRatio;
|
m_pixelRatio = newPixelRatio;
|
||||||
setCenterWorldPosition(m_worldCenter, true);
|
setCenterWorldPosition(m_rawWorldCenter, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user