diff options
| author | Crozet Sébastien <developer@crozet.re> | 2021-04-26 17:59:25 +0200 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2021-04-26 18:00:50 +0200 |
| commit | c32da78f2a6014c491aa3e975fb83ddb7c80610e (patch) | |
| tree | edd20f23270baee1577c486f78d825eb93ea0de0 /examples2d | |
| parent | aaf80bfa872c6f29b248cab8eb5658ab0d73cb4a (diff) | |
| download | rapier-c32da78f2a6014c491aa3e975fb83ddb7c80610e.tar.gz rapier-c32da78f2a6014c491aa3e975fb83ddb7c80610e.tar.bz2 rapier-c32da78f2a6014c491aa3e975fb83ddb7c80610e.zip | |
Split rigid-bodies and colliders into multiple components
Diffstat (limited to 'examples2d')
| -rw-r--r-- | examples2d/add_remove2.rs | 9 | ||||
| -rw-r--r-- | examples2d/joints2.rs | 6 | ||||
| -rw-r--r-- | examples2d/one_way_platforms2.rs | 33 |
3 files changed, 27 insertions, 21 deletions
diff --git a/examples2d/add_remove2.rs b/examples2d/add_remove2.rs index 0aeffbe..826d5c9 100644 --- a/examples2d/add_remove2.rs +++ b/examples2d/add_remove2.rs @@ -31,9 +31,12 @@ pub fn init_world(testbed: &mut Testbed) { .map(|e| e.0) .collect(); for handle in to_remove { - physics - .bodies - .remove(handle, &mut physics.colliders, &mut physics.joints); + physics.bodies.remove( + handle, + &mut physics.islands, + &mut physics.colliders, + &mut physics.joints, + ); if let (Some(graphics), Some(window)) = (&mut graphics, &mut window) { graphics.remove_body_nodes(*window, handle); diff --git a/examples2d/joints2.rs b/examples2d/joints2.rs index d1a1942..4d7d060 100644 --- a/examples2d/joints2.rs +++ b/examples2d/joints2.rs @@ -1,5 +1,5 @@ use na::Point2; -use rapier2d::dynamics::{BallJoint, BodyStatus, JointSet, RigidBodyBuilder, RigidBodySet}; +use rapier2d::dynamics::{BallJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType}; use rapier2d::geometry::{ColliderBuilder, ColliderSet}; use rapier_testbed2d::Testbed; @@ -31,9 +31,9 @@ pub fn init_world(testbed: &mut Testbed) { let fi = i as f32; let status = if i == 0 && k == 0 { - BodyStatus::Static + RigidBodyType::Static } else { - BodyStatus::Dynamic + RigidBodyType::Dynamic }; let rigid_body = RigidBodyBuilder::new(status) diff --git a/examples2d/one_way_platforms2.rs b/examples2d/one_way_platforms2.rs index fc3acb1..90607f7 100644 --- a/examples2d/one_way_platforms2.rs +++ b/examples2d/one_way_platforms2.rs @@ -9,12 +9,15 @@ struct OneWayPlatformHook { platform2: ColliderHandle, } -impl PhysicsHooks for OneWayPlatformHook { +impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook { fn active_hooks(&self) -> PhysicsHooksFlags { PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS } - fn modify_solver_contacts(&self, context: &mut ContactModificationContext) { + fn modify_solver_contacts( + &self, + context: &mut ContactModificationContext<RigidBodySet, ColliderSet>, + ) { // The allowed normal for the first platform is its local +y axis, and the // allowed normal for the second platform is its local -y axis. // @@ -29,16 +32,16 @@ impl PhysicsHooks for OneWayPlatformHook { // - If context.collider_handle2 == self.platform2 then the allowed normal -y needs to be flipped to +y. let mut allowed_local_n1 = Vector2::zeros(); - if context.collider_handle1 == self.platform1 { + if context.collider1 == self.platform1 { allowed_local_n1 = Vector2::y(); - } else if context.collider_handle2 == self.platform1 { + } else if context.collider2 == self.platform1 { // Flip the allowed direction. allowed_local_n1 = -Vector2::y(); } - if context.collider_handle1 == self.platform2 { + if context.collider1 == self.platform2 { allowed_local_n1 = -Vector2::y(); - } else if context.collider_handle2 == self.platform2 { + } else if context.collider2 == self.platform2 { // Flip the allowed direction. allowed_local_n1 = Vector2::y(); } @@ -47,13 +50,12 @@ impl PhysicsHooks for OneWayPlatformHook { context.update_as_oneway_platform(&allowed_local_n1, 0.1); // Set the surface velocity of the accepted contacts. - let tangent_velocity = if context.collider_handle1 == self.platform1 - || context.collider_handle2 == self.platform2 - { - -12.0 - } else { - 12.0 - }; + let tangent_velocity = + if context.collider1 == self.platform1 || context.collider2 == self.platform2 { + -12.0 + } else { + 12.0 + }; for contact in context.solver_contacts.iter_mut() { contact.tangent_velocity.x = tangent_velocity; @@ -115,13 +117,14 @@ pub fn init_world(testbed: &mut Testbed) { } } - physics.bodies.foreach_active_dynamic_body_mut(|_, body| { + for handle in physics.islands.active_dynamic_bodies() { + let body = &mut physics.bodies[*handle]; if body.position().translation.y > 1.0 { body.set_gravity_scale(1.0, false); } else if body.position().translation.y < -1.0 { body.set_gravity_scale(-1.0, false); } - }); + } }); /* |
