1use crate::core::NULL_INDEX;
7use crate::math_functions::{
8 Matrix3, Pos, Quat, Vec3, WorldTransform, MAT3_ZERO, POS_ZERO, QUAT_IDENTITY, VEC3_ZERO,
9 WORLD_TRANSFORM_IDENTITY,
10};
11use crate::types::BodyType;
12
13pub mod body_flags {
15 pub const LOCK_LINEAR_X: u32 = 0x0000_0001;
17 pub const LOCK_LINEAR_Y: u32 = 0x0000_0002;
19 pub const LOCK_LINEAR_Z: u32 = 0x0000_0004;
21 pub const LOCK_ANGULAR_X: u32 = 0x0000_0008;
23 pub const LOCK_ANGULAR_Y: u32 = 0x0000_0010;
25 pub const LOCK_ANGULAR_Z: u32 = 0x0000_0020;
27 pub const IS_FAST: u32 = 0x0000_0040;
29 pub const IS_BULLET: u32 = 0x0000_0080;
31 pub const IS_SPEED_CAPPED: u32 = 0x0000_0100;
33 pub const HAD_TIME_OF_IMPACT: u32 = 0x0000_0200;
35 pub const ALLOW_FAST_ROTATION: u32 = 0x0000_0400;
37 pub const ENLARGE_BOUNDS: u32 = 0x0000_0800;
39 pub const DYNAMIC_FLAG: u32 = 0x0000_1000;
41 pub const ENABLE_SLEEP: u32 = 0x0000_2000;
42 pub const BODY_ENABLE_CONTACT_RECYCLING: u32 = 0x0000_4000;
43 pub const DIRTY_MASS: u32 = 0x0000_8000;
45
46 pub const ALL_LOCKS: u32 = LOCK_LINEAR_X
48 | LOCK_LINEAR_Y
49 | LOCK_LINEAR_Z
50 | LOCK_ANGULAR_X
51 | LOCK_ANGULAR_Y
52 | LOCK_ANGULAR_Z;
53
54 pub const FIXED_ROTATION: u32 = LOCK_ANGULAR_X | LOCK_ANGULAR_Y | LOCK_ANGULAR_Z;
56
57 pub const BODY_TRANSIENT_FLAGS: u32 = IS_FAST | IS_SPEED_CAPPED | HAD_TIME_OF_IMPACT;
59}
60
61#[derive(Debug, Clone)]
63pub struct Body {
64 pub user_data: u64,
65
66 pub set_index: i32,
68
69 pub local_index: i32,
71
72 pub head_contact_key: i32,
74 pub contact_count: i32,
75
76 pub head_shape_id: i32,
77 pub shape_count: i32,
78
79 pub head_chain_id: i32,
80
81 pub head_joint_key: i32,
83 pub joint_count: i32,
84
85 pub island_id: i32,
87
88 pub island_index: i32,
91
92 pub sleep_threshold: f32,
93 pub sleep_time: f32,
94 pub sleep_velocity: f32,
95 pub mass: f32,
96
97 pub inertia: Matrix3,
99
100 pub body_move_index: i32,
102
103 pub id: i32,
104
105 pub flags: u32,
107 pub name_id: u32,
108
109 pub type_: BodyType,
110
111 pub generation: u16,
114}
115
116impl Default for Body {
117 fn default() -> Self {
118 Body {
119 user_data: 0,
120 set_index: NULL_INDEX,
121 local_index: NULL_INDEX,
122 head_contact_key: NULL_INDEX,
123 contact_count: 0,
124 head_shape_id: NULL_INDEX,
125 shape_count: 0,
126 head_chain_id: NULL_INDEX,
127 head_joint_key: NULL_INDEX,
128 joint_count: 0,
129 island_id: NULL_INDEX,
130 island_index: NULL_INDEX,
131 sleep_threshold: 0.0,
132 sleep_time: 0.0,
133 sleep_velocity: 0.0,
134 mass: 0.0,
135 inertia: MAT3_ZERO,
136 body_move_index: NULL_INDEX,
137 id: NULL_INDEX,
138 flags: 0,
139 name_id: 0,
140 type_: BodyType::Static,
141 generation: 0,
142 }
143 }
144}
145
146#[derive(Debug, Clone, Copy, PartialEq)]
150pub struct BodyState {
151 pub linear_velocity: Vec3,
152 pub angular_velocity: Vec3,
153
154 pub delta_position: Vec3,
156
157 pub delta_rotation: Quat,
159
160 pub flags: u32,
162}
163
164pub const IDENTITY_BODY_STATE: BodyState = BodyState {
166 linear_velocity: VEC3_ZERO,
167 angular_velocity: VEC3_ZERO,
168 delta_position: VEC3_ZERO,
169 delta_rotation: QUAT_IDENTITY,
170 flags: 0,
171};
172
173impl Default for BodyState {
174 fn default() -> Self {
175 IDENTITY_BODY_STATE
176 }
177}
178
179#[derive(Debug, Clone, Copy, PartialEq)]
182pub struct BodySim {
183 pub transform: WorldTransform,
185
186 pub center: Pos,
188
189 pub rotation0: Quat,
191 pub center0: Pos,
192
193 pub local_center: Vec3,
195
196 pub force: Vec3,
197 pub torque: Vec3,
198
199 pub inv_mass: f32,
200
201 pub inv_inertia_local: Matrix3,
204 pub inv_inertia_world: Matrix3,
205
206 pub min_extent: f32,
207 pub max_extent: Vec3,
208 pub max_angular_velocity: f32,
209 pub linear_damping: f32,
210 pub angular_damping: f32,
211 pub gravity_scale: f32,
212
213 pub body_id: i32,
215
216 pub flags: u32,
218}
219
220impl Default for BodySim {
221 fn default() -> Self {
222 BodySim {
223 transform: WORLD_TRANSFORM_IDENTITY,
224 center: POS_ZERO,
225 rotation0: QUAT_IDENTITY,
226 center0: POS_ZERO,
227 local_center: VEC3_ZERO,
228 force: VEC3_ZERO,
229 torque: VEC3_ZERO,
230 inv_mass: 0.0,
231 inv_inertia_local: MAT3_ZERO,
232 inv_inertia_world: MAT3_ZERO,
233 min_extent: 0.0,
234 max_extent: VEC3_ZERO,
235 max_angular_velocity: 0.0,
236 linear_damping: 0.0,
237 angular_damping: 0.0,
238 gravity_scale: 1.0,
239 body_id: NULL_INDEX,
240 flags: 0,
241 }
242 }
243}
244
245#[derive(Debug, Clone, Copy, PartialEq)]
247pub struct BodyPlaneResult {
248 pub shape_id: crate::id::ShapeId,
250 pub result: crate::geometry::PlaneResult,
252}
253
254impl Default for BodyPlaneResult {
255 fn default() -> Self {
256 BodyPlaneResult {
257 shape_id: crate::id::NULL_SHAPE_ID,
258 result: crate::geometry::PlaneResult::default(),
259 }
260 }
261}
262
263#[derive(Debug, Clone, Copy, PartialEq)]
265pub struct BodyCastResult {
266 pub shape_id: crate::id::ShapeId,
268 pub point: crate::math_functions::Pos,
270 pub normal: crate::math_functions::Vec3,
272 pub fraction: f32,
275 pub triangle_index: i32,
277 pub user_material_id: u64,
279 pub iterations: i32,
281 pub hit: bool,
283}
284
285impl Default for BodyCastResult {
286 fn default() -> Self {
287 BodyCastResult {
288 shape_id: crate::id::NULL_SHAPE_ID,
289 point: crate::math_functions::POS_ZERO,
290 normal: crate::math_functions::VEC3_ZERO,
291 fraction: 0.0,
292 triangle_index: 0,
293 user_material_id: 0,
294 iterations: 0,
295 hit: false,
296 }
297 }
298}