diff options
| author | Sébastien Crozet <sebcrozet@dimforge.com> | 2024-04-14 15:54:39 +0200 |
|---|---|---|
| committer | Sébastien Crozet <sebastien@crozet.re> | 2024-04-30 23:10:46 +0200 |
| commit | 404e0324334acb2f7d2cb3b21b5da2e362926dd2 (patch) | |
| tree | f45c3fce2f808b5cfb4efda3109ed36f7218ddf3 /src/dynamics | |
| parent | 3ddf2441ea6c43aa98718e0ce8650c3b804062d4 (diff) | |
| download | rapier-404e0324334acb2f7d2cb3b21b5da2e362926dd2.tar.gz rapier-404e0324334acb2f7d2cb3b21b5da2e362926dd2.tar.bz2 rapier-404e0324334acb2f7d2cb3b21b5da2e362926dd2.zip | |
feat: add soft (solver-based) ccd implementation
Diffstat (limited to 'src/dynamics')
| -rw-r--r-- | src/dynamics/rigid_body.rs | 35 | ||||
| -rw-r--r-- | src/dynamics/rigid_body_components.rs | 3 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index 5af4131..e1075e6 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -436,7 +436,7 @@ impl RigidBody { ] } - /// Enables of disable CCD (continuous collision-detection) for this rigid-body. + /// Enables of disable CCD (Continuous Collision-Detection) for this rigid-body. /// /// CCD prevents tunneling, but may still allow limited interpenetration of colliders. pub fn enable_ccd(&mut self, enabled: bool) { @@ -448,6 +448,19 @@ impl RigidBody { self.ccd.ccd_enabled } + /// Enables of disable soft CCD (soft Continuous Collision-Detection) for this rigid-body. + /// + /// Soft-CCD helps prevent tunneling, but may still let tunnelling happen depending on solver + /// convergence. This is cheaper than the full ccd enabled by [`RigidBody::enable_ccd`]. + pub fn enable_soft_ccd(&mut self, enabled: bool) { + self.ccd.soft_ccd_enabled = enabled; + } + + /// Is Soft-CCD (Soft Continous Collision-Detection) enabled for this rigid-body? + pub fn is_soft_ccd_enabled(&self) -> bool { + self.ccd.soft_ccd_enabled + } + // 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. @@ -1101,10 +1114,15 @@ pub struct RigidBodyBuilder { pub can_sleep: bool, /// Whether or not the rigid-body is to be created asleep. pub sleeping: bool, - /// Whether continuous collision-detection is enabled for the rigid-body to be built. + /// Whether Continuous Collision-Detection is enabled for the rigid-body to be built. /// /// CCD prevents tunneling, but may still allow limited interpenetration of colliders. pub ccd_enabled: bool, + /// Whether Soft Continuous Collision-Detection is enabled for the rigid-body to be built. + /// + /// Soft-CCD helps prevent tunneling, but may still let tunnelling happen depending on solver + /// convergence. This is cheaper than the full ccd enabled by [`RigidBodyBuilder::ccd_enabled`]. + pub soft_ccd_enabled: bool, /// The dominance group of the rigid-body to be built. pub dominance_group: i8, /// Will the rigid-body being built be enabled? @@ -1134,6 +1152,7 @@ impl RigidBodyBuilder { can_sleep: true, sleeping: false, ccd_enabled: false, + soft_ccd_enabled: false, dominance_group: 0, enabled: true, user_data: 0, @@ -1378,7 +1397,7 @@ impl RigidBodyBuilder { self } - /// Sets whether or not continuous collision-detection is enabled for this rigid-body. + /// Sets whether or not Continuous Collision-Detection is enabled for this rigid-body. /// /// CCD prevents tunneling, but may still allow limited interpenetration of colliders. pub fn ccd_enabled(mut self, enabled: bool) -> Self { @@ -1386,6 +1405,15 @@ impl RigidBodyBuilder { self } + /// Sets whether or not Soft Continuous Collision-Detection is enabled for this rigid-body. + /// + /// Soft-CCD helps prevent tunneling, but may still let tunnelling happen depending on solver + /// convergence. This is cheaper than the full ccd enabled by [`RigidBodyBuilder::ccd_enabled`]. + pub fn soft_ccd_enabled(mut self, enabled: bool) -> Self { + self.soft_ccd_enabled = enabled; + self + } + /// Sets whether or not the rigid-body is to be created asleep. pub fn sleeping(mut self, sleeping: bool) -> Self { self.sleeping = sleeping; @@ -1423,6 +1451,7 @@ impl RigidBodyBuilder { rb.dominance = RigidBodyDominance(self.dominance_group); rb.enabled = self.enabled; rb.enable_ccd(self.ccd_enabled); + rb.enable_soft_ccd(self.soft_ccd_enabled); if self.can_sleep && self.sleeping { rb.sleep(); diff --git a/src/dynamics/rigid_body_components.rs b/src/dynamics/rigid_body_components.rs index 2291742..3eea73c 100644 --- a/src/dynamics/rigid_body_components.rs +++ b/src/dynamics/rigid_body_components.rs @@ -821,6 +821,8 @@ pub struct RigidBodyCcd { pub ccd_active: bool, /// Is CCD enabled for this rigid-body? pub ccd_enabled: bool, + /// Is soft-CCD enabled for this rigid-body? + pub soft_ccd_enabled: bool, } impl Default for RigidBodyCcd { @@ -830,6 +832,7 @@ impl Default for RigidBodyCcd { ccd_max_dist: 0.0, ccd_active: false, ccd_enabled: false, + soft_ccd_enabled: false, } } } |
