diff options
| author | Sébastien Crozet <developer@crozet.re> | 2022-05-30 18:21:35 +0200 |
|---|---|---|
| committer | Sébastien Crozet <developer@crozet.re> | 2022-05-30 18:29:18 +0200 |
| commit | 6ce26f3818492682a8572c895264f1e63f94b9d5 (patch) | |
| tree | d8efa80fafcc94584417c7da24f2bf99f6eb31ec /src/dynamics/solver/generic_velocity_ground_constraint.rs | |
| parent | c630635e57624385123b4a0fb658018bc6fdba91 (diff) | |
| download | rapier-6ce26f3818492682a8572c895264f1e63f94b9d5.tar.gz rapier-6ce26f3818492682a8572c895264f1e63f94b9d5.tar.bz2 rapier-6ce26f3818492682a8572c895264f1e63f94b9d5.zip | |
CCD improvements
- Fix bug where the CCD thickness wasn’t initialized properly.
- Fix bug where the contact compliance would result in unwanted tunelling, despite CCD being enabled.
Diffstat (limited to 'src/dynamics/solver/generic_velocity_ground_constraint.rs')
| -rw-r--r-- | src/dynamics/solver/generic_velocity_ground_constraint.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/dynamics/solver/generic_velocity_ground_constraint.rs b/src/dynamics/solver/generic_velocity_ground_constraint.rs index 16648c4..24a9de5 100644 --- a/src/dynamics/solver/generic_velocity_ground_constraint.rs +++ b/src/dynamics/solver/generic_velocity_ground_constraint.rs @@ -32,6 +32,7 @@ impl GenericVelocityGroundConstraint { jacobian_id: &mut usize, insert_at: Option<usize>, ) { + let cfm_factor = params.cfm_factor(); let inv_dt = params.inv_dt(); let erp_inv_dt = params.erp_inv_dt(); @@ -130,19 +131,24 @@ impl GenericVelocityGroundConstraint { let is_bouncy = manifold_point.is_bouncy() as u32 as Real; let is_resting = 1.0 - is_bouncy; - let mut rhs_wo_bias = (1.0 + is_bouncy * manifold_point.restitution) - * (vel1 - vel2).dot(&force_dir1); + let dvel = (vel1 - vel2).dot(&force_dir1); + let mut rhs_wo_bias = (1.0 + is_bouncy * manifold_point.restitution) * dvel; rhs_wo_bias += manifold_point.dist.max(0.0) * inv_dt; rhs_wo_bias *= is_bouncy + is_resting; let rhs_bias = /* is_resting * */ erp_inv_dt * manifold_point.dist.clamp(-params.max_penetration_correction, 0.0); + let rhs = rhs_wo_bias + rhs_bias; + let is_fast_contact = -rhs * params.dt > rb2.ccd.ccd_thickness * 0.5; + let cfm = if is_fast_contact { 1.0 } else { cfm_factor }; + constraint.elements[k].normal_part = VelocityGroundConstraintNormalPart { gcross2: na::zero(), // Unused for generic constraints. - rhs: rhs_wo_bias + rhs_bias, + rhs, rhs_wo_bias, impulse: na::zero(), r, + cfm, }; } |
