Skip to main content

Module camera_math

Module camera_math 

Source
Expand description

Per-frame camera-derived state — port of voxlaptest’s setcamera (voxlap5.c:2246).

Inputs:

  • Camera with f64 position and f64 orthonormal right / down / forward basis (matching dpoint3d in voxlap5.h).
  • xres / yres: framebuffer dimensions in pixels.
  • hx / hy / hz: screen-projection parameters voxlap calls dahx / dahy / dahz. The oracle and most demos use (width/2, height/2, width/2) — that’s a 90° horizontal FOV with square pixels.

Outputs (all f32 — voxlap narrows once at the start of every frame and does the rest of the per-frame math at single precision):

  • pos / right / down / forward: copies of the camera basis.
  • xs / ys / zs: the transposed basis (column-vectors of the 3×3 rotation), useful for projecting world deltas into camera- relative (right, down, forward) coordinates.
  • add: -pos · {right, down, forward} — the translation half of the world → camera transform.
  • corn[4]: the four corners of the view frustum as direction vectors from the camera. corn[0] = top-left, corn[1] = top-right, corn[2] = bottom-right, corn[3] = bottom-left.
  • nor[4]: cross-products of consecutive corner pairs, giving inward-facing frustum-edge normals (nor[i] = corn[i] × corn[(i+1) % 4]). The grouscan ray-stepper uses these to clip columns against the visible rectangle.

Structs§

CameraState
Per-frame state derived from a Camera + screen parameters.

Functions§

derive
Derive the per-frame CameraState.