diff --git a/src/game/camera/tracking_view.cpp b/src/game/camera/tracking_view.cpp index c172fca..403d768 100644 --- a/src/game/camera/tracking_view.cpp +++ b/src/game/camera/tracking_view.cpp @@ -57,7 +57,15 @@ void TrackingView::setSize(sf::Vector2f newSize) return; } - if (options.softResizeSpeed != 0) { + bool didAspectRationChange = false; + auto prevRatio = size.x / size.y; + auto newRatio = newSize.x / newSize.y; + if (abs(prevRatio - newRatio) > 0.001) + { + didAspectRationChange = true; + } + + if (options.softResizeSpeed != 0 && !didAspectRationChange) { // Smooth out transition to new size newSize = size + (newSize - size) * options.softResizeSpeed * FRAME_TIME.asSeconds(); } @@ -71,6 +79,12 @@ sf::Vector2f TrackingView::getSize() const return view->getSize(); } +sf::Vector2f TrackingView::getWindowSize() const +{ + auto size = Game::getInstance()->window->getSize(); + return {static_cast(size.x), static_cast(size.y)}; +} + sf::Vector2f TrackingView::getCenter() const { return view->getCenter(); @@ -189,8 +203,8 @@ void TrackingView::adjustSizeToTrackables() newViewSize = restrainToBounds(newViewSize); // Extend view to match aspect ratio - auto currentViewSize = getSize(); - auto aspectRatio = currentViewSize.x / currentViewSize.y; + auto windowSize = getWindowSize(); + auto aspectRatio = windowSize.x / windowSize.y; if (newViewSize.x / newViewSize.y > aspectRatio) { // Extend x-axis @@ -251,8 +265,8 @@ float TrackingView::getRadius(float threshold) const return threshold; } - auto viewSize = getSize(); - float smallestSide = std::min(viewSize.x, viewSize.y); + auto windowSize = getWindowSize(); + float smallestSide = std::min(windowSize.x, windowSize.y); // Only half of the side, since we are calculating radius return smallestSide / 2.f * threshold; diff --git a/src/game/camera/tracking_view.h b/src/game/camera/tracking_view.h index 5abe30b..5a7079d 100644 --- a/src/game/camera/tracking_view.h +++ b/src/game/camera/tracking_view.h @@ -55,6 +55,8 @@ private: sf::Vector2f restrainToBounds(sf::Vector2f viewSize) const; float getRadius(float threshold) const; + + sf::Vector2f getWindowSize() const; };