diff options
Diffstat (limited to 'examples2d')
| -rw-r--r-- | examples2d/add_remove2.rs | 10 | ||||
| -rw-r--r-- | examples2d/ccd2.rs | 52 | ||||
| -rw-r--r-- | examples2d/collision_groups2.rs | 33 | ||||
| -rw-r--r-- | examples2d/convex_polygons2.rs | 24 | ||||
| -rw-r--r-- | examples2d/damping2.rs | 14 | ||||
| -rw-r--r-- | examples2d/debug_box_ball2.rs | 14 | ||||
| -rw-r--r-- | examples2d/heightfield2.rs | 19 | ||||
| -rw-r--r-- | examples2d/joints2.rs | 16 | ||||
| -rw-r--r-- | examples2d/locked_rotations2.rs | 18 | ||||
| -rw-r--r-- | examples2d/one_way_platforms2.rs | 39 | ||||
| -rw-r--r-- | examples2d/platform2.rs | 20 | ||||
| -rw-r--r-- | examples2d/polyline2.rs | 23 | ||||
| -rw-r--r-- | examples2d/pyramid2.rs | 14 | ||||
| -rw-r--r-- | examples2d/restitution2.rs | 14 | ||||
| -rw-r--r-- | examples2d/sensor2.rs | 40 | ||||
| -rw-r--r-- | examples2d/trimesh2.rs | 22 |
16 files changed, 183 insertions, 189 deletions
diff --git a/examples2d/add_remove2.rs b/examples2d/add_remove2.rs index 9f9f65a..056e63e 100644 --- a/examples2d/add_remove2.rs +++ b/examples2d/add_remove2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -12,13 +10,13 @@ pub fn init_world(testbed: &mut Testbed) { // Callback that will be executed on the main loop to handle proximities. testbed.add_callback(move |mut graphics, physics, _, _| { let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 10.0) + .translation(vector![0.0, 10.0]) .build(); let handle = physics.bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad).build(); physics .colliders - .insert(collider, handle, &mut physics.bodies); + .insert_with_parent(collider, handle, &mut physics.bodies); if let Some(graphics) = &mut graphics { graphics.add_body(handle, &physics.bodies, &physics.colliders); @@ -48,5 +46,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 0.0), 20.0); + testbed.look_at(point![0.0, 0.0], 20.0); } diff --git a/examples2d/ccd2.rs b/examples2d/ccd2.rs index 18a6bfe..1200f29 100644 --- a/examples2d/ccd2.rs +++ b/examples2d/ccd2.rs @@ -1,6 +1,4 @@ -use na::{Isometry2, Point2, Point3}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet, SharedShape}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -21,23 +19,23 @@ pub fn init_world(testbed: &mut Testbed) { let ground_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); let collider = ColliderBuilder::cuboid(ground_thickness, ground_size) - .translation(-3.0, 0.0) + .translation(vector![-3.0, 0.0]) .build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); let collider = ColliderBuilder::cuboid(ground_thickness, ground_size) - .translation(6.0, 0.0) + .translation(vector![6.0, 0.0]) .build(); - colliders.insert(collider, ground_handle, &mut bodies); + colliders.insert_with_parent(collider, ground_handle, &mut bodies); let collider = ColliderBuilder::cuboid(ground_thickness, ground_size) - .translation(2.5, 0.0) + .translation(vector![2.5, 0.0]) .sensor(true) .build(); - let sensor_handle = colliders.insert(collider, ground_handle, &mut bodies); + let sensor_handle = colliders.insert_with_parent(collider, ground_handle, &mut bodies); /* * Create the shapes @@ -45,9 +43,9 @@ pub fn init_world(testbed: &mut Testbed) { let radx = 0.4; let rady = 0.05; - let delta1 = Isometry2::translation(0.0, radx - rady); - let delta2 = Isometry2::translation(-radx + rady, 0.0); - let delta3 = Isometry2::translation(radx - rady, 0.0); + let delta1 = Isometry::translation(0.0, radx - rady); + let delta2 = Isometry::translation(-radx + rady, 0.0); + let delta3 = Isometry::translation(radx - rady, 0.0); let mut compound_parts = Vec::new(); let vertical = SharedShape::cuboid(rady, radx); @@ -70,8 +68,8 @@ pub fn init_world(testbed: &mut Testbed) { // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(x, y) - .linvel(100.0, -10.0) + .translation(vector![x, y]) + .linvel(vector![100.0, -10.0]) .ccd_enabled(true) .build(); let handle = bodies.insert(rigid_body); @@ -80,12 +78,12 @@ pub fn init_world(testbed: &mut Testbed) { // let collider = ColliderBuilder::new(part.1.clone()) // .position_wrt_parent(part.0) // .build(); - // colliders.insert(collider, handle, &mut bodies); + // colliders.insert_with_parent(collider, handle, &mut bodies); // } let collider = ColliderBuilder::new(compound_shape.clone()).build(); // let collider = ColliderBuilder::cuboid(radx, rady).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -93,13 +91,23 @@ pub fn init_world(testbed: &mut Testbed) { testbed.add_callback(move |mut graphics, physics, events, _| { while let Ok(prox) = events.intersection_events.try_recv() { let color = if prox.intersecting { - Point3::new(1.0, 1.0, 0.0) + [1.0, 1.0, 0.0] } else { - Point3::new(0.5, 0.5, 1.0) + [0.5, 0.5, 1.0] }; - let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent(); - let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent(); + let parent_handle1 = physics + .colliders + .get(prox.collider1) + .unwrap() + .parent() + .unwrap(); + let parent_handle2 = physics + .colliders + .get(prox.collider2) + .unwrap() + .parent() + .unwrap(); if let Some(graphics) = &mut graphics { if parent_handle1 != ground_handle && prox.collider1 != sensor_handle { graphics.set_body_color(parent_handle1, color); @@ -115,5 +123,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 2.5), 20.0); + testbed.look_at(point![0.0, 2.5], 20.0); } diff --git a/examples2d/collision_groups2.rs b/examples2d/collision_groups2.rs index 08b73fb..3f2a786 100644 --- a/examples2d/collision_groups2.rs +++ b/examples2d/collision_groups2.rs @@ -1,6 +1,4 @@ -use na::{Point2, Point3}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet, InteractionGroups}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height) + .translation(vector![0.0, -ground_height]) .build(); let floor_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height).build(); - colliders.insert(collider, floor_handle, &mut bodies); + colliders.insert_with_parent(collider, floor_handle, &mut bodies); /* * Setup groups @@ -34,23 +32,24 @@ pub fn init_world(testbed: &mut Testbed) { * A green floor that will collide with the GREEN group only. */ let green_floor = ColliderBuilder::cuboid(1.0, 0.1) - .translation(0.0, 1.0) + .translation(vector![0.0, 1.0]) .collision_groups(GREEN_GROUP) .build(); - let green_collider_handle = colliders.insert(green_floor, floor_handle, &mut bodies); + let green_collider_handle = + colliders.insert_with_parent(green_floor, floor_handle, &mut bodies); - testbed.set_initial_collider_color(green_collider_handle, Point3::new(0.0, 1.0, 0.0)); + testbed.set_initial_collider_color(green_collider_handle, [0.0, 1.0, 0.0]); /* * A blue floor that will collide with the BLUE group only. */ let blue_floor = ColliderBuilder::cuboid(1.0, 0.1) - .translation(0.0, 2.0) + .translation(vector![0.0, 2.0]) .collision_groups(BLUE_GROUP) .build(); - let blue_collider_handle = colliders.insert(blue_floor, floor_handle, &mut bodies); + let blue_collider_handle = colliders.insert_with_parent(blue_floor, floor_handle, &mut bodies); - testbed.set_initial_collider_color(blue_collider_handle, Point3::new(0.0, 0.0, 1.0)); + testbed.set_initial_collider_color(blue_collider_handle, [0.0, 0.0, 1.0]); /* * Create the cubes @@ -69,17 +68,19 @@ pub fn init_world(testbed: &mut Testbed) { // Alternate between the green and blue groups. let (group, color) = if i % 2 == 0 { - (GREEN_GROUP, Point3::new(0.0, 1.0, 0.0)) + (GREEN_GROUP, [0.0, 1.0, 0.0]) } else { - (BLUE_GROUP, Point3::new(0.0, 0.0, 1.0)) + (BLUE_GROUP, [0.0, 0.0, 1.0]) }; - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad) .collision_groups(group) .build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); testbed.set_initial_body_color(handle, color); } @@ -89,5 +90,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 1.0), 100.0); + testbed.look_at(point![0.0, 1.0], 100.0); } diff --git a/examples2d/convex_polygons2.rs b/examples2d/convex_polygons2.rs index 0e4fb0c..4373fcb 100644 --- a/examples2d/convex_polygons2.rs +++ b/examples2d/convex_polygons2.rs @@ -1,8 +1,6 @@ -use na::Point2; use rand::distributions::{Distribution, Standard}; use rand::{rngs::StdRng, SeedableRng}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -21,23 +19,23 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(ground_size, ground_size * 2.0) + .translation(vector![ground_size, ground_size * 2.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); let rigid_body = RigidBodyBuilder::new_static() .rotation(std::f32::consts::FRAC_PI_2) - .translation(-ground_size, ground_size * 2.0) + .translation(vector![-ground_size, ground_size * 2.0]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the convex polygons @@ -58,18 +56,20 @@ pub fn init_world(testbed: &mut Testbed) { let x = i as f32 * shift - centerx; let y = j as f32 * shift * 2.0 + centery + 2.0; - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let mut points = Vec::new(); for _ in 0..10 { - let pt: Point2<f32> = distribution.sample(&mut rng); + let pt: Point<f32> = distribution.sample(&mut rng); points.push(pt * scale); } let collider = ColliderBuilder::convex_hull(&points).unwrap().build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -77,5 +77,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 50.0), 10.0); + testbed.look_at(point![0.0, 50.0], 10.0); } diff --git a/examples2d/damping2.rs b/examples2d/damping2.rs index 68fd77d..e308de6 100644 --- a/examples2d/damping2.rs +++ b/examples2d/damping2.rs @@ -1,6 +1,4 @@ -use na::{Point2, Vector2}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -24,8 +22,8 @@ pub fn init_world(testbed: &mut Testbed) { // Build the rigid body. let rb = RigidBodyBuilder::new_dynamic() - .translation(x, y) - .linvel(x * 10.0, y * 10.0) + .translation(vector![x, y]) + .linvel(vector![x * 10.0, y * 10.0]) .angvel(100.0) .linear_damping((i + 1) as f32 * subdiv * 10.0) .angular_damping((num - i) as f32 * subdiv * 10.0) @@ -34,12 +32,12 @@ pub fn init_world(testbed: &mut Testbed) { // Build the collider. let co = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(co, rb_handle, &mut bodies); + colliders.insert_with_parent(co, rb_handle, &mut bodies); } /* * Set up the testbed. */ - testbed.set_world_with_params(bodies, colliders, joints, Vector2::zeros(), ()); - testbed.look_at(Point2::new(3.0, 2.0), 50.0); + testbed.set_world_with_params(bodies, colliders, joints, Vector::zeros(), ()); + testbed.look_at(point![3.0, 2.0], 50.0); } diff --git a/examples2d/debug_box_ball2.rs b/examples2d/debug_box_ball2.rs index aad72ae..63b6f95 100644 --- a/examples2d/debug_box_ball2.rs +++ b/examples2d/debug_box_ball2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -16,25 +14,25 @@ pub fn init_world(testbed: &mut Testbed) { */ let rad = 1.0; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -rad) + .translation(vector![0.0, -rad]) .rotation(std::f32::consts::PI / 4.0) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); // Build the dynamic box rigid body. let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 3.0 * rad) + .translation(vector![0.0, 3.0 * rad]) .can_sleep(false) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 0.0), 50.0); + testbed.look_at(point![0.0, 0.0], 50.0); } diff --git a/examples2d/heightfield2.rs b/examples2d/heightfield2.rs index a834a2c..6246c40 100644 --- a/examples2d/heightfield2.rs +++ b/examples2d/heightfield2.rs @@ -1,6 +1,5 @@ -use na::{DVector, Point2, Vector2}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use na::DVector; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) { /* * Ground */ - let ground_size = Vector2::new(50.0, 1.0); + let ground_size = Vector::new(50.0, 1.0); let nsubdivs = 2000; let heights = DVector::from_fn(nsubdivs + 1, |i, _| { @@ -28,7 +27,7 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::heightfield(heights, ground_size).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -46,15 +45,17 @@ pub fn init_world(testbed: &mut Testbed) { let y = j as f32 * shift + centery + 3.0; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); if j % 2 == 0 { let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } else { let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -63,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 0.0), 10.0); + testbed.look_at(point![0.0, 0.0], 10.0); } diff --git a/examples2d/joints2.rs b/examples2d/joints2.rs index ff5c663..9c94968 100644 --- a/examples2d/joints2.rs +++ b/examples2d/joints2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{BallJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -15,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) { * Create the balls */ // Build the rigid body. - // NOTE: a smaller radius (e.g. 0.1) breaks Box2D so + // NOTE: a smaller radius (e.g. 0.1) breaks Box2D so // in order to be able to compare rapier with Box2D, // we set it to 0.4. let rad = 0.4; @@ -37,16 +35,16 @@ pub fn init_world(testbed: &mut Testbed) { }; let rigid_body = RigidBodyBuilder::new(status) - .translation(fk * shift, -fi * shift) + .translation(vector![fk * shift, -fi * shift]) .build(); let child_handle = bodies.insert(rigid_body); let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, child_handle, &mut bodies); + colliders.insert_with_parent(collider, child_handle, &mut bodies); // Vertical joint. if i > 0 { let parent_handle = *body_handles.last().unwrap(); - let joint = BallJoint::new(Point2::origin(), Point2::new(0.0, shift)); + let joint = BallJoint::new(Point::origin(), point![0.0, shift]); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -54,7 +52,7 @@ pub fn init_world(testbed: &mut Testbed) { if k > 0 { let parent_index = body_handles.len() - numi; let parent_handle = body_handles[parent_index]; - let joint = BallJoint::new(Point2::origin(), Point2::new(-shift, 0.0)); + let joint = BallJoint::new(Point::origin(), point![-shift, 0.0]); joints.insert(&mut bodies, parent_handle, child_handle, joint); } @@ -66,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(numk as f32 * rad, numi as f32 * -rad), 20.0); + testbed.look_at(point![numk as f32 * rad, numi as f32 * -rad], 20.0); } diff --git a/examples2d/locked_rotations2.rs b/examples2d/locked_rotations2.rs index 03fb2e7..a1f7ba5 100644 --- a/examples2d/locked_rotations2.rs +++ b/examples2d/locked_rotations2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; // This shows a bug when a cylinder is in contact with a very large @@ -21,38 +19,38 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height) + .translation(vector![0.0, -ground_height]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * A rectangle that only rotate. */ let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 3.0) + .translation(vector![0.0, 3.0]) .lock_translations() .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(2.0, 0.6).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * A tilted capsule that cannot rotate. */ let rigid_body = RigidBodyBuilder::new_dynamic() - .translation(0.0, 5.0) + .translation(vector![0.0, 5.0]) .rotation(1.0) .lock_rotations() .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::capsule_y(0.6, 0.4).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 0.0), 40.0); + testbed.look_at(point![0.0, 0.0], 40.0); } diff --git a/examples2d/one_way_platforms2.rs b/examples2d/one_way_platforms2.rs index 19b9968..b0f2212 100644 --- a/examples2d/one_way_platforms2.rs +++ b/examples2d/one_way_platforms2.rs @@ -1,7 +1,4 @@ -use na::{Point2, Vector2}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderHandle, ColliderSet}; -use rapier2d::pipeline::{ContactModificationContext, PhysicsHooks, PhysicsHooksFlags}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; struct OneWayPlatformHook { @@ -10,10 +7,6 @@ struct OneWayPlatformHook { } impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook { - fn active_hooks(&self) -> PhysicsHooksFlags { - PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS - } - fn modify_solver_contacts( &self, context: &mut ContactModificationContext<RigidBodySet, ColliderSet>, @@ -30,20 +23,20 @@ impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook { // - If context.collider_handle2 == self.platform1 then the allowed normal is -y. // - If context.collider_handle1 == self.platform2 then its allowed normal +y needs to be flipped to -y. // - If context.collider_handle2 == self.platform2 then the allowed normal -y needs to be flipped to +y. - let mut allowed_local_n1 = Vector2::zeros(); + let mut allowed_local_n1 = Vector::zeros(); if context.collider1 == self.platform1 { - allowed_local_n1 = Vector2::y(); + allowed_local_n1 = Vector::y(); } else if context.collider2 == self.platform1 { // Flip the allowed direction. - allowed_local_n1 = -Vector2::y(); + allowed_local_n1 = -Vector::y(); } if context.collider1 == self.platform2 { - allowed_local_n1 = -Vector2::y(); + allowed_local_n1 = -Vector::y(); } else if context.collider2 == self.platform2 { // Flip the allowed direction. - allowed_local_n1 = Vector2::y(); + allowed_local_n1 = Vector::y(); } // Call the helper function that simulates one-way platforms. @@ -78,15 +71,15 @@ pub fn init_world(testbed: &mut Testbed) { let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(25.0, 0.5) - .translation(30.0, 2.0) - .modify_solver_contacts(true) + .translation(vector![30.0, 2.0]) + .active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS) .build(); - let platform1 = colliders.insert(collider, handle, &mut bodies); + let platform1 = colliders.insert_with_parent(collider, handle, &mut bodies); let collider = ColliderBuilder::cuboid(25.0, 0.5) - .translation(-30.0, -2.0) - .modify_solver_contacts(true) + .translation(vector![-30.0, -2.0]) + .active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS) .build(); - let platform2 = colliders.insert(collider, handle, &mut bodies); + let platform2 = colliders.insert_with_parent(collider, handle, &mut bodies); /* * Setup the one-way platform hook. @@ -105,12 +98,12 @@ pub fn init_world(testbed: &mut Testbed) { // Spawn a new cube. let collider = ColliderBuilder::cuboid(1.5, 2.0).build(); let body = RigidBodyBuilder::new_dynamic() - .translation(20.0, 10.0) + .translation(vector![20.0, 10.0]) .build(); let handle = physics.bodies.insert(body); physics .colliders - .insert(collider, handle, &mut physics.bodies); + .insert_with_parent(collider, handle, &mut physics.bodies); if let Some(graphics) = graphics { graphics.add_body(handle, &physics.bodies, &physics.colliders); @@ -134,8 +127,8 @@ pub fn init_world(testbed: &mut Testbed) { bodies, colliders, joints, - Vector2::new(0.0, -9.81), + vector![0.0, -9.81], physics_hooks, ); - testbed.look_at(Point2::new(0.0, 0.0), 20.0); + testbed.look_at(point![0.0, 0.0], 20.0); } diff --git a/examples2d/platform2.rs b/examples2d/platform2.rs index 7542cd6..6aa73b7 100644 --- a/examples2d/platform2.rs +++ b/examples2d/platform2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) { let ground_height = 0.1; let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height) + .translation(vector![0.0, -ground_height]) .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(ground_size, ground_height).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the boxes @@ -40,10 +38,12 @@ pub fn init_world(testbed: &mut Testbed) { let y = j as f32 * shift + centery; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } @@ -51,11 +51,11 @@ pub fn init_world(testbed: &mut Testbed) { * Setup a kinematic rigid body. */ let platform_body = RigidBodyBuilder::new_kinematic() - .translation(-10.0 * rad, 1.5 + 0.8) + .translation(vector![-10.0 * rad, 1.5 + 0.8]) .build(); let platform_handle = bodies.insert(platform_body); let collider = ColliderBuilder::cuboid(rad * 10.0, rad).build(); - colliders.insert(collider, platform_handle, &mut bodies); + colliders.insert_with_parent(collider, platform_handle, &mut bodies); /* * Setup a callback to control the platform. @@ -82,5 +82,5 @@ pub fn init_world(testbed: &mut Testbed) { * Run the simulation. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 1.0), 40.0); + testbed.look_at(point![0.0, 1.0], 40.0); } diff --git a/examples2d/polyline2.rs b/examples2d/polyline2.rs index 0b3be0c..7405e24 100644 --- a/examples2d/polyline2.rs +++ b/examples2d/polyline2.rs @@ -1,6 +1,5 @@ -use na::{ComplexField, Point2}; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use na::ComplexField; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -19,18 +18,18 @@ pub fn init_world(testbed: &mut Testbed) { let step_size = ground_size / (nsubdivs as f32); let mut points = Vec::new(); - points.push(Point2::new(-ground_size / 2.0, 40.0)); + points.push(point![-ground_size / 2.0, 40.0]); for i in 1..nsubdivs - 1 { let x = -ground_size / 2.0 + i as f32 * step_size; let y = ComplexField::cos(i as f32 * step_size) * 2.0; - points.push(Point2::new(x, y)); + points.push(point![x, y]); } - points.push(Point2::new(ground_size / 2.0, 40.0)); + points.push(point![ground_size / 2.0, 40.0]); let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); let collider = ColliderBuilder::polyline(points, None).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); /* * Create the cubes @@ -48,15 +47,17 @@ pub fn init_world(testbed: &mut Testbed) { let y = j as f32 * shift + centery + 3.0; // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let rigid_body = RigidBodyBuilder::new_dynamic() + .translation(vector![x, y]) + .build(); let handle = bodies.insert(rigid_body); if j % 2 == 0 { let collider = ColliderBuilder::cuboid(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } else { let collider = ColliderBuilder::ball(rad).build(); - colliders.insert(collider, handle, &mut bodies); + colliders.insert_with_parent(collider, handle, &mut bodies); } } } @@ -65,5 +66,5 @@ pub fn init_world(testbed: &mut Testbed) { * Set up the testbed. */ testbed.set_world(bodies, colliders, joints); - testbed.look_at(Point2::new(0.0, 0.0), 10.0); + testbed.look_at(point![0.0, 0.0], 10.0); } diff --git a/examples2d/pyramid2.rs b/examples2d/pyramid2.rs index dfa64c9..76616be 100644 --- a/examples2d/pyramid2.rs +++ b/examples2d/pyramid2.rs @@ -1,6 +1,4 @@ -use na::Point2; -use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier2d::prelude::*; use rapier_testbed2d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -20,7 +18,7 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::new_static().build(); let ground_handle = bodies.insert(rigid_body); let colli |
