diff options
| author | Sébastien Crozet <developer@crozet.re> | 2022-04-19 18:57:40 +0200 |
|---|---|---|
| committer | Sébastien Crozet <sebastien@crozet.re> | 2022-04-20 19:02:49 +0200 |
| commit | 2b1374c596957ac8cabe085859be3b823a1ba0c6 (patch) | |
| tree | a7f37ec29199a5a2c6198a6b001e665524fdab96 /src/dynamics | |
| parent | ee679427cda6363e4de94a59e293d01133a44d1f (diff) | |
| download | rapier-2b1374c596957ac8cabe085859be3b823a1ba0c6.tar.gz rapier-2b1374c596957ac8cabe085859be3b823a1ba0c6.tar.bz2 rapier-2b1374c596957ac8cabe085859be3b823a1ba0c6.zip | |
First round deleting the component sets.
Diffstat (limited to 'src/dynamics')
23 files changed, 411 insertions, 815 deletions
diff --git a/src/dynamics/ccd/ccd_solver.rs b/src/dynamics/ccd/ccd_solver.rs index bd3b20b..8fc5a7f 100644 --- a/src/dynamics/ccd/ccd_solver.rs +++ b/src/dynamics/ccd/ccd_solver.rs @@ -1,11 +1,11 @@ use super::TOIEntry; -use crate::data::{BundleSet, ComponentSet, ComponentSetMut, ComponentSetOption}; -use crate::dynamics::{IslandManager, RigidBodyColliders, RigidBodyForces}; use crate::dynamics::{ - RigidBodyCcd, RigidBodyHandle, RigidBodyMassProps, RigidBodyPosition, RigidBodyVelocity, + IslandManager, RigidBodyCcd, RigidBodyColliders, RigidBodyForces, RigidBodyHandle, + RigidBodyMassProps, RigidBodyPosition, RigidBodySet, RigidBodyVelocity, }; use crate::geometry::{ - ColliderParent, ColliderPosition, ColliderShape, ColliderType, CollisionEvent, NarrowPhase, + ColliderParent, ColliderPosition, ColliderSet, ColliderShape, ColliderType, CollisionEvent, + NarrowPhase, }; use crate::math::Real; use crate::parry::utils::SortedPair; @@ -57,13 +57,7 @@ impl CCDSolver { /// Apply motion-clamping to the bodies affected by the given `impacts`. /// /// The `impacts` should be the result of a previous call to `self.predict_next_impacts`. - pub fn clamp_motions<Bodies>(&self, dt: Real, bodies: &mut Bodies, impacts: &PredictedImpacts) - where - Bodies: ComponentSet<RigidBodyCcd> - + ComponentSetMut<RigidBodyPosition> - + ComponentSet<RigidBodyVelocity> - + ComponentSet<RigidBodyMassProps>, - { + pub fn clamp_motions(&self, dt: Real, bodies: &mut RigidBodySet, impacts: &PredictedImpacts) { match impacts { PredictedImpacts::Impacts(tois) => { for (handle, toi) in tois { @@ -93,18 +87,13 @@ impl CCDSolver { /// Updates the set of bodies that needs CCD to be resolved. /// /// Returns `true` if any rigid-body must have CCD resolved. - pub fn update_ccd_active_flags<Bodies>( + pub fn update_ccd_active_flags( &self, islands: &IslandManager, - bodies: &mut Bodies, + bodies: &mut RigidBodySet, dt: Real, include_forces: bool, - ) -> bool - where - Bodies: ComponentSetMut<RigidBodyCcd> - + ComponentSet<RigidBodyVelocity> - + ComponentSet<RigidBodyForces>, - { + ) -> bool { let mut ccd_active = false; // println!("Checking CCD activation"); @@ -128,27 +117,14 @@ impl CCDSolver { } /// Find the first time a CCD-enabled body has a non-sensor collider hitting another non-sensor collider. - pub fn find_first_impact<Bodies, Colliders>( + pub fn find_first_impact( &mut self, dt: Real, islands: &IslandManager, - bodies: &Bodies, - colliders: &Colliders, + bodies: &RigidBodySet, + colliders: &ColliderSet, narrow_phase: &NarrowPhase, - ) -> Option<Real> - where - Bodies: ComponentSet<RigidBodyPosition> - + ComponentSet<RigidBodyVelocity> - + ComponentSet<RigidBodyCcd> - + ComponentSet<RigidBodyColliders> - + ComponentSet<RigidBodyForces> - + ComponentSet<RigidBodyMassProps>, - Colliders: ComponentSetOption<ColliderParent> - + ComponentSet<ColliderPosition> - + ComponentSet<ColliderShape> - + ComponentSet<ColliderType> - + ComponentSet<ColliderFlags>, - { + ) -> Option<Real> { // Update the query pipeline. self.query_pipeline.update_with_mode( islands, @@ -266,29 +242,15 @@ impl CCDSolver { } /// Outputs the set of bodies as well as their first time-of-impact event. - pub fn predict_impacts_at_next_positions<Bodies, Colliders>( + pub fn predict_impacts_at_next_positions( &mut self, dt: Real, islands: &IslandManager, - bodies: &Bodies, - colliders: &Colliders, + bodies: &RigidBodySet, + colliders: &ColliderSet, narrow_phase: &NarrowPhase, events: &dyn EventHandler, - ) -> PredictedImpacts - where - Bodies: ComponentSet<RigidBodyPosition> - + ComponentSet<RigidBodyVelocity> - + ComponentSet<RigidBodyCcd> - + ComponentSet<RigidBodyColliders> - + ComponentSet<RigidBodyForces> - + ComponentSet<RigidBodyMassProps>, - Colliders: ComponentSetOption<ColliderParent> - + ComponentSet<ColliderPosition> - + ComponentSet<ColliderShape> - + ComponentSet<ColliderType> - + ComponentSet<ColliderFlags> - + ComponentSet<ColliderFlags>, - { + ) -> PredictedImpacts { let mut frozen = HashMap::<_, Real>::default(); let mut all_toi = BinaryHeap::new(); let mut pairs_seen = HashMap::default(); diff --git a/src/dynamics/island_manager.rs b/src/dynamics/island_manager.rs index 06f3820..0cb92e9 100644 --- a/src/dynamics/island_manager.rs +++ b/src/dynamics/island_manager.rs @@ -1,9 +1,8 @@ -use crate::data::{BundleSet, ComponentSet, ComponentSetMut, ComponentSetOption}; use crate::dynamics::{ ImpulseJointSet, MultibodyJointSet, RigidBodyActivation, RigidBodyColliders, RigidBodyHandle, - RigidBodyIds, RigidBodyType, RigidBodyVelocity, + RigidBodyIds, RigidBodySet, RigidBodyType, RigidBodyVelocity, }; -use crate::geometry::{ColliderParent, NarrowPhase}; +use crate::geometry::{ColliderSet, NarrowPhase}; use crate::math::Real; use crate::utils::WDot; @@ -40,10 +39,7 @@ impl IslandManager { } /// Update this data-structure after one or multiple rigid-bodies have been removed for `bodies`. - pub fn cleanup_removed_rigid_bodies( - &mut self, - bodies: &mut impl ComponentSetMut<RigidBodyIds>, - ) { + pub fn cleanup_removed_rigid_bodies(&mut self, bodies: &mut RigidBodySet) { let mut active_sets = [&mut self.active_kinematic_set, &mut self.active_dynamic_set]; for active_set in &mut active_sets { @@ -69,7 +65,7 @@ impl IslandManager { &mut self, removed_handle: RigidBodyHandle, removed_ids: &RigidBodyIds, - bodies: &mut impl ComponentSetMut<RigidBodyIds>, + bodies: &mut RigidBodySet, ) { let mut active_sets = [&mut self.active_kinematic_set, &mut self.active_dynamic_set]; @@ -77,10 +73,11 @@ impl IslandManager { if active_set.get(removed_ids.active_set_id) == Some(&removed_handle) { active_set.swap_remove(removed_ids.active_set_id); - if let Some(replacement) = active_set.get(removed_ids.active_set_id) { - bodies.map_mut_internal(replacement.0, |ids| { - ids.active_set_id = removed_ids.active_set_id; - }); + if let Some(replacement) = active_set + .get(removed_ids.active_set_id) + .and_then(|h| bodies.get_mut_internal(*h)) + { + replacement.ids.active_set_id = removed_ids.active_set_id; } } } @@ -90,17 +87,11 @@ impl IslandManager { /// /// If `strong` is `true` then it is assured that the rigid-body will /// remain awake during multiple subsequent timesteps. - pub fn wake_up<Bodies>(&mut self, bodies: &mut Bodies, handle: RigidBodyHandle, strong: bool) - where - Bodies: ComponentSetMut<RigidBodyActivation> - + ComponentSetOption<RigidBodyType> - + ComponentSetMut<RigidBodyIds>, - { + pub fn wake_up(&mut self, bodies: &mut RigidBodySet, handle: RigidBodyHandle, strong: bool) { // NOTE: the use an Option here because there are many legitimate cases (like when // deleting a joint attached to an already-removed body) where we could be // attempting to wake-up a rigid-body that has already been deleted. - let rb_type: Option<RigidBodyType> = bodies.get(handle.0).copied(); - if rb_type == Some(RigidBodyType::Dynamic) { + if bodies.get(handle).map(|rb| rb.body_type()) == Some(RigidBodyType::Dynamic) { bodies.map_mut_internal(handle.0, |activation: &mut RigidBodyActivation| { activation.wake_up(strong) }); @@ -141,23 +132,16 @@ impl IslandManager { self.active_islands[island_id]..self.active_islands[island_id + 1] } - pub(crate) fn update_active_set_with_contacts<Bodies, Colliders>( + pub(crate) fn update_active_set_with_contacts( &mut self, dt: Real, - bodies: &mut Bodies, - colliders: &Colliders, + bodies: &mut RigidBodySet, + colliders: &ColliderSet, narrow_phase: &NarrowPhase, impulse_joints: &ImpulseJointSet, multibody_joints: &MultibodyJointSet, min_island_size: usize, - ) where - Bodies: ComponentSetMut<RigidBodyIds> - + ComponentSetMut<RigidBodyActivation> - + ComponentSetMut<RigidBodyVelocity> - + ComponentSet<RigidBodyColliders> - + ComponentSet<RigidBodyType>, - Colliders: ComponentSetOption<ColliderParent>, - { + ) { assert!( min_island_size > 0, "The minimum island size must be at least 1." @@ -203,7 +187,7 @@ impl IslandManager { #[inline(always)] fn push_contacting_bodies( rb_colliders: &RigidBodyColliders, - colliders: &impl ComponentSetOption<ColliderParent>, + colliders: &ColliderSet, narrow_phase: &NarrowPhase, stack: &mut Vec<RigidBodyHandle>, ) { diff --git a/src/dynamics/joint/impulse_joint/impulse_joint_set.rs b/src/dynamics/joint/impulse_joint/impulse_joint_set.rs index 448b87d..6b6d980 100644 --- a/src/dynamics/joint/impulse_joint/impulse_joint_set.rs +++ b/src/dynamics/joint/impulse_joint/impulse_joint_set.rs @@ -2,9 +2,11 @@ use super::ImpulseJoint; use crate::geometry::{InteractionGraph, RigidBodyGraphIndex, TemporaryInteractionIndex}; use crate::data::arena::Arena; -use crate::data::{BundleSet, Coarena, ComponentSet, ComponentSetMut}; -use crate::dynamics::{GenericJoint, RigidBodyHandle}; -use crate::dynamics::{IslandManager, RigidBodyActivation, RigidBodyIds, RigidBodyType}; +use crate::data::Coarena; +use crate::dynamics::{ + GenericJoint, IslandManager, RigidBodyActivation, RigidBodyHandle, RigidBodyIds, RigidBodySet, + RigidBodyType, +}; /// The unique identifier of a joint added to the joint set. /// The unique identifier of a collider added to a collider set. @@ -215,16 +217,12 @@ impl ImpulseJointSet { /// Retrieve all the impulse_joints happening between two active bodies. // NOTE: this is very similar to the code from NarrowPhase::select_active_interactions. - pub(crate) fn select_active_interactions<Bodies>( + pub(crate) fn select_active_interactions( &self, islands: &IslandManager, - bodies: &Bodies, + bodies: &RigidBodySet, out: &mut Vec<Vec<JointIndex>>, - ) where - Bodies: ComponentSet<RigidBodyType> - + ComponentSet<RigidBodyActivation> - + ComponentSet<RigidBodyIds>, - { + ) { for out_island in &mut out[..islands.num_islands()] { out_island.clear(); } @@ -263,18 +261,13 @@ impl ImpulseJointSet { /// /// If `wake_up` is set to `true`, then the bodies attached to this joint will be /// automatically woken up. - pub fn remove<Bodies>( + pub fn remove( &mut self, handle: ImpulseJointHandle, islands: &mut IslandManager, - bodies: &mut Bodies, + bodies: &mut RigidBodySet, wake_up: bool, - ) -> Option<ImpulseJoint> - where - Bodies: ComponentSetMut<RigidBodyActivation> - + ComponentSet<RigidBodyType> - + ComponentSetMut<RigidBodyIds>, - { + ) -> Option<ImpulseJoint> { let id = self.joint_ids.remove(handle.0)?; let endpoints = self.joint_graph.graph.edge_endpoints(id)?; @@ -302,17 +295,12 @@ impl ImpulseJointSet { /// The provided rigid-body handle is not required to identify a rigid-body that /// is still contained by the `bodies` component set. /// Returns the (now invalid) handles of the removed impulse_joints. - pub fn remove_joints_attached_to_rigid_body<Bodies>( + pub fn remove_joints_attached_to_rigid_body( &mut self, handle: RigidBodyHandle, islands: &mut IslandManager, - bodies: &mut Bodies, - ) -> Vec<ImpulseJointHandle> - where - Bodies: ComponentSetMut<RigidBodyActivation> - + ComponentSet<RigidBodyType> - + ComponentSetMut<RigidBodyIds>, - { + bodies: &mut RigidBodySet, + ) -> Vec<ImpulseJointHandle> { let mut deleted = vec![]; if let Some(deleted_id) = self diff --git a/src/dynamics/joint/multibody_joint/multibody.rs b/src/dynamics/joint/multibody_joint/multibody.rs index c4cc85f..5bd790a 100644 --- a/src/dynamics/joint/multibody_joint/multibody.rs +++ b/src/dynamics/joint/multibody_joint/multibody.rs @@ -1,10 +1,8 @@ use super::multibody_link::{MultibodyLink, MultibodyLinkVec}; use super::multibody_workspace::MultibodyWorkspace; -use crate::data::{BundleSet, ComponentSet, ComponentSetMut}; -use crate::dynamics::solver::AnyJointVelocityConstraint; use crate::dynamics::{ - IntegrationParameters, RigidBodyForces, RigidBodyHandle, RigidBodyMassProps, RigidBodyPosition, - RigidBodyType, RigidBodyVelocity, + solver::AnyJointVelocityConstraint, IntegrationParameters, RigidBodyForces, RigidBodyHandle, + RigidBodyMassProps, RigidBodySet, RigidBodyType, RigidBodyVelocity, }; #[cfg(feature = "dim3")] use crate::math::Matrix; @@ -369,12 +367,7 @@ impl Multibody { .extend((0..num_jacobians).map(|_| Jacobian::zeros(0))); } - pub(crate) fn update_acceleration<Bodies>(&mut self, bodies: &Bodies) - where - Bodies: ComponentSet<RigidBodyMassProps> - + ComponentSet<RigidBodyForces> - + ComponentSet<RigidBodyVelocity>, - { + pub(crate) fn update_acceleration(&mut self, bodies: &RigidBodySet) { if self.ndofs == 0 { return; // Nothing to do. } @@ -452,10 +445,7 @@ impl Multibody { } /// Computes the constant terms of the dynamics. - pub(crate) fn update_dynamics<Bodies>(&mut self, dt: Real, bodies: &mut Bodies) - where - Bodies: ComponentSetMut<RigidBodyVelocity> + ComponentSet<RigidBodyMassProps>, - { + pub(crate) fn update_dynamics(&mut self, dt: Real, bodies: &mut RigidBodySet) { /* * Compute velocities. * NOTE: this is needed for kinematic bodies too. @@ -545,10 +535,7 @@ impl Multibody { } } - fn update_inertias<Bodies>(&mut self, dt: Real, bodies: &Bodies) - where - Bodies: ComponentSet<RigidBodyMassProps> + ComponentSet<RigidBodyVelocity>, - { + fn update_inertias(&mut self, dt: Real, bodies: &RigidBodySet) { if self.ndofs == 0 { return; // Nothing to do. } @@ -790,17 +777,11 @@ impl Multibody { } } - pub(crate) fn update_root_type<Bodies>(&mut self, bodies: &mut Bodies) - where - Bodies: ComponentSet<RigidBodyType> + ComponentSet<RigidBodyPosition>, - { - let rb_type: Option<&RigidBodyType> = bodies.get(self.links[0].rigid_body.0); - if let Some(rb_type) = rb_type { - let rb_pos: &RigidBodyPosition = bodies.index(self.links[0].rigid_body.0); - - if rb_type.is_dynamic() != self.root_is_dynamic { - if rb_type.is_dynamic() { - let free_joint = MultibodyJoint::free(rb_pos.position); + pub(crate) fn update_root_type(&mut self, bodies: &mut RigidBodySet) { + if let Some(rb) = bodies.get(self.links[0].rigid_body) { + if rb.is_dynamic() != self.root_is_dynamic { + if rb.is_dynamic() { + let free_joint = MultibodyJoint::free(*rb.position()); let prev_root_ndofs = self.links[0].joint().ndofs(); self.links[0].joint = free_joint; self.links[0].assembly_id = 0; @@ -819,7 +800,7 @@ impl Multibody { assert!(self.damping.len() >= SPATIAL_DIM); assert!(self.accelerations.len() >= SPATIAL_DIM); - let fixed_joint = MultibodyJoint::fixed(rb_pos.position); + let fixed_joint = MultibodyJoint::fixed(*rb.position()); let prev_root_ndofs = self.links[0].joint().ndofs(); self.links[0].joint = fixed_joint; self.links[0].assembly_id = 0; @@ -844,39 +825,31 @@ impl Multibody { } } - self.root_is_dynamic = rb_type.is_dynamic(); + self.root_is_dynamic = rb.is_dynamic(); } // Make sure the positions are properly set to match the rigid-body’s. if self.links[0].joint.data.locked_axes.is_empty() { - self.links[0].joint.set_free_pos(rb_pos.position); + self.links[0].joint.set_free_pos(*rb.position()); } else { - self.links[0].joint.data.local_frame1 = rb_pos.position; + self.links[0].joint.data.local_frame1 = *rb.position(); } } } /// Apply forward-kinematics to this multibody and its related rigid-bodies. - pub fn forward_kinematics<Bodies>(&mut self, bodies: &mut Bodies, update_mass_props: bool) - where - Bodies: ComponentSet<RigidBodyType> - + ComponentSetMut<RigidBodyMassProps> - + ComponentSetMut<RigidBodyPosition>, - { + pub fn forward_kinematics(&mut self, bodies: &mut RigidBodySet, update_mass_props: bool) { // Special case for the root, which has no parent. { let link = &mut self.links[0]; link.local_to_parent = link.joint.body_to_parent(); link.local_to_world = link.local_to_parent; - bodies.map_mut_internal(link.rigid_body.0, |rb_pos: &mut RigidBodyPosition| { - rb_pos.next_position = link.local_to_world; - }); - - if update_mass_props { - bodies.map_mut_internal(link.rigid_body.0, |mprops: &mut RigidBodyMassProps| { - mprops.update_world_mass_properties(&link.local_to_world) - }); + if let Some(rb) = bodies.get_mut_internal(link.rigid_body) { + rb.pos.next_position = link.local_to_world; + if update_mass_props { + rb.mprops.update_world_mass_properties(&link.local_to_world); + } } } @@ -888,32 +861,30 @@ impl Multibody { link.local_to_world = parent_link.local_to_world * link.local_to_parent; { - let parent_rb_mprops: &RigidBodyMassProps = bodies.index(parent_link.rigid_body.0); - let rb_mprops: &RigidBodyMassProps = bodies.index(link.rigid_body.0); - let c0 = parent_link.local_to_world * parent_rb_mprops.local_mprops.local_com; + let parent_rb = &bodies[parent_link.rigid_body]; + let link_rb = &bodies[link.rigid_body]; + let c0 = parent_link.local_to_world * parent_rb.mprops.local_mprops.local_com; let c2 = link.local_to_world * Point::from(link.joint.data.local_frame2.translation.vector); - let c3 = link.local_to_world * rb_mprops.local_mprops.local_com; + let c3 = link.local_to_world * link_rb.mprops.local_mprops.local_com; link.shift02 = c2 - c0; link.shift23 = c3 - c2; } - bodies.map_mut_internal(link.rigid_body.0, |rb_pos: &mut RigidBodyPosition| { - rb_pos.next_position = link.local_to_world; - }); + let link_rb = bodies.index_mut_internal(link.rigid_body); + link_rb.pos.next_position = link.local_to_world; - let rb_type: &RigidBodyType = bodies.index(link.rigid_body.0); assert_eq!( - *rb_type, + link_rb.body_type, RigidBodyType::Dynamic, "A rigid-body that is not at the root of a multibody must be dynamic." ); if update_mass_props { - bodies.map_mut_internal(link.rigid_body.0, |rb_mprops: &mut RigidBodyMassProps| { - rb_mprops.update_world_mass_properties(&link.local_to_world) - }); + link_rb + .mprops + .update_world_mass_properties(&link.local_to_world); } } diff --git a/src/dynamics/joint/multibody_joint/multibody_joint_set.rs b/src/dynamics/joint/multibody_joint/multibody_joint_set.rs index 0365062..748530f 100644 --- a/src/dynamics/joint/multibody_joint/multibody_joint_set.rs +++ b/src/dynamics/joint/multibody_joint/multibody_joint_set.rs @@ -1,8 +1,7 @@ -use crate::data::{Arena, Coarena, ComponentSet, ComponentSetMut, Index}; +use crate::data::{Arena, Coarena, Index}; use crate::dynamics::joint::MultibodyLink; use crate::dynamics::{ - GenericJoint, IslandManager, Multibody, MultibodyJoint, RigidBodyActivation, RigidBodyHandle, - RigidBodyIds, RigidBodyType, + GenericJoint, IslandManager, Multibody, MultibodyJoint, RigidBodyHandle, RigidBodySet, }; use crate::geometry::{InteractionGraph, RigidBodyGraphIndex}; use crate::parry::partitioning::IndexedData; @@ -163,17 +162,13 @@ impl MultibodyJointSet { } /// Removes an multibody_joint from this set. - pub fn remove<Bodies>( + pub fn remove( &mut self, handle: MultibodyJointHandle, islands: &mut IslandManager, - bodies: &mut Bodies, + bodies: &mut RigidBodySet, wake_up: bool, - ) where - Bodies: ComponentSetMut<RigidBodyActivation> - + ComponentSet<RigidBodyType> - + ComponentSetMut<RigidBodyIds>, - { + ) { if let Some(removed) = self.rb2mb.get(handle.0).copied() { let multibody = self.multibodies.remove(removed.multibody.0).unwrap(); @@ -216,17 +211,13 @@ impl MultibodyJointSet { } /// Removes all the multibody_joints from the multibody the given rigid-body is part of. - pub fn remove_multibody_articulations<Bodies>( + pub fn remove_multibody_articulations( &mut self, handle: RigidBodyHandle, islands: &mut IslandManager, - bodies: &mut Bodies, + bodies: &mut RigidBodySet, wake_up: bool, - ) where - Bodies: ComponentSetMut<RigidBodyActivation> - + ComponentSet<RigidBodyType> - + ComponentSetMut<RigidBodyIds>, - { + ) { if let Some(removed) = self.rb2mb.get(handle.0).copied() { // Remove the multibody. let multibody = self.multibodies.remove(removed.multibody.0).unwrap(); @@ -248,16 +239,12 @@ impl MultibodyJointSet { } /// Removes all the multibody joints attached to a rigid-body. - pub fn remove_joints_attached_to_rigid_body<Bodies>( + pub fn remove_joints_attached_to_rigid_body( &mut self, rb_to_remove: RigidBodyHandle, islands: &mut IslandManager, - bodies: &mut Bodies, - ) where - Bodies: ComponentSetMut<RigidBodyActivation> - + ComponentSet<RigidBodyType> - + ComponentSetMut<RigidBodyIds>, - { + bodies: &mut RigidBodySet, + ) { // TODO: optimize this. if let Some(link_to_remove) = self.rb2mb.get(rb_to_remove.0).copied() { let mut articulations_to_remove = vec![]; diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index d4746ba..cf52c1f 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -17,21 +17,21 @@ use num::Zero; /// To create a new rigid-body, use the `RigidBodyBuilder` structure. #[derive(Debug, Clone)] pub struct RigidBody { - pub(crate) rb_pos: RigidBodyPosition, - pub(crate) rb_mprops: RigidBodyMassProps, - pub(crate) rb_vels: RigidBodyVelocity, - pub(crate) rb_damping: RigidBodyDamping, - pub(crate) rb_forces: RigidBodyForces, - pub(crate) rb_ccd: RigidBodyCcd, - pub(crate) rb_ids: RigidBodyIds, - pub(crate) rb_colliders: RigidBodyColliders, + pub(crate) pos: RigidBodyPosition, + pub(crate) mprops: RigidBodyMassProps, + pub(crate) vels: RigidBodyVelocity, + pub(crate) damping: RigidBodyDamping, + pub(crate) forces: RigidBodyForces, + pub(crate) ccd: RigidBodyCcd, + pub(crate) ids: RigidBodyIds, + pub(crate) colliders: RigidBodyColliders, /// Whether or not this rigid-body is sleeping. - pub(crate) rb_activation: RigidBodyActivation, + pub(crate) activation: RigidBodyActivation, pub(crate) changes: RigidBodyChanges, /// The status of the body, governing how it is affected by external forces. - pub(crate) rb_type: RigidBodyType, + pub(crate) body_type: RigidBodyType, /// The dominance group this rigid-body is part of. - pub(crate) rb_dominance: RigidBodyDominance, + pub(crate) dominance: RigidBodyDominance, /// User-defined data associated to this rigid-body. pub user_data: u128, } @@ -45,75 +45,75 @@ impl Default for RigidBody { impl RigidBody { fn new() -> Self { Self { - rb_pos: RigidBodyPosition::default(), - rb_mprops: RigidBodyMassProps::default(), - rb_vels: RigidBodyVelocity::default(), - rb_damping: RigidBodyDamping::default(), - rb_forces: RigidBodyForces::default(), - rb_ccd: RigidBodyCcd::default(), - rb_ids: RigidBodyIds::default(), - rb_colliders: RigidBodyColliders::default(), - rb_activation: RigidBodyActivation::active(), + pos: RigidBodyPosition::default(), + mprops: RigidBodyMassProps::default(), + vels: RigidBodyVelocity::default(), + damping: RigidBodyDamping::default(), + forces: RigidBodyForces::default(), + ccd: RigidBodyCcd::default(), + ids: RigidBodyIds::default(), + colliders: RigidBodyColliders::default(), + activation: RigidBodyActivation::active(), changes: RigidBodyChanges::all(), - rb_type: RigidBodyType::Dynamic, - rb_dominance: RigidBodyDominance::default(), + body_type: RigidBodyType::Dynamic, + dominance: RigidBodyDominance::default(), user_data: 0, } } pub(crate) fn reset_internal_references(&mut self) { - self.rb_colliders.0 = Vec::new(); - self.rb_ids = Default::default(); + self.colliders.0 = Vec::new(); + self.ids = Default::default(); } /// The activation status of this rigid-body. pub fn activation(&self) -> &RigidBodyActivation { - &self.rb_activation + &self.activation } /// Mutable reference to the activation status of this rigid-body. pub fn activation_mut(&mut self) -> &mut RigidBodyActivation { self.changes |= RigidBodyChanges::SLEEP; - &mut self.rb_activation + &mut self.activation } /// The linear damping coefficient of this rigid-body. #[inline] pub fn linear_damping(&self) -> Real { - self.rb_damping.linear_damping + self.damping.linear_damping } /// Sets the linear damping coefficient of this rigid-body. #[inline] pub fn set_linear_damping(&mut self, damping: Real) { - self.rb_damping.linear_damping = damping; + self.damping.linear_damping = damping; } /// The angular damping coefficient of this rigid-body. #[inline] pub fn angular_damping(&self) -> Real { - self.rb_damping.angular_damping + self.damping.angular_damping } /// Sets the angular damping coefficient of this rigid-body. #[inline] pub fn set_angular_damping(&mut self, damping: Real) { - self.rb_damping.angular_damping = damping + self.damping.angular_damping = damping } /// The type of this rigid-body. pub fn body_type(&self) -> RigidBodyType { - self.rb_type + self.body_type } /// Sets the type of this rigid-body. pub fn set_body_type(&mut self, status: RigidBodyType) { - if status != self.rb_type { + if status != self.body_type { self.changes.insert(RigidBodyChanges::TYPE); - self.rb_type = status; + self.body_type = status; if status == RigidBodyType::Fixed { - self.rb_vels = RigidBodyVelocity::zero(); + self.vels = RigidBodyVelocity::zero(); } } } @@ -121,7 +121,7 @@ impl RigidBody { /// The mass properties of this rigid-body. #[inline] pub fn mass_properties(&self) -> &MassProperties { - &self.rb_mprops.local_mprops + &self.mprops.local_mprops } /// The dominance group of this rigid-body. @@ -130,18 +130,18 @@ impl RigidBody { /// rigid-bodies. #[inline] pub fn effective_dominance_group(&self) -> i16 { - self.rb_dominance.effective_group(&self.rb_type) + |
