Add a max penetration correction integration parameter
This commit is contained in:
committed by
Sébastien Crozet
parent
34b0d51455
commit
1535db87c7
@@ -36,6 +36,8 @@ pub struct IntegrationParameters {
|
||||
|
||||
/// Amount of penetration the engine wont attempt to correct (default: `0.001m`).
|
||||
pub allowed_linear_error: Real,
|
||||
/// Maximum amount of penetration the solver will attempt to resolve in one timestep.
|
||||
pub max_penetration_correction: Real,
|
||||
/// The maximal distance separating two objects that will generate predictive contacts (default: `0.002`).
|
||||
pub prediction_distance: Real,
|
||||
/// Maximum number of iterations performed to solve non-penetration and joint constraints (default: `4`).
|
||||
@@ -150,6 +152,7 @@ impl Default for IntegrationParameters {
|
||||
joint_erp: 1.0,
|
||||
joint_damping_ratio: 1.0,
|
||||
allowed_linear_error: 0.001, // 0.005
|
||||
max_penetration_correction: Real::MAX,
|
||||
prediction_distance: 0.002,
|
||||
max_velocity_iterations: 4,
|
||||
max_velocity_friction_iterations: 8,
|
||||
|
||||
@@ -212,7 +212,7 @@ impl GenericVelocityConstraint {
|
||||
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.min(0.0);
|
||||
/* is_resting * */ erp_inv_dt * manifold_point.dist.clamp(-params.max_penetration_correction, 0.0);
|
||||
|
||||
constraint.elements[k].normal_part = VelocityConstraintNormalPart {
|
||||
gcross1,
|
||||
|
||||
@@ -148,7 +148,7 @@ impl GenericVelocityGroundConstraint {
|
||||
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.min(0.0);
|
||||
/* is_resting * */ erp_inv_dt * manifold_point.dist.clamp(-params.max_penetration_correction, 0.0);
|
||||
|
||||
constraint.elements[k].normal_part = VelocityGroundConstraintNormalPart {
|
||||
gcross2: na::zero(), // Unused for generic constraints.
|
||||
|
||||
@@ -283,7 +283,7 @@ impl VelocityConstraint {
|
||||
rhs_wo_bias *= is_bouncy + is_resting;
|
||||
let rhs_bias = /* is_resting
|
||||
* */ erp_inv_dt
|
||||
* (manifold_point.dist + params.allowed_linear_error).min(0.0);
|
||||
* (manifold_point.dist + params.allowed_linear_error).clamp(-params.max_penetration_correction, 0.0);
|
||||
constraint.elements[k].normal_part = VelocityConstraintNormalPart {
|
||||
gcross1,
|
||||
gcross2,
|
||||
|
||||
@@ -49,6 +49,7 @@ impl WVelocityConstraint {
|
||||
let inv_dt = SimdReal::splat(params.inv_dt());
|
||||
let allowed_lin_err = SimdReal::splat(params.allowed_linear_error);
|
||||
let erp_inv_dt = SimdReal::splat(params.erp_inv_dt());
|
||||
let max_penetration_correction = SimdReal::splat(params.max_penetration_correction);
|
||||
|
||||
let handles1 = gather![|ii| manifolds[ii].data.rigid_body1.unwrap()];
|
||||
let handles2 = gather![|ii| manifolds[ii].data.rigid_body2.unwrap()];
|
||||
@@ -145,7 +146,8 @@ impl WVelocityConstraint {
|
||||
(SimdReal::splat(1.0) + is_bouncy * restitution) * projected_velocity;
|
||||
rhs_wo_bias += dist.simd_max(SimdReal::zero()) * inv_dt;
|
||||
rhs_wo_bias *= is_bouncy + is_resting;
|
||||
let rhs_bias = (dist + allowed_lin_err).simd_min(SimdReal::zero())
|
||||
let rhs_bias = (dist + allowed_lin_err)
|
||||
.simd_clamp(-max_penetration_correction, SimdReal::zero())
|
||||
* (erp_inv_dt/* * is_resting */);
|
||||
|
||||
constraint.elements[k].normal_part = VelocityConstraintNormalPart {
|
||||
|
||||
@@ -167,7 +167,7 @@ impl VelocityGroundConstraint {
|
||||
rhs_wo_bias *= is_bouncy + is_resting;
|
||||
let rhs_bias = /* is_resting
|
||||
* */ erp_inv_dt
|
||||
* (manifold_point.dist + params.allowed_linear_error).min(0.0);
|
||||
* (manifold_point.dist + params.allowed_linear_error).clamp(-params.max_penetration_correction, 0.0);
|
||||
|
||||
constraint.elements[k].normal_part = VelocityGroundConstraintNormalPart {
|
||||
gcross2,
|
||||
|
||||
@@ -44,6 +44,7 @@ impl WVelocityGroundConstraint {
|
||||
let inv_dt = SimdReal::splat(params.inv_dt());
|
||||
let allowed_lin_err = SimdReal::splat(params.allowed_linear_error);
|
||||
let erp_inv_dt = SimdReal::splat(params.erp_inv_dt());
|
||||
let max_penetration_correction = SimdReal::splat(params.max_penetration_correction);
|
||||
|
||||
let mut handles1 = gather![|ii| manifolds[ii].data.rigid_body1];
|
||||
let mut handles2 = gather![|ii| manifolds[ii].data.rigid_body2];
|
||||
@@ -150,7 +151,8 @@ impl WVelocityGroundConstraint {
|
||||
(SimdReal::splat(1.0) + is_bouncy * restitution) * projected_velocity;
|
||||
rhs_wo_bias += dist.simd_max(SimdReal::zero()) * inv_dt;
|
||||
rhs_wo_bias *= is_bouncy + is_resting;
|
||||
let rhs_bias = (dist + allowed_lin_err).simd_min(SimdReal::zero())
|
||||
let rhs_bias = (dist + allowed_lin_err)
|
||||
.simd_clamp(-max_penetration_correction, SimdReal::zero())
|
||||
* (erp_inv_dt/* * is_resting */);
|
||||
|
||||
constraint.elements[k].normal_part = VelocityGroundConstraintNormalPart {
|
||||
|
||||
Reference in New Issue
Block a user