The part of the world shown on screen: where it looks, how close, within which bounds.
More...
|
| | Camera (Vec2 view) |
| | Creates a camera looking at the middle of a view-sized world, at zoom 1.
|
| |
| Vec2 | view () const noexcept |
| | Size of the view on screen.
|
| |
| void | follow (Vec2 target) noexcept |
| | Looks at a point, or as close to it as the bounds allow.
|
| |
| Vec2 | center () const noexcept |
| | World point at the middle of the view.
|
| |
| void | set_zoom (float zoom) |
| | Changes the zoom, keeping the center within the bounds.
|
| |
| float | zoom () const noexcept |
| | Screen pixels per world pixel.
|
| |
| void | set_bounds (const std::optional< Rect > &bounds) |
| | Limits the view to an area of the world, or lets it go anywhere.
|
| |
| const std::optional< Rect > & | bounds () const noexcept |
| | The area the view stays within.
|
| |
| void | set_shake (Vec2 offset) noexcept |
| | Moves the picture on screen without moving the camera, for screen shake.
|
| |
| Vec2 | shake () const noexcept |
| | The shake of this frame.
|
| |
| Rect | visible () const noexcept |
| | World area shown, without the shake, for culling.
|
| |
| Vec2 | to_screen (Vec2 world) const noexcept |
| | Where a world point appears on screen.
|
| |
| Vec2 | to_world (Vec2 screen) const noexcept |
| | Which world point is under a screen point, such as the mouse.
|
| |
| Sprite | to_screen (const Sprite &sprite) const noexcept |
| | A sprite of the world, placed and scaled on screen.
|
| |
The part of the world shown on screen: where it looks, how close, within which bounds.
World and screen are both in logical pixels from the top-left corner. The camera shows the world point center() at the middle of a view of a fixed size on screen, zoom() screen pixels per world pixel; with bounds, the view never shows anything outside them. Give it to the renderer (IRenderer::set_camera()), which places the sprites drawn after; draw the HUD without it.
...
camera.follow(player_position);
camera.set_shake(effects.offset());
renderer.set_camera(camera);
... draw the world, in world coordinates ...
renderer.set_camera(std::nullopt);
... draw the HUD, in screen coordinates ...
The part of the world shown on screen: where it looks, how close, within which bounds.
Definition camera.hpp:31
void set_bounds(const std::optional< Rect > &bounds)
Limits the view to an area of the world, or lets it go anywhere.
Axis-aligned rectangle.
Definition renderer.hpp:20
float width
Width, positive.
Definition renderer.hpp:26