aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/rigid_body_components.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-04-20 12:29:57 +0200
committerSébastien Crozet <sebastien@crozet.re>2022-04-20 19:02:49 +0200
commitf108520b5a110cf59864abac7ac6a37e2b5a1dd9 (patch)
tree3ed03fbce2128e5eb04ca29d25b42717987eb424 /src/dynamics/rigid_body_components.rs
parent2b1374c596957ac8cabe085859be3b823a1ba0c6 (diff)
downloadrapier-f108520b5a110cf59864abac7ac6a37e2b5a1dd9.tar.gz
rapier-f108520b5a110cf59864abac7ac6a37e2b5a1dd9.tar.bz2
rapier-f108520b5a110cf59864abac7ac6a37e2b5a1dd9.zip
Finalize refactoring
Diffstat (limited to 'src/dynamics/rigid_body_components.rs')
-rw-r--r--src/dynamics/rigid_body_components.rs25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/dynamics/rigid_body_components.rs b/src/dynamics/rigid_body_components.rs
index c7655e0..b818ce2 100644
--- a/src/dynamics/rigid_body_components.rs
+++ b/src/dynamics/rigid_body_components.rs
@@ -231,6 +231,7 @@ pub struct RigidBodyMassProps {
pub flags: LockedAxes,
/// The local mass properties of the rigid-body.
pub local_mprops: MassProperties,
+ /// Mass-properties of this rigid-bodies, added to the contributions of its attached colliders.
pub additional_local_mprops: Option<Box<MassProperties>>,
/// The world-space center of mass of the rigid-body.
pub world_com: Point<Real>,
@@ -307,11 +308,11 @@ impl RigidBodyMassProps {
.unwrap_or_else(MassProperties::default);
for handle in &attached_colliders.0 {
- if let Some(co) = colliders.get(handle) {
+ if let Some(co) = colliders.get(*handle) {
if let Some(co_parent) = co.parent {
let to_add = co
.mprops
- .mass_properties(&**co.shape)
+ .mass_properties(&*co.shape)
.transform_by(&co_parent.pos_wrt_parent);
self.local_mprops += to_add;
}
@@ -895,21 +896,17 @@ impl RigidBodyColliders {
) {
for handle in &self.0 {
// NOTE: the ColliderParent component must exist if we enter this method.
- let co_parent: &ColliderParent = colliders
- .get(handle.0)
- .expect("Could not find the ColliderParent component.");
- let new_pos = parent_pos * co_parent.pos_wrt_parent;
+ let co = colliders.index_mut_internal(*handle);
+ let new_pos = parent_pos * co.parent.as_ref().unwrap().pos_wrt_parent;
+
+ if !co.changes.contains(ColliderChanges::MODIFIED) {
+ modified_colliders.push(*handle);
+ }
// Set the modification flag so we can benefit from the modification-tracking
// when updating the narrow-phase/broad-phase afterwards.
- colliders.map_mut_internal(handle.0, |co_changes: &mut ColliderChanges| {
- if !co_changes.contains(ColliderChanges::MODIFIED) {
- modified_colliders.push(*handle);
- }
-
- *co_changes |= ColliderChanges::POSITION;
- });
- colliders.set_internal(handle.0, ColliderPosition(new_pos));
+ co.changes |= ColliderChanges::POSITION;
+ co.pos = ColliderPosition(new_pos);
}
}
}