Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
CameraController.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "core/WorldState.hpp"
7#include "raylib.h"
8
10 public:
11 // ── Tuning ─────────────────────────────────────────────────────────────
12 float orbitalMoveSpeed = 2.0f;
13 float freecamMoveSpeed = 5.0f;
14 float freecamLookSpeed = 0.002f;
15 float followDist = 2.5f;
16 float followHeight = 1.8f;
17 float followLookOffsetY = 0.5f;
18 float transitionDuration = 0.8f;
19
20 // ── Lifecycle ──────────────────────────────────────────────────────────
21 void init(float worldWidth, float worldHeight);
22 void update(float dt, float worldWidth, float worldHeight, const WorldState* world);
23 void handleInput();
24
25 const Camera3D& camera() const { return _camera; }
26
27 // ── Mode switching ─────────────────────────────────────────────────────
28 void enterFreecam();
29 void exitFreecam();
30 void startFollow(int playerId);
31 void stopFollow();
32
33 // ── State queries ──────────────────────────────────────────────────────
34 bool isFreecamActive() const { return _mode == Mode::Freecam; }
35 bool isFollowActive() const { return _followedPlayerId != -1; }
37 int followedPlayerId() const { return _followedPlayerId; }
38
39 private:
41
42 Camera3D _camera = {};
44
45 float _angle = 0.0f;
46 float _height = 5.0f;
47 float _savedOrbitalAngle = 0.0f;
48 float _savedOrbitalHeight = 5.0f;
49
50 float _freecamYaw = 0.0f;
51 float _freecamPitch = 0.0f;
52
54 float _lastWorldWidth = 10.0f;
55 float _lastWorldHeight = 10.0f;
56
57 float _transitionT = 1.0f;
58 Vector3 _fromPos = {};
59 Vector3 _fromTarget = {};
60 Vector3 _toPos = {};
61 Vector3 _toTarget = {};
63
64 void _startTransition(Vector3 toPos, Vector3 toTarget, Mode nextMode);
65 void _applyOrbital(float worldWidth, float worldHeight);
66 void _orbitalDest(float worldWidth, float worldHeight, Vector3& outPos,
67 Vector3& outTarget) const;
68 bool _followTarget(const WorldState* world, Vector3& outPos, Vector3& outLookAt) const;
71};
void _applyOrbital(float worldWidth, float worldHeight)
void init(float worldWidth, float worldHeight)
int followedPlayerId() const
bool isFollowActive() const
bool isTransitioning() const
void _startTransition(Vector3 toPos, Vector3 toTarget, Mode nextMode)
bool isFreecamActive() const
void _orbitalDest(float worldWidth, float worldHeight, Vector3 &outPos, Vector3 &outTarget) const
void update(float dt, float worldWidth, float worldHeight, const WorldState *world)
bool _followTarget(const WorldState *world, Vector3 &outPos, Vector3 &outLookAt) const
void startFollow(int playerId)
const Camera3D & camera() const
Represents the state of the world in the game, including the map size, tile contents,...