Fix collider insertion/removal tracking.

This commit is contained in:
Crozet Sébastien
2020-11-26 11:41:43 +01:00
parent f293dc6024
commit 391bcf372a
8 changed files with 53 additions and 75 deletions

View File

@@ -167,12 +167,10 @@ impl RigidBody {
/// Adds a collider to this rigid-body.
pub(crate) fn add_collider(&mut self, handle: ColliderHandle, coll: &Collider) {
if !self.changes.contains(RigidBodyChanges::MODIFIED) {
self.changes.set(
RigidBodyChanges::MODIFIED | RigidBodyChanges::COLLIDERS,
true,
);
}
self.changes.set(
RigidBodyChanges::MODIFIED | RigidBodyChanges::COLLIDERS,
true,
);
let mass_properties = coll
.mass_properties()
@@ -193,6 +191,7 @@ impl RigidBody {
/// Removes a collider from this rigid-body.
pub(crate) fn remove_collider_internal(&mut self, handle: ColliderHandle, coll: &Collider) {
if let Some(i) = self.colliders.iter().position(|e| *e == handle) {
self.changes.set(RigidBodyChanges::COLLIDERS, true);
self.colliders.swap_remove(i);
let mass_properties = coll
.mass_properties()

View File

@@ -63,8 +63,11 @@ impl ColliderSet {
coll.reset_internal_references();
coll.parent = parent_handle;
// NOTE: we use `get_mut` instead of `get_mut_internal` so that the
// modification flag is updated properly.
let parent = bodies
.get_mut_internal(parent_handle)
.get_mut(parent_handle)
.expect("Parent rigid body not found.");
coll.position = parent.position * coll.delta;
coll.predicted_position = parent.predicted_position * coll.delta;
@@ -89,7 +92,9 @@ impl ColliderSet {
/*
* Delete the collider from its parent body.
*/
if let Some(parent) = bodies.get_mut_internal(collider.parent) {
// NOTE: we use `get_mut` instead of `get_mut_internal` so that the
// modification flag is updated properly.
if let Some(parent) = bodies.get_mut(collider.parent) {
parent.remove_collider_internal(handle, &collider);
if wake_up {