Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
camera.hpp
Go to the documentation of this file.
1
3#pragma once
4
6#include <aegis2d/render/export.hpp>
8
9#include <optional>
10
11namespace aegis2d::render {
12
31class AEGIS2D_RENDER_EXPORT Camera {
32public:
37 explicit Camera(Vec2 view);
38
41 [[nodiscard]] Vec2 view() const noexcept;
42
48 void follow(Vec2 target) noexcept;
49
52 [[nodiscard]] Vec2 center() const noexcept;
53
57 void set_zoom(float zoom);
58
61 [[nodiscard]] float zoom() const noexcept;
62
67 void set_bounds(const std::optional<Rect>& bounds);
68
71 [[nodiscard]] const std::optional<Rect>& bounds() const noexcept;
72
76 void set_shake(Vec2 offset) noexcept;
77
80 [[nodiscard]] Vec2 shake() const noexcept;
81
84 [[nodiscard]] Rect visible() const noexcept;
85
89 [[nodiscard]] Vec2 to_screen(Vec2 world) const noexcept;
90
94 [[nodiscard]] Vec2 to_world(Vec2 screen) const noexcept;
95
99 [[nodiscard]] Sprite to_screen(const Sprite& sprite) const noexcept;
100
101private:
102 void clamp() noexcept;
103
104 Vec2 view_;
105 Vec2 center_;
106 float zoom_ = 1.0F;
107 std::optional<Rect> bounds_;
108 Vec2 shake_;
109};
110
111} // namespace aegis2d::render
The part of the world shown on screen: where it looks, how close, within which bounds.
Definition camera.hpp:31
Vec2 view() const noexcept
Size of the view on screen.
Camera(Vec2 view)
Creates a camera looking at the middle of a view-sized world, at zoom 1.
Vector and matrix types of the engine (GLM behind engine names).
OpenGL renderer: sprites, text and camera (client only).
Definition bitmap_font.hpp:16
aegis2d::Vec2 Vec2
2D vector of floats, in logical pixels: the engine-wide aegis2d::Vec2.
Definition renderer.hpp:17
Definition endpoint.hpp:85
Backend-independent renderer interface and the sprite it draws.
Axis-aligned rectangle.
Definition renderer.hpp:20
One textured quad to draw.
Definition renderer.hpp:46