From e8c9a14199b80c87ed09f694a60b6232f4502a1f Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Wed, 5 Jul 2023 15:22:20 +0200 Subject: [PATCH] Implemented better relative sizing for tracking view --- src/config.h | 4 +++- src/game/camera/tracking_view.cpp | 19 ++++++++----------- src/game/camera/tracking_view.h | 2 +- src/game/camera/tracking_view_options.hpp | 7 +++---- src/texture_config.h | 2 +- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/config.h b/src/config.h index 0ec2fdd..d793e0a 100644 --- a/src/config.h +++ b/src/config.h @@ -32,12 +32,14 @@ #define WORLD_TO_ISO_SCALE 50.0f // 50.f, don't change. Rather adjust the zoom of the camera // Tracking view defaults +#define DEF_TV_IS_ABSOLUTE_FREE_MOVE_THRESHOLD false #define DEF_TV_FREE_MOVE_THRESHOLD 0.f #define DEF_TV_SOFT_FOLLOW_SPEED 2.5f #define DEF_TV_SOFT_RESIZE_SPEED 5.f #define DEF_TV_MIN_VIEW_SIZE sf::Vector2f(6, 6) * WORLD_TO_ISO_SCALE #define DEF_TV_MAX_VIEW_SIZE sf::Vector2f(0, 0) -#define DEF_TV_VIEW_SIZE_PADDING sf::Vector2f(0.5f, 0.5f) +#define DEF_TV_IS_ABSOLUTE_VIEW_SIZE_PADDING false +#define DEF_TV_VIEW_SIZE_PADDING sf::Vector2f(3.5f, 3.5f) #define MP_VIEW_ADD_NEW_PLAYERS true #define MP_VIEW_REMOVE_DISCONNECTED_PLAYERS true #define MP_VIEW_BORDER_COLOR sf::Color::Black diff --git a/src/game/camera/tracking_view.cpp b/src/game/camera/tracking_view.cpp index 99d4be5..4b72412 100644 --- a/src/game/camera/tracking_view.cpp +++ b/src/game/camera/tracking_view.cpp @@ -83,7 +83,7 @@ void TrackingView::followTrackables() auto vectorToTarget = trackingPoint - currentCenter; auto distanceToTarget = length(vectorToTarget); - if (distanceToTarget <= getRadius(options.freeMoveThreshold)) + if (distanceToTarget <= getFreeMovementRadius()) { // Nothing to do return; @@ -95,7 +95,7 @@ void TrackingView::followTrackables() auto deltaToDesiredView = normalize(vectorToTarget); // Reduce delta to edge of free-move area to make it less jaring - deltaToDesiredView *= distanceToTarget - getRadius(options.freeMoveThreshold); + deltaToDesiredView *= distanceToTarget - getFreeMovementRadius(); moveCenter(deltaToDesiredView); } @@ -227,34 +227,31 @@ sf::Vector2f TrackingView::restrainToBounds(sf::Vector2f viewSize) const sf::Vector2f TrackingView::applyPadding(sf::Vector2f viewSize) const { auto padding = options.viewSizePadding; - if (padding.x <= 1) + if (!options.isAbsoluteViewSizePadding) { padding.x *= viewSize.x; - } - if (padding.y <= 1) - { padding.y *= viewSize.y; } return viewSize + padding; } -float TrackingView::getRadius(float threshold) const +float TrackingView::getFreeMovementRadius() const { - if (threshold <= 0) + if (options.freeMoveThreshold <= 0) { return 0; } - if (threshold > 1) + if (options.isAbsoluteFreeMoveThreshold) { - return threshold; + return options.freeMoveThreshold; } auto windowSize = getSizeInWindow(); float smallestSide = std::min(windowSize.x, windowSize.y); // Only half of the side, since we are calculating radius - return smallestSide / 2.f * threshold; + return smallestSide / 2.f * options.freeMoveThreshold; } void TrackingView::removeTrackable(const std::shared_ptr &trackable) diff --git a/src/game/camera/tracking_view.h b/src/game/camera/tracking_view.h index 7e21708..634f5dc 100644 --- a/src/game/camera/tracking_view.h +++ b/src/game/camera/tracking_view.h @@ -56,7 +56,7 @@ private: sf::Vector2f restrainToBounds(sf::Vector2f viewSize) const; - float getRadius(float threshold) const; + float getFreeMovementRadius() const; sf::Vector2f getSizeInWindow() const; }; diff --git a/src/game/camera/tracking_view_options.hpp b/src/game/camera/tracking_view_options.hpp index 955ae82..98d1beb 100644 --- a/src/game/camera/tracking_view_options.hpp +++ b/src/game/camera/tracking_view_options.hpp @@ -7,10 +7,9 @@ struct TrackingViewOptions { /** - * Value >1 to setWorld pixel radius. - * Value between 0 and 1 to setWorld relative radius based on smallest half-axis-size. */ float freeMoveThreshold = DEF_TV_FREE_MOVE_THRESHOLD; + bool isAbsoluteFreeMoveThreshold = DEF_TV_IS_ABSOLUTE_FREE_MOVE_THRESHOLD; /** * 0 for instant follow. @@ -33,10 +32,10 @@ struct TrackingViewOptions /** * Will be added to tracked area size twice, as padding for each side. - * Value >1 to setWorld pixel padding. - * Value between 0 and 1 to setWorld relative padding. + * If isAbsoluteViewSizePadding is setWorld to true, padding will be added to view size, is multiplied with tracking size and added. */ sf::Vector2f viewSizePadding = DEF_TV_VIEW_SIZE_PADDING; + bool isAbsoluteViewSizePadding = DEF_TV_IS_ABSOLUTE_VIEW_SIZE_PADDING; }; #endif //HOLESOME_TRACKING_VIEW_OPTIONS_HPP diff --git a/src/texture_config.h b/src/texture_config.h index 5ff6a8c..e6878ec 100644 --- a/src/texture_config.h +++ b/src/texture_config.h @@ -8,7 +8,7 @@ #include "sprites/configs/sprite_config.hpp" #include "sprites/tiling/tileset_config.hpp" -#define PLAYER_SKIN "ring" +#define PLAYER_SKIN "hole" /** * All textures used in the game.