roxlap_core/camera.rs
1//! Camera state — position + orthonormal basis.
2//!
3//! Mirrors voxlaptest's `setcamera(ipo, ist, ihe, ifo, ...)` ABI: a
4//! starting point and three orthonormal axes (right, down, forward).
5//! The convention matches the voxlap C engine so a `.vxl` file's
6//! camera vectors load directly.
7
8/// Camera state. All vectors are in voxel-world units (1 unit = 1
9/// voxel); the basis is right-handed with `down` aligned to +z (i.e.
10/// z grows downward into the map, matching voxlap's coordinate
11/// system).
12///
13/// # Examples
14///
15/// ```
16/// use roxlap_core::Camera;
17///
18/// let cam = Camera::default();
19/// assert_eq!(cam.pos, [1024.0, 1024.0, 128.0]);
20/// assert_eq!(cam.forward, [0.0, 1.0, 0.0]); // looking +y (north)
21/// ```
22#[derive(Debug, Clone, Copy, PartialEq)]
23pub struct Camera {
24 /// Camera position (`ipo` / `dpoint3d` in voxlaptest).
25 pub pos: [f64; 3],
26 /// Right vector (`ist`).
27 pub right: [f64; 3],
28 /// Down vector (`ihe`).
29 pub down: [f64; 3],
30 /// Forward vector (`ifo`).
31 pub forward: [f64; 3],
32}
33
34impl Default for Camera {
35 /// Centred at the middle of a 2048-VSID map, looking +y, level.
36 /// Matches the placeholder vectors voxlaptest's oracle writes
37 /// into the `.vxl` header (see `tests/oracle/oracle.c`).
38 fn default() -> Self {
39 Self {
40 pos: [1024.0, 1024.0, 128.0],
41 right: [1.0, 0.0, 0.0],
42 down: [0.0, 0.0, 1.0],
43 forward: [0.0, 1.0, 0.0],
44 }
45 }
46}