euv_core/game/engine3d/physics/struct.rs
1use super::*;
2
3/// Dynamic or static 3D rigid body with axis-aligned box collider and physical restitution/friction.
4#[derive(Clone, Copy, Data, Debug, PartialEq)]
5pub struct RigidBody3D {
6 /// Center position in world meters.
7 #[get(type(copy))]
8 pub(crate) position: Vec3,
9 /// Linear velocity in meters per second.
10 #[get(type(copy))]
11 pub(crate) velocity: Vec3,
12 /// Axis-aligned box collider half-extents `(hx, hy, hz)`.
13 #[get(type(copy))]
14 pub(crate) half_extents: Vec3,
15 /// Inverse mass (`0.0` = immovable static collider).
16 #[get(type(copy))]
17 pub(crate) inv_mass: f32,
18 /// Coefficient of restitution (`0.0` = inelastic, `1.0` = perfectly bouncy).
19 #[get(type(copy))]
20 pub(crate) restitution: f32,
21 /// Linear velocity damping factor per second (`0.0..=1.0`).
22 #[get(type(copy))]
23 pub(crate) linear_damping: f32,
24 /// Whether this body is currently resting on the ground or another solid surface.
25 #[get(type(copy))]
26 pub(crate) grounded: bool,
27}
28
29/// Result of a 3D physics raycast against `PhysicsWorld3D` rigid bodies.
30#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
31pub struct RayHitPhysics3D {
32 /// Index of the hit `RigidBody3D`.
33 #[get(type(copy))]
34 pub(crate) body_index: usize,
35 /// Hit distance along the query ray in meters.
36 #[get(type(copy))]
37 pub(crate) distance: f32,
38 /// World-space contact point.
39 #[get(type(copy))]
40 pub(crate) point: Vec3,
41}
42
43/// Deterministic 3D rigid-body physics world with gravity, ground plane, spatial-hash broadphase, impulse resolution, and raycasting.
44#[derive(Clone, Data, Debug)]
45pub struct PhysicsWorld3D {
46 /// Uniform gravitational acceleration vector (defaults to `(0.0, -9.81, 0.0)`).
47 #[get(type(copy))]
48 pub(crate) gravity: Vec3,
49 /// Horizontal ground plane height in meters (`y = ground_y`).
50 #[get(type(copy))]
51 pub(crate) ground_y: f32,
52 /// Simulated 3D rigid bodies.
53 pub(crate) bodies: Vec<RigidBody3D>,
54 /// Reusable fixed-bucket spatial hash heads (`u32::MAX` = empty bucket) for O(N) 3D broadphase.
55 #[get(skip)]
56 #[get_mut(skip)]
57 #[set(skip)]
58 pub(crate) hash_heads: Vec<u32>,
59 /// Reusable linked-list next indices for entries inserted into `hash_heads`.
60 #[get(skip)]
61 #[get_mut(skip)]
62 #[set(skip)]
63 pub(crate) hash_next: Vec<u32>,
64 /// Reusable body index payload per hash-grid entry.
65 #[get(skip)]
66 #[get_mut(skip)]
67 #[set(skip)]
68 pub(crate) hash_body: Vec<u32>,
69 /// Indices of buckets touched during the current step so clearing touches only occupied slots.
70 #[get(skip)]
71 #[get_mut(skip)]
72 #[set(skip)]
73 pub(crate) touched_buckets: Vec<usize>,
74 /// Reusable deduplicated candidate pair buffer `(i, j)` with `i < j`.
75 #[get(skip)]
76 #[get_mut(skip)]
77 #[set(skip)]
78 pub(crate) pair_scratch: Vec<(usize, usize)>,
79}