Implemented better relative sizing for tracking view
This commit is contained in:
parent
b4eeb90ce9
commit
e8c9a14199
5 changed files with 16 additions and 18 deletions
|
@ -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
|
||||
|
|
|
@ -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<ITrackable> &trackable)
|
||||
|
|
|
@ -56,7 +56,7 @@ private:
|
|||
|
||||
sf::Vector2f restrainToBounds(sf::Vector2f viewSize) const;
|
||||
|
||||
float getRadius(float threshold) const;
|
||||
float getFreeMovementRadius() const;
|
||||
|
||||
sf::Vector2f getSizeInWindow() const;
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue