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, 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}