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 --- 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 ++--- 31 files changed, 433 insertions(+), 462 deletions(-) (limited to 'examples3d') 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