aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml8
-rw-r--r--benchmarks3d/all_benchmarks3.rs2
-rw-r--r--benchmarks3d/ccd3.rs85
-rw-r--r--build/rapier2d-f64/Cargo.toml4
-rw-r--r--build/rapier2d/Cargo.toml4
-rw-r--r--build/rapier3d-f64/Cargo.toml4
-rw-r--r--build/rapier3d/Cargo.toml4
-rw-r--r--examples2d/Cargo.toml3
-rw-r--r--examples2d/all_examples2.rs2
-rw-r--r--examples2d/ccd2.rs124
-rw-r--r--examples3d/Cargo.toml1
-rw-r--r--examples3d/all_examples3.rs4
-rw-r--r--examples3d/ccd3.rs145
-rw-r--r--examples3d/debug_big_colliders3.rs50
-rw-r--r--examples3d/debug_infinite_fall3.rs25
-rw-r--r--examples3d/fountain3.rs10
-rw-r--r--src/counters/collision_detection_counters.rs7
-rw-r--r--src/counters/mod.rs12
-rw-r--r--src/counters/stages_counters.rs9
-rw-r--r--src/data/coarena.rs14
-rw-r--r--src/dynamics/ccd/ccd_solver.rs430
-rw-r--r--src/dynamics/ccd/mod.rs5
-rw-r--r--src/dynamics/ccd/toi_entry.rs163
-rw-r--r--src/dynamics/coefficient_combine_rule.rs10
-rw-r--r--src/dynamics/integration_parameters.rs74
-rw-r--r--src/dynamics/mod.rs2
-rw-r--r--src/dynamics/rigid_body.rs275
-rw-r--r--src/dynamics/rigid_body_set.rs207
-rw-r--r--src/dynamics/solver/interaction_groups.rs11
-rw-r--r--src/dynamics/solver/island_solver.rs38
-rw-r--r--src/dynamics/solver/joint_constraint/ball_position_constraint.rs4
-rw-r--r--src/dynamics/solver/joint_constraint/ball_position_constraint_wide.rs2
-rw-r--r--src/dynamics/solver/joint_constraint/fixed_position_constraint.rs4
-rw-r--r--src/dynamics/solver/joint_constraint/prismatic_position_constraint.rs8
-rw-r--r--src/dynamics/solver/joint_constraint/revolute_position_constraint.rs16
-rw-r--r--src/dynamics/solver/parallel_island_solver.rs160
-rw-r--r--src/dynamics/solver/position_solver.rs9
-rw-r--r--src/dynamics/solver/solver_constraints.rs9
-rw-r--r--src/dynamics/solver/velocity_constraint.rs17
-rw-r--r--src/dynamics/solver/velocity_constraint_wide.rs27
-rw-r--r--src/dynamics/solver/velocity_ground_constraint.rs16
-rw-r--r--src/dynamics/solver/velocity_ground_constraint_wide.rs26
-rw-r--r--src/geometry/broad_phase_multi_sap.rs794
-rw-r--r--src/geometry/broad_phase_multi_sap/broad_phase.rs556
-rw-r--r--src/geometry/broad_phase_multi_sap/broad_phase_pair_event.rs33
-rw-r--r--src/geometry/broad_phase_multi_sap/mod.rs19
-rw-r--r--src/geometry/broad_phase_multi_sap/sap_axis.rs274
-rw-r--r--src/geometry/broad_phase_multi_sap/sap_endpoint.rs60
-rw-r--r--src/geometry/broad_phase_multi_sap/sap_layer.rs372
-rw-r--r--src/geometry/broad_phase_multi_sap/sap_proxy.rs139
-rw-r--r--src/geometry/broad_phase_multi_sap/sap_region.rs231
-rw-r--r--src/geometry/broad_phase_multi_sap/sap_utils.rs62
-rw-r--r--src/geometry/collider.rs148
-rw-r--r--src/geometry/collider_set.rs178
-rw-r--r--src/geometry/contact_pair.rs51
-rw-r--r--src/geometry/mod.rs2
-rw-r--r--src/geometry/narrow_phase.rs405
-rw-r--r--src/pipeline/collision_pipeline.rs26
-rw-r--r--src/pipeline/mod.rs2
-rw-r--r--src/pipeline/physics_pipeline.rs347
-rw-r--r--src/pipeline/query_pipeline.rs125
-rw-r--r--src/utils.rs32
-rw-r--r--src_testbed/box2d_backend.rs11
-rw-r--r--src_testbed/engine.rs30
-rw-r--r--src_testbed/harness/mod.rs5
-rw-r--r--src_testbed/nphysics_backend.rs6
-rw-r--r--src_testbed/physics/mod.rs4
-rw-r--r--src_testbed/physx_backend.rs41
-rw-r--r--src_testbed/testbed.rs84
69 files changed, 4637 insertions, 1430 deletions
diff --git a/Cargo.toml b/Cargo.toml
index b6ae4da..cfdb3ba 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,10 +19,10 @@ members = [ "build/rapier2d", "build/rapier2d-f64", "build/rapier_testbed2d", "e
#kiss3d = { git = "https://github.com/sebcrozet/kiss3d" }
#nalgebra = { git = "https://github.com/dimforge/nalgebra", branch = "dev" }
-#parry2d = { git = "https://github.com/dimforge/parry" }
-#parry3d = { git = "https://github.com/dimforge/parry" }
-#parry2d-f64 = { git = "https://github.com/dimforge/parry" }
-#parry3d-f64 = { git = "https://github.com/dimforge/parry" }
+parry2d = { git = "https://github.com/dimforge/parry", branch = "special_cases" }
+parry3d = { git = "https://github.com/dimforge/parry", branch = "special_cases" }
+parry2d-f64 = { git = "https://github.com/dimforge/parry", branch = "special_cases" }
+parry3d-f64 = { git = "https://github.com/dimforge/parry", branch = "special_cases" }
#ncollide2d = { git = "https://github.com/dimforge/ncollide" }
#ncollide3d = { git = "https://github.com/dimforge/ncollide" }
#nphysics2d = { git = "https://github.com/dimforge/nphysics" }
diff --git a/benchmarks3d/all_benchmarks3.rs b/benchmarks3d/all_benchmarks3.rs
index f35cb8e..38d71cd 100644
--- a/benchmarks3d/all_benchmarks3.rs
+++ b/benchmarks3d/all_benchmarks3.rs
@@ -13,6 +13,7 @@ use std::cmp::Ordering;
mod balls3;
mod boxes3;
mod capsules3;
+mod ccd3;
mod compound3;
mod convex_polyhedron3;
mod heightfield3;
@@ -52,6 +53,7 @@ pub fn main() {
("Balls", balls3::init_world),
("Boxes", boxes3::init_world),
("Capsules", capsules3::init_world),
+ ("CCD", ccd3::init_world),
("Compound", compound3::init_world),
("Convex polyhedron", convex_polyhedron3::init_world),
("Heightfield", heightfield3::init_world),
diff --git a/benchmarks3d/ccd3.rs b/benchmarks3d/ccd3.rs
new file mode 100644
index 0000000..f1831e7
--- /dev/null
+++ b/benchmarks3d/ccd3.rs
@@ -0,0 +1,85 @@
+use na::Point3;
+use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
+use rapier3d::geometry::{ColliderBuilder, ColliderSet};
+use rapier_testbed3d::Testbed;
+
+pub fn init_world(testbed: &mut Testbed) {
+ /*
+ * World
+ */
+ let mut bodies = RigidBodySet::new();
+ let mut colliders = ColliderSet::new();
+ let joints = JointSet::new();
+
+ /*
+ * Ground
+ */
+ let ground_size = 100.1;
+ let ground_height = 0.1;
+
+ let rigid_body = RigidBodyBuilder::new_static()
+ .translation(0.0, -ground_height, 0.0)
+ .build();
+ let handle = bodies.insert(rigid_body);
+ let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
+ colliders.insert(collider, handle, &mut bodies);
+
+ /*
+ * Create the cubes
+ */
+ let num = 4;
+ let numj = 20;
+ let rad = 1.0;
+
+ let shiftx = rad * 2.0 + rad;
+ let shifty = rad * 2.0 + rad;
+ let shiftz = rad * 2.0 + rad;
+ let centerx = shiftx * (num / 2) as f32;
+ let centery = shifty / 2.0;
+ let centerz = shiftz * (num / 2) as f32;
+
+ let mut offset = -(num as f32) * (rad * 2.0 + rad) * 0.5;
+
+ for j in 0usize..numj {
+ for i in 0..num {
+ for k in 0usize..num {
+ let x = i as f32 * shiftx - centerx + offset;
+ let y = j as f32 * shifty + centery + 3.0;
+ let z = k as f32 * shiftz - centerz + offset;
+
+ // Build the rigid body.
+ let rigid_body = RigidBodyBuilder::new_dynamic()
+ .translation(x, y, z)
+ .linvel(0.0, -1000.0, 0.0)
+ .ccd_enabled(true)
+ .build();
+ let handle = bodies.insert(rigid_body);
+
+ let collider = match j % 5 {
+ 0 => ColliderBuilder::cuboid(rad, rad, rad),
+ 1 => ColliderBuilder::ball(rad),
+ // Rounded cylinders are much more efficient that cylinder, even if the
+ // rounding margin is small.
+ // 2 => ColliderBuilder::round_cylinder(rad, rad, rad / 10.0),
+ // 3 => ColliderBuilder::cone(rad, rad),
+ _ => ColliderBuilder::capsule_y(rad, rad),
+ };
+
+ colliders.insert(collider.build(), handle, &mut bodies);
+ }
+ }
+
+ offset -= 0.05 * rad * (num as f32 - 1.0);
+ }
+
+ /*
+ * Set up the testbed.
+ */
+ testbed.set_world(bodies, colliders, joints);
+ testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
+}
+
+fn main() {
+ let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
+ testbed.run()
+}
diff --git a/build/rapier2d-f64/Cargo.toml b/build/rapier2d-f64/Cargo.toml
index c6bc8f3..8924c40 100644
--- a/build/rapier2d-f64/Cargo.toml
+++ b/build/rapier2d-f64/Cargo.toml
@@ -29,6 +29,10 @@ wasm-bindgen = [ "instant/wasm-bindgen" ]
serde-serialize = [ "nalgebra/serde-serialize", "parry2d-f64/serde-serialize", "serde", "bit-vec/serde", "arrayvec/serde" ]
enhanced-determinism = [ "simba/libm_force", "parry2d-f64/enhanced-determinism", "indexmap" ]
+# Feature used for development and debugging only.
+# Do not enable this unless you are working on the engine internals.
+dev-remove-slow-accessors = []
+
[lib]
name = "rapier2d_f64"
path = "../../src/lib.rs"
diff --git a/build/rapier2d/Cargo.toml b/build/rapier2d/Cargo.toml
index fa73f4e..d936bb6 100644
--- a/build/rapier2d/Cargo.toml
+++ b/build/rapier2d/Cargo.toml
@@ -29,6 +29,10 @@ wasm-bindgen = [ "instant/wasm-bindgen" ]
serde-serialize = [ "nalgebra/serde-serialize", "parry2d/serde-serialize", "serde", "bit-vec/serde", "arrayvec/serde" ]
enhanced-determinism = [ "simba/libm_force", "parry2d/enhanced-determinism", "indexmap" ]
+# Feature used for development and debugging only.
+# Do not enable this unless you are working on the engine internals.
+dev-remove-slow-accessors = []
+
[lib]
name = "rapier2d"
path = "../../src/lib.rs"
diff --git a/build/rapier3d-f64/Cargo.toml b/build/rapier3d-f64/Cargo.toml
index e201811..49c0a35 100644
--- a/build/rapier3d-f64/Cargo.toml
+++ b/build/rapier3d-f64/Cargo.toml
@@ -29,6 +29,10 @@ wasm-bindgen = [ "instant/wasm-bindgen" ]
serde-serialize = [ "nalgebra/serde-serialize", "parry3d-f64/serde-serialize", "serde", "bit-vec/serde" ]
enhanced-determinism = [ "simba/libm_force", "parry3d-f64/enhanced-determinism" ]
+# Feature used for development and debugging only.
+# Do not enable this unless you are working on the engine internals.
+dev-remove-slow-accessors = []
+
[lib]
name = "rapier3d_f64"
path = "../../src/lib.rs"
diff --git a/build/rapier3d/Cargo.toml b/build/rapier3d/Cargo.toml
index 0a83872..aec823d 100644
--- a/build/rapier3d/Cargo.toml
+++ b/build/rapier3d/Cargo.toml
@@ -29,6 +29,10 @@ wasm-bindgen = [ "instant/wasm-bindgen" ]
serde-serialize = [ "nalgebra/serde-serialize", "parry3d/serde-serialize", "serde", "bit-vec/serde" ]
enhanced-determinism = [ "simba/libm_force", "parry3d/enhanced-determinism" ]
+# Feature used for development and debugging only.
+# Do not enable this unless you are working on the engine internals.
+dev-remove-slow-accessors = []
+
[lib]
name = "rapier3d"
path = "../../src/lib.rs"
diff --git a/examples2d/Cargo.toml b/examples2d/Cargo.toml
index 48f5a65..a226f12 100644
--- a/examples2d/Cargo.toml
+++ b/examples2d/Cargo.toml
@@ -3,6 +3,7 @@ name = "rapier-examples-2d"
version = "0.1.0"
authors = [ "Sébastien Crozet <developer@crozet.re>" ]
edition = "2018"
+default-run = "all_examples2"
[features]
parallel = [ "rapier2d/parallel", "rapier_testbed2d/parallel" ]
@@ -26,4 +27,4 @@ path = "../build/rapier2d"
[[bin]]
name = "all_examples2"
-path = "./all_examples2.rs" \ No newline at end of file
+path = "./all_examples2.rs"
diff --git a/examples2d/all_examples2.rs b/examples2d/all_examples2.rs
index f4430aa..8f38ced 100644
--- a/examples2d/all_examples2.rs
+++ b/examples2d/all_examples2.rs
@@ -11,6 +11,7 @@ use rapier_testbed2d::Testbed;
use std::cmp::Ordering;
mod add_remove2;
+mod ccd2;
mod collision_groups2;
mod convex_polygons2;
mod damping2;
@@ -60,6 +61,7 @@ pub fn main() {
let mut builders: Vec<(_, fn(&mut Testbed))> = vec![
("Add remove", add_remove2::init_world),
+ ("CCD", ccd2::init_world),
("Collision groups", collision_groups2::init_world),
("Convex polygons", convex_polygons2::init_world),
("Damping", damping2::init_world),
diff --git a/examples2d/ccd2.rs b/examples2d/ccd2.rs
new file mode 100644
index 0000000..852fad3
--- /dev/null
+++ b/examples2d/ccd2.rs
@@ -0,0 +1,124 @@
+use na::{Isometry2, Point2, Point3};
+use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
+use rapier2d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
+use rapier_testbed2d::Testbed;
+
+pub fn init_world(testbed: &mut Testbed) {
+ /*
+ * World
+ */
+ let mut bodies = RigidBodySet::new();
+ let mut colliders = ColliderSet::new();
+ let joints = JointSet::new();
+
+ /*
+ * Ground
+ */
+ let ground_size = 25.0;
+ let ground_thickness = 0.1;
+
+ let rigid_body = RigidBodyBuilder::new_static().ccd_enabled(true).build();
+ let ground_handle = bodies.insert(rigid_body);
+
+ let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build();
+ colliders.insert(collider, ground_handle, &mut bodies);
+
+ let collider = ColliderBuilder::cuboid(ground_thickness, ground_size)
+ .translation(-3.0, 0.0)
+ .build();
+ colliders.insert(collider, ground_handle, &mut bodies);
+
+ let collider = ColliderBuilder::cuboid(ground_thickness, ground_size)
+ .translation(6.0, 0.0)
+ .build();
+ colliders.insert(collider, ground_handle, &mut bodies);
+
+ let collider = ColliderBuilder::cuboid(ground_thickness, ground_size)
+ .translation(2.5, 0.0)
+ .sensor(true)
+ .build();
+ let sensor_handle = colliders.insert(collider, ground_handle, &mut bodies);
+
+ /*
+ * Create the shapes
+ */
+ let radx = 0.4;
+ let rady = 0.05;
+
+ let delta1 = Isometry2::translation(0.0, radx - rady);
+ let delta2 = Isometry2::translation(-radx + rady, 0.0);
+ let delta3 = Isometry2::translation(radx - rady, 0.0);
+
+ let mut compound_parts = Vec::new();
+ let vertical = SharedShape::cuboid(rady, radx);
+ let horizontal = SharedShape::cuboid(radx, rady);
+ compound_parts.push((delta1, horizontal));
+ compound_parts.push((delta2, vertical.clone()));
+ compound_parts.push((delta3, vertical));
+
+ let compound_shape = SharedShape::compound(compound_parts);
+
+ let num = 6;
+ let shift = (radx + 0.01) * 2.0;
+ let centerx = shift * num as f32 / 2.0 - 0.5;
+ let centery = shift / 2.0 + 4.0;
+
+ for i in 0usize..num {
+ for j in 0..num {
+ let x = i as f32 * shift - centerx;
+ let y = j as f32 * shift + centery;
+
+ // Build the rigid body.
+ let rigid_body = RigidBodyBuilder::new_dynamic()
+ .translation(x, y)
+ .linvel(100.0, -10.0)
+ .ccd_enabled(true)
+ .build();
+ let handle = bodies.insert(rigid_body);
+
+ // for part in &compound_parts {
+ // let collider = ColliderBuilder::new(part.1.clone())
+ // .position_wrt_parent(part.0)
+ // .build();
+ // colliders.insert(collider, handle, &mut bodies);
+ // }
+
+ let collider = ColliderBuilder::new(compound_shape.clone()).build();
+ // let collider = ColliderBuilder::cuboid(radx, rady).build();
+ colliders.insert(collider, handle, &mut bodies);
+ }
+ }
+
+ // Callback that will be executed on the main loop to handle proximities.
+ testbed.add_callback(move |_, mut graphics, physics, events, _| {
+ while let Ok(prox) = events.intersection_events.try_recv() {
+ let color = if prox.intersecting {
+ Point3::new(1.0, 1.0, 0.0)
+ } else {
+ Point3::new(0.5, 0.5, 1.0)
+ };
+
+ let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent();
+ let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent();
+ if let Some(graphics) = &mut graphics {
+ if parent_handle1 != ground_handle && prox.collider1 != sensor_handle {
+ graphics.set_body_color(parent_handle1, color);
+ }
+ if parent_handle2 != ground_handle && prox.collider2 != sensor_handle {
+ graphics.set_body_color(parent_handle2, color);
+ }
+ }
+ }
+ });
+
+ /*
+ * Set up the testbed.
+ */
+ testbed.set_world(bodies, colliders, joints);
+ testbed.look_at(Point2::new(0.0, 2.5), 20.0);
+}
+
+fn main() {
+ let testbed = Testbed::from_builders(0, vec![("Balls", init_world)]);
+ testbed.run()
+}
diff --git a/examples3d/Cargo.toml b/examples3d/Cargo.toml
index b27b97c..1f84857 100644
--- a/examples3d/Cargo.toml
+++ b/examples3d/Cargo.toml
@@ -3,6 +3,7 @@ name = "rapier-examples-3d"
version = "0.1.0"
authors = [ "Sébastien Crozet <developer@crozet.re>" ]
edition = "2018"
+default-run = "all_examples3"
[features]
parallel = [ "rapier3d/parallel", "rapier_testbed3d/parallel" ]
diff --git a/examples3d/all_examples3.rs b/examples3d/all_examples3.rs
index 724aa45..8122583 100644
--- a/examples3d/all_examples3.rs
+++ b/examples3d/all_examples3.rs
@@ -10,12 +10,14 @@ use inflector::Inflector;
use rapier_testbed3d::Testbed;
use std::cmp::Ordering;
+mod ccd3;
mod collision_groups3;
mod compound3;
mod convex_decomposition3;
mod convex_polyhedron3;
mod damping3;
mod debug_add_remove_collider3;
+mod debug_big_colliders3;
mod debug_boxes3;
mod debug_cylinder3;
mod debug_dynamic_collider_add3;
@@ -76,6 +78,7 @@ pub fn main() {
let mut builders: Vec<(_, fn(&mut Testbed))> = vec![
("Fountain", fountain3::init_world),
("Primitives", primitives3::init_world),
+ ("CCD", ccd3::init_world),
("Collision groups", collision_groups3::init_world),
("Compound", compound3::init_world),
("Convex decomposition", convex_decomposition3::init_world),
@@ -95,6 +98,7 @@ pub fn main() {
"(Debug) add/rm collider",
debug_add_remove_collider3::init_world,
),
+ ("(Debug) big colliders", debug_big_colliders3::init_world),
("(Debug) boxes", debug_boxes3::init_world),
(
"(Debug) dyn. coll. add",
diff --git a/examples3d/ccd3.rs b/examples3d/ccd3.rs
new file mode 100644
index 0000000..19381fd
--- /dev/null
+++ b/examples3d/ccd3.rs
@@ -0,0 +1,145 @@
+use na::{Point3, Vector3};
+use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
+use rapier3d::geometry::{ColliderBuilder, ColliderSet};
+use rapier_testbed3d::Testbed;
+
+fn create_wall(
+ testbed: &mut Testbed,
+ bodies: &mut RigidBodySet,
+ colliders: &mut ColliderSet,
+ offset: Vector3<f32>,
+ stack_height: usize,
+ half_extents: Vector3<f32>,
+) {
+ let shift = half_extents * 2.0;
+ for i in 0usize..stack_height {
+ for j in i..stack_height {
+ let fj = j as f32;
+ let fi = i as f32;
+ let x = offset.x;
+ let y = fi * shift.y + offset.y;
+ let z = (fi * shift.z / 2.0) + (fj - fi) * shift.z + offset.z
+ - stack_height as f32 * half_extents.z;
+
+ // Build the rigid body.
+ let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
+ let handle = bodies.insert(rigid_body);
+ let collider =
+ ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
+ colliders.insert(collider, handle, bodies);
+ testbed.set_body_color(handle, Point3::new(218. / 255., 201. / 255., 1.0));
+ }
+ }
+}
+
+pub fn init_world(testbed: &mut Testbed) {
+ /*
+ * World
+ */
+ let mut bodies = RigidBodySet::new();
+ let mut colliders = ColliderSet::new();
+ let joints = JointSet::new();
+
+ /*
+ * Ground
+ */
+ let ground_size = 50.0;
+ let ground_height = 0.1;
+
+ let rigid_body = RigidBodyBuilder::new_static()
+ .translation(0.0, -ground_height, 0.0)
+ .build();
+ let ground_handle = bodies.insert(rigid_body);
+ let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
+ colliders.insert(collider, ground_handle, &mut bodies);
+
+ /*
+ * Create the pyramids.
+ */
+ let num_z = 8;
+ let num_x = 5;
+ let shift_y = ground_height + 0.5;
+ let shift_z = (num_z as f32 + 2.0) * 2.0;
+
+ for i in 0..num_x {
+ let x = i as f32 * 6.0;
+ create_wall(
+ testbed,
+ &mut bodies,
+ &mut colliders,
+ Vector3::new(x, shift_y, 0.0),
+ num_z,
+ Vector3::new(0.5, 0.5, 1.0),
+ );
+
+ create_wall(
+ testbed,
+ &mut bodies,
+ &mut colliders,
+ Vector3::new(x, shift_y, shift_z),
+ num_z,
+ Vector3::new(0.5, 0.5, 1.0),
+ );
+ }
+
+ /*
+ * Create two very fast rigid-bodies.
+ * The first one has CCD enabled and a sensor collider attached to it.
+