From 1bef66fea941307a7305ddaebdb0abe3d0cb281f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crozet=20S=C3=A9bastien?= Date: Tue, 25 May 2021 11:00:13 +0200 Subject: [PATCH] Add prelude + use vectors for setting linvel/translation in builders --- CHANGELOG.md | 23 +++ benchmarks2d/balls2.rs | 14 +- benchmarks2d/boxes2.rs | 22 +-- benchmarks2d/capsules2.rs | 22 +-- benchmarks2d/convex_polygons2.rs | 24 +-- benchmarks2d/heightfield2.rs | 19 +- benchmarks2d/joint_ball2.rs | 14 +- benchmarks2d/joint_fixed2.rs | 18 +- benchmarks2d/joint_prismatic2.rs | 24 +-- benchmarks2d/pyramid2.rs | 14 +- benchmarks3d/balls3.rs | 12 +- benchmarks3d/boxes3.rs | 16 +- benchmarks3d/capsules3.rs | 16 +- benchmarks3d/ccd3.rs | 16 +- benchmarks3d/compound3.rs | 24 +-- benchmarks3d/convex_polyhedron3.rs | 18 +- benchmarks3d/heightfield3.rs | 19 +- benchmarks3d/joint_ball3.rs | 17 +- benchmarks3d/joint_fixed3.rs | 21 +- benchmarks3d/joint_prismatic3.rs | 31 ++- benchmarks3d/joint_revolute3.rs | 37 ++-- benchmarks3d/keva3.rs | 38 ++-- benchmarks3d/pyramid3.rs | 24 +-- benchmarks3d/stacks3.rs | 60 +++--- benchmarks3d/trimesh3.rs | 19 +- examples2d/add_remove2.rs | 10 +- examples2d/ccd2.rs | 52 ++--- examples2d/collision_groups2.rs | 33 ++-- examples2d/convex_polygons2.rs | 24 +-- examples2d/damping2.rs | 14 +- examples2d/debug_box_ball2.rs | 14 +- examples2d/heightfield2.rs | 19 +- examples2d/joints2.rs | 16 +- examples2d/locked_rotations2.rs | 18 +- examples2d/one_way_platforms2.rs | 39 ++-- examples2d/platform2.rs | 20 +- examples2d/polyline2.rs | 23 +-- examples2d/pyramid2.rs | 14 +- examples2d/restitution2.rs | 14 +- examples2d/sensor2.rs | 40 ++-- examples2d/trimesh2.rs | 22 +-- examples3d/ccd3.rs | 70 +++---- examples3d/collision_groups3.rs | 33 ++-- examples3d/compound3.rs | 32 +-- examples3d/convex_decomposition3.rs | 18 +- examples3d/convex_polyhedron3.rs | 18 +- examples3d/damping3.rs | 16 +- examples3d/debug_add_remove_collider3.rs | 22 +-- examples3d/debug_big_colliders3.rs | 14 +- examples3d/debug_boxes3.rs | 16 +- examples3d/debug_cylinder3.rs | 16 +- examples3d/debug_dynamic_collider_add3.rs | 28 ++- examples3d/debug_friction3.rs | 16 +- examples3d/debug_infinite_fall3.rs | 18 +- examples3d/debug_prismatic3.rs | 50 +++-- examples3d/debug_rollback3.rs | 22 +-- examples3d/debug_shape_modification3.rs | 28 +-- examples3d/debug_triangle3.rs | 20 +- examples3d/debug_trimesh3.rs | 32 ++- examples3d/domino3.rs | 20 +- examples3d/fountain3.rs | 14 +- examples3d/harness_capsules3.rs | 15 +- examples3d/heightfield3.rs | 23 +-- examples3d/joints3.rs | 143 +++++++------- examples3d/keva3.rs | 38 ++-- examples3d/locked_rotations3.rs | 22 +-- examples3d/one_way_platforms3.rs | 39 ++-- examples3d/platform3.rs | 20 +- examples3d/primitives3.rs | 16 +- examples3d/restitution3.rs | 14 +- examples3d/sensor3.rs | 39 ++-- examples3d/trimesh3.rs | 23 +-- src/data/coarena.rs | 8 + src/dynamics/integration_parameters.rs | 13 +- src/dynamics/joint/fixed_joint.rs | 10 +- src/dynamics/rigid_body.rs | 174 +++++++++++++--- .../fixed_position_constraint.rs | 34 ++-- .../fixed_velocity_constraint.rs | 12 +- .../fixed_velocity_constraint_wide.rs | 24 +-- src/geometry/collider.rs | 187 +++++++++++------- src/geometry/collider_components.rs | 10 +- src/geometry/collider_set.rs | 42 +++- src/geometry/contact_pair.rs | 16 +- src/geometry/interaction_groups.rs | 54 ++--- src/geometry/narrow_phase.rs | 108 +++++++--- src/lib.rs | 9 + src/pipeline/physics_hooks.rs | 47 +++-- src_testbed/box2d_backend.rs | 25 ++- src_testbed/graphics.rs | 65 +++--- src_testbed/nphysics_backend.rs | 36 ++-- src_testbed/objects/node.rs | 14 +- src_testbed/physx_backend.rs | 45 +++-- src_testbed/testbed.rs | 25 +-- 93 files changed, 1528 insertions(+), 1259 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d3dcf9..f7c1d3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,31 @@ ## v0.9.0 +The user-guide has been fully rewritten and is now exhaustive! Check it out on [rapier.rs](https://rapier.rs/) + +### Added +- A prelude has been added in order to simplify the most common imports. For example: `use rapier3d::prelude::*` ### Modified - Renamed `BodyStatus` to `RigidBodyType`. +FIXME: +- `RigidBodyBuilder::translation` now takes a vector instead of individual components. +- `RigidBodyBuilder::linvel` now takes a vector instead of individual components. +- `Colliderbuilder::translation` now takes a vector instead of individual components. +- The way `PhysicsHooks` are enabled changed. Now, a physics hooks is executed if any of the two + colliders involved in the contact/intersection pair contains the related `PhysicsHooksFlag`. + These flags are configured on each collider with `ColliderBuilder::active_hooks`. As a result, + there is no `PhysicsHooks::active_hooks` method any more. +- Before, sensor colliders had a default density set to 0.0 whereas non-sensor colliders had a + default density of 1.0. This has been unified by setting the default density to 1.0 for both + sensor and non-sensor colliders. +- Colliders are no longer required to be attached to a rigid-body. Therefore, `ColliderSet::insert` + only takes the collider as argument now. In order to attach the collider to a rigid-body, + (i.e., the old behavior of `ColliderSet::insert`), use `ColliderSet::insert_with_parent`. +- The field `ContactPair::pair` (which contained two collider handles) has been replaced by two + fields: `ContactPair::collider1` and `ContactPair::collider2`. +- The fields `FixedJoint::local_anchor1` and `FixedJoint::local_anchor2` have been renamed to + `FixedJoint::local_frame1` and `FixedJoint::local_frame2`. + ## v0.8.0 ### Modified - Switch to nalgebra 0.26. diff --git a/benchmarks2d/balls2.rs b/benchmarks2d/balls2.rs index 8fa9775..ec55f24 100644 --- a/benchmarks2d/balls2.rs +++ b/benchmarks2d/balls2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -22,7 +20,7 @@ pub fn init_world(testbed: &mut Testbed) { let co = ColliderDesc::new(ground_shape) .translation(-Vector2::y()) .build(BodyPartHandle(ground_handle, 0)); - colliders.insert(co); + colliders.insert_with_parent(co); */ /* @@ -48,10 +46,12 @@ pub fn init_world(testbed: &mut Testbed) { }; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new(status).translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new(status) + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -59,5 +59,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 2.5), 5.0); + testbed.look_at(point![0.0, 2.5], 5.0); } diff --git a/benchmarks2d/boxes2.rs b/benchmarks2d/boxes2.rs index e524386..2e4c5e4 100644 --- a/benchmarks2d/boxes2.rs +++ b/benchmarks2d/boxes2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -19,23 +17,23 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(ground_size, ground_size * 2.0) + .translation(vector![ground_size, ground_size * 2.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(-ground_size, ground_size * 2.0) + .translation(vector![-ground_size, ground_size * 2.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -53,10 +51,12 @@ pub fn init_world(testbed: &mut Testbed) { let y = j as f32 * shift + centery + 2.0; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -64,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 50.0), 10.0); + testbed.look_at(point![0.0, 50.0], 10.0); } diff --git a/benchmarks2d/capsules2.rs b/benchmarks2d/capsules2.rs index 89ddfde..e75afe4 100644 --- a/benchmarks2d/capsules2.rs +++ b/benchmarks2d/capsules2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -19,23 +17,23 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(ground_size, ground_size * 4.0) + .translation(vector![ground_size, ground_size * 4.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size * 4.0, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(-ground_size, ground_size * 4.0) + .translation(vector![-ground_size, ground_size * 4.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size * 4.0, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -55,10 +53,12 @@ pub fn init_world(testbed: &mut Testbed) { let y = j as f32 * shifty + centery + 3.0; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::capsule_y(rad * 1.5, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -66,5 +66,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 50.0), 10.0); + testbed.look_at(point![0.0, 50.0], 10.0); } diff --git a/benchmarks2d/convex_polygons2.rs b/benchmarks2d/convex_polygons2.rs index 99f5a14..6c9792e 100644 --- a/benchmarks2d/convex_polygons2.rs +++ b/benchmarks2d/convex_polygons2.rs @@ -1,8 +1,6 @@ -use na::Point2; use rand::distributions::{Distribution, Standard}; use rand::{rngs::StdRng, SeedableRng}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -21,23 +19,23 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(ground_size, ground_size * 2.0) + .translation(vector![ground_size, ground_size * 2.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(-ground_size, ground_size * 2.0) + .translation(vector![-ground_size, ground_size * 2.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the convex polygons @@ -58,18 +56,20 @@ pub fn init_world(testbed: &mut Testbed) { let x = i as f32 * shift - centerx; let y = j as f32 * shift * 2.0 + centery + 2.0; - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let mut points = Vec::new(); for _ in 0..10 { - let pt: Point2 = distribution.sample(&mut rng); + let pt: Point = distribution.sample(&mut rng); points.push(pt * scale); } let collider = ColliderBuilder::convex_hull(&points).unwrap().build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -77,5 +77,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 50.0), 10.0); + testbed.look_at(point![0.0, 50.0], 10.0); } diff --git a/benchmarks2d/heightfield2.rs b/benchmarks2d/heightfield2.rs index 1a30849..a07eb6e 100644 --- a/benchmarks2d/heightfield2.rs +++ b/benchmarks2d/heightfield2.rs @@ -1,6 +1,5 @@ -use na::{DVector, Point2, Vector2}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use na::DVector; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Ground */ - let ground_size = Vector2::new(50.0, 1.0); + let ground_size = Vector::new(50.0, 1.0); let nsubdivs = 2000; let heights = DVector::from_fn(nsubdivs + 1, |i, _| { @@ -28,7 +27,7 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::heightfield(heights, ground_size).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -46,15 +45,17 @@ pub fn init_world(testbed: &mut Testbed) { let y = j as f32 * shift + centery + 3.0; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); if j % 2 == 0 { let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } else { let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -63,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 50.0), 10.0); + testbed.look_at(point![0.0, 50.0], 10.0); } diff --git a/benchmarks2d/joint_ball2.rs b/benchmarks2d/joint_ball2.rs index 1ad2d39..aadf91e 100644 --- a/benchmarks2d/joint_ball2.rs +++ b/benchmarks2d/joint_ball2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{BallJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -34,16 +32,16 @@ pub fn init_world(testbed: &mut Testbed) { }; let rigid_body = RigidBodyBuilder::new(status) - .translation(fk * shift, -fi * shift) + .translation(vector![fk * shift, -fi * shift]) .build(); let child_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, child_handle, &mut bodies); + colliders.insert_with_parent(collider, child_handle, &mut bodies); // Vertical joint. if i > 0 { let parent_handle = *body_handles.last().unwrap(); - let joint = BallJoint::new(Point2::origin(), Point2::new(0.0, shift)); + let joint = BallJoint::new(Point::origin(), point![0.0, shift]); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -51,7 +49,7 @@ pub fn init_world(testbed: &mut Testbed) { if k > 0 { let parent_index = body_handles.len() - numi; let parent_handle = body_handles[parent_index]; - let joint = BallJoint::new(Point2::origin(), Point2::new(-shift, 0.0)); + let joint = BallJoint::new(Point::origin(), point![-shift, 0.0]); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -63,5 +61,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(numk as f32 * rad, numi as f32 * -rad), 5.0); + testbed.look_at(point![numk as f32 * rad, numi as f32 * -rad], 5.0); } diff --git a/benchmarks2d/joint_fixed2.rs b/benchmarks2d/joint_fixed2.rs index e42ad99..baaa250 100644 --- a/benchmarks2d/joint_fixed2.rs +++ b/benchmarks2d/joint_fixed2.rs @@ -1,6 +1,4 @@ -use na::{Isometry2, Point2}; -use rapier2d::dynamics::{FixedJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -39,18 +37,18 @@ pub fn init_world(testbed: &mut Testbed) { }; let rigid_body = RigidBodyBuilder::new(status) - .translation(x + fk * shift, y - fi * shift) + .translation(vector![x + fk * shift, y - fi * shift]) .build(); let child_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, child_handle, &mut bodies); + colliders.insert_with_parent(collider, child_handle, &mut bodies); // Vertical joint. if i > 0 { let parent_handle = *body_handles.last().unwrap(); let joint = FixedJoint::new( - Isometry2::identity(), - Isometry2::translation(0.0, shift), + Isometry::identity(), + Isometry::translation(0.0, shift), ); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -60,8 +58,8 @@ pub fn init_world(testbed: &mut Testbed) { let parent_index = body_handles.len() - num; let parent_handle = body_handles[parent_index]; let joint = FixedJoint::new( - Isometry2::identity(), - Isometry2::translation(-shift, 0.0), + Isometry::identity(), + Isometry::translation(-shift, 0.0), ); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -76,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(50.0, 50.0), 5.0); + testbed.look_at(point![50.0, 50.0], 5.0); } diff --git a/benchmarks2d/joint_prismatic2.rs b/benchmarks2d/joint_prismatic2.rs index e393542..0cbf859 100644 --- a/benchmarks2d/joint_prismatic2.rs +++ b/benchmarks2d/joint_prismatic2.rs @@ -1,6 +1,4 @@ -use na::{Point2, Unit, Vector2}; -use rapier2d::dynamics::{JointSet, PrismaticJoint, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -25,27 +23,31 @@ pub fn init_world(testbed: &mut Testbed) { for j in 0..50 { let x = j as f32 * shift * 4.0; - let ground = RigidBodyBuilder::new_static().translation(x, y).build(); + let ground = RigidBodyBuilder::new_static() + .translation(vector![x, y]) + .build(); let mut curr_parent = bodies.insert(ground); let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, curr_parent, &mut bodies); + colliders.insert_with_parent(collider, curr_parent, &mut bodies); for i in 0..num { let y = y - (i + 1) as f32 * shift; let density = 1.0; - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let curr_child = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad).density(density).build(); - colliders.insert(collider, curr_child, &mut bodies); + colliders.insert_with_parent(collider, curr_child, &mut bodies); let axis = if i % 2 == 0 { - Unit::new_normalize(Vector2::new(1.0, 1.0)) + UnitVector::new_normalize(vector![1.0, 1.0]) } else { - Unit::new_normalize(Vector2::new(-1.0, 1.0)) + UnitVector::new_normalize(vector![-1.0, 1.0]) }; let mut prism = - PrismaticJoint::new(Point2::origin(), axis, Point2::new(0.0, shift), axis); + PrismaticJoint::new(Point::origin(), axis, point![0.0, shift], axis); prism.limits_enabled = true; prism.limits[0] = -1.5; prism.limits[1] = 1.5; @@ -60,5 +62,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(80.0, 80.0), 15.0); + testbed.look_at(point![80.0, 80.0], 15.0); } diff --git a/benchmarks2d/pyramid2.rs b/benchmarks2d/pyramid2.rs index c3eb6ad..a557ff4 100644 --- a/benchmarks2d/pyramid2.rs +++ b/benchmarks2d/pyramid2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -20,7 +18,7 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let ground_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Create the cubes @@ -40,10 +38,12 @@ pub fn init_world(testbed: &mut Testbed) { let y = fi * shift + centery; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -51,5 +51,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 2.5), 5.0); + testbed.look_at(point![0.0, 2.5], 5.0); } diff --git a/benchmarks3d/balls3.rs b/benchmarks3d/balls3.rs index 492aeac..3f0bf36 100644 --- a/benchmarks3d/balls3.rs +++ b/benchmarks3d/balls3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -37,10 +35,12 @@ pub fn init_world(testbed: &mut Testbed) { let density = 0.477; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new(status).translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new(status) + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).density(density).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -49,5 +49,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/benchmarks3d/boxes3.rs b/benchmarks3d/boxes3.rs index 86213af..9c7ed81 100644 --- a/benchmarks3d/boxes3.rs +++ b/benchmarks3d/boxes3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -45,10 +43,12 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shift - centerz + offset; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -59,5 +59,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/benchmarks3d/capsules3.rs b/benchmarks3d/capsules3.rs index edd6d57..8565503 100644 --- a/benchmarks3d/capsules3.rs +++ b/benchmarks3d/capsules3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -46,10 +44,12 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shift - centerz + offset; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::capsule_y(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -60,5 +60,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/benchmarks3d/ccd3.rs b/benchmarks3d/ccd3.rs index a496648..987aba6 100644 --- a/benchmarks3d/ccd3.rs +++ b/benchmarks3d/ccd3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -49,8 +47,8 @@ pub fn init_world(testbed: &mut Testbed) { // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(x, y, z) - .linvel(0.0, -1000.0, 0.0) + .translation(vector![x, y, z]) + .linvel(vector![0.0, -1000.0, 0.0]) .ccd_enabled(true) .build(); let handle = bodies.insert(rigid_body); @@ -65,7 +63,7 @@ pub fn init_world(testbed: &mut Testbed) { _ => ColliderBuilder::capsule_y(rad, rad), }; - colliders.insert(collider.build(), handle, &mut bodies); + colliders.insert_with_parent(collider.build(), handle, &mut bodies); } } @@ -76,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/benchmarks3d/compound3.rs b/benchmarks3d/compound3.rs index 3f82ca0..a914ce9 100644 --- a/benchmarks3d/compound3.rs +++ b/benchmarks3d/compound3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -45,18 +43,20 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shift * 2.0 - centerz + offset; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider1 = ColliderBuilder::cuboid(rad * 10.0, rad, rad).build(); let collider2 = ColliderBuilder::cuboid(rad, rad * 10.0, rad) - .translation(rad * 10.0, rad * 10.0, 0.0) + .translation(vector![rad * 10.0, rad * 10.0, 0.0]) .build(); let collider3 = ColliderBuilder::cuboid(rad, rad * 10.0, rad) - .translation(-rad * 10.0, rad * 10.0, 0.0) + .translation(vector![-rad * 10.0, rad * 10.0, 0.0]) .build(); - colliders.insert(collider1, handle, &mut bodies); - colliders.insert(collider2, handle, &mut bodies); - colliders.insert(collider3, handle, &mut bodies); + colliders.insert_with_parent(collider1, handle, &mut bodies); + colliders.insert_with_parent(collider2, handle, &mut bodies); + colliders.insert_with_parent(collider3, handle, &mut bodies); } } @@ -67,5 +67,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/benchmarks3d/convex_polyhedron3.rs b/benchmarks3d/convex_polyhedron3.rs index 0e14782..7065cd5 100644 --- a/benchmarks3d/convex_polyhedron3.rs +++ b/benchmarks3d/convex_polyhedron3.rs @@ -1,8 +1,6 @@ -use na::Point3; use rand::distributions::{Distribution, Standard}; use rand::{rngs::StdRng, SeedableRng}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -20,11 +18,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -53,17 +51,19 @@ pub fn init_world(testbed: &mut Testbed) { let mut points = Vec::new(); for _ in 0..10 { - let pt: Point3 = distribution.sample(&mut rng); + let pt: Point = distribution.sample(&mut rng); points.push(pt * scale); } // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::round_convex_hull(&points, border_rad) .unwrap() .build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -74,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/benchmarks3d/heightfield3.rs b/benchmarks3d/heightfield3.rs index 062e7c5..3ddc0ec 100644 --- a/benchmarks3d/heightfield3.rs +++ b/benchmarks3d/heightfield3.rs @@ -1,6 +1,5 @@ -use na::{ComplexField, DMatrix, Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use na::ComplexField; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Ground */ - let ground_size = Vector3::new(200.0, 1.0, 200.0); + let ground_size = vector![200.0, 1.0, 200.0]; let nsubdivs = 20; let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| { @@ -34,7 +33,7 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::heightfield(heights, ground_size).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -55,15 +54,17 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shift - centerz; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); if j % 2 == 0 { let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } else { let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -73,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/benchmarks3d/joint_ball3.rs b/benchmarks3d/joint_ball3.rs index e7b3e3d..5e3eb10 100644 --- a/benchmarks3d/joint_ball3.rs +++ b/benchmarks3d/joint_ball3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{BallJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -29,16 +27,16 @@ pub fn init_world(testbed: &mut Testbed) { }; let rigid_body = RigidBodyBuilder::new(status) - .translation(fk * shift, 0.0, fi * shift) + .translation(vector![fk * shift, 0.0, fi * shift]) .build(); let child_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, child_handle, &mut bodies); + colliders.insert_with_parent(collider, child_handle, &mut bodies); // Vertical joint. if i > 0 { let parent_handle = *body_handles.last().unwrap(); - let joint = BallJoint::new(Point3::origin(), Point3::new(0.0, 0.0, -shift)); + let joint = BallJoint::new(Point::origin(), point![0.0, 0.0, -shift]); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -46,7 +44,7 @@ pub fn init_world(testbed: &mut Testbed) { if k > 0 { let parent_index = body_handles.len() - num; let parent_handle = body_handles[parent_index]; - let joint = BallJoint::new(Point3::origin(), Point3::new(-shift, 0.0, 0.0)); + let joint = BallJoint::new(Point::origin(), point![-shift, 0.0, 0.0]); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -58,8 +56,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at( - Point3::new(-110.0, -46.0, 170.0), - Point3::new(54.0, -38.0, 29.0), - ); + testbed.look_at(point![-110.0, -46.0, 170.0], point![54.0, -38.0, 29.0]); } diff --git a/benchmarks3d/joint_fixed3.rs b/benchmarks3d/joint_fixed3.rs index 0475258..5647dde 100644 --- a/benchmarks3d/joint_fixed3.rs +++ b/benchmarks3d/joint_fixed3.rs @@ -1,6 +1,4 @@ -use na::{Isometry3, Point3}; -use rapier3d::dynamics::{FixedJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -42,18 +40,18 @@ pub fn init_world(testbed: &mut Testbed) { }; let rigid_body = RigidBodyBuilder::new(status) - .translation(x + fk * shift, y, z + fi * shift) + .translation(vector![x + fk * shift, y, z + fi * shift]) .build(); let child_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, child_handle, &mut bodies); + colliders.insert_with_parent(collider, child_handle, &mut bodies); // Vertical joint. if i > 0 { let parent_handle = *body_handles.last().unwrap(); let joint = FixedJoint::new( - Isometry3::identity(), - Isometry3::translation(0.0, 0.0, -shift), + Isometry::identity(), + Isometry::translation(0.0, 0.0, -shift), ); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -63,8 +61,8 @@ pub fn init_world(testbed: &mut Testbed) { let parent_index = body_handles.len() - num; let parent_handle = body_handles[parent_index]; let joint = FixedJoint::new( - Isometry3::identity(), - Isometry3::translation(-shift, 0.0, 0.0), + Isometry::identity(), + Isometry::translation(-shift, 0.0, 0.0), ); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -80,8 +78,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at( - Point3::new(-38.0, 14.0, 108.0), - Point3::new(46.0, 12.0, 23.0), - ); + testbed.look_at(point![-38.0, 14.0, 108.0], point![46.0, 12.0, 23.0]); } diff --git a/benchmarks3d/joint_prismatic3.rs b/benchmarks3d/joint_prismatic3.rs index afc18fb..b310b14 100644 --- a/benchmarks3d/joint_prismatic3.rs +++ b/benchmarks3d/joint_prismatic3.rs @@ -1,6 +1,4 @@ -use na::{Point3, Unit, Vector3}; -use rapier3d::dynamics::{JointSet, PrismaticJoint, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -24,33 +22,37 @@ pub fn init_world(testbed: &mut Testbed) { for j in 0..50 { let x = j as f32 * shift * 4.0; - let ground = RigidBodyBuilder::new_static().translation(x, y, z).build(); + let ground = RigidBodyBuilder::new_static() + .translation(vector![x, y, z]) + .build(); let mut curr_parent = bodies.insert(ground); let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, curr_parent, &mut bodies); + colliders.insert_with_parent(collider, curr_parent, &mut bodies); for i in 0..num { let z = z + (i + 1) as f32 * shift; let density = 1.0; - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let curr_child = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad, rad) .density(density) .build(); - colliders.insert(collider, curr_child, &mut bodies); + colliders.insert_with_parent(collider, curr_child, &mut bodies); let axis = if i % 2 == 0 { - Unit::new_normalize(Vector3::new(1.0, 1.0, 0.0)) + UnitVector::new_normalize(vector![1.0, 1.0, 0.0]) } else { - Unit::new_normalize(Vector3::new(-1.0, 1.0, 0.0)) + UnitVector::new_normalize(vector![-1.0, 1.0, 0.0]) }; - let z = Vector3::z(); + let z = Vector::z(); let mut prism = PrismaticJoint::new( - Point3::origin(), + Point::origin(), axis, z, - Point3::new(0.0, 0.0, -shift), + point![0.0, 0.0, -shift], axis, z, ); @@ -69,8 +71,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at( - Point3::new(262.0, 63.0, 124.0), - Point3::new(101.0, 4.0, -3.0), - ); + testbed.look_at(point![262.0, 63.0, 124.0], point![101.0, 4.0, -3.0]); } diff --git a/benchmarks3d/joint_revolute3.rs b/benchmarks3d/joint_revolute3.rs index 0c647a6..7c0f6cb 100644 --- a/benchmarks3d/joint_revolute3.rs +++ b/benchmarks3d/joint_revolute3.rs @@ -1,6 +1,4 @@ -use na::{Isometry3, Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RevoluteJoint, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -22,20 +20,20 @@ pub fn init_world(testbed: &mut Testbed) { let x = j as f32 * shift * 4.0; let ground = RigidBodyBuilder::new_static() - .translation(x, y, 0.0) + .translation(vector![x, y, 0.0]) .build(); let mut curr_parent = bodies.insert(ground); let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, curr_parent, &mut bodies); + colliders.insert_with_parent(collider, curr_parent, &mut bodies); for i in 0..num { // Create four bodies. let z = i as f32 * shift * 2.0 + shift; let positions = [ - Isometry3::translation(x, y, z), - Isometry3::translation(x + shift, y, z), - Isometry3::translation(x + shift, y, z + shift), - Isometry3::translation(x, y, z + shift), + Isometry::translation(x, y, z), + Isometry::translation(x + shift, y, z), + Isometry::translation(x + shift, y, z + shift), + Isometry::translation(x, y, z + shift), ]; let mut handles = [curr_parent; 4]; @@ -48,19 +46,19 @@ pub fn init_world(testbed: &mut Testbed) { let collider = ColliderBuilder::cuboid(rad, rad, rad) .density(density) .build(); - colliders.insert(collider, handles[k], &mut bodies); + colliders.insert_with_parent(collider, handles[k], &mut bodies); } // Setup four joints. - let o = Point3::origin(); - let x = Vector3::x_axis(); - let z = Vector3::z_axis(); + let o = Point::origin(); + let x = Vector::x_axis(); + let z = Vector::z_axis(); let revs = [ - RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z), - RevoluteJoint::new(o, x, Point3::new(-shift, 0.0, 0.0), x), - RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z), - RevoluteJoint::new(o, x, Point3::new(shift, 0.0, 0.0), x), + RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z), + RevoluteJoint::new(o, x, point![-shift, 0.0, 0.0], x), + RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z), + RevoluteJoint::new(o, x, point![shift, 0.0, 0.0], x), ]; joints.insert(&mut bodies, curr_parent, handles[0], revs[0]); @@ -77,8 +75,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at( - Point3::new(478.0, 83.0, 228.0), - Point3::new(134.0, 83.0, -116.0), - ); + testbed.look_at(point![478.0, 83.0, 228.0], point![134.0, 83.0, -116.0]); } diff --git a/benchmarks3d/keva3.rs b/benchmarks3d/keva3.rs index 9e6807a..38a0432 100644 --- a/benchmarks3d/keva3.rs +++ b/benchmarks3d/keva3.rs @@ -1,14 +1,12 @@ -use na::{Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn build_block( testbed: &mut Testbed, bodies: &mut RigidBodySet, colliders: &mut ColliderSet, - half_extents: Vector3, - shift: Vector3, + half_extents: Vector, + shift: Vector, mut numx: usize, numy: usize, mut numz: usize, @@ -17,8 +15,8 @@ pub fn build_block( let block_width = 2.0 * half_extents.z * numx as f32; let block_height = 2.0 * half_extents.y * numy as f32; let spacing = (half_extents.z * numx as f32 - half_extents.x) / (numz as f32 - 1.0); - let mut color0 = Point3::new(0.7, 0.5, 0.9); - let mut color1 = Point3::new(0.6, 1.0, 0.6); + let mut color0 = [0.7, 0.5, 0.9]; + let mut color1 = [0.6, 1.0, 0.6]; for i in 0..numy { std::mem::swap(&mut numx, &mut numz); @@ -41,15 +39,15 @@ pub fn build_block( // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation( + .translation(vector![ x + dim.x + shift.x, y + dim.y + shift.y, - z + dim.z + shift.z, - ) + z + dim.z + shift.z + ]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build(); - colliders.insert(collider, handle, bodies); + colliders.insert_with_parent(collider, handle, bodies); testbed.set_initial_body_color(handle, color0); std::mem::swap(&mut color0, &mut color1); @@ -64,15 +62,15 @@ pub fn build_block( for j in 0..(block_width / (dim.z as f32 * 2.0)) as usize { // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation( + .translation(vector![ i as f32 * dim.x * 2.0 + dim.x + shift.x, dim.y + shift.y + block_height, - j as f32 * dim.z * 2.0 + dim.z + shift.z, - ) + j as f32 * dim.z * 2.0 + dim.z + shift.z + ]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build(); - colliders.insert(collider, handle, bodies); + colliders.insert_with_parent(collider, handle, bodies); testbed.set_initial_body_color(handle, color0); std::mem::swap(&mut color0, &mut color1); } @@ -94,16 +92,16 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes */ - let half_extents = Vector3::new(0.02, 0.1, 0.4) / 2.0 * 10.0; + let half_extents = vector![0.02, 0.1, 0.4] / 2.0 * 10.0; let mut block_height = 0.0; // These should only be set to odd values otherwise // the blocks won't align in the nicest way. @@ -120,7 +118,7 @@ pub fn init_world(testbed: &mut Testbed) { &mut bodies, &mut colliders, half_extents, - Vector3::new(-block_width / 2.0, block_height, -block_width / 2.0), + vector![-block_width / 2.0, block_height, -block_width / 2.0], numx, numy, numz, @@ -135,5 +133,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/benchmarks3d/pyramid3.rs b/benchmarks3d/pyramid3.rs index 3b31eac..655ecb7 100644 --- a/benchmarks3d/pyramid3.rs +++ b/benchmarks3d/pyramid3.rs @@ -1,14 +1,12 @@ -use na::{Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; fn create_pyramid( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, - offset: Vector3, + offset: Vector, stack_height: usize, - half_extents: Vector3, + half_extents: Vector, ) { let shift = half_extents * 2.5; for i in 0usize..stack_height { @@ -24,12 +22,14 @@ fn create_pyramid( - stack_height as f32 * half_extents.z; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let rigid_body_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build(); - colliders.insert(collider, rigid_body_handle, bodies); + colliders.insert_with_parent(collider, rigid_body_handle, bodies); } } } @@ -50,22 +50,22 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Create the cubes */ let cube_size = 1.0; - let hext = Vector3::repeat(cube_size); + let hext = Vector::repeat(cube_size); let bottomy = cube_size; create_pyramid( &mut bodies, &mut colliders, - Vector3::new(0.0, bottomy, 0.0), + vector![0.0, bottomy, 0.0], 24, hext, ); @@ -74,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/benchmarks3d/stacks3.rs b/benchmarks3d/stacks3.rs index 31dff0a..39386ea 100644 --- a/benchmarks3d/stacks3.rs +++ b/benchmarks3d/stacks3.rs @@ -1,15 +1,13 @@ -use na::{Point3, Translation3, UnitQuaternion, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; fn create_tower_circle( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, - offset: Vector3, + offset: Vector, stack_height: usize, nsubdivs: usize, - half_extents: Vector3, + half_extents: Vector, ) { let ang_step = std::f32::consts::PI * 2.0 / nsubdivs as f32; let radius = 1.3 * nsubdivs as f32 * half_extents.x / std::f32::consts::PI; @@ -20,16 +18,16 @@ fn create_tower_circle( let fj = j as f32; let fi = i as f32; let y = fi * shift.y; - let pos = Translation3::from(offset) - * UnitQuaternion::new(Vector3::y() * (fi / 2.0 + fj) * ang_step) - * Translation3::new(0.0, y, radius); + let pos = Translation::from(offset) + * Rotation::new(Vector::y() * (fi / 2.0 + fj) * ang_step) + * Translation::new(0.0, y, radius); // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic().position(pos).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); + colliders.insert_with_parent(collider, handle, bodies); } } } @@ -37,9 +35,9 @@ fn create_tower_circle( fn create_wall( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, - offset: Vector3, + offset: Vector, stack_height: usize, - half_extents: Vector3, + half_extents: Vector, ) { let shift = half_extents * 2.0; for i in 0usize..stack_height { @@ -52,11 +50,13 @@ fn create_wall( - stack_height as f32 * half_extents.z; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![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); + colliders.insert_with_parent(collider, handle, bodies); } } } @@ -64,9 +64,9 @@ fn create_wall( fn create_pyramid( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, - offset: Vector3, + offset: Vector, stack_height: usize, - half_extents: Vector3, + half_extents: Vector, ) { let shift = half_extents * 2.0; @@ -83,11 +83,13 @@ fn create_pyramid( - stack_height as f32 * half_extents.z; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![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); + colliders.insert_with_parent(collider, handle, bodies); } } } @@ -108,71 +110,71 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes */ let cube_size = 1.0; - let hext = Vector3::repeat(cube_size); + let hext = Vector::repeat(cube_size); let bottomy = cube_size * 50.0; create_pyramid( &mut bodies, &mut colliders, - Vector3::new(-110.0, bottomy, 0.0), + vector![-110.0, bottomy, 0.0], 12, hext, ); create_pyramid( &mut bodies, &mut colliders, - Vector3::new(-80.0, bottomy, 0.0), + vector![-80.0, bottomy, 0.0], 12, hext, ); create_pyramid( &mut bodies, &mut colliders, - Vector3::new(-50.0, bottomy, 0.0), + vector![-50.0, bottomy, 0.0], 12, hext, ); create_pyramid( &mut bodies, &mut colliders, - Vector3::new(-20.0, bottomy, 0.0), + vector![-20.0, bottomy, 0.0], 12, hext, ); create_wall( &mut bodies, &mut colliders, - Vector3::new(-2.0, bottomy, 0.0), + vector![-2.0, bottomy, 0.0], 12, hext, ); create_wall( &mut bodies, &mut colliders, - Vector3::new(4.0, bottomy, 0.0), + vector![4.0, bottomy, 0.0], 12, hext, ); create_wall( &mut bodies, &mut colliders, - Vector3::new(10.0, bottomy, 0.0), + vector![10.0, bottomy, 0.0], 12, hext, ); create_tower_circle( &mut bodies, &mut colliders, - Vector3::new(25.0, bottomy, 0.0), + vector![25.0, bottomy, 0.0], 8, 24, hext, @@ -182,5 +184,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/benchmarks3d/trimesh3.rs b/benchmarks3d/trimesh3.rs index 0501d6f..fe8f377 100644 --- a/benchmarks3d/trimesh3.rs +++ b/benchmarks3d/trimesh3.rs @@ -1,6 +1,5 @@ -use na::{ComplexField, DMatrix, Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet, HeightField}; +use na::ComplexField; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Ground */ - let ground_size = Vector3::new(200.0, 1.0, 200.0); + let ground_size = vector![200.0, 1.0, 200.0]; let nsubdivs = 20; let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| { @@ -39,7 +38,7 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::trimesh(vertices, indices).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -60,15 +59,17 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shift - centerz; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); if j % 2 == 0 { let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } else { let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -78,5 +79,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/examples2d/add_remove2.rs b/examples2d/add_remove2.rs index 9f9f65a..056e63e 100644 --- a/examples2d/add_remove2.rs +++ b/examples2d/add_remove2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -12,13 +10,13 @@ pub fn init_world(testbed: &mut Testbed) { // Callback that will be executed on the main loop to handle proximities. testbed.add_callback(move |mut graphics, physics, _, _| { let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 10.0) + .translation(vector![0.0, 10.0]) .build(); let handle = physics.bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad).build(); physics .colliders - .insert(collider, handle, &mut physics.bodies); + .insert_with_parent(collider, handle, &mut physics.bodies); if let Some(graphics) = &mut graphics { graphics.add_body(handle, &physics.bodies, &physics.colliders); @@ -48,5 +46,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 0.0), 20.0); + testbed.look_at(point![0.0, 0.0], 20.0); } diff --git a/examples2d/ccd2.rs b/examples2d/ccd2.rs index 18a6bfe..1200f29 100644 --- a/examples2d/ccd2.rs +++ b/examples2d/ccd2.rs @@ -1,6 +1,4 @@ -use na::{Isometry2, Point2, Point3}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet, SharedShape}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -21,23 +19,23 @@ pub fn init_world(testbed: &mut Testbed) { let ground_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); let collider = ColliderBuilder::cuboid(ground_thickness, ground_size) - .translation(-3.0, 0.0) + .translation(vector![-3.0, 0.0]) .build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); let collider = ColliderBuilder::cuboid(ground_thickness, ground_size) - .translation(6.0, 0.0) + .translation(vector![6.0, 0.0]) .build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); let collider = ColliderBuilder::cuboid(ground_thickness, ground_size) - .translation(2.5, 0.0) + .translation(vector![2.5, 0.0]) .sensor(true) .build(); - let sensor_handle = colliders.insert(collider, ground_handle, &mut bodies); + let sensor_handle = colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Create the shapes @@ -45,9 +43,9 @@ pub fn init_world(testbed: &mut Testbed) { 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 delta1 = Isometry::translation(0.0, radx - rady); + let delta2 = Isometry::translation(-radx + rady, 0.0); + let delta3 = Isometry::translation(radx - rady, 0.0); let mut compound_parts = Vec::new(); let vertical = SharedShape::cuboid(rady, radx); @@ -70,8 +68,8 @@ pub fn init_world(testbed: &mut Testbed) { // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(x, y) - .linvel(100.0, -10.0) + .translation(vector![x, y]) + .linvel(vector![100.0, -10.0]) .ccd_enabled(true) .build(); let handle = bodies.insert(rigid_body); @@ -80,12 +78,12 @@ pub fn init_world(testbed: &mut Testbed) { // let collider = ColliderBuilder::new(part.1.clone()) // .position_wrt_parent(part.0) // .build(); - // colliders.insert(collider, handle, &mut bodies); + // colliders.insert_with_parent(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); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -93,13 +91,23 @@ pub fn init_world(testbed: &mut Testbed) { 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) + [1.0, 1.0, 0.0] } else { - Point3::new(0.5, 0.5, 1.0) + [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(); + let parent_handle1 = physics + .colliders + .get(prox.collider1) + .unwrap() + .parent() + .unwrap(); + let parent_handle2 = physics + .colliders + .get(prox.collider2) + .unwrap() + .parent() + .unwrap(); if let Some(graphics) = &mut graphics { if parent_handle1 != ground_handle && prox.collider1 != sensor_handle { graphics.set_body_color(parent_handle1, color); @@ -115,5 +123,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 2.5), 20.0); + testbed.look_at(point![0.0, 2.5], 20.0); } diff --git a/examples2d/collision_groups2.rs b/examples2d/collision_groups2.rs index 08b73fb..3f2a786 100644 --- a/examples2d/collision_groups2.rs +++ b/examples2d/collision_groups2.rs @@ -1,6 +1,4 @@ -use na::{Point2, Point3}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet, InteractionGroups}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height) + .translation(vector![0.0, -ground_height]) .build(); let floor_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height).build(); - colliders.insert(collider, floor_handle, &mut bodies); + colliders.insert_with_parent(collider, floor_handle, &mut bodies); /* * Setup groups @@ -34,23 +32,24 @@ pub fn init_world(testbed: &mut Testbed) { * A green floor that will collide with the GREEN group only. */ let green_floor = ColliderBuilder::cuboid(1.0, 0.1) - .translation(0.0, 1.0) + .translation(vector![0.0, 1.0]) .collision_groups(GREEN_GROUP) .build(); - let green_collider_handle = colliders.insert(green_floor, floor_handle, &mut bodies); + let green_collider_handle = + colliders.insert_with_parent(green_floor, floor_handle, &mut bodies); - testbed.set_initial_collider_color(green_collider_handle, Point3::new(0.0, 1.0, 0.0)); + testbed.set_initial_collider_color(green_collider_handle, [0.0, 1.0, 0.0]); /* * A blue floor that will collide with the BLUE group only. */ let blue_floor = ColliderBuilder::cuboid(1.0, 0.1) - .translation(0.0, 2.0) + .translation(vector![0.0, 2.0]) .collision_groups(BLUE_GROUP) .build(); - let blue_collider_handle = colliders.insert(blue_floor, floor_handle, &mut bodies); + let blue_collider_handle = colliders.insert_with_parent(blue_floor, floor_handle, &mut bodies); - testbed.set_initial_collider_color(blue_collider_handle, Point3::new(0.0, 0.0, 1.0)); + testbed.set_initial_collider_color(blue_collider_handle, [0.0, 0.0, 1.0]); /* * Create the cubes @@ -69,17 +68,19 @@ pub fn init_world(testbed: &mut Testbed) { // Alternate between the green and blue groups. let (group, color) = if i % 2 == 0 { - (GREEN_GROUP, Point3::new(0.0, 1.0, 0.0)) + (GREEN_GROUP, [0.0, 1.0, 0.0]) } else { - (BLUE_GROUP, Point3::new(0.0, 0.0, 1.0)) + (BLUE_GROUP, [0.0, 0.0, 1.0]) }; - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad) .collision_groups(group) .build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); testbed.set_initial_body_color(handle, color); } @@ -89,5 +90,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 1.0), 100.0); + testbed.look_at(point![0.0, 1.0], 100.0); } diff --git a/examples2d/convex_polygons2.rs b/examples2d/convex_polygons2.rs index 0e4fb0c..4373fcb 100644 --- a/examples2d/convex_polygons2.rs +++ b/examples2d/convex_polygons2.rs @@ -1,8 +1,6 @@ -use na::Point2; use rand::distributions::{Distribution, Standard}; use rand::{rngs::StdRng, SeedableRng}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -21,23 +19,23 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(ground_size, ground_size * 2.0) + .translation(vector![ground_size, ground_size * 2.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(-ground_size, ground_size * 2.0) + .translation(vector![-ground_size, ground_size * 2.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the convex polygons @@ -58,18 +56,20 @@ pub fn init_world(testbed: &mut Testbed) { let x = i as f32 * shift - centerx; let y = j as f32 * shift * 2.0 + centery + 2.0; - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let mut points = Vec::new(); for _ in 0..10 { - let pt: Point2 = distribution.sample(&mut rng); + let pt: Point = distribution.sample(&mut rng); points.push(pt * scale); } let collider = ColliderBuilder::convex_hull(&points).unwrap().build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -77,5 +77,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 50.0), 10.0); + testbed.look_at(point![0.0, 50.0], 10.0); } diff --git a/examples2d/damping2.rs b/examples2d/damping2.rs index 68fd77d..e308de6 100644 --- a/examples2d/damping2.rs +++ b/examples2d/damping2.rs @@ -1,6 +1,4 @@ -use na::{Point2, Vector2}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -24,8 +22,8 @@ pub fn init_world(testbed: &mut Testbed) { // Build the rigid body. let rb = RigidBodyBuilder::new_dynamic() - .translation(x, y) - .linvel(x * 10.0, y * 10.0) + .translation(vector![x, y]) + .linvel(vector![x * 10.0, y * 10.0]) .angvel(100.0) .linear_damping((i + 1) as f32 * subdiv * 10.0) .angular_damping((num - i) as f32 * subdiv * 10.0) @@ -34,12 +32,12 @@ pub fn init_world(testbed: &mut Testbed) { // Build the collider. let co = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(co, rb_handle, &mut bodies); + colliders.insert_with_parent(co, rb_handle, &mut bodies); } /* * Set up the testbed. */ - testbed.set_world_with_params(bodies, colliders, joints, Vector2::zeros(), ()); - testbed.look_at(Point2::new(3.0, 2.0), 50.0); + testbed.set_world_with_params(bodies, colliders, joints, Vector::zeros(), ()); + testbed.look_at(point![3.0, 2.0], 50.0); } diff --git a/examples2d/debug_box_ball2.rs b/examples2d/debug_box_ball2.rs index aad72ae..63b6f95 100644 --- a/examples2d/debug_box_ball2.rs +++ b/examples2d/debug_box_ball2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -16,25 +14,25 @@ pub fn init_world(testbed: &mut Testbed) { */ let rad = 1.0; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -rad) + .translation(vector![0.0, -rad]) .rotation(std::f32::consts::PI / 4.0) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); // Build the dynamic box rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 3.0 * rad) + .translation(vector![0.0, 3.0 * rad]) .can_sleep(false) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 0.0), 50.0); + testbed.look_at(point![0.0, 0.0], 50.0); } diff --git a/examples2d/heightfield2.rs b/examples2d/heightfield2.rs index a834a2c..6246c40 100644 --- a/examples2d/heightfield2.rs +++ b/examples2d/heightfield2.rs @@ -1,6 +1,5 @@ -use na::{DVector, Point2, Vector2}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use na::DVector; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Ground */ - let ground_size = Vector2::new(50.0, 1.0); + let ground_size = Vector::new(50.0, 1.0); let nsubdivs = 2000; let heights = DVector::from_fn(nsubdivs + 1, |i, _| { @@ -28,7 +27,7 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::heightfield(heights, ground_size).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -46,15 +45,17 @@ pub fn init_world(testbed: &mut Testbed) { let y = j as f32 * shift + centery + 3.0; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); if j % 2 == 0 { let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } else { let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -63,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 0.0), 10.0); + testbed.look_at(point![0.0, 0.0], 10.0); } diff --git a/examples2d/joints2.rs b/examples2d/joints2.rs index ff5c663..9c94968 100644 --- a/examples2d/joints2.rs +++ b/examples2d/joints2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{BallJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -15,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) { * Create the balls */ // Build the rigid body. - // NOTE: a smaller radius (e.g. 0.1) breaks Box2D so + // NOTE: a smaller radius (e.g. 0.1) breaks Box2D so // in order to be able to compare rapier with Box2D, // we set it to 0.4. let rad = 0.4; @@ -37,16 +35,16 @@ pub fn init_world(testbed: &mut Testbed) { }; let rigid_body = RigidBodyBuilder::new(status) - .translation(fk * shift, -fi * shift) + .translation(vector![fk * shift, -fi * shift]) .build(); let child_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, child_handle, &mut bodies); + colliders.insert_with_parent(collider, child_handle, &mut bodies); // Vertical joint. if i > 0 { let parent_handle = *body_handles.last().unwrap(); - let joint = BallJoint::new(Point2::origin(), Point2::new(0.0, shift)); + let joint = BallJoint::new(Point::origin(), point![0.0, shift]); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -54,7 +52,7 @@ pub fn init_world(testbed: &mut Testbed) { if k > 0 { let parent_index = body_handles.len() - numi; let parent_handle = body_handles[parent_index]; - let joint = BallJoint::new(Point2::origin(), Point2::new(-shift, 0.0)); + let joint = BallJoint::new(Point::origin(), point![-shift, 0.0]); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -66,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(numk as f32 * rad, numi as f32 * -rad), 20.0); + testbed.look_at(point![numk as f32 * rad, numi as f32 * -rad], 20.0); } diff --git a/examples2d/locked_rotations2.rs b/examples2d/locked_rotations2.rs index 03fb2e7..a1f7ba5 100644 --- a/examples2d/locked_rotations2.rs +++ b/examples2d/locked_rotations2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; // This shows a bug when a cylinder is in contact with a very large @@ -21,38 +19,38 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height) + .translation(vector![0.0, -ground_height]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * A rectangle that only rotate. */ let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 3.0) + .translation(vector![0.0, 3.0]) .lock_translations() .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(2.0, 0.6).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * A tilted capsule that cannot rotate. */ let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 5.0) + .translation(vector![0.0, 5.0]) .rotation(1.0) .lock_rotations() .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::capsule_y(0.6, 0.4).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 0.0), 40.0); + testbed.look_at(point![0.0, 0.0], 40.0); } diff --git a/examples2d/one_way_platforms2.rs b/examples2d/one_way_platforms2.rs index 19b9968..b0f2212 100644 --- a/examples2d/one_way_platforms2.rs +++ b/examples2d/one_way_platforms2.rs @@ -1,7 +1,4 @@ -use na::{Point2, Vector2}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderHandle, ColliderSet}; -use rapier2d::pipeline::{ContactModificationContext, PhysicsHooks, PhysicsHooksFlags}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; struct OneWayPlatformHook { @@ -10,10 +7,6 @@ struct OneWayPlatformHook { } impl PhysicsHooks for OneWayPlatformHook { - fn active_hooks(&self) -> PhysicsHooksFlags { - PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS - } - fn modify_solver_contacts( &self, context: &mut ContactModificationContext, @@ -30,20 +23,20 @@ impl PhysicsHooks for OneWayPlatformHook { // - If context.collider_handle2 == self.platform1 then the allowed normal is -y. // - If context.collider_handle1 == self.platform2 then its allowed normal +y needs to be flipped to -y. // - If context.collider_handle2 == self.platform2 then the allowed normal -y needs to be flipped to +y. - let mut allowed_local_n1 = Vector2::zeros(); + let mut allowed_local_n1 = Vector::zeros(); if context.collider1 == self.platform1 { - allowed_local_n1 = Vector2::y(); + allowed_local_n1 = Vector::y(); } else if context.collider2 == self.platform1 { // Flip the allowed direction. - allowed_local_n1 = -Vector2::y(); + allowed_local_n1 = -Vector::y(); } if context.collider1 == self.platform2 { - allowed_local_n1 = -Vector2::y(); + allowed_local_n1 = -Vector::y(); } else if context.collider2 == self.platform2 { // Flip the allowed direction. - allowed_local_n1 = Vector2::y(); + allowed_local_n1 = Vector::y(); } // Call the helper function that simulates one-way platforms. @@ -78,15 +71,15 @@ pub fn init_world(testbed: &mut Testbed) { let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(25.0, 0.5) - .translation(30.0, 2.0) - .modify_solver_contacts(true) + .translation(vector![30.0, 2.0]) + .active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS) .build(); - let platform1 = colliders.insert(collider, handle, &mut bodies); + let platform1 = colliders.insert_with_parent(collider, handle, &mut bodies); let collider = ColliderBuilder::cuboid(25.0, 0.5) - .translation(-30.0, -2.0) - .modify_solver_contacts(true) + .translation(vector![-30.0, -2.0]) + .active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS) .build(); - let platform2 = colliders.insert(collider, handle, &mut bodies); + let platform2 = colliders.insert_with_parent(collider, handle, &mut bodies); /* * Setup the one-way platform hook. @@ -105,12 +98,12 @@ pub fn init_world(testbed: &mut Testbed) { // Spawn a new cube. let collider = ColliderBuilder::cuboid(1.5, 2.0).build(); let body = RigidBodyBuilder::new_dynamic() - .translation(20.0, 10.0) + .translation(vector![20.0, 10.0]) .build(); let handle = physics.bodies.insert(body); physics .colliders - .insert(collider, handle, &mut physics.bodies); + .insert_with_parent(collider, handle, &mut physics.bodies); if let Some(graphics) = graphics { graphics.add_body(handle, &physics.bodies, &physics.colliders); @@ -134,8 +127,8 @@ pub fn init_world(testbed: &mut Testbed) { bodies, colliders, joints, - Vector2::new(0.0, -9.81), + vector![0.0, -9.81], physics_hooks, ); - testbed.look_at(Point2::new(0.0, 0.0), 20.0); + testbed.look_at(point![0.0, 0.0], 20.0); } diff --git a/examples2d/platform2.rs b/examples2d/platform2.rs index 7542cd6..6aa73b7 100644 --- a/examples2d/platform2.rs +++ b/examples2d/platform2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height) + .translation(vector![0.0, -ground_height]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the boxes @@ -40,10 +38,12 @@ pub fn init_world(testbed: &mut Testbed) { let y = j as f32 * shift + centery; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -51,11 +51,11 @@ pub fn init_world(testbed: &mut Testbed) { * Setup a kinematic rigid body. */ let platform_body = RigidBodyBuilder::new_kinematic() - .translation(-10.0 * rad, 1.5 + 0.8) + .translation(vector![-10.0 * rad, 1.5 + 0.8]) .build(); let platform_handle = bodies.insert(platform_body); let collider = ColliderBuilder::cuboid(rad * 10.0, rad).build(); - colliders.insert(collider, platform_handle, &mut bodies); + colliders.insert_with_parent(collider, platform_handle, &mut bodies); /* * Setup a callback to control the platform. @@ -82,5 +82,5 @@ pub fn init_world(testbed: &mut Testbed) { * Run the simulation. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 1.0), 40.0); + testbed.look_at(point![0.0, 1.0], 40.0); } diff --git a/examples2d/polyline2.rs b/examples2d/polyline2.rs index 0b3be0c..7405e24 100644 --- a/examples2d/polyline2.rs +++ b/examples2d/polyline2.rs @@ -1,6 +1,5 @@ -use na::{ComplexField, Point2}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use na::ComplexField; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -19,18 +18,18 @@ pub fn init_world(testbed: &mut Testbed) { let step_size = ground_size / (nsubdivs as f32); let mut points = Vec::new(); - points.push(Point2::new(-ground_size / 2.0, 40.0)); + points.push(point![-ground_size / 2.0, 40.0]); for i in 1..nsubdivs - 1 { let x = -ground_size / 2.0 + i as f32 * step_size; let y = ComplexField::cos(i as f32 * step_size) * 2.0; - points.push(Point2::new(x, y)); + points.push(point![x, y]); } - points.push(Point2::new(ground_size / 2.0, 40.0)); + points.push(point![ground_size / 2.0, 40.0]); let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::polyline(points, None).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -48,15 +47,17 @@ pub fn init_world(testbed: &mut Testbed) { let y = j as f32 * shift + centery + 3.0; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); if j % 2 == 0 { let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } else { let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -65,5 +66,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 0.0), 10.0); + testbed.look_at(point![0.0, 0.0], 10.0); } diff --git a/examples2d/pyramid2.rs b/examples2d/pyramid2.rs index dfa64c9..76616be 100644 --- a/examples2d/pyramid2.rs +++ b/examples2d/pyramid2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -20,7 +18,7 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let ground_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Create the cubes @@ -40,10 +38,12 @@ pub fn init_world(testbed: &mut Testbed) { let y = fi * shift + centery; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -51,5 +51,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 2.5), 20.0); + testbed.look_at(point![0.0, 2.5], 20.0); } diff --git a/examples2d/restitution2.rs b/examples2d/restitution2.rs index 025a9cd..1be4298 100644 --- a/examples2d/restitution2.rs +++ b/examples2d/restitution2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,13 +16,13 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 1.0; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height) + .translation(vector![0.0, -ground_height]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height) .restitution(1.0) .build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let num = 10; let rad = 0.5; @@ -33,13 +31,13 @@ pub fn init_world(testbed: &mut Testbed) { for i in 0..=num { let x = (i as f32) - num as f32 / 2.0; let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(x * 2.0, 10.0 * (j as f32 + 1.0)) + .translation(vector![x * 2.0, 10.0 * (j as f32 + 1.0)]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad) .restitution((i as f32) / (num as f32)) .build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -47,5 +45,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 1.0), 25.0); + testbed.look_at(point![0.0, 1.0], 25.0); } diff --git a/examples2d/sensor2.rs b/examples2d/sensor2.rs index a651f64..17ed970 100644 --- a/examples2d/sensor2.rs +++ b/examples2d/sensor2.rs @@ -1,6 +1,4 @@ -use na::{Point2, Point3}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height) + .translation(vector![0.0, -ground_height]) .build(); let ground_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height).build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Create some boxes. @@ -38,12 +36,14 @@ pub fn init_world(testbed: &mut Testbed) { let y = 3.0; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); - testbed.set_initial_body_color(handle, Point3::new(0.5, 0.5, 1.0)); + testbed.set_initial_body_color(handle, [0.5, 0.5, 1.0]); } /* @@ -52,33 +52,37 @@ pub fn init_world(testbed: &mut Testbed) { // Rigid body so that the sensor can move. let sensor = RigidBodyBuilder::new_dynamic() - .translation(0.0, 10.0) + .translation(vector![0.0, 10.0]) .build(); let sensor_handle = bodies.insert(sensor); // Solid cube attached to the sensor which // other colliders can touch. let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, sensor_handle, &mut bodies); + colliders.insert_with_parent(collider, sensor_handle, &mut bodies); // We create a collider desc without density because we don't // want it to contribute to the rigid body mass. - let sensor_collider = ColliderBuilder::ball(rad * 5.0).sensor(true).build(); - colliders.insert(sensor_collider, sensor_handle, &mut bodies); + let sensor_collider = ColliderBuilder::ball(rad * 5.0) + .density(0.0) + .sensor(true) + .build(); + colliders.insert_with_parent(sensor_collider, sensor_handle, &mut bodies); - testbed.set_initial_body_color(sensor_handle, Point3::new(0.5, 1.0, 1.0)); + testbed.set_initial_body_color(sensor_handle, [0.5, 1.0, 1.0]); // 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) + [1.0, 1.0, 0.0] } else { - Point3::new(0.5, 0.5, 1.0) + [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(); + let parent_handle1 = physics.colliders[prox.collider1].parent().unwrap(); + let parent_handle2 = physics.colliders[prox.collider2].parent().unwrap(); + if let Some(graphics) = &mut graphics { if parent_handle1 != ground_handle && parent_handle1 != sensor_handle { graphics.set_body_color(parent_handle1, color); @@ -94,5 +98,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 1.0), 100.0); + testbed.look_at(point![0.0, 1.0], 100.0); } diff --git a/examples2d/trimesh2.rs b/examples2d/trimesh2.rs index adc8b6b..a4b049a 100644 --- a/examples2d/trimesh2.rs +++ b/examples2d/trimesh2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; use lyon::math::Point; @@ -25,23 +23,23 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(ground_size, ground_size) + .translation(vector![ground_size, ground_size]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(-ground_size, ground_size) + .translation(vector![-ground_size, ground_size]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the trimeshes from a tesselated SVG. @@ -83,18 +81,18 @@ pub fn init_world(testbed: &mut Testbed) { let vertices: Vec<_> = mesh .vertices .iter() - .map(|v| Point2::new(v.position[0] * sx, v.position[1] * -sy)) + .map(|v| point![v.position[0] * sx, v.position[1] * -sy]) .collect(); for k in 0..5 { let collider = ColliderBuilder::trimesh(vertices.clone(), indices.clone()).build(); let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(ith as f32 * 8.0 - 20.0, 20.0 + k as f32 * 11.0) + .translation(vector![ith as f32 * 8.0 - 20.0, 20.0 + k as f32 * 11.0]) .rotation(angle) .build(); let handle = bodies.insert(rigid_body); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } ith += 1; @@ -106,7 +104,7 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 20.0), 17.0); + testbed.look_at(point![0.0, 20.0], 17.0); } const RAPIER_SVG_STR: &'static str = r#" diff --git a/examples3d/ccd3.rs b/examples3d/ccd3.rs index e5dee33..facdec1 100644 --- a/examples3d/ccd3.rs +++ b/examples3d/ccd3.rs @@ -1,15 +1,13 @@ -use na::{Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; fn create_wall( testbed: &mut Testbed, bodies: &mut RigidBodySet, colliders: &mut ColliderSet, - offset: Vector3, + offset: Vector, stack_height: usize, - half_extents: Vector3, + half_extents: Vector, ) { let shift = half_extents * 2.0; let mut k = 0; @@ -23,22 +21,18 @@ fn create_wall( - stack_height as f32 * half_extents.z; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![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); + colliders.insert_with_parent(collider, handle, bodies); k += 1; if k % 2 == 0 { - testbed.set_initial_body_color( - handle, - Point3::new(255. / 255., 131. / 255., 244.0 / 255.), - ); + testbed.set_initial_body_color(handle, [255. / 255., 131. / 255., 244.0 / 255.]); } else { - testbed.set_initial_body_color( - handle, - Point3::new(131. / 255., 255. / 255., 244.0 / 255.), - ); + testbed.set_initial_body_color(handle, [131. / 255., 255. / 255., 244.0 / 255.]); } } } @@ -59,11 +53,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Create the pyramids. @@ -79,18 +73,18 @@ pub fn init_world(testbed: &mut Testbed) { testbed, &mut bodies, &mut colliders, - Vector3::new(x, shift_y, 0.0), + vector![x, shift_y, 0.0], num_z, - Vector3::new(0.5, 0.5, 1.0), + vector![0.5, 0.5, 1.0], ); create_wall( testbed, &mut bodies, &mut colliders, - Vector3::new(x, shift_y, shift_z), + vector![x, shift_y, shift_z], num_z, - Vector3::new(0.5, 0.5, 1.0), + vector![0.5, 0.5, 1.0], ); } @@ -104,35 +98,45 @@ pub fn init_world(testbed: &mut Testbed) { .sensor(true) .build(); let rigid_body = RigidBodyBuilder::new_dynamic() - .linvel(1000.0, 0.0, 0.0) - .translation(-20.0, shift_y + 2.0, 0.0) + .linvel(vector![1000.0, 0.0, 0.0]) + .translation(vector![-20.0, shift_y + 2.0, 0.0]) .ccd_enabled(true) .build(); let sensor_handle = bodies.insert(rigid_body); - colliders.insert(collider, sensor_handle, &mut bodies); + colliders.insert_with_parent(collider, sensor_handle, &mut bodies); // Second rigid-body with CCD enabled. let collider = ColliderBuilder::ball(1.0).density(10.0).build(); let rigid_body = RigidBodyBuilder::new_dynamic() - .linvel(1000.0, 0.0, 0.0) - .translation(-20.0, shift_y + 2.0, shift_z) + .linvel(vector![1000.0, 0.0, 0.0]) + .translation(vector![-20.0, shift_y + 2.0, shift_z]) .ccd_enabled(true) .build(); let handle = bodies.insert(rigid_body); - colliders.insert(collider.clone(), handle, &mut bodies); - testbed.set_initial_body_color(handle, Point3::new(0.2, 0.2, 1.0)); + colliders.insert_with_parent(collider.clone(), handle, &mut bodies); + testbed.set_initial_body_color(handle, [0.2, 0.2, 1.0]); // 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) + [1.0, 1.0, 0.0] } else { - Point3::new(0.5, 0.5, 1.0) + [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(); + let parent_handle1 = physics + .colliders + .get(prox.collider1) + .unwrap() + .parent() + .unwrap(); + let parent_handle2 = physics + .colliders + .get(prox.collider2) + .unwrap() + .parent() + .unwrap(); if let Some(graphics) = &mut graphics { if parent_handle1 != ground_handle && parent_handle1 != sensor_handle { @@ -149,5 +153,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/examples3d/collision_groups3.rs b/examples3d/collision_groups3.rs index a79a4bc..8db86fa 100644 --- a/examples3d/collision_groups3.rs +++ b/examples3d/collision_groups3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet, InteractionGroups}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![0.0, -ground_height, 0.0]) .build(); let floor_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build(); - colliders.insert(collider, floor_handle, &mut bodies); + colliders.insert_with_parent(collider, floor_handle, &mut bodies); /* * Setup groups @@ -34,23 +32,24 @@ pub fn init_world(testbed: &mut Testbed) { * A green floor that will collide with the GREEN group only. */ let green_floor = ColliderBuilder::cuboid(1.0, 0.1, 1.0) - .translation(0.0, 1.0, 0.0) + .translation(vector![0.0, 1.0, 0.0]) .collision_groups(GREEN_GROUP) .build(); - let green_collider_handle = colliders.insert(green_floor, floor_handle, &mut bodies); + let green_collider_handle = + colliders.insert_with_parent(green_floor, floor_handle, &mut bodies); - testbed.set_initial_collider_color(green_collider_handle, Point3::new(0.0, 1.0, 0.0)); + testbed.set_initial_collider_color(green_collider_handle, [0.0, 1.0, 0.0]); /* * A blue floor that will collide with the BLUE group only. */ let blue_floor = ColliderBuilder::cuboid(1.0, 0.1, 1.0) - .translation(0.0, 2.0, 0.0) + .translation(vector![0.0, 2.0, 0.0]) .collision_groups(BLUE_GROUP) .build(); - let blue_collider_handle = colliders.insert(blue_floor, floor_handle, &mut bodies); + let blue_collider_handle = colliders.insert_with_parent(blue_floor, floor_handle, &mut bodies); - testbed.set_initial_collider_color(blue_collider_handle, Point3::new(0.0, 0.0, 1.0)); + testbed.set_initial_collider_color(blue_collider_handle, [0.0, 0.0, 1.0]); /* * Create the cubes @@ -72,17 +71,19 @@ pub fn init_world(testbed: &mut Testbed) { // Alternate between the green and blue groups. let (group, color) = if k % 2 == 0 { - (GREEN_GROUP, Point3::new(0.0, 1.0, 0.0)) + (GREEN_GROUP, [0.0, 1.0, 0.0]) } else { - (BLUE_GROUP, Point3::new(0.0, 0.0, 1.0)) + (BLUE_GROUP, [0.0, 0.0, 1.0]) }; - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad, rad) .collision_groups(group) .build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); testbed.set_initial_body_color(handle, color); } @@ -93,5 +94,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin()); + testbed.look_at(point!(10.0, 10.0, 10.0), Point::origin()); } diff --git a/examples3d/compound3.rs b/examples3d/compound3.rs index 51523f3..f5f1de1 100644 --- a/examples3d/compound3.rs +++ b/examples3d/compound3.rs @@ -1,6 +1,4 @@ -use na::{Isometry3, Point3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -46,40 +44,42 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shift * 2.0 - centerz + offset; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); // First option: attach several colliders to a single rigid-body. if j < numy / 2 { let collider1 = ColliderBuilder::cuboid(rad * 10.0, rad, rad).build(); let collider2 = ColliderBuilder::cuboid(rad, rad * 10.0, rad) - .translation(rad * 10.0, rad * 10.0, 0.0) + .translation(vector![rad * 10.0, rad * 10.0, 0.0]) .build(); let collider3 = ColliderBuilder::cuboid(rad, rad * 10.0, rad) - .translation(-rad * 10.0, rad * 10.0, 0.0) + .translation(vector![-rad * 10.0, rad * 10.0, 0.0]) .build(); - colliders.insert(collider1, handle, &mut bodies); - colliders.insert(collider2, handle, &mut bodies); - colliders.insert(collider3, handle, &mut bodies); + colliders.insert_with_parent(collider1, handle, &mut bodies); + colliders.insert_with_parent(collider2, handle, &mut bodies); + colliders.insert_with_parent(collider3, handle, &mut bodies); } else { // Second option: create a compound shape and attach it to a single collider. let shapes = vec![ ( - Isometry3::identity(), + Isometry::identity(), SharedShape::cuboid(rad * 10.0, rad, rad), ), ( - Isometry3::translation(rad * 10.0, rad * 10.0, 0.0), + Isometry::translation(rad * 10.0, rad * 10.0, 0.0), SharedShape::cuboid(rad, rad * 10.0, rad), ), ( - Isometry3::translation(-rad * 10.0, rad * 10.0, 0.0), + Isometry::translation(-rad * 10.0, rad * 10.0, 0.0), SharedShape::cuboid(rad, rad * 10.0, rad), ), ]; let collider = ColliderBuilder::compound(shapes).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -91,5 +91,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/examples3d/convex_decomposition3.rs b/examples3d/convex_decomposition3.rs index 1d19597..5676f6d 100644 --- a/examples3d/convex_decomposition3.rs +++ b/examples3d/convex_decomposition3.rs @@ -1,8 +1,6 @@ -use na::Point3; use obj::raw::object::Polygon; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape}; use rapier3d::parry::bounding_volume; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; use std::fs::File; use std::io::BufReader; @@ -26,11 +24,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the convex decompositions. @@ -52,7 +50,7 @@ pub fn init_world(testbed: &mut Testbed) { let mut vertices: Vec<_> = model .positions .iter() - .map(|v| Point3::new(v.0, v.1, v.2)) + .map(|v| point![v.0, v.1, v.2]) .collect(); use std::iter::FromIterator; let indices: Vec<_> = model @@ -90,12 +88,14 @@ pub fn init_world(testbed: &mut Testbed) { let y = (igeom / width) as f32 * shift + 4.0; let z = k as f32 * shift; - let body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(body); for shape in &shapes { let collider = ColliderBuilder::new(shape.clone()).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -105,7 +105,7 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } fn models() -> Vec { diff --git a/examples3d/convex_polyhedron3.rs b/examples3d/convex_polyhedron3.rs index c43a781..896eb03 100644 --- a/examples3d/convex_polyhedron3.rs +++ b/examples3d/convex_polyhedron3.rs @@ -1,8 +1,6 @@ -use na::Point3; use rand::distributions::{Distribution, Standard}; use rand::{rngs::StdRng, SeedableRng}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -20,11 +18,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the polyhedra @@ -50,17 +48,19 @@ pub fn init_world(testbed: &mut Testbed) { let mut points = Vec::new(); for _ in 0..10 { - let pt: Point3 = distribution.sample(&mut rng); + let pt: Point = distribution.sample(&mut rng); points.push(pt * scale); } // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::round_convex_hull(&points, border_rad) .unwrap() .build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -69,5 +69,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(30.0, 30.0, 30.0), Point3::origin()); + testbed.look_at(point![30.0, 30.0, 30.0], Point::origin()); } diff --git a/examples3d/damping3.rs b/examples3d/damping3.rs index 3847ceb..c634a0a 100644 --- a/examples3d/damping3.rs +++ b/examples3d/damping3.rs @@ -1,6 +1,4 @@ -use na::{Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -24,9 +22,9 @@ pub fn init_world(testbed: &mut Testbed) { // Build the rigid body. let rb = RigidBodyBuilder::new_dynamic() - .translation(x, y, 0.0) - .linvel(x * 10.0, y * 10.0, 0.0) - .angvel(Vector3::z() * 100.0) + .translation(vector![x, y, 0.0]) + .linvel(vector![x * 10.0, y * 10.0, 0.0]) + .angvel(Vector::z() * 100.0) .linear_damping((i + 1) as f32 * subdiv * 10.0) .angular_damping((num - i) as f32 * subdiv * 10.0) .build(); @@ -34,12 +32,12 @@ pub fn init_world(testbed: &mut Testbed) { // Build the collider. let co = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(co, rb_handle, &mut bodies); + colliders.insert_with_parent(co, rb_handle, &mut bodies); } /* * Set up the testbed. */ - testbed.set_world_with_params(bodies, colliders, joints, Vector3::zeros(), ()); - testbed.look_at(Point3::new(2.0, 2.5, 20.0), Point3::new(2.0, 2.5, 0.0)); + testbed.set_world_with_params(bodies, colliders, joints, Vector::zeros(), ()); + testbed.look_at(point![2.0, 2.5, 20.0], point![2.0, 2.5, 0.0]); } diff --git a/examples3d/debug_add_remove_collider3.rs b/examples3d/debug_add_remove_collider3.rs index 00a0ff3..12d58ec 100644 --- a/examples3d/debug_add_remove_collider3.rs +++ b/examples3d/debug_add_remove_collider3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -17,22 +15,23 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![0.0, -ground_height, 0.0]) .build(); let ground_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4).build(); - let mut ground_collider_handle = colliders.insert(collider, ground_handle, &mut bodies); + let mut ground_collider_handle = + colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Rolling ball */ let ball_rad = 0.1; let rb = RigidBodyBuilder::new_dynamic() - .translation(0.0, 0.2, 0.0) + .translation(vector![0.0, 0.2, 0.0]) .build(); let ball_handle = bodies.insert(rb); let collider = ColliderBuilder::ball(ball_rad).density(100.0).build(); - colliders.insert(collider, ball_handle, &mut bodies); + colliders.insert_with_parent(collider, ball_handle, &mut bodies); testbed.add_callback(move |_, physics, _, _| { // Remove then re-add the ground collider. @@ -46,14 +45,15 @@ pub fn init_world(testbed: &mut Testbed) { true, ) .unwrap(); - ground_collider_handle = physics - .colliders - .insert(coll, ground_handle, &mut physics.bodies); + ground_collider_handle = + physics + .colliders + .insert_with_parent(coll, ground_handle, &mut physics.bodies); }); /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin()); + testbed.look_at(point![10.0, 10.0, 10.0], Point::origin()); } diff --git a/examples3d/debug_big_colliders3.rs b/examples3d/debug_big_colliders3.rs index a524f97..864782f 100644 --- a/examples3d/debug_big_colliders3.rs +++ b/examples3d/debug_big_colliders3.rs @@ -1,6 +1,4 @@ -use na::{Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet, HalfSpace, SharedShape}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -16,9 +14,9 @@ pub fn init_world(testbed: &mut Testbed) { */ let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); - let halfspace = SharedShape::new(HalfSpace::new(Vector3::y_axis())); + let halfspace = SharedShape::new(HalfSpace::new(Vector::y_axis())); let collider = ColliderBuilder::new(halfspace).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let mut curr_y = 0.0; let mut curr_width = 10_000.0; @@ -28,11 +26,11 @@ pub fn init_world(testbed: &mut Testbed) { curr_y += curr_height * 4.0; let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, curr_y, 0.0) + .translation(vector![0.0, curr_y, 0.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(curr_width, curr_height, curr_width).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); curr_width /= 5.0; } @@ -41,5 +39,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin()); + testbed.look_at(point![10.0, 10.0, 10.0], Point::origin()); } diff --git a/examples3d/debug_boxes3.rs b/examples3d/debug_boxes3.rs index cba9d01..ea39a8a 100644 --- a/examples3d/debug_boxes3.rs +++ b/examples3d/debug_boxes3.rs @@ -1,6 +1,4 @@ -use na::{Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -19,28 +17,28 @@ pub fn init_world(testbed: &mut Testbed) { for _ in 0..6 { let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); } // Build the dynamic box rigid body. for _ in 0..6 { let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(1.1, 0.0, 0.0) - .rotation(Vector3::new(0.8, 0.2, 0.1)) + .translation(vector![1.1, 0.0, 0.0]) + .rotation(vector![0.8, 0.2, 0.1]) .can_sleep(false) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(2.0, 0.1, 1.0).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin()); + testbed.look_at(point![10.0, 10.0, 10.0], Point::origin()); } diff --git a/examples3d/debug_cylinder3.rs b/examples3d/debug_cylinder3.rs index 0b68b62..88908c1 100644 --- a/examples3d/debug_cylinder3.rs +++ b/examples3d/debug_cylinder3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; // This shows a bug when a cylinder is in contact with a very large @@ -21,11 +19,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -47,14 +45,16 @@ pub fn init_world(testbed: &mut Testbed) { let z = -centerz + offset; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cylinder(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/examples3d/debug_dynamic_collider_add3.rs b/examples3d/debug_dynamic_collider_add3.rs index 6a4589b..f66d8ce 100644 --- a/examples3d/debug_dynamic_collider_add3.rs +++ b/examples3d/debug_dynamic_collider_add3.rs @@ -1,6 +1,4 @@ -use na::{Isometry3, Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -17,30 +15,30 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![0.0, -ground_height, 0.0]) .build(); let ground_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4) .friction(0.15) // .restitution(0.5) .build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Rolling ball */ let ball_rad = 0.1; let rb = RigidBodyBuilder::new_dynamic() - .translation(0.0, 0.2, 0.0) - .linvel(10.0, 0.0, 0.0) + .translation(vector![0.0, 0.2, 0.0]) + .linvel(vector![10.0, 0.0, 0.0]) .build(); let ball_handle = bodies.insert(rb); let collider = ColliderBuilder::ball(ball_rad).density(100.0).build(); - colliders.insert(collider, ball_handle, &mut bodies); + colliders.insert_with_parent(collider, ball_handle, &mut bodies); - let mut linvel = Vector3::zeros(); - let mut angvel = Vector3::zeros(); - let mut pos = Isometry3::identity(); + let mut linvel = Vector::zeros(); + let mut angvel = Vector::zeros(); + let mut pos = Isometry::identity(); let mut step = 0; let mut extra_colliders = Vec::new(); let snapped_frame = 51; @@ -55,7 +53,7 @@ pub fn init_world(testbed: &mut Testbed) { let new_ball_collider_handle = physics .colliders - .insert(collider, ball_handle, &mut physics.bodies); + .insert_with_parent(collider, ball_handle, &mut physics.bodies); if let Some(graphics) = &mut graphics { graphics.add_collider(new_ball_collider_handle, &physics.colliders); @@ -93,7 +91,7 @@ pub fn init_world(testbed: &mut Testbed) { // Remove then re-add the ground collider. // let ground = physics.bodies.get_mut(ground_handle).unwrap(); - // ground.set_position(Isometry3::translation(0.0, step as f32 * 0.001, 0.0), false); + // ground.set_position(Isometry::translation(0.0, step as f32 * 0.001, 0.0), false); // let coll = physics // .colliders // .remove(ground_collider_handle, &mut physics.bodies, true) @@ -104,7 +102,7 @@ pub fn init_world(testbed: &mut Testbed) { let new_ground_collider_handle = physics .colliders - .insert(coll, ground_handle, &mut physics.bodies); + .insert_with_parent(coll, ground_handle, &mut physics.bodies); if let Some(graphics) = &mut graphics { graphics.add_collider(new_ground_collider_handle, &physics.colliders); @@ -117,5 +115,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin()); + testbed.look_at(point![10.0, 10.0, 10.0], Point::origin()); } diff --git a/examples3d/debug_friction3.rs b/examples3d/debug_friction3.rs index 72631a7..7d01986 100644 --- a/examples3d/debug_friction3.rs +++ b/examples3d/debug_friction3.rs @@ -1,6 +1,4 @@ -use na::{Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -22,24 +20,24 @@ pub fn init_world(testbed: &mut Testbed) { let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size) .friction(1.5) .build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); // Build a dynamic box rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 1.1, 0.0) - .rotation(Vector3::y() * 0.3) + .translation(vector![0.0, 1.1, 0.0]) + .rotation(Vector::y() * 0.3) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(2.0, 1.0, 3.0).friction(1.5).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = &mut bodies[handle]; - let force = rigid_body.position() * Vector3::z() * 50.0; + let force = rigid_body.position() * Vector::z() * 50.0; rigid_body.set_linvel(force, true); /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/examples3d/debug_infinite_fall3.rs b/examples3d/debug_infinite_fall3.rs index ef41c92..dcf4f12 100644 --- a/examples3d/debug_infinite_fall3.rs +++ b/examples3d/debug_infinite_fall3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,33 +16,33 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 2.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, 4.0, 0.0) + .translation(vector![0.0, 4.0, 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); + colliders.insert_with_parent(collider, handle, &mut bodies); let rad = 1.0; // Build the dynamic box rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 7.0 * rad, 0.0) + .translation(vector![0.0, 7.0 * rad, 0.0]) .can_sleep(false) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 2.0 * rad, 0.0) + .translation(vector![0.0, 2.0 * rad, 0.0]) .can_sleep(false) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Set up the testbed. */ - testbed.look_at(Point3::new(100.0, -10.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, -10.0, 100.0], Point::origin()); testbed.set_world(bodies, colliders, joints); } diff --git a/examples3d/debug_prismatic3.rs b/examples3d/debug_prismatic3.rs index 07cf381..f41ef49 100644 --- a/examples3d/debug_prismatic3.rs +++ b/examples3d/debug_prismatic3.rs @@ -1,20 +1,18 @@ -use na::{Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; fn prismatic_repro( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, joints: &mut JointSet, - box_center: Point3, + box_center: Point, ) { let box_rb = bodies.insert( RigidBodyBuilder::new_dynamic() - .translation(box_center.x, box_center.y, box_center.z) + .translation(vector![box_center.x, box_center.y, box_center.z]) .build(), ); - colliders.insert( + colliders.insert_with_parent( ColliderBuilder::cuboid(1.0, 0.25, 1.0).build(), box_rb, bodies, @@ -22,32 +20,32 @@ fn prismatic_repro( let wheel_y = -1.0; let wheel_positions = vec![ - Vector3::new(1.0, wheel_y, -1.0), - Vector3::new(-1.0, wheel_y, -1.0), - Vector3::new(1.0, wheel_y, 1.0), - Vector3::new(-1.0, wheel_y, 1.0), + vector![1.0, wheel_y, -1.0], + vector![-1.0, wheel_y, -1.0], + vector![1.0, wheel_y, 1.0], + vector![-1.0, wheel_y, 1.0], ]; for pos in wheel_positions { let wheel_pos_in_world = box_center + pos; let wheel_rb = bodies.insert( RigidBodyBuilder::new_dynamic() - .translation( + .translation(vector![ wheel_pos_in_world.x, wheel_pos_in_world.y, - wheel_pos_in_world.z, - ) + wheel_pos_in_world.z + ]) .build(), ); - colliders.insert(ColliderBuilder::ball(0.5).build(), wheel_rb, bodies); + colliders.insert_with_parent(ColliderBuilder::ball(0.5).build(), wheel_rb, bodies); let mut prismatic = rapier3d::dynamics::PrismaticJoint::new( - Point3::new(pos.x, pos.y, pos.z), - Vector3::y_axis(), - Vector3::default(), - Point3::new(0.0, 0.0, 0.0), - Vector3::y_axis(), - Vector3::default(), + point![pos.x, pos.y, pos.z], + Vector::y_axis(), + Vector::zeros(), + Point::origin(), + Vector::y_axis(), + Vector::default(), ); prismatic.configure_motor_model(rapier3d::dynamics::SpringModel::VelocityBased); let (stiffness, damping) = (0.05, 0.2); @@ -59,10 +57,10 @@ fn prismatic_repro( // put a small box under one of the wheels let gravel = bodies.insert( RigidBodyBuilder::new_dynamic() - .translation(box_center.x + 1.0, box_center.y - 2.4, -1.0) + .translation(vector![box_center.x + 1.0, box_center.y - 2.4, -1.0]) .build(), ); - colliders.insert( + colliders.insert_with_parent( ColliderBuilder::cuboid(0.5, 0.1, 0.5).build(), gravel, bodies, @@ -84,22 +82,22 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); prismatic_repro( &mut bodies, &mut colliders, &mut joints, - Point3::new(0.0, 5.0, 0.0), + point![0.0, 5.0, 0.0], ); /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin()); + testbed.look_at(point![10.0, 10.0, 10.0], Point::origin()); } diff --git a/examples3d/debug_rollback3.rs b/examples3d/debug_rollback3.rs index 8f1bede..c5e5bde 100644 --- a/examples3d/debug_rollback3.rs +++ b/examples3d/debug_rollback3.rs @@ -1,6 +1,4 @@ -use na::{Isometry3, Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -17,30 +15,30 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![0.0, -ground_height, 0.0]) .build(); let ground_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4) .friction(0.15) // .restitution(0.5) .build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Rolling ball */ let ball_rad = 0.1; let rb = RigidBodyBuilder::new_dynamic() - .translation(0.0, 0.2, 0.0) - .linvel(10.0, 0.0, 0.0) + .translation(vector![0.0, 0.2, 0.0]) + .linvel(vector![10.0, 0.0, 0.0]) .build(); let ball_handle = bodies.insert(rb); let collider = ColliderBuilder::ball(ball_rad).density(100.0).build(); - colliders.insert(collider, ball_handle, &mut bodies); + colliders.insert_with_parent(collider, ball_handle, &mut bodies); - let mut linvel = Vector3::zeros(); - let mut angvel = Vector3::zeros(); - let mut pos = Isometry3::identity(); + let mut linvel = Vector::zeros(); + let mut angvel = Vector::zeros(); + let mut pos = Isometry::identity(); let mut step = 0; let snapped_frame = 51; @@ -68,5 +66,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin()); + testbed.look_at(point![10.0, 10.0, 10.0], Point::origin()); } diff --git a/examples3d/debug_shape_modification3.rs b/examples3d/debug_shape_modification3.rs index bef56fa..6c27288 100644 --- a/examples3d/debug_shape_modification3.rs +++ b/examples3d/debug_shape_modification3.rs @@ -1,6 +1,4 @@ -use na::{Isometry3, Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -17,30 +15,30 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![0.0, -ground_height, 0.0]) .build(); let ground_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size) .friction(0.15) // .restitution(0.5) .build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Rolling ball */ let ball_rad = 0.1; let rb = RigidBodyBuilder::new_dynamic() - .translation(0.0, 0.2, 0.0) - .linvel(10.0, 0.0, 0.0) + .translation(vector![0.0, 0.2, 0.0]) + .linvel(vector![10.0, 0.0, 0.0]) .build(); let ball_handle = bodies.insert(rb); let collider = ColliderBuilder::ball(ball_rad).density(100.0).build(); - let ball_coll_handle = colliders.insert(collider, ball_handle, &mut bodies); + let ball_coll_handle = colliders.insert_with_parent(collider, ball_handle, &mut bodies); - let mut linvel = Vector3::zeros(); - let mut angvel = Vector3::zeros(); - let mut pos = Isometry3::identity(); + let mut linvel = Vector::zeros(); + let mut angvel = Vector::zeros(); + let mut pos = Isometry::identity(); let mut step = 0; let snapped_frame = 51; @@ -90,7 +88,9 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shiftz - centerz + offset; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = match j % 5 { @@ -103,7 +103,7 @@ pub fn init_world(testbed: &mut Testbed) { _ => ColliderBuilder::capsule_y(rad, rad).build(), }; - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -114,5 +114,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin()); + testbed.look_at(point![10.0, 10.0, 10.0], Point::origin()); } diff --git a/examples3d/debug_triangle3.rs b/examples3d/debug_triangle3.rs index 341f396..0c40882 100644 --- a/examples3d/debug_triangle3.rs +++ b/examples3d/debug_triangle3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -13,31 +11,31 @@ pub fn init_world(testbed: &mut Testbed) { // Triangle ground. let vtx = [ - Point3::new(-10.0, 0.0, -10.0), - Point3::new(10.0, 0.0, -10.0), - Point3::new(0.0, 0.0, 10.0), + point![-10.0, 0.0, -10.0], + point![10.0, 0.0, -10.0], + point![0.0, 0.0, 10.0], ]; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, 0.0, 0.0) + .translation(vector![0.0, 0.0, 0.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::triangle(vtx[0], vtx[1], vtx[2]).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); // Dynamic box rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(1.1, 0.01, 0.0) + .translation(vector![1.1, 0.01, 0.0]) // .rotation(Vector3::new(0.8, 0.2, 0.1)) .can_sleep(false) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(20.0, 0.1, 1.0).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin()); + testbed.look_at(point![10.0, 10.0, 10.0], Point::origin()); } diff --git a/examples3d/debug_trimesh3.rs b/examples3d/debug_trimesh3.rs index 5a8ed4b..d21d0d3 100644 --- a/examples3d/debug_trimesh3.rs +++ b/examples3d/debug_trimesh3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -14,14 +12,14 @@ pub fn init_world(testbed: &mut Testbed) { // Triangle ground. let width = 0.5; let vtx = vec![ - Point3::new(-width, 0.0, -width), - Point3::new(width, 0.0, -width), - Point3::new(width, 0.0, width), - Point3::new(-width, 0.0, width), - Point3::new(-width, -width, -width), - Point3::new(width, -width, -width), - Point3::new(width, -width, width), - Point3::new(-width, -width, width), + point![-width, 0.0, -width], + point![width, 0.0, -width], + point![width, 0.0, width], + point![-width, 0.0, width], + point![-width, -width, -width], + point![width, -width, -width], + point![width, -width, width], + point![-width, -width, width], ]; let idx = vec![ [0, 2, 1], @@ -40,25 +38,25 @@ pub fn init_world(testbed: &mut Testbed) { // Dynamic box rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 35.0, 0.0) + .translation(vector![0.0, 35.0, 0.0]) // .rotation(Vector3::new(0.8, 0.2, 0.1)) .can_sleep(false) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.0).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, 0.0, 0.0) + .translation(vector![0.0, 0.0, 0.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::trimesh(vtx, idx).build(); - colliders.insert(collider, handle, &mut bodies); - testbed.set_initial_body_color(handle, Point3::new(0.3, 0.3, 0.3)); + colliders.insert_with_parent(collider, handle, &mut bodies); + testbed.set_initial_body_color(handle, [0.3, 0.3, 0.3]); /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin()); + testbed.look_at(point![10.0, 10.0, 10.0], Point::origin()); } diff --git a/examples3d/domino3.rs b/examples3d/domino3.rs index b619da5..7e9143f 100644 --- a/examples3d/domino3.rs +++ b/examples3d/domino3.rs @@ -1,6 +1,4 @@ -use na::{Point3, Translation3, UnitQuaternion, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -31,7 +29,7 @@ pub fn init_world(testbed: &mut Testbed) { let width = 1.0; let thickness = 0.1; - let colors = [Point3::new(0.7, 0.5, 0.9), Point3::new(0.6, 1.0, 0.6)]; + let colors = [[0.7, 0.5, 0.9], [0.6, 1.0, 0.6]]; let mut curr_angle = 0.0; let mut curr_rad = 10.0; @@ -50,16 +48,16 @@ pub fn init_world(testbed: &mut Testbed) { let tilt = if nudged || i == num - 1 { 0.2 } else { 0.0 }; if skip == 0 { - let rot = UnitQuaternion::new(Vector3::y() * curr_angle); - let tilt = UnitQuaternion::new(rot * Vector3::z() * tilt); + let rot = Rotation::new(Vector::y() * curr_angle); + let tilt = Rotation::new(rot * Vector::z() * tilt); let position = - Translation3::new(x * curr_rad, width * 2.0 + ground_height, z * curr_rad) + Translation::new(x * curr_rad, width * 2.0 + ground_height, z * curr_rad) * tilt * rot; let rigid_body = RigidBodyBuilder::new_dynamic().position(position).build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(thickness, width * 2.0, width).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); testbed.set_initial_body_color(handle, colors[i % 2]); } else { skip -= 1; @@ -76,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/examples3d/fountain3.rs b/examples3d/fountain3.rs index 0d228c7..788d05d 100644 --- a/examples3d/fountain3.rs +++ b/examples3d/fountain3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; const MAX_NUMBER_OF_BODIES: usize = 400; @@ -18,16 +16,16 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 2.1; // 16.0; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); // Callback that will be executed on the main loop to handle proximities. testbed.add_callback(move |mut graphics, physics, _, run_state| { let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 10.0, 0.0) + .translation(vector![0.0, 10.0, 0.0]) .build(); let handle = physics.bodies.insert(rigid_body); let collider = match run_state.timestep_id % 3 { @@ -38,7 +36,7 @@ pub fn init_world(testbed: &mut Testbed) { physics .colliders - .insert(collider, handle, &mut physics.bodies); + .insert_with_parent(collider, handle, &mut physics.bodies); if let Some(graphics) = &mut graphics { graphics.add_body(handle, &physics.bodies, &physics.colliders); @@ -83,5 +81,5 @@ pub fn init_world(testbed: &mut Testbed) { // .physics_state_mut() // .integration_parameters // .velocity_based_erp = 0.2; - testbed.look_at(Point3::new(-30.0, 4.0, -30.0), Point3::new(0.0, 1.0, 0.0)); + testbed.look_at(point![-30.0, 4.0, -30.0], point![0.0, 1.0, 0.0]); } diff --git a/examples3d/harness_capsules3.rs b/examples3d/harness_capsules3.rs index 4632811..e2f19d5 100644 --- a/examples3d/harness_capsules3.rs +++ b/examples3d/harness_capsules3.rs @@ -1,7 +1,4 @@ -extern crate nalgebra as na; - -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::harness::Harness; pub fn init_world(harness: &mut Harness) { @@ -19,11 +16,11 @@ pub fn init_world(harness: &mut Harness) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -47,10 +44,12 @@ pub fn init_world(harness: &mut Harness) { let z = k as f32 * shift - centerz + offset; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::capsule_y(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } diff --git a/examples3d/heightfield3.rs b/examples3d/heightfield3.rs index 414ffdd..7f5979a 100644 --- a/examples3d/heightfield3.rs +++ b/examples3d/heightfield3.rs @@ -1,6 +1,5 @@ -use na::{ComplexField, DMatrix, Isometry3, Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape}; +use na::ComplexField; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Ground */ - let ground_size = Vector3::new(100.0, 1.0, 100.0); + let ground_size = Vector::new(100.0, 1.0, 100.0); let nsubdivs = 20; let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| { @@ -34,7 +33,7 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::heightfield(heights, ground_size).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -55,7 +54,9 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shift - centerz; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = match j % 6 { @@ -69,15 +70,15 @@ pub fn init_world(testbed: &mut Testbed) { _ => { let shapes = vec![ ( - Isometry3::identity(), + Isometry::identity(), SharedShape::cuboid(rad, rad / 2.0, rad / 2.0), ), ( - Isometry3::translation(rad, 0.0, 0.0), + Isometry::translation(rad, 0.0, 0.0), SharedShape::cuboid(rad / 2.0, rad, rad / 2.0), ), ( - Isometry3::translation(-rad, 0.0, 0.0), + Isometry::translation(-rad, 0.0, 0.0), SharedShape::cuboid(rad / 2.0, rad, rad / 2.0), ), ]; @@ -86,7 +87,7 @@ pub fn init_world(testbed: &mut Testbed) { } }; - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -95,5 +96,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/examples3d/joints3.rs b/examples3d/joints3.rs index c7f8a1c..e22f293 100644 --- a/examples3d/joints3.rs +++ b/examples3d/joints3.rs @@ -1,49 +1,44 @@ -use na::{Isometry3, Point3, Unit, UnitQuaternion, Vector3}; -use rapier3d::dynamics::{ - BallJoint, FixedJoint, JointSet, PrismaticJoint, RevoluteJoint, RigidBodyBuilder, - RigidBodyHandle, RigidBodySet, RigidBodyType, -}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; fn create_prismatic_joints( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, joints: &mut JointSet, - origin: Point3, + origin: Point, num: usize, ) { let rad = 0.4; let shift = 2.0; let ground = RigidBodyBuilder::new_static() - .translation(origin.x, origin.y, origin.z) + .translation(vector![origin.x, origin.y, origin.z]) .build(); let mut curr_parent = bodies.insert(ground); let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, curr_parent, bodies); + colliders.insert_with_parent(collider, curr_parent, bodies); for i in 0..num { let z = origin.z + (i + 1) as f32 * shift; let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(origin.x, origin.y, z) + .translation(vector![origin.x, origin.y, z]) .build(); let curr_child = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, curr_child, bodies); + colliders.insert_with_parent(collider, curr_child, bodies); let axis = if i % 2 == 0 { - Unit::new_normalize(Vector3::new(1.0, 1.0, 0.0)) + UnitVector::new_normalize(vector![1.0, 1.0, 0.0]) } else { - Unit::new_normalize(Vector3::new(-1.0, 1.0, 0.0)) + UnitVector::new_normalize(vector![-1.0, 1.0, 0.0]) }; - let z = Vector3::z(); + let z = Vector::z(); let mut prism = PrismaticJoint::new( - Point3::new(0.0, 0.0, 0.0), + point![0.0, 0.0, 0.0], axis, z, - Point3::new(0.0, 0.0, -shift), + point![0.0, 0.0, -shift], axis, z, ); @@ -61,40 +56,40 @@ fn create_actuated_prismatic_joints( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, joints: &mut JointSet, - origin: Point3, + origin: Point, num: usize, ) { let rad = 0.4; let shift = 2.0; let ground = RigidBodyBuilder::new_static() - .translation(origin.x, origin.y, origin.z) + .translation(vector![origin.x, origin.y, origin.z]) .build(); let mut curr_parent = bodies.insert(ground); let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, curr_parent, bodies); + colliders.insert_with_parent(collider, curr_parent, bodies); for i in 0..num { let z = origin.z + (i + 1) as f32 * shift; let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(origin.x, origin.y, z) + .translation(vector![origin.x, origin.y, z]) .build(); let curr_child = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, curr_child, bodies); + colliders.insert_with_parent(collider, curr_child, bodies); let axis = if i % 2 == 0 { - Unit::new_normalize(Vector3::new(1.0, 1.0, 0.0)) + UnitVector::new_normalize(vector![1.0, 1.0, 0.0]) } else { - Unit::new_normalize(Vector3::new(-1.0, 1.0, 0.0)) + UnitVector::new_normalize(vector![-1.0, 1.0, 0.0]) }; - let z = Vector3::z(); + let z = Vector::z(); let mut prism = PrismaticJoint::new( - Point3::new(0.0, 0.0, 0.0), + point![0.0, 0.0, 0.0], axis, z, - Point3::new(0.0, 0.0, -shift), + point![0.0, 0.0, -shift], axis, z, ); @@ -128,27 +123,27 @@ fn create_revolute_joints( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, joints: &mut JointSet, - origin: Point3, + origin: Point, num: usize, ) { let rad = 0.4; let shift = 2.0; let ground = RigidBodyBuilder::new_static() - .translation(origin.x, origin.y, 0.0) + .translation(vector![origin.x, origin.y, 0.0]) .build(); let mut curr_parent = bodies.insert(ground); let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, curr_parent, bodies); + colliders.insert_with_parent(collider, curr_parent, bodies); for i in 0..num { // Create four bodies. let z = origin.z + i as f32 * shift * 2.0 + shift; let positions = [ - Isometry3::translation(origin.x, origin.y, z), - Isometry3::translation(origin.x + shift, origin.y, z), - Isometry3::translation(origin.x + shift, origin.y, z + shift), - Isometry3::translation(origin.x, origin.y, z + shift), + Isometry::translation(origin.x, origin.y, z), + Isometry::translation(origin.x + shift, origin.y, z), + Isometry::translation(origin.x + shift, origin.y, z + shift), + Isometry::translation(origin.x, origin.y, z + shift), ]; let mut handles = [curr_parent; 4]; @@ -158,19 +153,19 @@ fn create_revolute_joints( .build(); handles[k] = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, handles[k], bodies); + colliders.insert_with_parent(collider, handles[k], bodies); } // Setup four joints. - let o = Point3::origin(); - let x = Vector3::x_axis(); - let z = Vector3::z_axis(); + let o = Point::origin(); + let x = Vector::x_axis(); + let z = Vector::z_axis(); let revs = [ - RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z), - RevoluteJoint::new(o, x, Point3::new(-shift, 0.0, 0.0), x), - RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z), - RevoluteJoint::new(o, x, Point3::new(shift, 0.0, 0.0), x), + RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z), + RevoluteJoint::new(o, x, point![-shift, 0.0, 0.0], x), + RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z), + RevoluteJoint::new(o, x, point![shift, 0.0, 0.0], x), ]; joints.insert(bodies, curr_parent, handles[0], revs[0]); @@ -186,7 +181,7 @@ fn create_fixed_joints( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, joints: &mut JointSet, - origin: Point3, + origin: Point, num: usize, ) { let rad = 0.4; @@ -209,18 +204,22 @@ fn create_fixed_joints( }; let rigid_body = RigidBodyBuilder::new(status) - .translation(origin.x + fk * shift, origin.y, origin.z + fi * shift) + .translation(vector![ + origin.x + fk * shift, + origin.y, + origin.z + fi * shift + ]) .build(); let child_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, child_handle, bodies); + colliders.insert_with_parent(collider, child_handle, bodies); // Vertical joint. if i > 0 { let parent_handle = *body_handles.last().unwrap(); let joint = FixedJoint::new( - Isometry3::identity(), - Isometry3::translation(0.0, 0.0, -shift), + Isometry::identity(), + Isometry::translation(0.0, 0.0, -shift), ); joints.insert(bodies, parent_handle, child_handle, joint); } @@ -230,8 +229,8 @@ fn create_fixed_joints( let parent_index = body_handles.len() - num; let parent_handle = body_handles[parent_index]; let joint = FixedJoint::new( - Isometry3::identity(), - Isometry3::translation(-shift, 0.0, 0.0), + Isometry::identity(), + Isometry::translation(-shift, 0.0, 0.0), ); joints.insert(bodies, parent_handle, child_handle, joint); } @@ -264,16 +263,16 @@ fn create_ball_joints( }; let rigid_body = RigidBodyBuilder::new(status) - .translation(fk * shift, 0.0, fi * shift * 2.0) + .translation(vector![fk * shift, 0.0, fi * shift * 2.0]) .build(); let child_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::capsule_z(rad * 1.25, rad).build(); - colliders.insert(collider, child_handle, bodies); + colliders.insert_with_parent(collider, child_handle, bodies); // Vertical joint. if i > 0 { let parent_handle = *body_handles.last().unwrap(); - let joint = BallJoint::new(Point3::origin(), Point3::new(0.0, 0.0, -shift * 2.0)); + let joint = BallJoint::new(Point::origin(), point![0.0, 0.0, -shift * 2.0]); joints.insert(bodies, parent_handle, child_handle, joint); } @@ -281,7 +280,7 @@ fn create_ball_joints( if k > 0 { let parent_index = body_handles.len() - num; let parent_handle = body_handles[parent_index]; - let joint = BallJoint::new(Point3::origin(), Point3::new(-shift, 0.0, 0.0)); + let joint = BallJoint::new(Point::origin(), point![-shift, 0.0, 0.0]); joints.insert(bodies, parent_handle, child_handle, joint); } @@ -294,7 +293,7 @@ fn create_actuated_revolute_joints( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, joints: &mut JointSet, - origin: Point3, + origin: Point, num: usize, ) { let rad = 0.4; @@ -302,10 +301,10 @@ fn create_actuated_revolute_joints( // We will reuse this base configuration for all the joints here. let joint_template = RevoluteJoint::new( - Point3::origin(), - Vector3::z_axis(), - Point3::new(0.0, 0.0, -shift), - Vector3::z_axis(), + Point::origin(), + Vector::z_axis(), + point![0.0, 0.0, -shift], + Vector::z_axis(), ); let mut parent_handle = RigidBodyHandle::invalid(); @@ -325,13 +324,13 @@ fn create_actuated_revolute_joints( let shifty = (i >= 1) as u32 as f32 * -2.0; let rigid_body = RigidBodyBuilder::new(status) - .translation(origin.x, origin.y + shifty, origin.z + fi * shift) + .translation(vector![origin.x, origin.y + shifty, origin.z + fi * shift]) // .rotation(Vector3::new(0.0, fi * 1.1, 0.0)) .build(); let child_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad * 2.0, rad * 6.0 / (fi + 1.0), rad).build(); - colliders.insert(collider, child_handle, bodies); + colliders.insert_with_parent(collider, child_handle, bodies); if i > 0 { let mut joint = joint_template.clone(); @@ -360,14 +359,14 @@ fn create_actuated_ball_joints( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, joints: &mut JointSet, - origin: Point3, + origin: Point, num: usize, ) { let rad = 0.4; let shift = 2.0; // We will reuse this base configuration for all the joints here. - let joint_template = BallJoint::new(Point3::new(0.0, 0.0, shift), Point3::origin()); + let joint_template = BallJoint::new(point![0.0, 0.0, shift], Point::origin()); let mut parent_handle = RigidBodyHandle::invalid(); @@ -384,24 +383,24 @@ fn create_actuated_ball_joints( }; let rigid_body = RigidBodyBuilder::new(status) - .translation(origin.x, origin.y, origin.z + fi * shift) + .translation(vector![origin.x, origin.y, origin.z + fi * shift]) // .rotation(Vector3::new(0.0, fi * 1.1, 0.0)) .build(); let child_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::capsule_y(rad * 2.0 / (fi + 1.0), rad).build(); - colliders.insert(collider, child_handle, bodies); + colliders.insert_with_parent(collider, child_handle, bodies); if i > 0 { let mut joint = joint_template.clone(); if i == 1 { - joint.configure_motor_velocity(Vector3::new(0.0, 0.5, -2.0), 0.1); + joint.configure_motor_velocity(vector![0.0, 0.5, -2.0], 0.1); } else if i == num - 1 { let stiffness = 0.2; let damping = 1.0; joint.configure_motor_position( - UnitQuaternion::new(Vector3::new(0.0, 1.0, 3.14 / 2.0)), + Rotation::new(vector![0.0, 1.0, 3.14 / 2.0]), stiffness, damping, ); @@ -426,42 +425,42 @@ pub fn init_world(testbed: &mut Testbed) { &mut bodies, &mut colliders, &mut joints, - Point3::new(20.0, 5.0, 0.0), + point![20.0, 5.0, 0.0], 4, ); create_actuated_prismatic_joints( &mut bodies, &mut colliders, &mut joints, - Point3::new(25.0, 5.0, 0.0), + point![25.0, 5.0, 0.0], 4, ); create_revolute_joints( &mut bodies, &mut colliders, &mut joints, - Point3::new(20.0, 0.0, 0.0), + point![20.0, 0.0, 0.0], 3, ); create_fixed_joints( &mut bodies, &mut colliders, &mut joints, - Point3::new(0.0, 10.0, 0.0), + point![0.0, 10.0, 0.0], 10, ); create_actuated_revolute_joints( &mut bodies, &mut colliders, &mut joints, - Point3::new(20.0, 10.0, 0.0), + point![20.0, 10.0, 0.0], 6, ); create_actuated_ball_joints( &mut bodies, &mut colliders, &mut joints, - Point3::new(13.0, 10.0, 0.0), + point![13.0, 10.0, 0.0], 3, ); create_ball_joints(&mut bodies, &mut colliders, &mut joints, 15); @@ -470,5 +469,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(15.0, 5.0, 42.0), Point3::new(13.0, 1.0, 1.0)); + testbed.look_at(point![15.0, 5.0, 42.0], point![13.0, 1.0, 1.0]); } diff --git a/examples3d/keva3.rs b/examples3d/keva3.rs index 9e6807a..38a0432 100644 --- a/examples3d/keva3.rs +++ b/examples3d/keva3.rs @@ -1,14 +1,12 @@ -use na::{Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn build_block( testbed: &mut Testbed, bodies: &mut RigidBodySet, colliders: &mut ColliderSet, - half_extents: Vector3, - shift: Vector3, + half_extents: Vector, + shift: Vector, mut numx: usize, numy: usize, mut numz: usize, @@ -17,8 +15,8 @@ pub fn build_block( let block_width = 2.0 * half_extents.z * numx as f32; let block_height = 2.0 * half_extents.y * numy as f32; let spacing = (half_extents.z * numx as f32 - half_extents.x) / (numz as f32 - 1.0); - let mut color0 = Point3::new(0.7, 0.5, 0.9); - let mut color1 = Point3::new(0.6, 1.0, 0.6); + let mut color0 = [0.7, 0.5, 0.9]; + let mut color1 = [0.6, 1.0, 0.6]; for i in 0..numy { std::mem::swap(&mut numx, &mut numz); @@ -41,15 +39,15 @@ pub fn build_block( // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation( + .translation(vector![ x + dim.x + shift.x, y + dim.y + shift.y, - z + dim.z + shift.z, - ) + z + dim.z + shift.z + ]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build(); - colliders.insert(collider, handle, bodies); + colliders.insert_with_parent(collider, handle, bodies); testbed.set_initial_body_color(handle, color0); std::mem::swap(&mut color0, &mut color1); @@ -64,15 +62,15 @@ pub fn build_block( for j in 0..(block_width / (dim.z as f32 * 2.0)) as usize { // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation( + .translation(vector![ i as f32 * dim.x * 2.0 + dim.x + shift.x, dim.y + shift.y + block_height, - j as f32 * dim.z * 2.0 + dim.z + shift.z, - ) + j as f32 * dim.z * 2.0 + dim.z + shift.z + ]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build(); - colliders.insert(collider, handle, bodies); + colliders.insert_with_parent(collider, handle, bodies); testbed.set_initial_body_color(handle, color0); std::mem::swap(&mut color0, &mut color1); } @@ -94,16 +92,16 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes */ - let half_extents = Vector3::new(0.02, 0.1, 0.4) / 2.0 * 10.0; + let half_extents = vector![0.02, 0.1, 0.4] / 2.0 * 10.0; let mut block_height = 0.0; // These should only be set to odd values otherwise // the blocks won't align in the nicest way. @@ -120,7 +118,7 @@ pub fn init_world(testbed: &mut Testbed) { &mut bodies, &mut colliders, half_extents, - Vector3::new(-block_width / 2.0, block_height, -block_width / 2.0), + vector![-block_width / 2.0, block_height, -block_width / 2.0], numx, numy, numz, @@ -135,5 +133,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/examples3d/locked_rotations3.rs b/examples3d/locked_rotations3.rs index 9748c17..95dfae1 100644 --- a/examples3d/locked_rotations3.rs +++ b/examples3d/locked_rotations3.rs @@ -1,6 +1,4 @@ -use na::{Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; // This shows a bug when a cylinder is in contact with a very large @@ -21,41 +19,41 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * A rectangle that only rotates along the `x` axis. */ let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 3.0, 0.0) + .translation(vector![0.0, 3.0, 0.0]) .lock_translations() .restrict_rotations(true, false, false) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(0.2, 0.6, 2.0).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * A tilted capsule that cannot rotate. */ let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 5.0, 0.0) - .rotation(Vector3::x() * 1.0) + .translation(vector![0.0, 5.0, 0.0]) + .rotation(Vector::x() * 1.0) .lock_rotations() .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::capsule_y(0.6, 0.4).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let collider = ColliderBuilder::capsule_x(0.6, 0.4).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(10.0, 3.0, 0.0), Point3::new(0.0, 3.0, 0.0)); + testbed.look_at(point![10.0, 3.0, 0.0], point![0.0, 3.0, 0.0]); } diff --git a/examples3d/one_way_platforms3.rs b/examples3d/one_way_platforms3.rs index 7933f78..e4b533e 100644 --- a/examples3d/one_way_platforms3.rs +++ b/examples3d/one_way_platforms3.rs @@ -1,7 +1,4 @@ -use na::{Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderHandle, ColliderSet}; -use rapier3d::pipeline::{ContactModificationContext, PhysicsHooks, PhysicsHooksFlags}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; struct OneWayPlatformHook { @@ -10,10 +7,6 @@ struct OneWayPlatformHook { } impl PhysicsHooks for OneWayPlatformHook { - fn active_hooks(&self) -> PhysicsHooksFlags { - PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS - } - fn modify_solver_contacts( &self, context: &mut ContactModificationContext, @@ -30,20 +23,20 @@ impl PhysicsHooks for OneWayPlatformHook { // - If context.collider2 == self.platform1 then the allowed normal is -y. // - If context.collider1 == self.platform2 then its allowed normal +y needs to be flipped to -y. // - If context.collider2 == self.platform2 then the allowed normal -y needs to be flipped to +y. - let mut allowed_local_n1 = Vector3::zeros(); + let mut allowed_local_n1 = Vector::zeros(); if context.collider1 == self.platform1 { - allowed_local_n1 = Vector3::y(); + allowed_local_n1 = Vector::y(); } else if context.collider2 == self.platform1 { // Flip the allowed direction. - allowed_local_n1 = -Vector3::y(); + allowed_local_n1 = -Vector::y(); } if context.collider1 == self.platform2 { - allowed_local_n1 = -Vector3::y(); + allowed_local_n1 = -Vector::y(); } else if context.collider2 == self.platform2 { // Flip the allowed direction. - allowed_local_n1 = Vector3::y(); + allowed_local_n1 = Vector::y(); } // Call the helper function that simulates one-way platforms. @@ -78,15 +71,15 @@ pub fn init_world(testbed: &mut Testbed) { let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(9.0, 0.5, 25.0) - .translation(0.0, 2.0, 30.0) - .modify_solver_contacts(true) + .translation(vector![0.0, 2.0, 30.0]) + .active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS) .build(); - let platform1 = colliders.insert(collider, handle, &mut bodies); + let platform1 = colliders.insert_with_parent(collider, handle, &mut bodies); let collider = ColliderBuilder::cuboid(9.0, 0.5, 25.0) - .translation(0.0, -2.0, -30.0) - .modify_solver_contacts(true) + .translation(vector![0.0, -2.0, -30.0]) + .active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS) .build(); - let platform2 = colliders.insert(collider, handle, &mut bodies); + let platform2 = colliders.insert_with_parent(collider, handle, &mut bodies); /* * Setup the one-way platform hook. @@ -105,12 +98,12 @@ pub fn init_world(testbed: &mut Testbed) { // Spawn a new cube. let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.5).build(); let body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 6.0, 20.0) + .translation(vector![0.0, 6.0, 20.0]) .build(); let handle = physics.bodies.insert(body); physics .colliders - .insert(collider, handle, &mut physics.bodies); + .insert_with_parent(collider, handle, &mut physics.bodies); if let Some(graphics) = graphics { graphics.add_body(handle, &physics.bodies, &physics.colliders); @@ -134,8 +127,8 @@ pub fn init_world(testbed: &mut Testbed) { bodies, colliders, joints, - Vector3::new(0.0, -9.81, 0.0), + vector![0.0, -9.81, 0.0], physics_hooks, ); - testbed.look_at(Point3::new(-100.0, 0.0, 0.0), Point3::origin()); + testbed.look_at(point![-100.0, 0.0, 0.0], Point::origin()); } diff --git a/examples3d/platform3.rs b/examples3d/platform3.rs index 786ddbf..251e0d1 100644 --- a/examples3d/platform3.rs +++ b/examples3d/platform3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the boxes @@ -43,10 +41,12 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shift - centerz; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -55,11 +55,11 @@ pub fn init_world(testbed: &mut Testbed) { * Setup a kinematic rigid body. */ let platform_body = RigidBodyBuilder::new_kinematic() - .translation(0.0, 1.5 + 0.8, -10.0 * rad) + .translation(vector![0.0, 1.5 + 0.8, -10.0 * rad]) .build(); let platform_handle = bodies.insert(platform_body); let collider = ColliderBuilder::cuboid(rad * 10.0, rad, rad * 10.0).build(); - colliders.insert(collider, platform_handle, &mut bodies); + colliders.insert_with_parent(collider, platform_handle, &mut bodies); /* * Setup a callback to control the platform. @@ -93,5 +93,5 @@ pub fn init_world(testbed: &mut Testbed) { * Run the simulation. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(-10.0, 5.0, -10.0), Point3::origin()); + testbed.look_at(point![-10.0, 5.0, -10.0], Point::origin()); } diff --git a/examples3d/primitives3.rs b/examples3d/primitives3.rs index afa5dfd..db9143b 100644 --- a/examples3d/primitives3.rs +++ b/examples3d/primitives3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 2.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the primitives @@ -47,7 +45,9 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shiftz - centerz + offset; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = match j % 5 { @@ -60,7 +60,7 @@ pub fn init_world(testbed: &mut Testbed) { _ => ColliderBuilder::capsule_y(rad, rad).build(), }; - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -71,5 +71,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/examples3d/restitution3.rs b/examples3d/restitution3.rs index 8fa3275..4c08742 100644 --- a/examples3d/restitution3.rs +++ b/examples3d/restitution3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,13 +16,13 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 1.0; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![0.0, -ground_height, 0.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height, 2.0) .restitution(1.0) .build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let num = 10; let rad = 0.5; @@ -33,13 +31,13 @@ pub fn init_world(testbed: &mut Testbed) { for i in 0..=num { let x = (i as f32) - num as f32 / 2.0; let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(x * 2.0, 10.0 * (j as f32 + 1.0), 0.0) + .translation(vector![x * 2.0, 10.0 * (j as f32 + 1.0), 0.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad) .restitution((i as f32) / (num as f32)) .build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -47,5 +45,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(0.0, 3.0, 30.0), Point3::new(0.0, 3.0, 0.0)); + testbed.look_at(point![0.0, 3.0, 30.0], point![0.0, 3.0, 0.0]); } diff --git a/examples3d/sensor3.rs b/examples3d/sensor3.rs index e55bf72..1a3fc75 100644 --- a/examples3d/sensor3.rs +++ b/examples3d/sensor3.rs @@ -1,6 +1,4 @@ -use na::Point3; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) + .translation(vector![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); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Create some boxes. @@ -41,12 +39,14 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shift - centerz; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); - testbed.set_initial_body_color(handle, Point3::new(0.5, 0.5, 1.0)); + testbed.set_initial_body_color(handle, [0.5, 0.5, 1.0]); } } @@ -56,33 +56,36 @@ pub fn init_world(testbed: &mut Testbed) { // Rigid body so that the sensor can move. let sensor = RigidBodyBuilder::new_dynamic() - .translation(0.0, 5.0, 0.0) + .translation(vector![0.0, 5.0, 0.0]) .build(); let sensor_handle = bodies.insert(sensor); // Solid cube attached to the sensor which // other colliders can touch. let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); - colliders.insert(collider, sensor_handle, &mut bodies); + colliders.insert_with_parent(collider, sensor_handle, &mut bodies); // We create a collider desc without density because we don't // want it to contribute to the rigid body mass. - let sensor_collider = ColliderBuilder::ball(rad * 5.0).sensor(true).build(); - colliders.insert(sensor_collider, sensor_handle, &mut bodies); + let sensor_collider = ColliderBuilder::ball(rad * 5.0) + .density(0.0) + .sensor(true) + .build(); + colliders.insert_with_parent(sensor_collider, sensor_handle, &mut bodies); - testbed.set_initial_body_color(sensor_handle, Point3::new(0.5, 1.0, 1.0)); + testbed.set_initial_body_color(sensor_handle, [0.5, 1.0, 1.0]); // 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) + [1.0, 1.0, 0.0] } else { - Point3::new(0.5, 0.5, 1.0) + [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(); + let parent_handle1 = physics.colliders[prox.collider1].parent().unwrap(); + let parent_handle2 = physics.colliders[prox.collider2].parent().unwrap(); if let Some(graphics) = &mut graphics { if parent_handle1 != ground_handle && parent_handle1 != sensor_handle { @@ -99,5 +102,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(-6.0, 4.0, -6.0), Point3::new(0.0, 1.0, 0.0)); + testbed.look_at(point![-6.0, 4.0, -6.0], point![0.0, 1.0, 0.0]); } diff --git a/examples3d/trimesh3.rs b/examples3d/trimesh3.rs index 2a4bd24..23e4090 100644 --- a/examples3d/trimesh3.rs +++ b/examples3d/trimesh3.rs @@ -1,6 +1,5 @@ -use na::{ComplexField, DMatrix, Isometry3, Point3, Vector3}; -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet, HeightField, SharedShape}; +use na::ComplexField; +use rapier3d::prelude::*; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Ground */ - let ground_size = Vector3::new(100.0, 1.0, 100.0); + let ground_size = vector![100.0, 1.0, 100.0]; let nsubdivs = 20; let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| { @@ -39,7 +38,7 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::trimesh(vertices, indices).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -60,7 +59,9 @@ pub fn init_world(testbed: &mut Testbed) { let z = k as f32 * shift - centerz; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y, z]) + .build(); let handle = bodies.insert(rigid_body); let collider = match j % 6 { @@ -74,15 +75,15 @@ pub fn init_world(testbed: &mut Testbed) { _ => { let shapes = vec![ ( - Isometry3::identity(), + Isometry::identity(), SharedShape::cuboid(rad, rad / 2.0, rad / 2.0), ), ( - Isometry3::translation(rad, 0.0, 0.0), + Isometry::translation(rad, 0.0, 0.0), SharedShape::cuboid(rad / 2.0, rad, rad / 2.0), ), ( - Isometry3::translation(-rad, 0.0, 0.0), + Isometry::translation(-rad, 0.0, 0.0), SharedShape::cuboid(rad / 2.0, rad, rad / 2.0), ), ]; @@ -91,7 +92,7 @@ pub fn init_world(testbed: &mut Testbed) { } }; - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -100,5 +101,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); + testbed.look_at(point![100.0, 100.0, 100.0], Point::origin()); } diff --git a/src/data/coarena.rs b/src/data/coarena.rs index cd64910..ac6e43f 100644 --- a/src/data/coarena.rs +++ b/src/data/coarena.rs @@ -13,6 +13,14 @@ impl Coarena { Self { data: Vec::new() } } + /// Gets a specific element from the coarena without specifying its generation number. + /// + /// It is strongly encouraged to use `Coarena::get` instead of this method because this method + /// can suffer from the ABA problem. + pub fn get_unknown_gen(&self, index: u32) -> Option<&T> { + self.data.get(index as usize).map(|(_, t)| t) + } + /// Gets a specific element from the coarena, if it exists. pub fn get(&self, index: Index) -> Option<&T> { let (i, g) = index.into_raw_parts(); diff --git a/src/dynamics/integration_parameters.rs b/src/dynamics/integration_parameters.rs index e039bfc..4725319 100644 --- a/src/dynamics/integration_parameters.rs +++ b/src/dynamics/integration_parameters.rs @@ -10,7 +10,7 @@ pub struct IntegrationParameters { /// /// When CCD with multiple substeps is enabled, the timestep is subdivided /// into smaller pieces. This timestep subdivision won't generate timestep - /// lengths smaller than `min_dt`. + /// lengths smaller than `min_ccd_dt`. /// /// Setting this to a large value will reduce the opportunity to performing /// CCD substepping, resulting in potentially more time dropped by the @@ -18,17 +18,6 @@ pub struct IntegrationParameters { /// to numerical instabilities. pub min_ccd_dt: Real, - // /// If `true` and if rapier is compiled with the `parallel` feature, this will enable rayon-based multithreading (default: `true`). - // /// - // /// This parameter is ignored if rapier is not compiled with is `parallel` feature. - // /// Refer to rayon's documentation regarding how to configure the number of threads with either - // /// `rayon::ThreadPoolBuilder::new().num_threads(4).build_global().unwrap()` or `ThreadPool::install`. - // /// Note that using only one thread with `multithreading_enabled` set to `true` will result on a slower - // /// simulation than setting `multithreading_enabled` to `false`. - // pub multithreading_enabled: bool, - // /// If `true`, the world's `step` method will stop right after resolving exactly one CCD event (default: `false`). - // /// This allows the user to take action during a timestep, in-between two CCD events. - // pub return_after_ccd_substep: bool, /// The Error Reduction Parameter in `[0, 1]` is the proportion of /// the positional error to be corrected at each time step (default: `0.2`). pub erp: Real, diff --git a/src/dynamics/joint/fixed_joint.rs b/src/dynamics/joint/fixed_joint.rs index 2917757..3f87e8d 100644 --- a/src/dynamics/joint/fixed_joint.rs +++ b/src/dynamics/joint/fixed_joint.rs @@ -8,10 +8,10 @@ use crate::math::{Isometry, Real, SpacialVector}; pub struct FixedJoint { /// The frame of reference for the first body affected by this joint, expressed in the local frame /// of the first body. - pub local_anchor1: Isometry, + pub local_frame1: Isometry, /// The frame of reference for the second body affected by this joint, expressed in the local frame /// of the first body. - pub local_anchor2: Isometry, + pub local_frame2: Isometry, /// The impulse applied to the first body affected by this joint. /// /// The impulse applied to the second body affected by this joint is given by `-impulse`. @@ -23,10 +23,10 @@ pub struct FixedJoint { impl FixedJoint { /// Creates a new fixed joint from the frames of reference of both bodies. - pub fn new(local_anchor1: Isometry, local_anchor2: Isometry) -> Self { + pub fn new(local_frame1: Isometry, local_frame2: Isometry) -> Self { Self { - local_anchor1, - local_anchor2, + local_frame1, + local_frame2, impulse: SpacialVector::zeros(), } } diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index 824ec92..d53ff98 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -124,6 +124,72 @@ impl RigidBody { self.rb_dominance.effective_group(&self.rb_type) } + #[inline] + /// Locks or unlocks all the rotations of this rigid-body. + pub fn lock_rotations(&mut self, locked: bool, wake_up: bool) { + if self.is_dynamic() { + if wake_up { + self.wake_up(true); + } + + self.rb_mprops + .flags + .set(RigidBodyMassPropsFlags::ROTATION_LOCKED_X, locked); + self.rb_mprops + .flags + .set(RigidBodyMassPropsFlags::ROTATION_LOCKED_Y, locked); + self.rb_mprops + .flags + .set(RigidBodyMassPropsFlags::ROTATION_LOCKED_Z, locked); + self.update_world_mass_properties(); + } + } + + #[inline] + /// Locks or unlocks rotations of this rigid-body along each cartesian axes. + pub fn restrict_rotations( + &mut self, + allow_rotations_x: bool, + allow_rotations_y: bool, + allow_rotations_z: bool, + wake_up: bool, + ) { + if self.is_dynamic() { + if wake_up { + self.wake_up(true); + } + + self.rb_mprops.flags.set( + RigidBodyMassPropsFlags::ROTATION_LOCKED_X, + allow_rotations_x, + ); + self.rb_mprops.flags.set( + RigidBodyMassPropsFlags::ROTATION_LOCKED_Y, + allow_rotations_y, + ); + self.rb_mprops.flags.set( + RigidBodyMassPropsFlags::ROTATION_LOCKED_Z, + allow_rotations_z, + ); + self.update_world_mass_properties(); + } + } + + #[inline] + /// Locks or unlocks all the rotations of this rigid-body. + pub fn lock_translations(&mut self, locked: bool, wake_up: bool) { + if self.is_dynamic() { + if wake_up { + self.wake_up(true); + } + + self.rb_mprops + .flags + .set(RigidBodyMassPropsFlags::TRANSLATION_LOCKED, locked); + self.update_world_mass_properties(); + } + } + /// Are the translations of this rigid-body locked? pub fn is_translation_locked(&self) -> bool { self.rb_mprops @@ -251,6 +317,16 @@ impl RigidBody { self.rb_forces.gravity_scale = scale; } + /// The dominance group of this rigid-body. + pub fn dominance_group(&self) -> i8 { + self.rb_dominance.0 + } + + /// The dominance group of this rigid-body. + pub fn set_dominance_group(&mut self, dominance: i8) { + self.rb_dominance.0 = dominance + } + /// Adds a collider to this rigid-body. // TODO ECS: we keep this public for now just to simply our experiments on bevy_rapier. pub fn add_collider( @@ -279,9 +355,10 @@ impl RigidBody { if let Some(i) = self.rb_colliders.0.iter().position(|e| *e == handle) { self.changes.set(RigidBodyChanges::COLLIDERS, true); self.rb_colliders.0.swap_remove(i); + let mass_properties = coll .mass_properties() - .transform_by(coll.position_wrt_parent()); + .transform_by(coll.position_wrt_parent().unwrap()); self.rb_mprops.mass_properties -= mass_properties; self.update_world_mass_properties(); } @@ -384,6 +461,45 @@ impl RigidBody { &self.rb_pos.position } + /// The translational part of this rigid-body's position. + #[inline] + pub fn translation(&self) -> Vector { + self.rb_pos.position.translation.vector + } + + /// Sets the translational part of this rigid-body's position. + #[inline] + pub fn set_translation(&mut self, translation: Vector, wake_up: bool) { + self.changes.insert(RigidBodyChanges::POSITION); + self.rb_pos.position.translation.vector = translation; + self.rb_pos.next_position.translation.vector = translation; + + // TODO: Do we really need to check that the body isn't dynamic? + if wake_up && self.is_dynamic() { + self.wake_up(true) + } + } + + /// The translational part of this rigid-body's position. + #[inline] + pub fn rotation(&self) -> Rotation { + self.rb_pos.position.rotation + } + + /// Sets the rotational part of this rigid-body's position. + #[inline] + pub fn set_rotation(&mut self, rotation: AngVector, wake_up: bool) { + self.changes.insert(RigidBodyChanges::POSITION); + let rotation = Rotation::new(rotation); + self.rb_pos.position.rotation = rotation; + self.rb_pos.next_position.rotation = rotation; + + // TODO: Do we really need to check that the body isn't dynamic? + if wake_up && self.is_dynamic() { + self.wake_up(true) + } + } + /// Sets the position and `next_kinematic_position` of this rigid body. /// /// This will teleport the rigid-body to the specified position/orientation, @@ -404,6 +520,20 @@ impl RigidBody { } } + /// If this rigid body is kinematic, sets its future translation after the next timestep integration. + pub fn set_next_kinematic_rotation(&mut self, rotation: AngVector) { + if self.is_kinematic() { + self.rb_pos.next_position.rotation = Rotation::new(rotation); + } + } + + /// If this rigid body is kinematic, sets its future orientation after the next timestep integration. + pub fn set_next_kinematic_translation(&mut self, rotation: Rotation) { + if self.is_kinematic() { + self.rb_pos.next_position.rotation = rotation; + } + } + /// If this rigid body is kinematic, sets its future position after the next timestep integration. pub fn set_next_kinematic_position(&mut self, pos: Isometry) { if self.is_kinematic() { @@ -411,6 +541,17 @@ impl RigidBody { } } + /// Predicts the next position of this rigid-body, by integrating its velocity and forces + /// by a time of `dt`. + pub fn predict_position_using_velocity_and_forces(&self, dt: Real) -> Isometry { + self.rb_pos.integrate_forces_and_velocities( + dt, + &self.rb_forces, + &self.rb_vels, + &self.rb_mprops, + ) + } + pub(crate) fn update_world_mass_properties(&mut self) { self.rb_mprops .update_world_mass_properties(&self.rb_pos.position); @@ -618,8 +759,8 @@ impl RigidBodyBuilder { } /// Sets the scale applied to the gravity force affecting the rigid-body to be created. - pub fn gravity_scale(mut self, x: Real) -> Self { - self.gravity_scale = x; + pub fn gravity_scale(mut self, scale_factor: Real) -> Self { + self.gravity_scale = scale_factor; self } @@ -630,19 +771,8 @@ impl RigidBodyBuilder { } /// Sets the initial translation of the rigid-body to be created. - #[cfg(feature = "dim2")] - pub fn translation(mut self, x: Real, y: Real) -> Self { - self.position.translation.x = x; - self.position.translation.y = y; - self - } - - /// Sets the initial translation of the rigid-body to be created. - #[cfg(feature = "dim3")] - pub fn translation(mut self, x: Real, y: Real, z: Real) -> Self { - self.position.translation.x = x; - self.position.translation.y = y; - self.position.translation.z = z; + pub fn translation(mut self, translation: Vector) -> Self { + self.position.translation.vector = translation; self } @@ -811,16 +941,8 @@ impl RigidBodyBuilder { } /// Sets the initial linear velocity of the rigid-body to be created. - #[cfg(feature = "dim2")] - pub fn linvel(mut self, x: Real, y: Real) -> Self { - self.linvel = Vector::new(x, y); - self - } - - /// Sets the initial linear velocity of the rigid-body to be created. - #[cfg(feature = "dim3")] - pub fn linvel(mut self, x: Real, y: Real, z: Real) -> Self { - self.linvel = Vector::new(x, y, z); + pub fn linvel(mut self, linvel: Vector) -> Self { + self.linvel = linvel; self } diff --git a/src/dynamics/solver/joint_constraint/fixed_position_constraint.rs b/src/dynamics/solver/joint_constraint/fixed_position_constraint.rs index 239138f..f8945c3 100644 --- a/src/dynamics/solver/joint_constraint/fixed_position_constraint.rs +++ b/src/dynamics/solver/joint_constraint/fixed_position_constraint.rs @@ -8,8 +8,8 @@ use crate::utils::WAngularInertia; pub(crate) struct FixedPositionConstraint { position1: usize, position2: usize, - local_anchor1: Isometry, - local_anchor2: Isometry, + local_frame1: Isometry, + local_frame2: Isometry, local_com1: Point, local_com2: Point, im1: Real, @@ -38,8 +38,8 @@ impl FixedPositionConstraint { let ang_inv_lhs = (ii1 + ii2).inverse(); Self { - local_anchor1: cparams.local_anchor1, - local_anchor2: cparams.local_anchor2, + local_frame1: cparams.local_frame1, + local_frame2: cparams.local_frame2, position1: ids1.active_set_offset, position2: ids2.active_set_offset, im1, @@ -58,8 +58,8 @@ impl FixedPositionConstraint { let mut position2 = positions[self.position2 as usize]; // Angular correction. - let anchor1 = position1 * self.local_anchor1; - let anchor2 = position2 * self.local_anchor2; + let anchor1 = position1 * self.local_frame1; + let anchor2 = position2 * self.local_frame2; let ang_err = anchor2.rotation * anchor1.rotation.inverse(); #[cfg(feature = "dim3")] let ang_impulse = self @@ -75,8 +75,8 @@ impl FixedPositionConstraint { Rotation::new(self.ii2.transform_vector(-ang_impulse)) * position2.rotation; // Linear correction. - let anchor1 = position1 * Point::from(self.local_anchor1.translation.vector); - let anchor2 = position2 * Point::from(self.local_anchor2.translation.vector); + let anchor1 = position1 * Point::from(self.local_frame1.translation.vector); + let anchor2 = position2 * Point::from(self.local_frame2.translation.vector); let err = anchor2 - anchor1; let impulse = err * (self.lin_inv_lhs * params.joint_erp); position1.translation.vector += self.im1 * impulse; @@ -91,7 +91,7 @@ impl FixedPositionConstraint { pub(crate) struct FixedPositionGroundConstraint { position2: usize, anchor1: Isometry, - local_anchor2: Isometry, + local_frame2: Isometry, local_com2: Point, im2: Real, ii2: AngularInertia, @@ -109,19 +109,19 @@ impl FixedPositionGroundConstraint { let (mprops2, ids2) = rb2; let anchor1; - let local_anchor2; + let local_frame2; if flipped { - anchor1 = poss1.next_position * cparams.local_anchor2; - local_anchor2 = cparams.local_anchor1; + anchor1 = poss1.next_position * cparams.local_frame2; + local_frame2 = cparams.local_frame1; } else { - anchor1 = poss1.next_position * cparams.local_anchor1; - local_anchor2 = cparams.local_anchor2; + anchor1 = poss1.next_position * cparams.local_frame1; + local_frame2 = cparams.local_frame2; }; Self { anchor1, - local_anchor2, + local_frame2, position2: ids2.active_set_offset, im2: mprops2.effective_inv_mass, ii2: mprops2.effective_world_inv_inertia_sqrt.squared(), @@ -134,13 +134,13 @@ impl FixedPositionGroundConstraint { let mut position2 = positions[self.position2 as usize]; // Angular correction. - let anchor2 = position2 * self.local_anchor2; + let anchor2 = position2 * self.local_frame2; let ang_err = anchor2.rotation * self.anchor1.rotation.inverse(); position2.rotation = ang_err.powf(-params.joint_erp) * position2.rotation; // Linear correction. let anchor1 = Point::from(self.anchor1.translation.vector); - let anchor2 = position2 * Point::from(self.local_anchor2.translation.vector); + let anchor2 = position2 * Point::from(self.local_frame2.translation.vector); let err = anchor2 - anchor1; // NOTE: no need to divide by im2 just to multiply right after. let impulse = err * params.joint_erp; diff --git a/src/dynamics/solver/joint_constraint/fixed_velocity_constraint.rs b/src/dynamics/solver/joint_constraint/fixed_velocity_constraint.rs index a0c0739..8bfc1a6 100644 --- a/src/dynamics/solver/joint_constraint/fixed_velocity_constraint.rs +++ b/src/dynamics/solver/joint_constraint/fixed_velocity_constraint.rs @@ -63,8 +63,8 @@ impl FixedVelocityConstraint { let (poss1, vels1, mprops1, ids1) = rb1; let (poss2, vels2, mprops2, ids2) = rb2; - let anchor1 = poss1.position * cparams.local_anchor1; - let anchor2 = poss2.position * cparams.local_anchor2; + let anchor1 = poss1.position * cparams.local_frame1; + let anchor2 = poss2.position * cparams.local_frame2; let im1 = mprops1.effective_inv_mass; let im2 = mprops2.effective_inv_mass; let ii1 = mprops1.effective_world_inv_inertia_sqrt.squared(); @@ -280,13 +280,13 @@ impl FixedVelocityGroundConstraint { let (anchor1, anchor2) = if flipped { ( - poss1.position * cparams.local_anchor2, - poss2.position * cparams.local_anchor1, + poss1.position * cparams.local_frame2, + poss2.position * cparams.local_frame1, ) } else { ( - poss1.position * cparams.local_anchor1, - poss2.position * cparams.local_anchor2, + poss1.position * cparams.local_frame1, + poss2.position * cparams.local_frame2, ) }; diff --git a/src/dynamics/solver/joint_constraint/fixed_velocity_constraint_wide.rs b/src/dynamics/solver/joint_constraint/fixed_velocity_constraint_wide.rs index 84e1fca..0421d49 100644 --- a/src/dynamics/solver/joint_constraint/fixed_velocity_constraint_wide.rs +++ b/src/dynamics/solver/joint_constraint/fixed_velocity_constraint_wide.rs @@ -91,12 +91,12 @@ impl WFixedVelocityConstraint { ]); let mj_lambda2 = gather![|ii| ids2[ii].active_set_offset]; - let local_anchor1 = Isometry::from(gather![|ii| cparams[ii].local_anchor1]); - let local_anchor2 = Isometry::from(gather![|ii| cparams[ii].local_anchor2]); + let local_frame1 = Isometry::from(gather![|ii| cparams[ii].local_frame1]); + let local_frame2 = Isometry::from(gather![|ii| cparams[ii].local_frame2]); let impulse = SpacialVector::from(gather![|ii| cparams[ii].impulse]); - let anchor1 = position1 * local_anchor1; - let anchor2 = position2 * local_anchor2; + let anchor1 = position1 * local_frame1; + let anchor2 = position2 * local_frame2; let ii1 = ii1_sqrt.squared(); let ii2 = ii2_sqrt.squared(); let r1 = anchor1.translation.vector - world_com1.coords; @@ -363,20 +363,20 @@ impl WFixedVelocityGroundConstraint { ]); let mj_lambda2 = gather![|ii| ids2[ii].active_set_offset]; - let local_anchor1 = Isometry::from(gather![|ii| if flipped[ii] { - cparams[ii].local_anchor2 + let local_frame1 = Isometry::from(gather![|ii| if flipped[ii] { + cparams[ii].local_frame2 } else { - cparams[ii].local_anchor1 + cparams[ii].local_frame1 }]); - let local_anchor2 = Isometry::from(gather![|ii| if flipped[ii] { - cparams[ii].local_anchor1 + let local_frame2 = Isometry::from(gather![|ii| if flipped[ii] { + cparams[ii].local_frame1 } else { - cparams[ii].local_anchor2 + cparams[ii].local_frame2 }]); let impulse = SpacialVector::from(gather![|ii| cparams[ii].impulse]); - let anchor1 = position1 * local_anchor1; - let anchor2 = position2 * local_anchor2; + let anchor1 = position1 * local_frame1; + let anchor2 = position2 * local_frame2; let ii2 = ii2_sqrt.squared(); let r1 = anchor1.translation.vector - world_com1.coords; let r2 = anchor2.translation.vector - world_com2.coords; diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index 08295c1..e73c518 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -2,10 +2,11 @@ use crate::dynamics::{CoefficientCombineRule, MassProperties, RigidBodyHandle}; use crate::geometry::{ ColliderBroadPhaseData, ColliderChanges, ColliderGroups, ColliderMassProperties, ColliderMaterial, ColliderParent, ColliderPosition, ColliderShape, ColliderType, - InteractionGroups, SharedShape, SolverFlags, + InteractionGroups, SharedShape, }; use crate::math::{AngVector, Isometry, Point, Real, Rotation, Vector, DIM}; use crate::parry::transformation::vhacd::VHACDParameters; +use crate::pipeline::PhysicsHooksFlags; use na::Unit; use parry::bounding_volume::AABB; use parry::shape::Shape; @@ -20,7 +21,7 @@ pub struct Collider { pub(crate) co_shape: ColliderShape, pub(crate) co_mprops: ColliderMassProperties, pub(crate) co_changes: ColliderChanges, - pub(crate) co_parent: ColliderParent, + pub(crate) co_parent: Option, pub(crate) co_pos: ColliderPosition, pub(crate) co_material: ColliderMaterial, pub(crate) co_groups: ColliderGroups, @@ -31,14 +32,14 @@ pub struct Collider { impl Collider { pub(crate) fn reset_internal_references(&mut self) { - self.co_parent.handle = RigidBodyHandle::invalid(); + self.co_parent = None; self.co_bf_data.proxy_index = crate::INVALID_U32; self.co_changes = ColliderChanges::all(); } /// The rigid body this collider is attached to. - pub fn parent(&self) -> RigidBodyHandle { - self.co_parent.handle + pub fn parent(&self) -> Option { + self.co_parent.map(|parent| parent.handle) } /// Is this collider a sensor? @@ -46,6 +47,26 @@ impl Collider { self.co_type.is_sensor() } + /// The physics hooks enabled for this collider. + pub fn active_hooks(&self) -> PhysicsHooksFlags { + self.co_material.active_hooks + } + + /// Sets the physics hooks enabled for this collider. + pub fn set_active_hooks(&mut self, active_hooks: PhysicsHooksFlags) { + self.co_material.active_hooks = active_hooks; + } + + /// The friction coefficient of this collider. + pub fn friction(&self) -> Real { + self.co_material.friction + } + + /// Sets the friction coefficient of this collider. + pub fn set_friction(&mut self, coefficient: Real) { + self.co_material.friction = coefficient + } + /// The combine rule used by this collider to combine its friction /// coefficient with the friction coefficient of the other collider it /// is in contact with. @@ -60,6 +81,16 @@ impl Collider { self.co_material.friction_combine_rule = rule; } + /// The restitution coefficient of this collider. + pub fn restitution(&self) -> Real { + self.co_material.restitution + } + + /// Sets the restitution coefficient of this collider. + pub fn set_restitution(&mut self, coefficient: Real) { + self.co_material.restitution = coefficient + } + /// The combine rule used by this collider to combine its restitution /// coefficient with the restitution coefficient of the other collider it /// is in contact with. @@ -86,15 +117,22 @@ impl Collider { } } - #[doc(hidden)] - pub fn set_position_debug(&mut self, position: Isometry) { - self.co_pos.0 = position; + /// Sets the translational part of this collider's position. + pub fn set_translation(&mut self, translation: Vector) { + self.co_changes.insert(ColliderChanges::POSITION); + self.co_pos.0.translation.vector = translation; } - /// The position of this collider expressed in the local-space of the rigid-body it is attached to. - #[deprecated(note = "use `.position_wrt_parent()` instead.")] - pub fn delta(&self) -> &Isometry { - &self.co_parent.pos_wrt_parent + /// Sets the rotational part of this collider's position. + pub fn set_rotation(&mut self, rotation: AngVector) { + self.co_changes.insert(ColliderChanges::POSITION); + self.co_pos.0.rotation = Rotation::new(rotation); + } + + /// Sets the position of this collider. + pub fn set_position(&mut self, position: Isometry) { + self.co_changes.insert(ColliderChanges::POSITION); + self.co_pos.0 = position; } /// The world-space position of this collider. @@ -102,15 +140,31 @@ impl Collider { &self.co_pos } + /// The translational part of this rigid-body's position. + pub fn translation(&self) -> &Vector { + &self.co_pos.0.translation.vector + } + + /// The rotational part of this rigid-body's position. + pub fn rotation(&self) -> &Rotation { + &self.co_pos.0.rotation + } + /// The position of this collider wrt the body it is attached to. - pub fn position_wrt_parent(&self) -> &Isometry { - &self.co_parent.pos_wrt_parent + pub fn position_wrt_parent(&self) -> Option<&Isometry> { + self.co_parent.as_ref().map(|p| &p.pos_wrt_parent) } /// Sets the position of this collider wrt. its parent rigid-body. - pub fn set_position_wrt_parent(&mut self, position: Isometry) { + /// + /// Panics if the collider is not attached to a rigid-body. + pub fn set_position_wrt_parent(&mut self, pos_wrt_parent: Isometry) { self.co_changes.insert(ColliderChanges::PARENT); - self.co_parent.pos_wrt_parent = position; + let co_parent = self + .co_parent + .as_mut() + .expect("This collider has no parent."); + co_parent.pos_wrt_parent = pos_wrt_parent; } /// The collision groups used by this collider. @@ -213,13 +267,12 @@ pub struct ColliderBuilder { pub restitution: Real, /// The rule used to combine two restitution coefficients. pub restitution_combine_rule: CoefficientCombineRule, - /// The position of this collider relative to the local frame of the rigid-body it is attached to. - pub pos_wrt_parent: Isometry, + /// The position of this collider. + pub position: Isometry, /// Is this collider a sensor? pub is_sensor: bool, - /// Do we have to always call the contact modifier - /// on this collider? - pub modify_solver_contacts: bool, + /// Physics hooks enabled for this collider. + pub active_hooks: PhysicsHooksFlags, /// The user-data of the collider being built. pub user_data: u128, /// The collision groups for the collider being built. @@ -237,14 +290,14 @@ impl ColliderBuilder { mass_properties: None, friction: Self::default_friction(), restitution: 0.0, - pos_wrt_parent: Isometry::identity(), + position: Isometry::identity(), is_sensor: false, user_data: 0, collision_groups: InteractionGroups::all(), solver_groups: InteractionGroups::all(), friction_combine_rule: CoefficientCombineRule::Average, restitution_combine_rule: CoefficientCombineRule::Average, - modify_solver_contacts: false, + active_hooks: PhysicsHooksFlags::empty(), } } @@ -489,6 +542,11 @@ impl ColliderBuilder { 0.5 } + /// The default density used by the collider builder. + pub fn default_density() -> Real { + 1.0 + } + /// Sets an arbitrary user-defined 128-bit integer associated to the colliders built by this builder. pub fn user_data(mut self, data: u128) -> Self { self.user_data = data; @@ -522,10 +580,9 @@ impl ColliderBuilder { self } - /// If set to `true` then the physics hooks will always run to modify - /// contacts involving this collider. - pub fn modify_solver_contacts(mut self, modify_solver_contacts: bool) -> Self { - self.modify_solver_contacts = modify_solver_contacts; + /// The set of physics hooks enabled for this collider. + pub fn active_hooks(mut self, active_hooks: PhysicsHooksFlags) -> Self { + self.active_hooks = active_hooks; self } @@ -571,51 +628,45 @@ impl ColliderBuilder { self } - /// Sets the initial translation of the collider to be created, - /// relative to the rigid-body it is attached to. - #[cfg(feature = "dim2")] - pub fn translation(mut self, x: Real, y: Real) -> Self { - self.pos_wrt_parent.translation.x = x; - self.pos_wrt_parent.translation.y = y; + /// Sets the initial translation of the collider to be created. + /// + /// If the collider will be attached to a rigid-body, this sets the translation relative to the + /// rigid-body it will be attached to. + pub fn translation(mut self, translation: Vector) -> Self { + self.position.translation.vector = translation; self } - /// Sets the initial translation of the collider to be created, - /// relative to the rigid-body it is attached to. - #[cfg(feature = "dim3")] - pub fn translation(mut self, x: Real, y: Real, z: Real) -> Self { - self.pos_wrt_parent.translation.x = x; - self.pos_wrt_parent.translation.y = y; - self.pos_wrt_parent.translation.z = z; - self - } - - /// Sets the initial orientation of the collider to be created, - /// relative to the rigid-body it is attached to. + /// Sets the initial orientation of the collider to be created. + /// + /// If the collider will be attached to a rigid-body, this sets the orientation relative to the + /// rigid-body it will be attached to. pub fn rotation(mut self, angle: AngVector) -> Self { - self.pos_wrt_parent.rotation = Rotation::new(angle); + self.position.rotation = Rotation::new(angle); self } - /// Sets the initial position (translation and orientation) of the collider to be created, - /// relative to the rigid-body it is attached to. - pub fn position_wrt_parent(mut self, pos: Isometry) -> Self { - self.pos_wrt_parent = pos; - self - } - - /// Sets the initial position (translation and orientation) of the collider to be created, - /// relative to the rigid-body it is attached to. - #[deprecated(note = "Use `.position_wrt_parent` instead.")] + /// Sets the initial position (translation and orientation) of the collider to be created. + /// + /// If the collider will be attached to a rigid-body, this sets the position relative + /// to the rigid-body it will be attached to. pub fn position(mut self, pos: Isometry) -> Self { - self.pos_wrt_parent = pos; + self.position = pos; + self + } + + /// Sets the initial position (translation and orientation) of the collider to be created, + /// relative to the rigid-body it is attached to. + #[deprecated(note = "Use `.position` instead.")] + pub fn position_wrt_parent(mut self, pos: Isometry) -> Self { + self.position = pos; self } /// Set the position of this collider in the local-space of the rigid-body it is attached to. - #[deprecated(note = "Use `.position_wrt_parent` instead.")] + #[deprecated(note = "Use `.position` instead.")] pub fn delta(mut self, delta: Isometry) -> Self { - self.pos_wrt_parent = delta; + self.position = delta; self } @@ -623,15 +674,11 @@ impl ColliderBuilder { pub fn build(&self) -> Collider { let (co_changes, co_pos, co_bf_data, co_shape, co_type, co_groups, co_material, co_mprops) = self.components(); - let co_parent = ColliderParent { - pos_wrt_parent: co_pos.0, - handle: RigidBodyHandle::invalid(), - }; Collider { co_shape, co_mprops, co_material, - co_parent, + co_parent: None, co_changes, co_pos, co_bf_data, @@ -657,17 +704,11 @@ impl ColliderBuilder { let mass_info = if let Some(mp) = self.mass_properties { ColliderMassProperties::MassProperties(Box::new(mp)) } else { - let default_density = if self.is_sensor { 0.0 } else { 1.0 }; + let default_density = Self::default_density(); let density = self.density.unwrap_or(default_density); ColliderMassProperties::Density(density) }; - let mut solver_flags = SolverFlags::default(); - solver_flags.set( - SolverFlags::MODIFY_SOLVER_CONTACTS, - self.modify_solver_contacts, - ); - let co_shape = self.shape.clone(); let co_mprops = mass_info; let co_material = ColliderMaterial { @@ -675,10 +716,10 @@ impl ColliderBuilder { restitution: self.restitution, friction_combine_rule: self.friction_combine_rule, restitution_combine_rule: self.restitution_combine_rule, - solver_flags, + active_hooks: self.active_hooks, }; let co_changes = ColliderChanges::all(); - let co_pos = ColliderPosition(self.pos_wrt_parent); + let co_pos = ColliderPosition(self.position); let co_bf_data = ColliderBroadPhaseData::default(); let co_groups = ColliderGroups { collision_groups: self.collision_groups, diff --git a/src/geometry/collider_components.rs b/src/geometry/collider_components.rs index a02c706..b63b290 100644 --- a/src/geometry/collider_components.rs +++ b/src/geometry/collider_components.rs @@ -1,7 +1,8 @@ use crate::dynamics::{CoefficientCombineRule, MassProperties, RigidBodyHandle}; -use crate::geometry::{InteractionGroups, SAPProxyIndex, Shape, SharedShape, SolverFlags}; +use crate::geometry::{InteractionGroups, SAPProxyIndex, Shape, SharedShape}; use crate::math::{Isometry, Real}; use crate::parry::partitioning::IndexedData; +use crate::pipeline::PhysicsHooksFlags; use std::ops::Deref; /// The unique identifier of a collider added to a collider set. @@ -241,9 +242,8 @@ pub struct ColliderMaterial { pub friction_combine_rule: CoefficientCombineRule, /// The rule applied to combine the restitution coefficients of two colliders. pub restitution_combine_rule: CoefficientCombineRule, - /// The solver flags attached to this collider in order to customize the way the - /// constraints solver will work with contacts involving this collider. - pub solver_flags: SolverFlags, + /// The physics hooks enabled for contact pairs and intersection pairs involving this collider. + pub active_hooks: PhysicsHooksFlags, } impl ColliderMaterial { @@ -264,7 +264,7 @@ impl Default for ColliderMaterial { restitution: 0.0, friction_combine_rule: CoefficientCombineRule::default(), restitution_combine_rule: CoefficientCombineRule::default(), - solver_flags: SolverFlags::default(), + active_hooks: PhysicsHooksFlags::empty(), } } } diff --git a/src/geometry/collider_set.rs b/src/geometry/collider_set.rs index 14eb54c..268dbdd 100644 --- a/src/geometry/collider_set.rs +++ b/src/geometry/collider_set.rs @@ -61,12 +61,19 @@ impl_field_component_set!(ColliderType, co_type); impl_field_component_set!(ColliderShape, co_shape); impl_field_component_set!(ColliderMassProperties, co_mprops); impl_field_component_set!(ColliderChanges, co_changes); -impl_field_component_set!(ColliderParent, co_parent); impl_field_component_set!(ColliderPosition, co_pos); impl_field_component_set!(ColliderMaterial, co_material); impl_field_component_set!(ColliderGroups, co_groups); impl_field_component_set!(ColliderBroadPhaseData, co_bf_data); +impl ComponentSetOption for ColliderSet { + #[inline(always)] + fn get(&self, handle: crate::data::Index) -> Option<&ColliderParent> { + self.get(ColliderHandle(handle)) + .and_then(|b| b.co_parent.as_ref()) + } +} + impl ColliderSet { /// Create a new empty set of colliders. pub fn new() -> Self { @@ -122,7 +129,17 @@ impl ColliderSet { } /// Inserts a new collider to this set and retrieve its handle. - pub fn insert( + pub fn insert(&mut self, mut coll: Collider) -> ColliderHandle { + // Make sure the internal links are reset, they may not be + // if this rigid-body was obtained by cloning another one. + coll.reset_internal_references(); + let handle = ColliderHandle(self.colliders.insert(coll)); + self.modified_colliders.push(handle); + handle + } + + /// Inserts a new collider to this set, attach it to the given rigid-body, and retrieve its handle. + pub fn insert_with_parent( &mut self, mut coll: Collider, parent_handle: RigidBodyHandle, @@ -131,7 +148,10 @@ impl ColliderSet { // Make sure the internal links are reset, they may not be // if this rigid-body was obtained by cloning another one. coll.reset_internal_references(); - coll.co_parent.handle = parent_handle; + coll.co_parent = Some(ColliderParent { + handle: parent_handle, + pos_wrt_parent: coll.co_pos.0, + }); // NOTE: we use `get_mut` instead of `get_mut_internal` so that the // modification flag is updated properly. @@ -144,7 +164,7 @@ impl ColliderSet { let coll = self.colliders.get_mut(handle.0).unwrap(); parent.add_collider( handle, - &mut coll.co_parent, + coll.co_parent.as_mut().unwrap(), &mut coll.co_pos, &coll.co_shape, &coll.co_mprops, @@ -170,13 +190,15 @@ impl ColliderSet { */ // NOTE: we use `get_mut_internal_with_modification_tracking` instead of `get_mut_internal` so that the // modification flag is updated properly. - if let Some(parent) = - bodies.get_mut_internal_with_modification_tracking(collider.co_parent.handle) - { - parent.remove_collider_internal(handle, &collider); + if let Some(co_parent) = &collider.co_parent { + if let Some(parent) = + bodies.get_mut_internal_with_modification_tracking(co_parent.handle) + { + parent.remove_collider_internal(handle, &collider); - if wake_up { - islands.wake_up(bodies, collider.co_parent.handle, true); + if wake_up { + islands.wake_up(bodies, co_parent.handle, true); + } } } diff --git a/src/geometry/contact_pair.rs b/src/geometry/contact_pair.rs index 5a568fa..f4e7834 100644 --- a/src/geometry/contact_pair.rs +++ b/src/geometry/contact_pair.rs @@ -1,5 +1,5 @@ use crate::dynamics::RigidBodyHandle; -use crate::geometry::{ColliderPair, Contact, ContactManifold}; +use crate::geometry::{ColliderHandle, Contact, ContactManifold}; use crate::math::{Point, Real, Vector}; use parry::query::ContactManifoldsWorkspace; @@ -10,9 +10,6 @@ bitflags::bitflags! { /// The constraint solver will take this contact manifold into /// account for force computation. const COMPUTE_IMPULSES = 0b001; - /// The user-defined physics hooks will be used to - /// modify the solver contacts of this contact manifold. - const MODIFY_SOLVER_CONTACTS = 0b010; } } @@ -56,8 +53,10 @@ impl Default for ContactData { #[derive(Clone)] /// The description of all the contacts between a pair of colliders. pub struct ContactPair { - /// The pair of colliders involved. - pub pair: ColliderPair, + /// The first collider involved in the contact pair. + pub collider1: ColliderHandle, + /// The second collider involved in the contact pair. + pub collider2: ColliderHandle, /// The set of contact manifolds between the two colliders. /// /// All contact manifold contain themselves contact points between the colliders. @@ -68,9 +67,10 @@ pub struct ContactPair { } impl ContactPair { - pub(crate) fn new(pair: ColliderPair) -> Self { + pub(crate) fn new(collider1: ColliderHandle, collider2: ColliderHandle) -> Self { Self { - pair, + collider1, + collider2, has_any_active_contact: false, manifolds: Vec::new(), workspace: None, diff --git a/src/geometry/interaction_groups.rs b/src/geometry/interaction_groups.rs index 37b7586..b2961d9 100644 --- a/src/geometry/interaction_groups.rs +++ b/src/geometry/interaction_groups.rs @@ -1,56 +1,66 @@ -#[repr(transparent)] -#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] -#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] /// Pairwise filtering using bit masks. /// -/// This filtering method is based on two 16-bit values: -/// - The interaction groups (the 16 left-most bits of `self.0`). -/// - The interaction mask (the 16 right-most bits of `self.0`). +/// This filtering method is based on two 32-bit values: +/// - The interaction groups memberships. +/// - The interaction groups filter. /// /// An interaction is allowed between two filters `a` and `b` when two conditions /// are met simultaneously: -/// - The interaction groups of `a` has at least one bit set to `1` in common with the interaction mask of `b`. -/// - The interaction groups of `b` has at least one bit set to `1` in common with the interaction mask of `a`. +/// - The groups membership of `a` has at least one bit set to `1` in common with the groups filter of `b`. +/// - The groups membership of `b` has at least one bit set to `1` in common with the groups filter of `a`. /// /// In other words, interactions are allowed between two filter iff. the following condition is met: /// ```ignore -/// ((self.0 >> 16) & rhs.0) != 0 && ((rhs.0 >> 16) & self.0) != 0 +/// (self.memberships & rhs.filter) != 0 && (rhs.memberships & self.filter) != 0 /// ``` -pub struct InteractionGroups(pub u32); +#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] +#[repr(C)] +pub struct InteractionGroups { + /// Groups memberships. + pub memberships: u32, + /// Groups filter. + pub filter: u32, +} impl InteractionGroups { /// Initializes with the given interaction groups and interaction mask. - pub const fn new(groups: u16, masks: u16) -> Self { - Self::none().with_groups(groups).with_mask(masks) + pub const fn new(memberships: u32, filter: u32) -> Self { + Self { + memberships, + filter, + } } /// Allow interaction with everything. pub const fn all() -> Self { - Self(u32::MAX) + Self::new(u32::MAX, u32::MAX) } /// Prevent all interactions. pub const fn none() -> Self { - Self(0) + Self::new(0, 0) } /// Sets the group this filter is part of. - pub const fn with_groups(self, groups: u16) -> Self { - Self((self.0 & 0x0000ffff) | ((groups as u32) << 16)) + pub const fn with_memberships(mut self, memberships: u32) -> Self { + self.memberships = memberships; + self } /// Sets the interaction mask of this filter. - pub const fn with_mask(self, mask: u16) -> Self { - Self((self.0 & 0xffff0000) | (mask as u32)) + pub const fn with_filter(mut self, filter: u32) -> Self { + self.filter = filter; + self } - /// Check if interactions should be allowed based on the interaction groups and mask. + /// Check if interactions should be allowed based on the interaction memberships and filter. /// - /// An interaction is allowed iff. the groups of `self` contain at least one bit set to 1 in common - /// with the mask of `rhs`, and vice-versa. + /// An interaction is allowed iff. the memberships of `self` contain at least one bit set to 1 in common + /// with the filter of `rhs`, and vice-versa. #[inline] pub const fn test(self, rhs: Self) -> bool { - ((self.0 >> 16) & rhs.0) != 0 && ((rhs.0 >> 16) & self.0) != 0 + (self.memberships & rhs.filter) != 0 && (rhs.memberships & self.filter) != 0 } } diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs index 57504f5..e196798 100644 --- a/src/geometry/narrow_phase.rs +++ b/src/geometry/narrow_phase.rs @@ -97,6 +97,18 @@ impl NarrowPhase { &self.intersection_graph } + /// All the contacts involving the given collider. + /// + /// It is strongly recommended to use the [`NarrowPhase::contacts_with`] method instead. This + /// method can be used if the generation number of the collider handle isn't known. + pub fn contacts_with_unknown_gen( + &self, + collider: u32, + ) -> Option> { + let id = self.graph_indices.get_unknown_gen(collider)?; + Some(self.contact_graph.interactions_with(id.contact_graph_index)) + } + /// All the contacts involving the given collider. pub fn contacts_with( &self, @@ -106,6 +118,22 @@ impl NarrowPhase { Some(self.contact_graph.interactions_with(id.contact_graph_index)) } + /// All the intersections involving the given collider. + /// + /// It is strongly recommended to use the [`NarrowPhase::intersections_with`] method instead. + /// This method can be used if the generation number of the collider handle isn't known. + pub fn intersections_with_unknown_gen( + &self, + collider: u32, + ) -> Option + '_> { + let id = self.graph_indices.get_unknown_gen(collider)?; + Some( + self.intersection_graph + .interactions_with(id.intersection_graph_index) + .map(|e| (e.0, e.1, *e.2)), + ) + } + /// All the intersections involving the given collider. pub fn intersections_with( &self, @@ -119,6 +147,22 @@ impl NarrowPhase { ) } + /// The contact pair involving two specific colliders. + /// + /// It is strongly recommended to use the [`NarrowPhase::contact_pair`] method instead. This + /// method can be used if the generation number of the collider handle isn't known. + /// + /// If this returns `None`, there is no contact between the two colliders. + /// If this returns `Some`, then there may be a contact between the two colliders. Check the + /// result [`ContactPair::has_any_active_collider`] method to see if there is an actual contact. + pub fn contact_pair_unknown_gen(&self, collider1: u32, collider2: u32) -> Option<&ContactPair> { + let id1 = self.graph_indices.get_unknown_gen(collider1)?; + let id2 = self.graph_indices.get_unknown_gen(collider2)?; + self.contact_graph + .interaction_pair(id1.contact_graph_index, id2.contact_graph_index) + .map(|c| c.2) + } + /// The contact pair involving two specific colliders. /// /// If this returns `None`, there is no contact between the two colliders. @@ -136,6 +180,21 @@ impl NarrowPhase { .map(|c| c.2) } + /// The intersection pair involving two specific colliders. + /// + /// It is strongly recommended to use the [`NarrowPhase::intersection_pair`] method instead. This + /// method can be used if the generation number of the collider handle isn't known. + /// + /// If this returns `None` or `Some(false)`, then there is no intersection between the two colliders. + /// If this returns `Some(true)`, then there may be an intersection between the two colliders. + pub fn intersection_pair_unknown_gen(&self, collider1: u32, collider2: u32) -> Option { + let id1 = self.graph_indices.get_unknown_gen(collider1)?; + let id2 = self.graph_indices.get_unknown_gen(collider2)?; + self.intersection_graph + .interaction_pair(id1.intersection_graph_index, id2.intersection_graph_index) + .map(|c| *c.2) + } + /// The intersection pair involving two specific colliders. /// /// If this returns `None` or `Some(false)`, then there is no intersection between the two colliders. @@ -527,7 +586,7 @@ impl NarrowPhase { .find_edge(gid1.contact_graph_index, gid2.contact_graph_index) .is_none() { - let interaction = ContactPair::new(*pair); + let interaction = ContactPair::new(pair.collider1, pair.collider2); let _ = self.contact_graph.add_edge( gid1.contact_graph_index, gid2.contact_graph_index, @@ -585,7 +644,8 @@ impl NarrowPhase { + ComponentSetOption + ComponentSet + ComponentSet - + ComponentSet, + + ComponentSet + + ComponentSet, { if modified_colliders.is_empty() { return; @@ -593,7 +653,6 @@ impl NarrowPhase { let nodes = &self.intersection_graph.graph.nodes; let query_dispatcher = &*self.query_dispatcher; - let active_hooks = hooks.active_hooks(); // TODO: don't iterate on all the edges. par_iter_mut!(&mut self.intersection_graph.graph.edges).for_each(|edge| { @@ -601,19 +660,21 @@ impl NarrowPhase { let handle2 = nodes[edge.target().index()].weight; let co_parent1: Option<&ColliderParent> = colliders.get(handle1.0); - let (co_changes1, co_groups1, co_shape1, co_pos1): ( + let (co_changes1, co_groups1, co_shape1, co_pos1, co_material1): ( &ColliderChanges, &ColliderGroups, &ColliderShape, &ColliderPosition, + &ColliderMaterial, ) = colliders.index_bundle(handle1.0); let co_parent2: Option<&ColliderParent> = colliders.get(handle2.0); - let (co_changes2, co_groups2, co_shape2, co_pos2): ( + let (co_changes2, co_groups2, co_shape2, co_pos2, co_material2): ( &ColliderChanges, &ColliderGroups, &ColliderShape, &ColliderPosition, + &ColliderMaterial, ) = colliders.index_bundle(handle2.0); if !co_changes1.needs_narrow_phase_update() && !co_changes2.needs_narrow_phase_update() @@ -656,6 +717,8 @@ impl NarrowPhase { return; } + let active_hooks = co_material1.active_hooks | co_material2.active_hooks; + if !active_hooks.contains(PhysicsHooksFlags::FILTER_INTERSECTION_PAIR) && !status1.is_dynamic() && !status2.is_dynamic() @@ -721,29 +784,28 @@ impl NarrowPhase { } let query_dispatcher = &*self.query_dispatcher; - let active_hooks = hooks.active_hooks(); // TODO: don't iterate on all the edges. par_iter_mut!(&mut self.contact_graph.graph.edges).for_each(|edge| { let pair = &mut edge.weight; - let co_parent1: Option<&ColliderParent> = colliders.get(pair.pair.collider1.0); + let co_parent1: Option<&ColliderParent> = colliders.get(pair.collider1.0); let (co_changes1, co_groups1, co_shape1, co_pos1, co_material1): ( &ColliderChanges, &ColliderGroups, &ColliderShape, &ColliderPosition, &ColliderMaterial, - ) = colliders.index_bundle(pair.pair.collider1.0); + ) = colliders.index_bundle(pair.collider1.0); - let co_parent2: Option<&ColliderParent> = colliders.get(pair.pair.collider2.0); + let co_parent2: Option<&ColliderParent> = colliders.get(pair.collider2.0); let (co_changes2, co_groups2, co_shape2, co_pos2, co_material2): ( &ColliderChanges, &ColliderGroups, &ColliderShape, &ColliderPosition, &ColliderMaterial, - ) = colliders.index_bundle(pair.pair.collider2.0); + ) = colliders.index_bundle(pair.collider2.0); if !co_changes1.needs_narrow_phase_update() && !co_changes2.needs_narrow_phase_update() { @@ -785,6 +847,7 @@ impl NarrowPhase { return; } + let active_hooks = co_material1.active_hooks | co_material2.active_hooks; if !active_hooks.contains(PhysicsHooksFlags::FILTER_CONTACT_PAIR) && !status1.is_dynamic() && !status2.is_dynamic() @@ -800,8 +863,8 @@ impl NarrowPhase { colliders, rigid_body1: co_parent1.map(|p| p.handle), rigid_body2: co_parent2.map(|p| p.handle), - collider1: pair.pair.collider1, - collider2: pair.pair.collider2, + collider1: pair.collider1, + collider2: pair.collider2, }; if let Some(solver_flags) = hooks.filter_contact_pair(&context) { @@ -811,7 +874,7 @@ impl NarrowPhase { return; } } else { - co_material1.solver_flags | co_material2.solver_flags + SolverFlags::default() }; if !co_groups1.solver_groups.test(co_groups2.solver_groups) { @@ -896,12 +959,7 @@ impl NarrowPhase { } // Apply the user-defined contact modification. - if active_hooks.contains(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS) - && manifold - .data - .solver_flags - .contains(SolverFlags::MODIFY_SOLVER_CONTACTS) - { + if active_hooks.contains(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS) { let mut modifiable_solver_contacts = std::mem::replace(&mut manifold.data.solver_contacts, Vec::new()); let mut modifiable_user_data = manifold.data.user_data; @@ -912,8 +970,8 @@ impl NarrowPhase { colliders, rigid_body1: co_parent1.map(|p| p.handle), rigid_body2: co_parent2.map(|p| p.handle), - collider1: pair.pair.collider1, - collider2: pair.pair.collider2, + collider1: pair.collider1, + collider2: pair.collider2, manifold, solver_contacts: &mut modifiable_solver_contacts, normal: &mut modifiable_normal, @@ -931,13 +989,13 @@ impl NarrowPhase { if has_any_active_contact != pair.has_any_active_contact { if has_any_active_contact { events.handle_contact_event(ContactEvent::Started( - pair.pair.collider1, - pair.pair.collider2, + pair.collider1, + pair.collider2, )); } else { events.handle_contact_event(ContactEvent::Stopped( - pair.pair.collider1, - pair.pair.collider2, + pair.collider1, + pair.collider2, )); } diff --git a/src/lib.rs b/src/lib.rs index 79abaa5..1f32608 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -149,3 +149,12 @@ pub mod math { #[cfg(feature = "dim3")] pub const MAX_MANIFOLD_POINTS: usize = 4; } + +/// Prelude containing the common types defined by Rapier. +pub mod prelude { + pub use crate::dynamics::*; + pub use crate::geometry::*; + pub use crate::math::*; + pub use crate::pipeline::*; + pub use na::{point, vector, DMatrix, DVector}; +} diff --git a/src/pipeline/physics_hooks.rs b/src/pipeline/physics_hooks.rs index c4ef245..181c254 100644 --- a/src/pipeline/physics_hooks.rs +++ b/src/pipeline/physics_hooks.rs @@ -133,15 +133,30 @@ impl Default for PhysicsHooksFlags { } } -/// User-defined functions called by the physics engines during one timestep in order to customize its behavior. -pub trait PhysicsHooks: Send + Sync { - /// The sets of hooks that must be taken into account. +#[cfg(target_arch = "wasm32")] +pub trait PhysicsHooks { fn active_hooks(&self) -> PhysicsHooksFlags; + fn filter_contact_pair( + &self, + _context: &PairFilterContext, + ) -> Option { + None + } + fn filter_intersection_pair(&self, _context: &PairFilterContext) -> bool { + false + } + fn modify_solver_contacts(&self, _context: &mut ContactModificationContext) { + } +} +/// User-defined functions called by the physics engines during one timestep in order to customize its behavior. +#[cfg(not(target_arch = "wasm32"))] +pub trait PhysicsHooks: Send + Sync { /// Applies the contact pair filter. /// - /// Note that this method will only be called if `self.active_hooks()` - /// contains the `PhysicsHooksFlags::FILTER_CONTACT_PAIR` flags. + /// Note that this method will only be called if at least one of the colliders + /// involved in the contact contains the `PhysicsHooksFlags::FILTER_CONTACT_PAIR` flags + /// in its physics hooks flags. /// /// User-defined filter for potential contact pairs detected by the broad-phase. /// This can be used to apply custom logic in order to decide whether two colliders @@ -165,13 +180,14 @@ pub trait PhysicsHooks: Send + Sync { &self, _context: &PairFilterContext, ) -> Option { - None + Some(SolverFlags::COMPUTE_IMPULSES) } /// Applies the intersection pair filter. /// - /// Note that this method will only be called if `self.active_hooks()` - /// contains the `PhysicsHooksFlags::FILTER_INTERSECTION_PAIR` flags. + /// Note that this method will only be called if at least one of the colliders + /// involved in the contact contains the `PhysicsHooksFlags::FILTER_INTERSECTION_PAIR` flags + /// in its physics hooks flags. /// /// User-defined filter for potential intersection pairs detected by the broad-phase. /// @@ -188,13 +204,14 @@ pub trait PhysicsHooks: Send + Sync { /// If this return `true` then the narrow-phase will compute intersection /// information for this pair. fn filter_intersection_pair(&self, _context: &PairFilterContext) -> bool { - false + true } /// Modifies the set of contacts seen by the constraints solver. /// - /// Note that this method will only be called if `self.active_hooks()` - /// contains the `PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS` flags. + /// Note that this method will only be called if at least one of the colliders + /// involved in the contact contains the `PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS` flags + /// in its physics hooks flags. /// /// By default, the content of `solver_contacts` is computed from `manifold.points`. /// This method will be called on each contact manifold which have the flag `SolverFlags::modify_solver_contacts` set. @@ -220,16 +237,12 @@ pub trait PhysicsHooks: Send + Sync { } impl PhysicsHooks for () { - fn active_hooks(&self) -> PhysicsHooksFlags { - PhysicsHooksFlags::empty() - } - fn filter_contact_pair(&self, _: &PairFilterContext) -> Option { - None + Some(SolverFlags::default()) } fn filter_intersection_pair(&self, _: &PairFilterContext) -> bool { - false + true } fn modify_solver_contacts(&self, _: &mut ContactModificationContext) {} diff --git a/src_testbed/box2d_backend.rs b/src_testbed/box2d_backend.rs index db0f846..f0bffa3 100644 --- a/src_testbed/box2d_backend.rs +++ b/src_testbed/box2d_backend.rs @@ -87,9 +87,11 @@ impl Box2dWorld { fn insert_colliders(&mut self, colliders: &ColliderSet) { for (_, collider) in colliders.iter() { - let b2_body_handle = self.rapier2box2d[&collider.parent()]; - let mut b2_body = self.world.body_mut(b2_body_handle); - Self::create_fixture(&collider, &mut *b2_body); + if let Some(parent) = collider.parent() { + let b2_body_handle = self.rapier2box2d[&parent]; + let mut b2_body = self.world.body_mut(b2_body_handle); + Self::create_fixture(&collider, &mut *b2_body); + } } } @@ -122,8 +124,8 @@ impl Box2dWorld { body_a, body_b, collide_connected: true, - local_anchor_a: na_vec_to_b2_vec(params.local_anchor1.translation.vector), - local_anchor_b: na_vec_to_b2_vec(params.local_anchor2.translation.vector), + local_anchor_a: na_vec_to_b2_vec(params.local_frame1.translation.vector), + local_anchor_b: na_vec_to_b2_vec(params.local_frame2.translation.vector), reference_angle: 0.0, frequency: 0.0, damping_ratio: 0.0, @@ -155,7 +157,14 @@ impl Box2dWorld { } fn create_fixture(collider: &Collider, body: &mut b2::MetaBody) { - let center = na_vec_to_b2_vec(collider.position_wrt_parent().translation.vector); + let center = na_vec_to_b2_vec( + collider + .position_wrt_parent() + .copied() + .unwrap_or(na::one()) + .translation + .vector, + ); let mut fixture_def = b2::FixtureDef::new(); fixture_def.restitution = collider.material().restitution; @@ -230,7 +239,9 @@ impl Box2dWorld { for coll_handle in body.colliders() { let collider = &mut colliders[*coll_handle]; - collider.set_position_debug(pos * collider.position_wrt_parent()); + collider.set_position( + pos * collider.position_wrt_parent().copied().unwrap_or(na::one()), + ); } } } diff --git a/src_testbed/graphics.rs b/src_testbed/graphics.rs index 2e3d695..060798c 100644 --- a/src_testbed/graphics.rs +++ b/src_testbed/graphics.rs @@ -1,6 +1,6 @@ use bevy::prelude::*; -use na::Point3; +use na::{point, Point3}; use crate::math::Isometry; use crate::objects::node::EntityWithGraphics; @@ -34,7 +34,7 @@ impl GraphicsManager { b2sn: HashMap::new(), b2color: HashMap::new(), c2color: HashMap::new(), - ground_color: Point3::new(0.5, 0.5, 0.5), + ground_color: point![0.5, 0.5, 0.5], b2wireframe: HashMap::new(), prefab_meshes: HashMap::new(), } @@ -57,9 +57,10 @@ impl GraphicsManager { pub fn remove_collider_nodes( &mut self, commands: &mut Commands, - body: RigidBodyHandle, + body: Option, collider: ColliderHandle, ) { + let body = body.unwrap_or(RigidBodyHandle::invalid()); if let Some(sns) = self.b2sn.get_mut(&body) { for sn in sns.iter_mut() { if sn.collider == collider { @@ -83,23 +84,23 @@ impl GraphicsManager { &mut self, materials: &mut Assets, b: RigidBodyHandle, - color: Point3, + color: [f32; 3], ) { - self.b2color.insert(b, color); + self.b2color.insert(b, color.into()); if let Some(ns) = self.b2sn.get_mut(&b) { for n in ns.iter_mut() { - n.set_color(materials, color) + n.set_color(materials, color.into()) } } } - pub fn set_initial_body_color(&mut self, b: RigidBodyHandle, color: Point3) { - self.b2color.insert(b, color); + pub fn set_initial_body_color(&mut self, b: RigidBodyHandle, color: [f32; 3]) { + self.b2color.insert(b, color.into()); } - pub fn set_initial_collider_color(&mut self, c: ColliderHandle, color: Point3) { - self.c2color.insert(c, color); + pub fn set_initial_collider_color(&mut self, c: ColliderHandle, color: [f32; 3]) { + self.c2color.insert(c, color.into()); } pub fn set_body_wireframe(&mut self, b: RigidBodyHandle, enabled: bool) { @@ -118,18 +119,18 @@ impl GraphicsManager { } } - pub fn toggle_wireframe_mode(&mut self, colliders: &ColliderSet, _enabled: bool) { - for n in self.b2sn.values_mut().flat_map(|val| val.iter_mut()) { - let _force_wireframe = if let Some(collider) = colliders.get(n.collider) { - collider.is_sensor() - || self - .b2wireframe - .get(&collider.parent()) - .cloned() - .unwrap_or(false) - } else { - false - }; + pub fn toggle_wireframe_mode(&mut self, _colliders: &ColliderSet, _enabled: bool) { + for _n in self.b2sn.values_mut().flat_map(|val| val.iter_mut()) { + // let _force_wireframe = if let Some(collider) = colliders.get(n.collider) { + // collider.is_sensor() + // || self + // .b2wireframe + // .get(&collider.parent()) + // .cloned() + // .unwrap_or(false) + // } else { + // false + // }; // if let Some(node) = n.scene_node_mut() { // if force_wireframe || enabled { @@ -171,7 +172,7 @@ impl GraphicsManager { } } - self.set_body_color(materials, handle, color); + self.set_body_color(materials, handle, color.into()); color } @@ -257,10 +258,10 @@ impl GraphicsManager { colliders: &ColliderSet, ) { let collider = &colliders[handle]; - let color = *self.b2color.get(&collider.parent()).unwrap(); + let collider_parent = collider.parent().unwrap_or(RigidBodyHandle::invalid()); + let color = *self.b2color.get(&collider_parent).unwrap(); let color = self.c2color.get(&handle).copied().unwrap_or(color); - let mut nodes = - std::mem::replace(self.b2sn.get_mut(&collider.parent()).unwrap(), Vec::new()); + let mut nodes = std::mem::replace(self.b2sn.get_mut(&collider_parent).unwrap(), Vec::new()); self.do_add_shape( commands, meshes, @@ -273,7 +274,7 @@ impl GraphicsManager { color, &mut nodes, ); - self.b2sn.insert(collider.parent(), nodes); + self.b2sn.insert(collider_parent, nodes); } fn do_add_shape( @@ -338,9 +339,9 @@ impl GraphicsManager { // // if bo.is_dynamic() { // if bo.is_ccd_active() { - // n.set_color(Point3::new(1.0, 0.0, 0.0)); + // n.set_color(point![1.0, 0.0, 0.0]); // } else { - // n.set_color(Point3::new(0.0, 1.0, 0.0)); + // n.set_color(point![0.0, 1.0, 0.0]); // } // } // } @@ -365,9 +366,9 @@ impl GraphicsManager { // let y = rotmat.column(1) * 0.25f32; // let z = rotmat.column(2) * 0.25f32; - // window.draw_line(center, &(*center + x), &Point3::new(1.0, 0.0, 0.0)); - // window.draw_line(center, &(*center + y), &Point3::new(0.0, 1.0, 0.0)); - // window.draw_line(center, &(*center + z), &Point3::new(0.0, 0.0, 1.0)); + // window.draw_line(center, &(*center + x), &point![1.0, 0.0, 0.0]); + // window.draw_line(center, &(*center + y), &point![0.0, 1.0, 0.0]); + // window.draw_line(center, &(*center + z), &point![0.0, 0.0, 1.0]); // // } // } // } diff --git a/src_testbed/nphysics_backend.rs b/src_testbed/nphysics_backend.rs index 2657b19..c7d6c0e 100644 --- a/src_testbed/nphysics_backend.rs +++ b/src_testbed/nphysics_backend.rs @@ -55,15 +55,17 @@ impl NPhysicsWorld { } for (_, collider) in colliders.iter() { - let parent = &bodies[collider.parent()]; - let nphysics_rb_handle = rapier2nphysics[&collider.parent()]; - if let Some(collider) = - nphysics_collider_from_rapier_collider(&collider, parent.is_dynamic()) - { - let nphysics_collider = collider.build(BodyPartHandle(nphysics_rb_handle, 0)); - nphysics_colliders.insert(nphysics_collider); - } else { - eprintln!("Creating shape unknown to the nphysics backend.") + if let Some(parent_handle) = collider.parent() { + let parent = &bodies[parent_handle]; + let nphysics_rb_handle = rapier2nphysics[&parent_handle]; + if let Some(collider) = + nphysics_collider_from_rapier_collider(&collider, parent.is_dynamic()) + { + let nphysics_collider = collider.build(BodyPartHandle(nphysics_rb_handle, 0)); + nphysics_colliders.insert(nphysics_collider); + } else { + eprintln!("Creating shape unknown to the nphysics backend.") + } } } @@ -76,10 +78,10 @@ impl NPhysicsWorld { let c = FixedConstraint::new( b1, b2, - params.local_anchor1.translation.vector.into(), - params.local_anchor1.rotation, - params.local_anchor2.translation.vector.into(), - params.local_anchor2.rotation, + params.local_frame1.translation.vector.into(), + params.local_frame1.rotation, + params.local_frame2.translation.vector.into(), + params.local_frame2.rotation, ); nphysics_joints.insert(c); } @@ -172,7 +174,9 @@ impl NPhysicsWorld { for coll_handle in rb.colliders() { let collider = &mut colliders[*coll_handle]; - collider.set_position_debug(pos * collider.position_wrt_parent()); + collider.set_position( + pos * collider.position_wrt_parent().copied().unwrap_or(na::one()), + ); } } } @@ -183,7 +187,7 @@ fn nphysics_collider_from_rapier_collider( is_dynamic: bool, ) -> Option> { let mut margin = ColliderDesc::::default_margin(); - let mut pos = *collider.position_wrt_parent(); + let mut pos = collider.position_wrt_parent().copied().unwrap_or(na::one()); let shape = collider.shape(); let shape = if let Some(cuboid) = shape.as_cuboid() { @@ -209,7 +213,7 @@ fn nphysics_collider_from_rapier_collider( trimesh .indices() .iter() - .map(|idx| na::Point3::new(idx[0] as usize, idx[1] as usize, idx[2] as usize)) + .map(|idx| na::point![idx[0] as usize, idx[1] as usize, idx[2] as usize]) .collect(), None, )) diff --git a/src_testbed/objects/node.rs b/src_testbed/objects/node.rs index be2fa71..9acc62e 100644 --- a/src_testbed/objects/node.rs +++ b/src_testbed/objects/node.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; use bevy::render::mesh::{Indices, VertexAttributeValues}; //use crate::objects::plane::Plane; -use na::{Point3, Vector3}; +use na::{point, Point3, Vector3}; use std::collections::HashMap; use bevy::render::pipeline::PrimitiveTopology; @@ -106,7 +106,7 @@ impl EntityWithGraphics { pub fn select(&mut self, materials: &mut Assets) { // NOTE: we don't just call `self.set_color` because that would // overwrite self.base_color too. - self.color = Point3::new(1.0, 0.0, 0.0); + self.color = point![1.0, 0.0, 0.0]; if let Some(material) = materials.get_mut(&self.material) { material.base_color = Color::rgb(self.color.x, self.color.y, self.color.z); } @@ -210,10 +210,10 @@ impl EntityWithGraphics { // Halfspace // let vertices = vec![ - Point3::new(-1000.0, 0.0, -1000.0), - Point3::new(1000.0, 0.0, -1000.0), - Point3::new(1000.0, 0.0, 1000.0), - Point3::new(-1000.0, 0.0, 1000.0), + point![-1000.0, 0.0, -1000.0], + point![1000.0, 0.0, -1000.0], + point![1000.0, 0.0, 1000.0], + point![-1000.0, 0.0, 1000.0], ]; let indices = vec![[0, 1, 2], [0, 2, 3]]; let mesh = bevy_mesh((vertices, indices)); @@ -365,7 +365,7 @@ fn generate_collider_mesh(co_shape: &dyn Shape) -> Option { let vertices = trimesh .vertices() .iter() - .map(|p| Point3::new(p.x, p.y, 0.0)) + .map(|p| point![p.x, p.y, 0.0]) .collect(); bevy_mesh((vertices, trimesh.indices().to_vec())) } diff --git a/src_testbed/physx_backend.rs b/src_testbed/physx_backend.rs index 4c41e2c..6c3155f 100644 --- a/src_testbed/physx_backend.rs +++ b/src_testbed/physx_backend.rs @@ -220,23 +220,28 @@ impl PhysxWorld { if let Some((mut px_shape, px_material, collider_pos)) = physx_collider_from_rapier_collider(&mut *physics, &mut cooking, &collider) { - let parent_body = &bodies[collider.parent()]; + if let Some(parent_handle) = collider.parent() { + let parent_body = &bodies[parent_handle]; - if !parent_body.is_dynamic() { - let actor = rapier2static.get_mut(&collider.parent()).unwrap(); - actor.attach_shape(&mut px_shape); - } else { - let actor = rapier2dynamic.get_mut(&collider.parent()).unwrap(); - actor.attach_shape(&mut px_shape); + if !parent_body.is_dynamic() { + let actor = rapier2static.get_mut(&parent_handle).unwrap(); + actor.attach_shape(&mut px_shape); + } else { + let actor = rapier2dynamic.get_mut(&parent_handle).unwrap(); + actor.attach_shape(&mut px_shape); + } + + unsafe { + let pose = collider_pos.into_physx(); + physx_sys::PxShape_setLocalPose_mut( + px_shape.as_mut_ptr(), + &pose.into(), + ); + } + + shapes.push(px_shape); + materials.push(px_material); } - - unsafe { - let pose = collider_pos.into_physx(); - physx_sys::PxShape_setLocalPose_mut(px_shape.as_mut_ptr(), &pose.into()); - } - - shapes.push(px_shape); - materials.push(px_material); } } @@ -454,8 +459,8 @@ impl PhysxWorld { } } JointParams::FixedJoint(params) => { - let frame1 = params.local_anchor1.into_physx().into(); - let frame2 = params.local_anchor2.into_physx().into(); + let frame1 = params.local_frame1.into_physx().into(); + let frame2 = params.local_frame2.into_physx().into(); physx_sys::phys_PxFixedJointCreate( physics.as_mut_ptr(), @@ -500,7 +505,9 @@ impl PhysxWorld { for coll_handle in rb.colliders() { let collider = &mut colliders[*coll_handle]; - collider.set_position_debug(pos * collider.position_wrt_parent()); + collider.set_position( + pos * collider.position_wrt_parent().copied().unwrap_or(na::one()), + ); } } } @@ -511,7 +518,7 @@ fn physx_collider_from_rapier_collider( cooking: &PxCooking, collider: &Collider, ) -> Option<(Owner, Owner, Isometry3)> { - let mut local_pose = *collider.position_wrt_parent(); + let mut local_pose = collider.position_wrt_parent().copied().unwrap_or(na::one()); let shape = collider.shape(); let shape_flags = if collider.is_sensor() { ShapeFlag::TriggerShape.into() diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs index 6e314c8..ba09250 100644 --- a/src_testbed/testbed.rs +++ b/src_testbed/testbed.rs @@ -429,7 +429,7 @@ impl TestbedApp { } impl<'a, 'b, 'c, 'd> TestbedGraphics<'a, 'b, 'c, 'd> { - pub fn set_body_color(&mut self, body: RigidBodyHandle, color: Point3) { + pub fn set_body_color(&mut self, body: RigidBodyHandle, color: [f32; 3]) { self.manager .set_body_color(&mut self.materials, body, color); } @@ -588,13 +588,13 @@ impl<'a, 'b, 'c, 'd> Testbed<'a, 'b, 'c, 'd> { } } - pub fn set_initial_body_color(&mut self, body: RigidBodyHandle, color: Point3) { + pub fn set_initial_body_color(&mut self, body: RigidBodyHandle, color: [f32; 3]) { if let Some(graphics) = &mut self.graphics { graphics.manager.set_initial_body_color(body, color); } } - pub fn set_initial_collider_color(&mut self, collider: ColliderHandle, color: Point3) { + pub fn set_initial_collider_color(&mut self, collider: ColliderHandle, color: [f32; 3]) { if let Some(graphics) = &mut self.graphics { graphics.manager.set_initial_collider_color(collider, color); } @@ -752,14 +752,14 @@ fn draw_contacts(_nf: &NarrowPhase, _colliders: &ColliderSet) { // let n = manifold.data.normal; // // use crate::engine::GraphicsWindow; - // window.draw_graphics_line(&p, &(p + n * 0.4), &Point3::new(0.5, 1.0, 0.5)); + // window.draw_graphics_line(&p, &(p + n * 0.4), &point![0.5, 1.0, 0.5]); // } // */ // for pt in manifold.contacts() { // let color = if pt.dist > 0.0 { - // Point3::new(0.0, 0.0, 1.0) + // point![0.0, 0.0, 1.0] // } else { - // Point3::new(1.0, 0.0, 0.0) + // point![1.0, 0.0, 0.0] // }; // let pos1 = colliders[pair.pair.collider1].position(); // let pos2 = colliders[pair.pair.collider2].position(); @@ -771,7 +771,7 @@ fn draw_contacts(_nf: &NarrowPhase, _colliders: &ColliderSet) { // * manifold.subshape_pos1.unwrap_or(Isometry::identity()) // * manifold.local_n1; // - // // window.draw_graphics_line(&start, &(start + n * 0.4), &Point3::new(0.5, 1.0, 0.5)); + // // window.draw_graphics_line(&start, &(start + n * 0.4), &point![0.5, 1.0, 0.5]); // // window.draw_graphics_line(&start, &end, &color); // } // } @@ -1228,10 +1228,13 @@ fn highlight_hovered_body( if let Some((handle, _)) = hit { let collider = &physics.colliders[handle]; - if physics.bodies[collider.parent()].is_dynamic() { - testbed_state.highlighted_body = Some(collider.parent()); - for node in graphics_manager.body_nodes_mut(collider.parent()).unwrap() { - node.select(materials) + + if let Some(parent_handle) = collider.parent() { + if physics.bodies[parent_handle].is_dynamic() { + testbed_state.highlighted_body = Some(parent_handle); + for node in graphics_manager.body_nodes_mut(parent_handle).unwrap() { + node.select(materials) + } } } }