Camera
Generated from engine/render/camera.h at 0f4f503. The text under each declaration is the header's own comment, word for word. About the reference says how these pages are made.
Audience: game code.
#include "engine/render/camera.h" · namespace labrador
struct Camera
Section titled “struct Camera”A 2D pan and zoom: what a view's world coordinates have to go through to become screen coordinates. One per view, held by DrawList and applied as each draw is recorded.
A render type and not a math one, because the math library's contract is that it knows nothing about drawing - and a camera is constructible from a Viewport, which is a render type for the same reason.
translation
Section titled “translation”float scale = 1.0f;Camera · operator=
Section titled “Camera · operator=”Camera(const Camera&) = default;Camera& operator=(const Camera&) = default;Camera
Section titled “Camera”constexpr and defined here so default_camera is constant-initialised (camera.cpp defines it constinit), and a static in another translation unit that copies it can never read it before it is set.
operator== · operator!=
Section titled “operator== · operator!=”bool operator!=(const Camera& other) const;calculate_view_rectangle
Section titled “calculate_view_rectangle” const RectangleF& world_rectangle) const;Maps a world rectangle into view-local pixels: subtract translation from its position, then multiply position and extent by scale. The viewport's offset in the back buffer is not included.
calculate_view_rectangle
Section titled “calculate_view_rectangle”void calculate_view_rectangle(Applies the same world-to-view transform in place.
calculate_view_rectangle
Section titled “calculate_view_rectangle” const RectangleF& world_rectangle,The same transform using the supplied camera.
calculate_view_rectangle
Section titled “calculate_view_rectangle”static void calculate_view_rectangle( RectangleF& view_rectangle);Writes the supplied camera's transform to view_rectangle.
visible_rectangle
Section titled “visible_rectangle”What viewport actually shows of the world under this camera - the inverse of calculate_view_rectangle for the whole pane.
The forward transform is view = (world - translation) * scale, so the world extent behind viewport.width pixels is viewport.width / scale. Written by hand, the tempting arithmetic is a MULTIPLY, which is the right arithmetic upside down: it agrees at scale 1, is merely over-inclusive above it, and collapses below it. Camera::frame produces exactly the below-one case whenever a world rectangle is larger than the viewport showing it - framing 6000 world units into 1080 pixels gives scale 0.18, where the multiply reports a visible region 31 times too small in each axis and a cull built on it throws away almost everything on screen.
Throws std::invalid_argument for a zero scale, which is not a viewpoint but a division by nothing. Camera::frame cannot produce one; a hand-built camera can.
world_position
Section titled “world_position”The world point under a back-buffer pixel seen through viewport with this camera - the inverse of calculate_view_position. A mouse position or a touch point is one: the input devices report client pixels, which are the pixels a viewport is given in.
The pane starts where every backend puts it, at the top-left of viewport.pixel_rect(), so a viewport off a whole pixel answers for the pixels it is drawn into. The point is the pixel's top-left corner; a caller that wants its centre adds half a pixel divided by the scale. Nothing is clipped to the pane: a pixel outside it answers the world point the camera would put there, and which pane a pointer is in is the caller's question.
Throws std::invalid_argument for a zero scale, as visible_rectangle does.
The camera that shows all of world_rectangle in viewport.
Both axes are honoured: the scale is whichever of the two ratios fits, and the surplus on the other axis is split evenly so the requested rectangle ends up centred.
Throws std::invalid_argument if either rectangle has a non-positive extent: a zero there is an infinite or a zero scale, which poisons every cull and every draw taken through the result.
calculate_view_position
Section titled “calculate_view_position” const Vector2F& world_position) const;Maps a world point to view-local pixels: (world - translation) * scale. The viewport's offset in the back buffer is not included.
calculate_view_scale
Section titled “calculate_view_scale”float calculate_view_scale(float world_scale) const;Multiplies a world scale by this camera's scale.
default_camera
Section titled “default_camera”The identity camera: zero translation and unit scale, suitable for screen-space drawing in a view. Constant-initialised before use.
Related types
Section titled “Related types”Named in the public declarations above: RectangleF, Vector2F, Vector2I, Viewport.
In the samples and tests
Section titled “In the samples and tests”The files that include this header directly. A file can also reach it through another header.
samples/components/gallery_state.cppsamples/linesweeper/presentation/arrangement.htests/linesweeper/top_out_banner_tests.cpptests/render/camera_tests.cpp,null_tests.cpp,sprite_pixel_tests.cpp,text_pixel_tests.cpp,view_pixel_tests.cpptests/scene/cull_tests.cpp,fanout_tests.cpp
Explained in
Section titled “Explained in”Documentation for Labrador v0.3.0. Built from Labrador 0f4f503 of 2026-11-03.