Skip to main content

euv_engine/physics/
struct.rs

1use crate::*;
2
3/// Configuration parameters for the physics world simulation.
4#[derive(Clone, Copy, Data, Debug, New, PartialEq, PartialOrd)]
5pub struct PhysicsConfig {
6    /// The gravitational acceleration vector in pixels per second squared.
7    #[get(type(copy))]
8    pub(crate) gravity: Vector2D,
9    /// The linear velocity damping coefficient applied per second.
10    #[get(type(copy))]
11    pub(crate) linear_damping: f64,
12    /// The angular velocity damping coefficient applied per second.
13    #[get(type(copy))]
14    pub(crate) angular_damping: f64,
15}
16
17/// A 2D rigid body participating in the physics simulation.
18#[derive(Clone, Data, Debug, New, PartialEq)]
19pub struct RigidBody2D {
20    /// The unique identifier of this body, typically matching a game object ID.
21    #[get(type(copy))]
22    pub(crate) id: u64,
23    /// The world-space position of the body's center.
24    #[get(type(copy))]
25    #[get_mut(pub(crate))]
26    pub(crate) position: Vector2D,
27    /// The linear velocity in pixels per second.
28    #[get(type(copy))]
29    #[get_mut(pub(crate))]
30    #[new(skip)]
31    pub(crate) velocity: Vector2D,
32    /// The accumulated force to be applied during the next physics step.
33    #[get(pub(crate), type(copy))]
34    #[get_mut(pub(crate))]
35    #[set(pub(crate))]
36    #[new(skip)]
37    pub(crate) force_accumulator: Vector2D,
38    /// The rotation angle in radians.
39    #[get(type(copy))]
40    #[get_mut(pub(crate))]
41    #[new(skip)]
42    pub(crate) rotation: f64,
43    /// The angular velocity in radians per second.
44    #[get(type(copy))]
45    #[get_mut(pub(crate))]
46    #[new(skip)]
47    pub(crate) angular_velocity: f64,
48    /// The mass of the body in kilograms. Static bodies have a mass of 0.
49    #[get(type(copy))]
50    #[get_mut(pub(crate))]
51    pub(crate) mass: f64,
52    /// The precomputed inverse mass (1/mass). Static bodies have 0 inverse mass.
53    #[get(pub(crate), type(copy))]
54    #[get_mut(pub(crate))]
55    #[set(pub(crate))]
56    pub(crate) inverse_mass: f64,
57    /// The restitution (bounciness) coefficient in the range 0.0 to 1.0.
58    #[get(type(copy))]
59    pub(crate) restitution: f64,
60    /// The friction coefficient for surface contact.
61    #[get(type(copy))]
62    pub(crate) friction: f64,
63    /// How this body participates in the simulation.
64    #[get(type(copy))]
65    pub(crate) body_type: BodyType,
66    /// The collider shape attached to this body.
67    #[get(type(copy))]
68    #[new(skip)]
69    pub(crate) collider: Option<BodyCollider>,
70}
71
72/// The physics world managing all rigid bodies and simulation steps.
73#[derive(Clone, Data, Debug, New, PartialEq)]
74pub struct PhysicsWorld2D {
75    /// All rigid bodies in the world.
76    #[get(pub(crate))]
77    #[get_mut(pub(crate))]
78    #[set(pub(crate))]
79    #[new(skip)]
80    pub(crate) bodies: Vec<RigidBody2D>,
81    /// The simulation configuration.
82    #[get(type(copy))]
83    pub(crate) config: PhysicsConfig,
84}
85
86/// Configuration parameters for the 3D physics world simulation.
87#[derive(Clone, Copy, Data, Debug, New, PartialEq, PartialOrd)]
88pub struct PhysicsConfig3D {
89    /// The gravitational acceleration vector in meters per second squared.
90    #[get(type(copy))]
91    pub(crate) gravity: Vector3D,
92    /// The linear velocity damping coefficient applied per second.
93    #[get(type(copy))]
94    pub(crate) linear_damping: f64,
95    /// The angular velocity damping coefficient applied per second.
96    #[get(type(copy))]
97    pub(crate) angular_damping: f64,
98}
99
100/// A 3D rigid body participating in the physics simulation.
101#[derive(Clone, Data, Debug, New, PartialEq)]
102pub struct RigidBody3D {
103    /// The unique identifier of this body, typically matching a game object ID.
104    #[get(type(copy))]
105    pub(crate) id: u64,
106    /// The world-space position of the body's center.
107    #[get(type(copy))]
108    #[get_mut(pub(crate))]
109    pub(crate) position: Vector3D,
110    /// The linear velocity in meters per second.
111    #[get(type(copy))]
112    #[get_mut(pub(crate))]
113    #[new(skip)]
114    pub(crate) velocity: Vector3D,
115    /// The accumulated force to be applied during the next physics step.
116    #[get(pub(crate), type(copy))]
117    #[get_mut(pub(crate))]
118    #[set(pub(crate))]
119    #[new(skip)]
120    pub(crate) force_accumulator: Vector3D,
121    /// The rotation as a quaternion.
122    #[get(type(copy))]
123    #[get_mut(pub(crate))]
124    #[new(skip)]
125    pub(crate) rotation: Quaternion,
126    /// The angular velocity as a 3D vector (axis * speed).
127    #[get(type(copy))]
128    #[get_mut(pub(crate))]
129    #[new(skip)]
130    pub(crate) angular_velocity: Vector3D,
131    /// The accumulated torque to be applied during the next physics step.
132    #[get(pub(crate), type(copy))]
133    #[get_mut(pub(crate))]
134    #[set(pub(crate))]
135    #[new(skip)]
136    pub(crate) torque_accumulator: Vector3D,
137    /// The mass of the body in kilograms. Static bodies have a mass of 0.
138    #[get(type(copy))]
139    #[get_mut(pub(crate))]
140    pub(crate) mass: f64,
141    /// The precomputed inverse mass (1/mass). Static bodies have 0 inverse mass.
142    #[get(pub(crate), type(copy))]
143    #[get_mut(pub(crate))]
144    #[set(pub(crate))]
145    pub(crate) inverse_mass: f64,
146    /// The restitution (bounciness) coefficient in the range 0.0 to 1.0.
147    #[get(type(copy))]
148    pub(crate) restitution: f64,
149    /// The friction coefficient for surface contact.
150    #[get(type(copy))]
151    pub(crate) friction: f64,
152    /// How this body participates in the simulation.
153    #[get(type(copy))]
154    pub(crate) body_type: BodyType,
155    /// The 3D collider shape attached to this body.
156    #[get(type(copy))]
157    #[new(skip)]
158    pub(crate) collider: Option<BodyCollider3D>,
159}
160
161/// The 3D physics world managing all rigid bodies and simulation steps.
162#[derive(Clone, Data, Debug, New, PartialEq)]
163pub struct PhysicsWorld3D {
164    /// All rigid bodies in the world.
165    #[get(pub(crate))]
166    #[get_mut(pub(crate))]
167    #[set(pub(crate))]
168    #[new(skip)]
169    pub(crate) bodies: Vec<RigidBody3D>,
170    /// The simulation configuration.
171    #[get(type(copy))]
172    pub(crate) config: PhysicsConfig3D,
173}