euv_core/game/engine3d/math/struct.rs
1use super::*;
2
3/// Three-dimensional floating-point vector for 3D positions, directions, normals, and RGB radiance.
4#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
5pub struct Vec3 {
6 /// X component.
7 #[get(type(copy))]
8 pub(crate) x: f32,
9 /// Y component.
10 #[get(type(copy))]
11 pub(crate) y: f32,
12 /// Z component.
13 #[get(type(copy))]
14 pub(crate) z: f32,
15}
16
17/// Column-major 4x4 transformation and perspective projection matrix.
18#[derive(Clone, Copy, Data, Debug, PartialEq)]
19pub struct Mat4 {
20 /// Sixteen contiguous matrix elements in column-major order.
21 #[get(type(copy))]
22 pub(crate) m: [f32; 16],
23}
24
25/// Axis-aligned 3D bounding box used for frustum culling, chunk streaming, and BVH acceleration.
26#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
27pub struct Aabb3D {
28 /// Minimum corner `(min_x, min_y, min_z)`.
29 #[get(type(copy))]
30 pub(crate) min: Vec3,
31 /// Maximum corner `(max_x, max_y, max_z)`.
32 #[get(type(copy))]
33 pub(crate) max: Vec3,
34}
35
36/// 3D ray with origin, normalized direction, and precomputed reciprocal direction for fast BVH traversal.
37#[derive(Clone, Copy, Data, Debug, PartialEq)]
38pub struct Ray3D {
39 /// Ray origin in world space.
40 #[get(type(copy))]
41 pub(crate) origin: Vec3,
42 /// Unit ray direction vector.
43 #[get(type(copy))]
44 pub(crate) direction: Vec3,
45 /// Precomputed `1.0 / direction` for branchless slab AABB testing.
46 #[get(type(copy))]
47 pub(crate) inv_direction: Vec3,
48}
49
50/// Six-plane view frustum extracted from a view-projection matrix for O(1) AABB culling.
51#[derive(Clone, Copy, Data, Debug, PartialEq)]
52pub struct Frustum3D {
53 /// Six normalized plane equations `(a, b, c, d)` where `ax + by + cz + d >= 0` is inside.
54 #[get(type(copy))]
55 pub(crate) planes: [[f32; 4]; 6],
56}
57
58/// 3D perspective camera supporting free-fly, third-person follow, yaw/pitch orbit, and frustum culling.
59#[derive(Clone, Copy, Data, Debug, PartialEq)]
60pub struct Camera3D {
61 /// World-space eye position.
62 #[get(type(copy))]
63 pub(crate) position: Vec3,
64 /// Horizontal yaw angle in radians.
65 #[get(type(copy))]
66 pub(crate) yaw: f32,
67 /// Vertical pitch angle in radians (clamped to `[-1.4, 1.4]`).
68 #[get(type(copy))]
69 pub(crate) pitch: f32,
70 /// Vertical field of view in degrees.
71 #[get(type(copy))]
72 pub(crate) fov_deg: f32,
73 /// Near clipping plane distance.
74 #[get(type(copy))]
75 pub(crate) near: f32,
76 /// Far clipping plane distance.
77 #[get(type(copy))]
78 pub(crate) far: f32,
79}