diff options
| author | Thierry Berger <contact@thierryberger.com> | 2024-06-09 13:20:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-09 13:20:58 +0200 |
| commit | 8160b4ebdb06afb39f493b5c8f65d1dd280b3dfb (patch) | |
| tree | 1ce461648d0bec5f0dcd343ed213e41764ab2ccd | |
| parent | a8a0f297f52d4336c0d3b0effc24401e8066183b (diff) | |
| download | rapier-8160b4ebdb06afb39f493b5c8f65d1dd280b3dfb.tar.gz rapier-8160b4ebdb06afb39f493b5c8f65d1dd280b3dfb.tar.bz2 rapier-8160b4ebdb06afb39f493b5c8f65d1dd280b3dfb.zip | |
feat: change the character controller’s solve_character_collision_impulses to take multiple CharacterCollision (#646)
* character controller: solve multiple collisions
* add solve multiple collisions to changelog
* chore: apply review comments
---------
Co-authored-by: Sébastien Crozet <sebcrozet@dimforge.com>
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | src/control/character_controller.rs | 33 | ||||
| -rw-r--r-- | src_testbed/testbed.rs | 23 |
3 files changed, 43 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index dcd0ae9..429fb82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,8 @@ This release introduces two new crates: - Rename `JointAxesMask::X/Y/Z` to `::LIN_X/LIN_Y/LIN_Z` to avoid confusing it with `::ANG_X/ANG_Y/ANG_Z`. - The function `RigidBody::add_collider` is now private. It was only public because it was needed for some internal `bevy_rapier` plumbings, but it is no longer useful. Adding a collider must always go througthe `ColliderSet`. +- `CharacterController::solve_character_collision_impulses` now takes multiple `CharacterCollision` as parameter: + this change will allow further internal optimizations. ## v0.19.0 (05 May 2024) diff --git a/src/control/character_controller.rs b/src/control/character_controller.rs index 87b5c16..dc7381f 100644 --- a/src/control/character_controller.rs +++ b/src/control/character_controller.rs @@ -782,8 +782,8 @@ impl KinematicCharacterController { true } - /// For a given collision between a character and its environment, this method will apply - /// impulses to the rigid-bodies surrounding the character shape at the time of the collision. + /// For the given collisions between a character and its environment, this method will apply + /// impulses to the rigid-bodies surrounding the character shape at the time of the collisions. /// Note that the impulse calculation is only approximate as it is not based on a global /// constraints resolution scheme. pub fn solve_character_collision_impulses( @@ -794,6 +794,35 @@ impl KinematicCharacterController { queries: &QueryPipeline, character_shape: &dyn Shape, character_mass: Real, + collisions: impl IntoIterator<Item = CharacterCollision>, + filter: QueryFilter, + ) { + for collision in collisions { + self.solve_single_character_collision_impulse( + dt, + bodies, + colliders, + queries, + character_shape, + character_mass, + &collision, + filter, + ); + } + } + + /// For the given collision between a character and its environment, this method will apply + /// impulses to the rigid-bodies surrounding the character shape at the time of the collision. + /// Note that the impulse calculation is only approximate as it is not based on a global + /// constraints resolution scheme. + fn solve_single_character_collision_impulse( + &self, + dt: Real, + bodies: &mut RigidBodySet, + colliders: &ColliderSet, + queries: &QueryPipeline, + character_shape: &dyn Shape, + character_mass: Real, collision: &CharacterCollision, filter: QueryFilter, ) { diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs index 1defef6..dc747ed 100644 --- a/src_testbed/testbed.rs +++ b/src_testbed/testbed.rs @@ -811,19 +811,16 @@ impl<'a, 'b, 'c, 'd, 'e, 'f> Testbed<'a, 'b, 'c, 'd, 'e, 'f> { QueryFilter::new().exclude_rigid_body(character_handle), |c| collisions.push(c), ); - - for collision in &collisions { - controller.solve_character_collision_impulses( - phx.integration_parameters.dt, - &mut phx.bodies, - &phx.colliders, - &phx.query_pipeline, - character_collider.shape(), - character_mass, - collision, - QueryFilter::new().exclude_rigid_body(character_handle), - ) - } + controller.solve_character_collision_impulses( + phx.integration_parameters.dt, + &mut phx.bodies, + &phx.colliders, + &phx.query_pipeline, + character_collider.shape(), + character_mass, + collisions, + QueryFilter::new().exclude_rigid_body(character_handle), + ); let character_body = &mut phx.bodies[character_handle]; let pos = character_body.position(); |
