From 1bef66fea941307a7305ddaebdb0abe3d0cb281f Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 25 May 2021 11:00:13 +0200 Subject: 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 +++++++++++++++++--- .../joint_constraint/fixed_position_constraint.rs | 34 ++-- .../joint_constraint/fixed_velocity_constraint.rs | 12 +- .../fixed_velocity_constraint_wide.rs | 24 +-- src/geometry/collider.rs | 179 +++++++++++++-------- src/geometry/collider_components.rs | 10 +- src/geometry/collider_set.rs | 44 +++-- 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, 1525 insertions(+), 1256 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(