Rebranded world view to tracking view

This commit is contained in:
Maximilian Giller 2023-05-23 23:38:37 +02:00
parent beb87da14b
commit 15e63094fd
8 changed files with 34 additions and 34 deletions

View file

@ -45,12 +45,12 @@ set(SOURCES
src/game/player/player.cpp src/game/player/player.cpp
src/game/player/player.hpp src/game/player/player.hpp
src/game/input/key_features.hpp src/game/input/key_features.hpp
src/game/world/world_view.cpp src/game/camera/tracking_view.cpp
src/game/world/world_view.h src/game/camera/tracking_view.h
src/utilities/smart_list.cpp src/utilities/smart_list.cpp
src/utilities/smart_list.h src/utilities/smart_list.h
src/utilities/vector_utils.hpp src/utilities/vector_utils.hpp
src/game/world/ITrackable.h src/game/camera/ITrackable.h
src/game/input/input_identity.h src/game/input/input_identity.h
src/utilities/magic_enum.hpp src/utilities/magic_enum.hpp
src/game/player/player_spawner.cpp src/game/player/player_spawner.cpp

View file

@ -9,7 +9,7 @@ IsometricCoordinates TranslatedCoordinates::isometric() const {
} }
GridCoordinates TranslatedCoordinates::grid() const { GridCoordinates TranslatedCoordinates::grid() const {
// Grid coords are just world coords without height, and scaled differently // Grid coords are just camera coords without height, and scaled differently
return {worldCoordinates.x * worldToGridFactor, worldCoordinates.y * worldToGridFactor}; return {worldCoordinates.x * worldToGridFactor, worldCoordinates.y * worldToGridFactor};
} }

View file

@ -1,13 +1,13 @@
#include "world_view.h" #include "tracking_view.h"
#include "../../utilities/vector_utils.hpp" #include "../../utilities/vector_utils.hpp"
WorldView::~WorldView() TrackingView::~TrackingView()
{ {
delete view; delete view;
delete marker; delete marker;
} }
void WorldView::lateUpdate(Game *game) void TrackingView::lateUpdate(Game *game)
{ {
// Initialize if necessary // Initialize if necessary
if (view == nullptr) if (view == nullptr)
@ -31,13 +31,13 @@ void WorldView::lateUpdate(Game *game)
} }
} }
void WorldView::initializeView(Game *game) void TrackingView::initializeView(Game *game)
{ {
auto size = game->window->getView().getSize(); auto size = game->window->getView().getSize();
view = new sf::View({0, 0}, size); view = new sf::View({0, 0}, size);
} }
void WorldView::setSize(sf::Vector2u windowSize) void TrackingView::setSize(sf::Vector2u windowSize)
{ {
// TODO: Maybe listen to resize events instead of checking every frame? // TODO: Maybe listen to resize events instead of checking every frame?
// Is different? // Is different?
@ -52,24 +52,24 @@ void WorldView::setSize(sf::Vector2u windowSize)
hasViewChanged = true; hasViewChanged = true;
} }
WorldView::WorldView(ITrackable *trackable, sf::Vector2f freeMoveArea, sf::Vector2f dynamicFollowArea) TrackingView::TrackingView(ITrackable *trackable, sf::Vector2f freeMoveArea, sf::Vector2f dynamicFollowArea)
: target(trackable), freeMoveArea(freeMoveArea), dynamicFollowArea(dynamicFollowArea), view(nullptr), : target(trackable), freeMoveArea(freeMoveArea), dynamicFollowArea(dynamicFollowArea), view(nullptr),
hasViewChanged(false) hasViewChanged(false)
{ {
marker = new CircleObject(2, sf::Color::Yellow); marker = new CircleObject(2, sf::Color::Yellow);
} }
sf::Vector2f WorldView::getSize() const sf::Vector2f TrackingView::getSize() const
{ {
return view->getSize(); return view->getSize();
} }
sf::Vector2f WorldView::getCenter() const sf::Vector2f TrackingView::getCenter() const
{ {
return view->getCenter(); return view->getCenter();
} }
void WorldView::followTarget() void TrackingView::followTarget()
{ {
// TODO // TODO
auto closestPositionInDynamic = getClosestPositionInArea(dynamicFollowArea); auto closestPositionInDynamic = getClosestPositionInArea(dynamicFollowArea);
@ -94,7 +94,7 @@ void WorldView::followTarget()
// } // }
} }
bool WorldView::isTargetInArea(sf::Vector2f areaSize) bool TrackingView::isTargetInArea(sf::Vector2f areaSize)
{ {
// Assuming target is not null // Assuming target is not null
@ -119,7 +119,7 @@ bool WorldView::isTargetInArea(sf::Vector2f areaSize)
return true; return true;
} }
sf::Vector2f WorldView::getClosestPositionInArea(sf::Vector2f areaSize) const sf::Vector2f TrackingView::getClosestPositionInArea(sf::Vector2f areaSize) const
{ {
// Reduce area to only consider target position, not size // Reduce area to only consider target position, not size
auto positionOnlyAreaSize = areaSize - target->getTrackableSize(); auto positionOnlyAreaSize = areaSize - target->getTrackableSize();
@ -148,32 +148,32 @@ sf::Vector2f WorldView::getClosestPositionInArea(sf::Vector2f areaSize) const
return rubber * length; return rubber * length;
} }
sf::Vector2f WorldView::getRubber() const sf::Vector2f TrackingView::getRubber() const
{ {
return normalize(target->getTrackablePosition() - getCenter()); return normalize(target->getTrackablePosition() - getCenter());
} }
void WorldView::performHardFollow() void TrackingView::performHardFollow()
{ {
auto closestPositionInDynamic = getClosestPositionInArea(dynamicFollowArea); auto closestPositionInDynamic = getClosestPositionInArea(dynamicFollowArea);
auto delta = getCenter() - closestPositionInDynamic; auto delta = getCenter() - closestPositionInDynamic;
moveCenter(-delta); moveCenter(-delta);
} }
void WorldView::moveCenter(sf::Vector2<float> delta) void TrackingView::moveCenter(sf::Vector2<float> delta)
{ {
view->move(delta); view->move(delta);
hasViewChanged = true; hasViewChanged = true;
} }
void WorldView::performDynamicFollow() void TrackingView::performDynamicFollow()
{ {
auto closestPositionInDynamic = getClosestPositionInArea(freeMoveArea); auto closestPositionInDynamic = getClosestPositionInArea(freeMoveArea);
auto delta = getCenter() - closestPositionInDynamic; auto delta = getCenter() - closestPositionInDynamic;
moveCenter(delta * VIEW_RUBBER_FOLLOW_SPEED * FRAME_TIME.asSeconds()); moveCenter(delta * VIEW_RUBBER_FOLLOW_SPEED * FRAME_TIME.asSeconds());
} }
void WorldView::draw(sf::RenderWindow *window) const void TrackingView::draw(sf::RenderWindow *window) const
{ {
marker->draw(window); marker->draw(window);
} }

View file

@ -1,5 +1,5 @@
#ifndef HOLESOME_WORLD_VIEW_H #ifndef HOLESOME_TRACKING_VIEW_H
#define HOLESOME_WORLD_VIEW_H #define HOLESOME_TRACKING_VIEW_H
#include "../game_object.h" #include "../game_object.h"
@ -7,14 +7,14 @@
#include "ITrackable.h" #include "ITrackable.h"
#include "../../primitives/circle_object.h" #include "../../primitives/circle_object.h"
class WorldView : public GameObject class TrackingView : public GameObject
{ {
public: public:
explicit WorldView(ITrackable *trackable = nullptr, explicit TrackingView(ITrackable *trackable = nullptr,
sf::Vector2f freeMoveArea = {200, 200}, sf::Vector2f freeMoveArea = {200, 200},
sf::Vector2f dynamicFollowArea = {500, 500}); sf::Vector2f dynamicFollowArea = {500, 500});
~WorldView(); ~TrackingView();
void draw(sf::RenderWindow *window) const override; void draw(sf::RenderWindow *window) const override;
@ -54,4 +54,4 @@ private:
}; };
#endif //HOLESOME_WORLD_VIEW_H #endif //HOLESOME_TRACKING_VIEW_H

View file

@ -2,7 +2,7 @@
#define HOLESOME_PLAYER_HPP #define HOLESOME_PLAYER_HPP
#include "../game_object.h" #include "../game_object.h"
#include "../world/ITrackable.h" #include "../camera/ITrackable.h"
#include "../../primitives/circle_object.h" #include "../../primitives/circle_object.h"
class Player : public GameObject, public ITrackable class Player : public GameObject, public ITrackable

View file

@ -2,7 +2,7 @@
#include "logging/easylogging++.h" #include "logging/easylogging++.h"
#include "game/game_factory.hpp" #include "game/game_factory.hpp"
#include "debug/grid_debug_layer.h" #include "debug/grid_debug_layer.h"
#include "game/world/world_view.h" #include "game/camera/tracking_view.h"
#include "game/player/player_spawner.hpp" #include "game/player/player_spawner.hpp"
INITIALIZE_EASYLOGGINGPP INITIALIZE_EASYLOGGINGPP
@ -14,7 +14,7 @@ int main(int argc, char *argv[])
auto game = GameFactory::createWindowed("Holesome"); auto game = GameFactory::createWindowed("Holesome");
game->addGameObject(new GridDebugLayer(0, 50, 0, 50)); game->addGameObject(new GridDebugLayer(0, 50, 0, 50));
game->addGameObject(new WorldView()); game->addGameObject(new TrackingView());
game->addGameObject(new PlayerSpawner()); game->addGameObject(new PlayerSpawner());
game->run(); game->run();

View file

@ -9,14 +9,14 @@ int main(int argc, char** argv) {
// First you need to create the PhysicsCommon object. // First you need to create the PhysicsCommon object.
// This is a factory module that you can use to create physics // This is a factory module that you can use to create physics
// world and other objects. It is also responsible for // camera and other objects. It is also responsible for
// logging and memory management // logging and memory management
PhysicsCommon physicsCommon; PhysicsCommon physicsCommon;
// Create a physics world // Create a physics camera
PhysicsWorld* world = physicsCommon.createPhysicsWorld(); PhysicsWorld* world = physicsCommon.createPhysicsWorld();
// Create a rigid body in the world // Create a rigid body in the camera
Vector3 position(0, 20, 0); Vector3 position(0, 20, 0);
Quaternion orientation = Quaternion::identity(); Quaternion orientation = Quaternion::identity();
Transform transform(position, orientation); Transform transform(position, orientation);