Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
camera.h
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2025-2026 Manuel Osorio
3#pragma once
4
5#include "flint/math/types.h"
6
7namespace Flint {
8
9 class Camera {
10 public:
11 Camera() = default;
12
13 Camera(Vec2f viewSize, Vec2f worldSize);
14
22 void setTargetCenter(Vec2f center);
23
25 void setViewSize(Vec2f size);
26
28 void setWorldSize(Vec2f size);
29
35 void update(float smoothing = 0.25f);
36
39
42
49 Vec2f screenToWorld(const Vec2f &sp, const Vec2i &screen) const;
50
52 void setZoom(float zoom);
53
55 float getZoom() const;
56
65 void followClamped(const Vec2f &targetPos, const Vec2i &bufferSize, const Vec2i &mapPixelSize,
66 float smoothing = 0.2f);
67
68 private:
69 float m_x = 0.f;
70 float m_y = 0.f;
71 float m_zoom = 1.f;
72 int m_screenW = 0;
73 int m_screenH = 0;
74 FloatRect m_bounds{};
75 float m_lerp = 1.f;
77 FloatRect m_viewRect{};
78
79 void follow(float targetX, float targetY);
80 void clampToBounds();
81 void updateViewRect();
82 };
83}
void setViewSize(Vec2f size)
float getZoom() const
void setTargetCenter(Vec2f center)
Soft‑lock camera centre on a target (uses current smoothing).
void update(float smoothing=0.25f)
Adjust smoothing factor (lerp) used by future setTargetCenter.
FloatRect getViewRect() const
Vec2f getCenter() const
void setWorldSize(Vec2f size)
void followClamped(const Vec2f &targetPos, const Vec2i &bufferSize, const Vec2i &mapPixelSize, float smoothing=0.2f)
Follow a target but clamp so that the view never leaves map.
void setZoom(float zoom)
Vec2f screenToWorld(const Vec2f &sp, const Vec2i &screen) const
Transform screen‑space point back to world‑space.