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.hpp
src/game/input/key_features.hpp
src/game/world/world_view.cpp
src/game/world/world_view.h
src/game/camera/tracking_view.cpp
src/game/camera/tracking_view.h
src/utilities/smart_list.cpp
src/utilities/smart_list.h
src/utilities/vector_utils.hpp
src/game/world/ITrackable.h
src/game/camera/ITrackable.h
src/game/input/input_identity.h
src/utilities/magic_enum.hpp
src/game/player/player_spawner.cpp

View file

@ -9,7 +9,7 @@ IsometricCoordinates TranslatedCoordinates::isometric() 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};
}

View file

@ -1,13 +1,13 @@
#include "world_view.h"
#include "tracking_view.h"
#include "../../utilities/vector_utils.hpp"
WorldView::~WorldView()
TrackingView::~TrackingView()
{
delete view;
delete marker;
}
void WorldView::lateUpdate(Game *game)
void TrackingView::lateUpdate(Game *game)
{
// Initialize if necessary
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();
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?
// Is different?
@ -52,24 +52,24 @@ void WorldView::setSize(sf::Vector2u windowSize)
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),
hasViewChanged(false)
{
marker = new CircleObject(2, sf::Color::Yellow);
}
sf::Vector2f WorldView::getSize() const
sf::Vector2f TrackingView::getSize() const
{
return view->getSize();
}
sf::Vector2f WorldView::getCenter() const
sf::Vector2f TrackingView::getCenter() const
{
return view->getCenter();
}
void WorldView::followTarget()
void TrackingView::followTarget()
{
// TODO
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
@ -119,7 +119,7 @@ bool WorldView::isTargetInArea(sf::Vector2f areaSize)
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
auto positionOnlyAreaSize = areaSize - target->getTrackableSize();
@ -148,32 +148,32 @@ sf::Vector2f WorldView::getClosestPositionInArea(sf::Vector2f areaSize) const
return rubber * length;
}
sf::Vector2f WorldView::getRubber() const
sf::Vector2f TrackingView::getRubber() const
{
return normalize(target->getTrackablePosition() - getCenter());
}
void WorldView::performHardFollow()
void TrackingView::performHardFollow()
{
auto closestPositionInDynamic = getClosestPositionInArea(dynamicFollowArea);
auto delta = getCenter() - closestPositionInDynamic;
moveCenter(-delta);
}
void WorldView::moveCenter(sf::Vector2<float> delta)
void TrackingView::moveCenter(sf::Vector2<float> delta)
{
view->move(delta);
hasViewChanged = true;
}
void WorldView::performDynamicFollow()
void TrackingView::performDynamicFollow()
{
auto closestPositionInDynamic = getClosestPositionInArea(freeMoveArea);
auto delta = getCenter() - closestPositionInDynamic;
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);
}

View file

@ -1,5 +1,5 @@
#ifndef HOLESOME_WORLD_VIEW_H
#define HOLESOME_WORLD_VIEW_H
#ifndef HOLESOME_TRACKING_VIEW_H
#define HOLESOME_TRACKING_VIEW_H
#include "../game_object.h"
@ -7,14 +7,14 @@
#include "ITrackable.h"
#include "../../primitives/circle_object.h"
class WorldView : public GameObject
class TrackingView : public GameObject
{
public:
explicit WorldView(ITrackable *trackable = nullptr,
sf::Vector2f freeMoveArea = {200, 200},
sf::Vector2f dynamicFollowArea = {500, 500});
explicit TrackingView(ITrackable *trackable = nullptr,
sf::Vector2f freeMoveArea = {200, 200},
sf::Vector2f dynamicFollowArea = {500, 500});
~WorldView();
~TrackingView();
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
#include "../game_object.h"
#include "../world/ITrackable.h"
#include "../camera/ITrackable.h"
#include "../../primitives/circle_object.h"
class Player : public GameObject, public ITrackable

View file

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

View file

@ -9,14 +9,14 @@ int main(int argc, char** argv) {
// First you need to create the PhysicsCommon object.
// 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
PhysicsCommon physicsCommon;
// Create a physics world
// Create a physics camera
PhysicsWorld* world = physicsCommon.createPhysicsWorld();
// Create a rigid body in the world
// Create a rigid body in the camera
Vector3 position(0, 20, 0);
Quaternion orientation = Quaternion::identity();
Transform transform(position, orientation);