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 +++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 33 deletions(-) (limited to 'examples3d/ccd3.rs') 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()); } -- cgit From 826ce5f014281fd04b7a18238f102f2591d0b255 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 1 Jun 2021 12:36:01 +0200 Subject: Rework the event system --- examples3d/ccd3.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'examples3d/ccd3.rs') diff --git a/examples3d/ccd3.rs b/examples3d/ccd3.rs index facdec1..8d676e3 100644 --- a/examples3d/ccd3.rs +++ b/examples3d/ccd3.rs @@ -96,6 +96,7 @@ pub fn init_world(testbed: &mut Testbed) { let collider = ColliderBuilder::ball(1.0) .density(10.0) .sensor(true) + .active_events(ActiveEvents::INTERSECTION_EVENTS) .build(); let rigid_body = RigidBodyBuilder::new_dynamic() .linvel(vector![1000.0, 0.0, 0.0]) -- cgit