diff options
| author | Crozet Sébastien <developer@crozet.re> | 2021-03-29 17:21:49 +0200 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2021-03-29 17:21:49 +0200 |
| commit | a733f97028f5cd532212572f9561ab64e09f002b (patch) | |
| tree | 7b776c21660f1069ad472dd17e7e6fa9083cbd8f /src/dynamics/rigid_body.rs | |
| parent | 8173e7ada2e3f5c99de53b532adc085a26c1cefd (diff) | |
| download | rapier-a733f97028f5cd532212572f9561ab64e09f002b.tar.gz rapier-a733f97028f5cd532212572f9561ab64e09f002b.tar.bz2 rapier-a733f97028f5cd532212572f9561ab64e09f002b.zip | |
Implement the ability to run multiple CCD substeps.
Diffstat (limited to 'src/dynamics/rigid_body.rs')
| -rw-r--r-- | src/dynamics/rigid_body.rs | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index 3c6bd65..08c5629 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -5,7 +5,7 @@ use crate::geometry::{ use crate::math::{ AngVector, AngularInertia, Isometry, Point, Real, Rotation, Translation, Vector, }; -use crate::utils::{self, WCross, WDot}; +use crate::utils::{self, WAngularInertia, WCross, WDot}; use na::ComplexField; use num::Zero; @@ -37,6 +37,7 @@ bitflags::bitflags! { const ROTATION_LOCKED_Y = 1 << 2; const ROTATION_LOCKED_Z = 1 << 3; const CCD_ENABLED = 1 << 4; + const CCD_ACTIVE = 1 << 5; } } @@ -204,12 +205,20 @@ impl RigidBody { self.flags.contains(RigidBodyFlags::CCD_ENABLED) } - pub(crate) fn is_moving_fast(&self, dt: Real) -> bool { - self.is_dynamic() && self.linvel.norm() * dt > self.ccd_thickness + // This is different from `is_ccd_enabled`. This checks that CCD + // is active for this rigid-body, i.e., if it was seen to move fast + // enough to justify a CCD run. + pub(crate) fn is_ccd_active(&self) -> bool { + self.flags.contains(RigidBodyFlags::CCD_ACTIVE) + } + + pub(crate) fn update_ccd_active_flag(&mut self, dt: Real) { + let ccd_active = self.is_ccd_enabled() && self.is_moving_fast(dt); + self.flags.set(RigidBodyFlags::CCD_ACTIVE, ccd_active); } - pub(crate) fn should_resolve_ccd(&self, dt: Real) -> bool { - self.is_ccd_enabled() && self.is_moving_fast(dt) + pub(crate) fn is_moving_fast(&self, dt: Real) -> bool { + self.is_dynamic() && self.linvel.norm() * dt > self.ccd_thickness } /// Sets the rigid-body's mass properties. @@ -373,6 +382,19 @@ impl RigidBody { !self.linvel.is_zero() || !self.angvel.is_zero() } + pub(crate) fn predict_position_using_velocity_and_forces(&self, dt: Real) -> Isometry<Real> { + let dlinvel = self.force * (self.effective_inv_mass * dt); + let dangvel = self + .effective_world_inv_inertia_sqrt + .transform_vector(self.torque * dt); + let linvel = self.linvel + dlinvel; + let angvel = self.angvel + dangvel; + + let com = self.position * self.mass_properties.local_com; + let shift = Translation::from(com.coords); + shift * Isometry::new(linvel * dt, angvel * dt) * shift.inverse() * self.position + } + pub(crate) fn integrate_velocity(&self, dt: Real) -> Isometry<Real> { let com = self.position * self.mass_properties.local_com; let shift = Translation::from(com.coords); |
