aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/solver/velocity_ground_constraint.rs
diff options
context:
space:
mode:
authorEmil Ernerfeldt <emil.ernerfeldt@gmail.com>2021-02-15 21:18:26 +0100
committerEmil Ernerfeldt <emil.ernerfeldt@gmail.com>2021-02-18 15:41:46 +0100
commitf9e3d382d2ee097dce05997735982f5e120cca03 (patch)
tree6f85b071c8a4faf1d548950e250d36195f0d5ace /src/dynamics/solver/velocity_ground_constraint.rs
parent9a15838ad568958273218b678ac22e53bb0a0842 (diff)
downloadrapier-f9e3d382d2ee097dce05997735982f5e120cca03.tar.gz
rapier-f9e3d382d2ee097dce05997735982f5e120cca03.tar.bz2
rapier-f9e3d382d2ee097dce05997735982f5e120cca03.zip
New contacts are bouncy, old are resting
If a contact is new (previous impluse = 0), then we treat it as bouncy (respecting restitution). If the contact is old we treat it as resting. Exceptions for restitutions <=0 and >= 1.
Diffstat (limited to 'src/dynamics/solver/velocity_ground_constraint.rs')
-rw-r--r--src/dynamics/solver/velocity_ground_constraint.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/dynamics/solver/velocity_ground_constraint.rs b/src/dynamics/solver/velocity_ground_constraint.rs
index 20642ec..f147ccb 100644
--- a/src/dynamics/solver/velocity_ground_constraint.rs
+++ b/src/dynamics/solver/velocity_ground_constraint.rs
@@ -154,15 +154,13 @@ impl VelocityGroundConstraint {
let r = 1.0 / (rb2.effective_inv_mass + gcross2.gdot(gcross2));
- let mut rhs = (vel1 - vel2).dot(&force_dir1);
-
- if rhs <= -params.restitution_velocity_threshold {
- rhs += manifold_point.restitution * rhs
- }
-
- rhs += manifold_point.dist.max(0.0) * inv_dt;
+ let rhs = if manifold_point.is_bouncy() {
+ (1.0 + manifold_point.restitution) * (vel1 - vel2).dot(&force_dir1)
+ } else {
+ (vel1 - vel2).dot(&force_dir1) + manifold_point.dist.max(0.0) * inv_dt
+ };
- let impulse = manifold_points[k].data.impulse * warmstart_coeff;
+ let impulse = manifold_point.data.impulse * warmstart_coeff;
constraint.elements[k].normal_part = VelocityGroundConstraintElementPart {
gcross2,