Refined tracking view and extracted concept of tracking area
This commit is contained in:
parent
269d40aec9
commit
7f1530bdec
5 changed files with 70 additions and 47 deletions
|
@ -55,7 +55,7 @@ set(SOURCES
|
||||||
src/utilities/magic_enum.hpp
|
src/utilities/magic_enum.hpp
|
||||||
src/game/player/player_spawner.cpp
|
src/game/player/player_spawner.cpp
|
||||||
src/game/player/player_spawner.hpp
|
src/game/player/player_spawner.hpp
|
||||||
)
|
src/game/camera/tracking_area.h)
|
||||||
|
|
||||||
set(PHYSICS_00_SOURCES
|
set(PHYSICS_00_SOURCES
|
||||||
src/prototypes/physics_00.cpp)
|
src/prototypes/physics_00.cpp)
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#define ISOMETRIC_SKEW 0.3f
|
#define ISOMETRIC_SKEW 0.3f
|
||||||
#define WORLD_TO_ISO_SCALE 10.0f
|
#define WORLD_TO_ISO_SCALE 10.0f
|
||||||
|
|
||||||
#define VIEW_DYNAMIC_FOLLOW_SPEED 0.05f
|
#define VIEW_DYNAMIC_FOLLOW_SPEED 2.f
|
||||||
|
|
||||||
// Inputs
|
// Inputs
|
||||||
#define JOYSTICK_DEADZONE 0.1f
|
#define JOYSTICK_DEADZONE 0.1f
|
||||||
|
|
18
src/game/camera/tracking_area.h
Normal file
18
src/game/camera/tracking_area.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef HOLESOME_TRACKING_AREA_H
|
||||||
|
#define HOLESOME_TRACKING_AREA_H
|
||||||
|
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
|
struct TrackingArea
|
||||||
|
{
|
||||||
|
sf::Vector2f topLeft;
|
||||||
|
sf::Vector2f bottomRight;
|
||||||
|
|
||||||
|
sf::Vector2f getCenter() const
|
||||||
|
{
|
||||||
|
return topLeft + (bottomRight - topLeft) / 2.f;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //HOLESOME_TRACKING_AREA_H
|
|
@ -78,8 +78,9 @@ sf::Vector2f TrackingView::getCenter() const
|
||||||
|
|
||||||
void TrackingView::followTarget()
|
void TrackingView::followTarget()
|
||||||
{
|
{
|
||||||
auto trackingPoint = getCollectiveTrackingPoint();
|
auto trackingPoint = getTrackingArea().getCenter();
|
||||||
if (DEVELOPER_MODE) {
|
if (DEVELOPER_MODE)
|
||||||
|
{
|
||||||
marker->coordinates.set(IsometricCoordinates(trackingPoint));
|
marker->coordinates.set(IsometricCoordinates(trackingPoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,12 +96,14 @@ void TrackingView::followTarget()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move view to place tracking-point at edge of area
|
// Move view to place tracking-point at edge of area
|
||||||
auto deltaToDesiredView = normalize(vectorToTarget);
|
auto deltaToDesiredView = normalize(vectorToTarget) * FRAME_TIME.asSeconds();
|
||||||
|
|
||||||
if (distanceToTarget <= dynamicFollowRadius) {
|
if (distanceToTarget <= dynamicFollowRadius)
|
||||||
|
{
|
||||||
// Reduce delta to make it less jaring
|
// Reduce delta to make it less jaring
|
||||||
deltaToDesiredView *= VIEW_DYNAMIC_FOLLOW_SPEED * (distanceToTarget - freeMoveRadius);
|
deltaToDesiredView *= VIEW_DYNAMIC_FOLLOW_SPEED * (distanceToTarget - freeMoveRadius);
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
// Hard follow
|
// Hard follow
|
||||||
deltaToDesiredView *= dynamicFollowRadius;
|
deltaToDesiredView *= dynamicFollowRadius;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +119,8 @@ void TrackingView::moveCenter(sf::Vector2<float> delta)
|
||||||
|
|
||||||
void TrackingView::draw(sf::RenderWindow *window) const
|
void TrackingView::draw(sf::RenderWindow *window) const
|
||||||
{
|
{
|
||||||
if (!DEVELOPER_MODE) {
|
if (!DEVELOPER_MODE)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,43 +132,6 @@ void TrackingView::addTrackable(ITrackable *trackable)
|
||||||
trackables.push_back(trackable);
|
trackables.push_back(trackable);
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Vector2f TrackingView::getCollectiveTrackingPoint() const
|
|
||||||
{
|
|
||||||
sf::Vector2f minPoint = trackables[0]->getTrackablePosition();
|
|
||||||
sf::Vector2f maxPoint = minPoint;
|
|
||||||
|
|
||||||
// Find min and max point coordinates for x and y axis over all trackables
|
|
||||||
for (auto trackable : trackables)
|
|
||||||
{
|
|
||||||
auto trackableCoordinates = trackable->getTrackablePosition();
|
|
||||||
auto trackableSize = trackable->getTrackableSize();
|
|
||||||
|
|
||||||
auto minPointX = trackableCoordinates.x - trackableSize.x / 2.f;
|
|
||||||
auto maxPointX = trackableCoordinates.x + trackableSize.x / 2.f;
|
|
||||||
auto minPointY = trackableCoordinates.y - trackableSize.y / 2.f;
|
|
||||||
auto maxPointY = trackableCoordinates.y + trackableSize.y / 2.f;
|
|
||||||
|
|
||||||
if (minPointX < minPoint.x)
|
|
||||||
{
|
|
||||||
minPoint.x = minPointX;
|
|
||||||
}
|
|
||||||
if (maxPointX > maxPoint.x)
|
|
||||||
{
|
|
||||||
maxPoint.x = maxPointX;
|
|
||||||
}
|
|
||||||
if (minPointY < minPoint.y)
|
|
||||||
{
|
|
||||||
minPoint.y = minPointY;
|
|
||||||
}
|
|
||||||
if (maxPointY > maxPoint.y)
|
|
||||||
{
|
|
||||||
maxPoint.y = maxPointY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return minPoint + (maxPoint - minPoint) / 2.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackingView::processTrackableStates()
|
void TrackingView::processTrackableStates()
|
||||||
{
|
{
|
||||||
// Remove trackables that have ended tracking
|
// Remove trackables that have ended tracking
|
||||||
|
@ -179,3 +146,40 @@ void TrackingView::setCenter(sf::Vector2<float> newCenter)
|
||||||
view->setCenter(newCenter);
|
view->setCenter(newCenter);
|
||||||
hasViewChanged = true;
|
hasViewChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TrackingArea TrackingView::getTrackingArea() const
|
||||||
|
{
|
||||||
|
sf::Vector2f initialPoints = trackables[0]->getTrackablePosition();
|
||||||
|
TrackingArea area = {initialPoints, initialPoints};
|
||||||
|
|
||||||
|
// Find min and max point coordinates for x and y axis over all trackables
|
||||||
|
for (auto trackable: trackables)
|
||||||
|
{
|
||||||
|
auto trackableCoordinates = trackable->getTrackablePosition();
|
||||||
|
auto trackableSize = trackable->getTrackableSize();
|
||||||
|
|
||||||
|
auto minPointX = trackableCoordinates.x - trackableSize.x / 2.f;
|
||||||
|
auto maxPointX = trackableCoordinates.x + trackableSize.x / 2.f;
|
||||||
|
auto minPointY = trackableCoordinates.y - trackableSize.y / 2.f;
|
||||||
|
auto maxPointY = trackableCoordinates.y + trackableSize.y / 2.f;
|
||||||
|
|
||||||
|
if (minPointX < area.topLeft.x)
|
||||||
|
{
|
||||||
|
area.topLeft.x = minPointX;
|
||||||
|
}
|
||||||
|
if (maxPointX > area.bottomRight.x)
|
||||||
|
{
|
||||||
|
area.bottomRight.x = maxPointX;
|
||||||
|
}
|
||||||
|
if (minPointY < area.topLeft.y)
|
||||||
|
{
|
||||||
|
area.topLeft.y = minPointY;
|
||||||
|
}
|
||||||
|
if (maxPointY > area.bottomRight.y)
|
||||||
|
{
|
||||||
|
area.bottomRight.y = maxPointY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return area;
|
||||||
|
}
|
||||||
|
|
|
@ -5,13 +5,14 @@
|
||||||
#include "../game_object.h"
|
#include "../game_object.h"
|
||||||
#include "ITrackable.h"
|
#include "ITrackable.h"
|
||||||
#include "../../primitives/circle_object.h"
|
#include "../../primitives/circle_object.h"
|
||||||
|
#include "tracking_area.h"
|
||||||
|
|
||||||
class CircleObject;
|
class CircleObject;
|
||||||
|
|
||||||
class TrackingView : public GameObject
|
class TrackingView : public GameObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TrackingView(float freeMoveRadius = 150,
|
explicit TrackingView(float freeMoveRadius = 0,
|
||||||
float dynamicFollowRadius = 300);
|
float dynamicFollowRadius = 300);
|
||||||
|
|
||||||
~TrackingView();
|
~TrackingView();
|
||||||
|
@ -44,7 +45,7 @@ private:
|
||||||
|
|
||||||
void moveCenter(sf::Vector2<float> delta);
|
void moveCenter(sf::Vector2<float> delta);
|
||||||
|
|
||||||
sf::Vector2f getCollectiveTrackingPoint() const;
|
TrackingArea getTrackingArea() const;
|
||||||
|
|
||||||
void processTrackableStates();
|
void processTrackableStates();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue