1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
//! Safe Rust API for [Jolt Physics](https://github.com/jrouwe/JoltPhysics) 5.6 over the
//! [joltc](https://github.com/amerkoleci/joltc) raw layer in
//! [`oxijolt-sys`](https://github.com/pockerhead/oxijolt/tree/main/crates/oxijolt-sys).
//!
//! A [`PhysicsWorld`] owns a Jolt physics system with its collision layers
//! ([`CollisionLayers`]), its job system and temp allocator. Bodies are created from a [`Shape`]
//! and [`BodySettings`] and named by a [`BodyId`]; one shape may serve many bodies in many worlds.
//!
//! ```
//! use oxijolt::prelude::math::*;
//! use oxijolt::prelude::*;
//!
//! # fn main() -> oxijolt::error::Result<()> {
//! let mut world = PhysicsWorld::new(WorldSettings::default())?;
//!
//! let floor_shape = Shape::new_box(Vec3::new(100.0, 1.0, 100.0))?;
//! let floor = BodySettings::new_static().position(RVec3::new(0.0, -1.0, 0.0));
//! world.create_body(&floor_shape, &floor)?;
//!
//! let ball_shape = Shape::new_sphere(0.5)?;
//! let ball = world.create_body(
//! &ball_shape,
//! &BodySettings::new_dynamic().position(RVec3::new(0.0, 2.0, 0.0)),
//! )?;
//!
//! for _ in 0..60 {
//! let report = world.step(1.0 / 60.0)?;
//! assert!(report.is_complete());
//! }
//! assert!(world.body(ball)?.position().y < 2.0);
//! # Ok(())
//! # }
//! ```
//!
//! # What a world holds
//! - Rigid bodies of box, sphere, cylinder, capsule, tapered capsule and cylinder, convex hull,
//! triangle mesh, heightfield, compound and scaled [`Shape`]s, with [`PhysicsMaterial`]s that
//! carry the caller's user data. [`BodyMut`] adds impulses, kinematic moves, waking and
//! sleeping, and shape and motion type changes; [`BodySettings`] makes sensors and sets user
//! data and locked axes ([body controls guide]).
//! - Scene queries on `&PhysicsWorld`: [`PhysicsWorld::cast_ray`], [`PhysicsWorld::cast_shape`]
//! and [`PhysicsWorld::collide_shape`], filtered by [`QueryFilter`].
//! - Virtual characters: [`PhysicsWorld::create_character`], with a standing humanoid from
//! [`CharacterSettings::humanoid`].
//! - Wheeled and tracked vehicles and motorcycles on a chassis body:
//! [`PhysicsWorld::create_wheeled_vehicle`], [`PhysicsWorld::create_tracked_vehicle`] and
//! [`PhysicsWorld::create_motorcycle`], with ready settings from [`WheeledVehicleSettings::car`]
//! and [`MotorcycleSettings::bike`] and wheel poses for drawing from
//! [`VehicleRef::wheel_world_transform`].
//! - Ragdolls: [`PhysicsWorld::create_ragdoll`].
//! - Constraints of twelve kinds between two bodies: [`PhysicsWorld::create_constraint`]
//! ([constraints guide]).
//! - Soft bodies: [`PhysicsWorld::create_soft_body`] ([soft body guide]).
//! - Contact, activation and soft body contact events and a [`ContactListener`]:
//! [`PhysicsWorld::set_event_settings`], [`PhysicsWorld::take_events`] ([events guide]).
//! - Snapshots for rollback: [`PhysicsWorld::save_state`], [`PhysicsWorld::restore_state`]
//! ([state guide]).
//! - A floating origin: [`PhysicsWorld::rebase`].
//! - With the `debug-renderer` feature, the colliders' wireframe as line data
//! (`PhysicsWorld::debug_lines`); nothing is drawn.
//!
//! The [guide] builds a game scene with terrain, queries, a character, a vehicle and a ragdoll.
//!
//! # Contract
//! - **Errors.** A call that returns `Err` was refused and changed nothing, unless its
//! documentation says otherwise. A step that ran but dropped work returns `Ok`, and its
//! [`StepReport`] says what was dropped. Code that calls several areas can return
//! [`error::Result`]; `?` converts every area error into [`error::Error`].
//! - **Magnitudes.** Positions, extents, velocities, masses and the other inputs [`limits`]
//! bounds are checked against it before they reach Jolt. Some inputs, such as damping and ray
//! directions, are only checked to be finite. Some bounds are derived from Jolt's arithmetic
//! ([limits doc]), some are only tested at the bound, and some cases no bound excludes
//! ([coverage]).
//! - **Threads.** Changing a world, [`PhysicsWorld::step`] included, takes `&mut PhysicsWorld`;
//! reading it takes `&PhysicsWorld`. `PhysicsWorld` is `Send` and `Sync`: many threads may read
//! one world while nobody steps it, and different worlds may step on different threads at the
//! same time. A world runs Jolt's jobs on Jolt's thread pool
//! ([`WorldSettings::worker_threads`]) or on the caller's pool through a [`JobSystem`]
//! ([job system guide]).
//! - **Determinism.** The order of calls, including the order of body creation and removal, is
//! part of the state. The tests check bit-identical results with 1 and 4 worker threads and
//! with caller job systems on one machine; results agree across platforms and compilers only
//! with the `cross-platform-deterministic` feature ([determinism]).
//!
//! # Global state
//! oxijolt calls `JPH_Init` once per process and never calls `JPH_Shutdown`. It installs
//! joltc's process-global procs once and owns them: the object-layer, body and shape filters,
//! the contact, body activation and soft body contact listeners (the first time a world records
//! events), the debug renderer (with `debug-renderer`, which also serializes debug drawing) and
//! Jolt's assertion handler (before `JPH_Init`). Code that also uses `oxijolt-sys` directly must
//! leave them alone; see the notes on the raw API in `oxijolt-sys`.
//!
//! With the `asserts` feature, which compiles Jolt with its debug assertions, a failed assertion
//! prints its expression, message, file and line to stderr and aborts the process. The only
//! exception is the physics-update-error assertion, whose condition [`PhysicsWorld::step`]
//! returns in its [`StepReport`].
//!
//! # Features
//! Every feature adds to the API except `double-precision`, which changes [`Real`] in every
//! signature: only the final application enables it, and libraries built on oxijolt forward it.
//! `bindgen` is a build switch outside the semver promise.
//!
//! - `double-precision`: world positions ([`Real`], [`RVec3`]) use `f64`.
//! - `cross-platform-deterministic`: Jolt's cross-platform deterministic floating point settings.
//! - `debug-renderer`: collider wireframes as line data, see above.
//! - `asserts`: Jolt's debug assertions, reported as above.
//! - `bindgen`: generates the raw bindings with libclang at build time.
//! - `glam032`: `From` conversions both ways between [`Vec3`], [`Quat`], [`RVec3`] and glam
//! 0.32's `Vec3`, `Quat` and vector of [`Real`] (`DVec3` in double precision).
//! - `mint`: `From` conversions both ways between [`Vec3`], [`Quat`], [`RVec3`] and mint's
//! `Vector3<f32>`, `Quaternion<f32>` and `Vector3<Real>`.
//!
//! The conversions copy the fields: a value converted there and back has the same bits, and
//! nothing is normalized or checked until a call takes the value.
//!
//! ```
//! # #[cfg(feature = "glam032")]
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use oxijolt::{BodySettings, PhysicsWorld, Shape, WorldSettings};
//!
//! let mut world = PhysicsWorld::new(WorldSettings::default())?;
//! let ball = world.create_body(
//! &Shape::new_sphere(0.5)?,
//! &BodySettings::new_dynamic()
//! .rotation(glam::Quat::from_rotation_y(1.0).into())
//! .linear_velocity(glam::Vec3::new(1.0, 0.0, 0.0).into()),
//! )?;
//! let velocity: glam::Vec3 = world.body(ball)?.linear_velocity().into();
//! assert_eq!(velocity, glam::Vec3::X);
//! # Ok(())
//! # }
//! # #[cfg(not(feature = "glam032"))]
//! # fn main() {}
//! ```
//!
//! [guide]: https://github.com/pockerhead/oxijolt/blob/main/docs/guide.md
//! [body controls guide]: https://github.com/pockerhead/oxijolt/blob/main/docs/bodies.md
//! [constraints guide]: https://github.com/pockerhead/oxijolt/blob/main/docs/constraints.md
//! [soft body guide]: https://github.com/pockerhead/oxijolt/blob/main/docs/soft-bodies.md
//! [events guide]: https://github.com/pockerhead/oxijolt/blob/main/docs/events.md
//! [state guide]: https://github.com/pockerhead/oxijolt/blob/main/docs/state.md
//! [job system guide]: https://github.com/pockerhead/oxijolt/blob/main/docs/job-system.md
//! [determinism]: https://github.com/pockerhead/oxijolt/blob/main/docs/determinism.md
//! [limits doc]: https://github.com/pockerhead/oxijolt/blob/main/docs/limits.md
//! [coverage]: https://github.com/pockerhead/oxijolt/blob/main/docs/coverage.md#not-covered
// Examples, including the README and the guides, are code users copy: they must build clean.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use QueryFilter;
pub use ;
pub use ;
pub use ;
pub use PhysicsMaterial;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// The repository's guide, `docs/guide.md`, whose examples run as doctests.
;
/// The repository's README, whose example runs as a doctest.
;
/// The constraints guide, `docs/constraints.md`.
;
/// The soft body guide, `docs/soft-bodies.md`.
;
/// The events guide, `docs/events.md`.
;
/// The body controls guide, `docs/bodies.md`.
;
/// The save and restore guide, `docs/state.md`.
;
/// The job system guide, `docs/job-system.md`.
;
/// The shape cooking guide, `docs/shape-cooking.md`.
;
/// The vehicles guide, `docs/vehicles.md`.
;