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/core/api.h"
6#include "flint/math/types.h"
7
8namespace Flint {
9
10 class Camera {
11 public:
12 Camera() = default;
13
14 FLINT_API Camera(Vec2f viewSize, Vec2f worldSize);
15
23 FLINT_API void setTargetCenter(Vec2f center);
24
26 FLINT_API void setViewSize(Vec2f size);
27
29 FLINT_API void setWorldSize(Vec2f size);
30
36 FLINT_API void update(float smoothing = 0.25f);
37
39 FLINT_API FloatRect getViewRect() const;
40
42 FLINT_API Vec2f getCenter() const;
43
50 FLINT_API Vec2f screenToWorld(const Vec2f &sp, const Vec2i &screen) const;
51
53 FLINT_API void setZoom(float zoom);
54
56 FLINT_API float getZoom() const;
57
66 FLINT_API void followClamped(const Vec2f &targetPos, const Vec2i &bufferSize,
67 const Vec2i &mapPixelSize, float smoothing = 0.2f);
68
69 private:
70 float m_x = 0.f;
71 float m_y = 0.f;
72 float m_zoom = 1.f;
73 int m_screenW = 0;
74 int m_screenH = 0;
75 FloatRect m_bounds{};
76 float m_lerp = 1.f;
78 FloatRect m_viewRect{};
79
80 void follow(float targetX, float targetY);
81 void clampToBounds();
82 void updateViewRect();
83 };
84}
FLINT_API void update(float smoothing=0.25f)
Adjust smoothing factor (lerp) used by future setTargetCenter.
FLINT_API float getZoom() const
FLINT_API void setViewSize(Vec2f size)
FLINT_API Vec2f screenToWorld(const Vec2f &sp, const Vec2i &screen) const
Transform screen‑space point back to world‑space.
FLINT_API Vec2f getCenter() const
FLINT_API 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.
FLINT_API FloatRect getViewRect() const
FLINT_API void setWorldSize(Vec2f size)
FLINT_API void setTargetCenter(Vec2f center)
Soft-lock camera center on a target (uses current smoothing).
FLINT_API void setZoom(float zoom)