diff options
| author | Sébastien Crozet <developer@crozet.re> | 2021-05-01 10:17:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-01 10:17:23 +0200 |
| commit | a385efc5582c7918f11c01a2b6bf26a46919d3a0 (patch) | |
| tree | c5b9c5e6fcb5561421e2b4b9d99f28e4c83c745e /examples2d/one_way_platforms2.rs | |
| parent | aaf80bfa872c6f29b248cab8eb5658ab0d73cb4a (diff) | |
| parent | 2dfbd9ae92c139e306afc87994adac82489f30eb (diff) | |
| download | rapier-a385efc5582c7918f11c01a2b6bf26a46919d3a0.tar.gz rapier-a385efc5582c7918f11c01a2b6bf26a46919d3a0.tar.bz2 rapier-a385efc5582c7918f11c01a2b6bf26a46919d3a0.zip | |
Merge pull request #183 from dimforge/bundles
Make Rapier accept any kind of data storage instead of RigidBodySet/ColliderSet
Diffstat (limited to 'examples2d/one_way_platforms2.rs')
| -rw-r--r-- | examples2d/one_way_platforms2.rs | 33 |
1 files changed, 18 insertions, 15 deletions
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); } - }); + } }); /* |
