Camera

:= []

Camera module - pure 2D camera settings for world-space drawing.

A camera is a value, not a host-owned resource. Build the camera you want for the current frame and pass it to Draw.with_camera!.

default : Camera2D

Identity camera: no offset or rotation, with unit zoom.

new : Settings -> Try(Camera2D, [ZeroZoom, NonFiniteZoom, NonFiniteTarget, NonFiniteOffset, NonFiniteRotation, ..])

Construct a camera from explicit settings, rejecting every non-finite transform field and zero zoom.

centered : Vec2, Vec2 -> Try(Camera2D, [NonFiniteTarget, NonFiniteOffset, ..])

Place target at the center of a screen with unit zoom.

follow : Vec2, { screen : Vec2, zoom : F32 } -> Try(Camera2D, [ZeroZoom, NonFiniteZoom, NonFiniteTarget, NonFiniteOffset, ..])

A common player-follow camera with a validated configurable zoom.

Settings : {
    target : Vec2,
    offset : Vec2,
    rotation : F32,
    zoom : F32,
}

Target, screen offset, clockwise rotation in degrees, and zoom factor.

Camera2D

Camera.Camera2D :: # (opaque)

Immutable camera value accepted by drawing and coordinate transforms. Its representation is opaque so non-finite transform fields or a non-invertible zero zoom cannot bypass validation.

target : Camera2D -> Vec2

World-space point placed at the camera offset.

offset : Camera2D -> Vec2

Logical screen-space offset of the target.

rotation : Camera2D -> F32

Clockwise camera rotation in degrees.

zoom : Camera2D -> F32

Non-zero camera zoom factor. Negative values intentionally mirror axes.

with_target : Camera2D, Vec2 -> Try(Camera2D, [NonFiniteTarget, ..])

Return a copy focused on a finite world-space target.

with_offset : Camera2D, Vec2 -> Try(Camera2D, [NonFiniteOffset, ..])

Return a copy with a finite logical screen-space offset.

with_rotation : Camera2D, F32 -> Try(Camera2D, [NonFiniteRotation, ..])

Return a copy with a finite clockwise rotation in degrees.

with_zoom : Camera2D, F32 -> Try(Camera2D, [ZeroZoom, NonFiniteZoom, ..])

Return a copy with a validated finite, non-zero zoom factor.

clamp_zoom : Camera2D, { min : F32, max : F32 } -> Try(Camera2D, [ZeroZoom, NonFiniteZoom, ..])

Clamp zoom to inclusive limits, reporting a range that produces zero.

world_to_screen : Camera2D, Vec2 -> Vec2

Convert a world-space point to logical screen coordinates. Rotation uses degrees, matching raylib and Draw.with_camera!.

screen_to_world : Camera2D, Vec2 -> Vec2

Convert logical screen coordinates back to world space. Every Camera2D is invertible because construction rejects zero zoom.

viewport : Camera2D, Vec2 -> Rect

World-space axis-aligned bounds visible through this camera. This handles non-centered offsets, rotation, and mirrored (negative) zoom.