Skip to main content

Module camera

Module camera 

Source
Available on crate feature raster only.
Expand description

Camera + perspective projection + painter’s depth sort (Task 2).

Pipeline (PHASE-R-MAP §3, deck topology-deck.html cam.ry/cam.rx model, mined from tui-3d-renderer/src/raster.rs::prepare_position + src/clip.rs, but pure f64 and rotate-Y-then-X per the deck):

  1. Camera space: v' = RotX(rx) · RotY(ry) · v, then z' += dist.
  2. Near-plane clip FIRST: reject the whole primitive if any vertex has z' <= NEAR_EPS (never divide by a near-zero/negative z').
  3. Perspective divide with focal length f = 1 / tan(fov*pi/360), aspect-corrected for braille subcell space (cols*2 x rows*4).
  4. Viewport remap to subcell coordinates; depth = v'.z (smaller = nearer).

Structs§

Camera
Camera model: rotate about Y then X, camera distance, vertical FOV (degrees) — mirrors the deck’s cam.ry/cam.rx.
Projected
A vertex projected to subcell screen space; depth is camera-space z after rotation+translation (before the perspective divide), smaller = nearer. scale is the local perspective magnification in target units per world unit at this vertex’s depth — the Rust analogue of the deck’s proj() returning s = fov/z3 alongside x/y (topology-deck.html :273-277), which every disc the deck draws uses for its radius (2.1*p.s/300, :308; 2.6*top.s/300, :325; 2.4*p.s/300, :357; √(c+v)*.62*top.s/300, :412). Measured on the vertical axis (d sy / d world-y), which is the isotropic one in braille subcell space (a 2x4 subcell of a 1:2 terminal cell is square).

Constants§

NEAR_EPS
Near-plane epsilon: a vertex at/behind the camera (z' <= NEAR_EPS) makes its whole primitive rejected rather than risking a near-zero or negative perspective divide (Power-of-10 rule 4; tui-3d/src/clip.rs).

Functions§

depth_sort
Stable painter’s depth sort: farthest-first, keyed on each primitive’s centroid camera-space depth. Stable so equal-depth primitives keep scene (insertion) order — no draw-order nondeterminism. Bounded: one pass over each finite slice.
depth_sort_nodes
Stable painter’s depth sort for node discs: farthest-first on each node’s own center depth. Separate from depth_sort so the existing (faces, struts) signature (and its golden-pinned behaviour) is untouched; nodes are drawn after faces/struts in both raster tiers so an annotation dot at exactly equal depth wins its subcell. Bounded: one pass over a finite slice.
face_is_clipped
true if any vertex of the face is at/behind the near plane.
node_is_clipped
true if the node’s center is at/behind the near plane (the whole disc is rejected — a node is a point primitive, never split).
project
Project a single 3D point into subcell screen space under cam, for a cols x rows character grid (braille 2x4 subcells per cell). Returns None if the vertex is at/behind the near plane (z' <= NEAR_EPS).
strut_is_clipped
true if either endpoint of the strut is at/behind the near plane.