11 t = t < 0.0f ? 0.0f : (t > 1.0f ? 1.0f : t);
12 return t * t * (3.0f - 2.0f * t);
17 _camera = {.position = {0.0f, 10.0f, 10.0f},
18 .target = {0.0f, 0.0f, 0.0f},
19 .up = {0.0f, 1.0f, 0.0f},
21 .projection = CAMERA_PERSPECTIVE};
27 Vector3& outTarget)
const
29 float maxDim = fmaxf(worldWidth, worldHeight);
30 float radius = maxDim * 1.25f;
31 float aspectX = 0.5f * (1.0f + worldWidth / maxDim);
32 float aspectZ = 0.5f * (1.0f + worldHeight / maxDim);
33 outPos.x = cosf(
_angle) * radius * aspectX;
34 outPos.z = sinf(
_angle) * radius * aspectZ;
35 float currentRadius = sqrtf(outPos.x * outPos.x + outPos.z * outPos.z);
36 outPos.y =
_height * (currentRadius / radius);
37 outTarget = {0.0f, 0.0f, 0.0f};
42 float maxDim = fmaxf(worldWidth, worldHeight);
43 float radius = maxDim * 1.25f;
44 float aspectX = 0.5f * (1.0f + worldWidth / maxDim);
45 float aspectZ = 0.5f * (1.0f + worldHeight / maxDim);
53 _camera.target = {0.0f, 0.0f, 0.0f};
57 Vector3& outLookAt)
const
61 Vector3 pivot = p.visual.
pos;
62 float yawRad = p.visual.
angle * DEG2RAD;
63 float facingX = -cosf(yawRad);
64 float facingZ = sinf(yawRad);
92 Vector3 livePos, liveLookAt;
150 float dt = GetFrameTime();
158 Vector2 delta = GetMouseDelta();
165 Vector3 right = Vector3Normalize(Vector3CrossProduct(forward, {0.0f, 1.0f, 0.0f}));
169 if (IsKeyDown(KEY_W))
170 _camera.position = Vector3Add(
_camera.position, Vector3Scale(forward, sp));
171 if (IsKeyDown(KEY_S))
172 _camera.position = Vector3Add(
_camera.position, Vector3Scale(forward, -sp));
173 if (IsKeyDown(KEY_D))
_camera.position = Vector3Add(
_camera.position, Vector3Scale(right, sp));
174 if (IsKeyDown(KEY_A))
_camera.position = Vector3Add(
_camera.position, Vector3Scale(right, -sp));
175 if (IsKeyDown(KEY_SPACE))
_camera.position.y += sp;
176 if (IsKeyDown(KEY_LEFT_SHIFT))
_camera.position.y -= sp;
186 _freecamPitch = atan2f(dir.y, sqrtf(dir.x * dir.x + dir.z * dir.z));
199 Vector3 orbPos, orbTarget;
216 Vector3 orbPos, orbTarget;
static float smoothstep(float t)
Owns all camera logic: orbital, freecam, follow, and smooth transitions.
static float smoothstep(float t)
void _applyOrbital(float worldWidth, float worldHeight)
void init(float worldWidth, float worldHeight)
bool isFollowActive() const
void _handleFreecamInput()
bool isTransitioning() const
void _startTransition(Vector3 toPos, Vector3 toTarget, Mode nextMode)
float _savedOrbitalHeight
void _orbitalDest(float worldWidth, float worldHeight, Vector3 &outPos, Vector3 &outTarget) const
void _handleOrbitalInput()
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)
Represents the state of the world in the game, including the map size, tile contents,...
bool playerExists(int id) const
Checks if a player with the given ID exists in the world.
std::unordered_map< int, Player > players