Skip to main content

roxlap_gpu/
camera.rs

1//! World-space camera state passed to [`crate::GpuRenderer::render_chunk`].
2//!
3//! Mirrors `roxlap-core::Camera`'s shape (position + orthonormal
4//! right / down / forward basis) but in `f32` since the GPU does its
5//! ray math at single precision. Host bridges by casting f64 → f32
6//! after computing chunk-local coordinates.
7
8/// World-space camera state in the voxlap convention (Z = down).
9///
10/// `right`, `down`, `forward` form a right-handed orthonormal basis;
11/// `position` is in voxel-world units. `fov_y_rad` is the vertical
12/// field-of-view in radians — voxlap's default is roughly 60°
13/// (`std::f32::consts::FRAC_PI_3`).
14#[derive(Debug, Clone, Copy)]
15pub struct Camera {
16    pub position: [f32; 3],
17    pub right: [f32; 3],
18    pub down: [f32; 3],
19    pub forward: [f32; 3],
20    pub fov_y_rad: f32,
21}
22
23impl Default for Camera {
24    fn default() -> Self {
25        Self {
26            position: [0.0, 0.0, 0.0],
27            right: [1.0, 0.0, 0.0],
28            down: [0.0, 0.0, 1.0],
29            forward: [0.0, 1.0, 0.0],
30            fov_y_rad: std::f32::consts::FRAC_PI_3,
31        }
32    }
33}