@aressera
Thinking through the implementation details of this brought up a question. When I'm calculating the magnitude of the impulse applied to the bias velocity (the bias lambda), I need the contact velocity. See the line of code below marked HERE.
for constraint_set in &fixed_constraint_sets {
rigid_body := constraint_set.rigid_body;
for constraint in &constraint_set.constraints {
{ // Normal velocity correction
contact_velocity := rigid_body.velocity + linalg.cross(rigid_body.angular_velocity, constraint.r);
velocity_error_n := linalg.dot(contact_velocity, constraint_set.n);
lambda_n := -velocity_error_n / constraint.effective_mass_inv_n;
prev_total_impulse_n := constraint.total_impulse_n;
constraint.total_impulse_n = max(constraint.total_impulse_n + lambda_n, 0.0);
total_impulse_delta_n := constraint.total_impulse_n - prev_total_impulse_n;
rigid_body.velocity += constraint_set.n * total_impulse_delta_n / rigid_body.mass;
rigid_body.angular_velocity += rigid_body.tentative_inv_global_inertia_tensor * constraint.rxn * total_impulse_delta_n;
}
{ // Normal position correction
bias_contact_velocity := rigid_body.velocity + rigid_body.bias_velocity + linalg.cross(rigid_body.angular_velocity + rigid_body.bias_angular_velocity, constraint.r); // HERE
bias_velocity := linalg.dot(bias_contact_velocity, constraint_set.n);
bias_lambda_n := -(bias_velocity + constraint.bias) / constraint.effective_mass_inv_n;
prev_total_bias_impulse_n := constraint.total_bias_impulse_n;
constraint.total_bias_impulse_n = max(constraint.total_bias_impulse_n + bias_lambda_n, 0.0);
total_bias_impulse_delta_n := constraint.total_bias_impulse_n - prev_total_bias_impulse_n;
rigid_body.bias_velocity += constraint_set.n * total_bias_impulse_delta_n / rigid_body.mass;
rigid_body.bias_angular_velocity += rigid_body.tentative_inv_global_inertia_tensor * constraint.rxn * total_bias_impulse_delta_n;
}
}
}
To get the bias lambda n variable, I need the bias contact velocity. My question is about the correctness of this line:
bias_contact_velocity := rigid_body.velocity + rigid_body.bias_velocity + linalg.cross(rigid_body.angular_velocity + rigid_body.bias_angular_velocity, constraint.r);
Was I right to include both the regular and bias velocities here? This feels like the right thing to do. My thinking is, if the regular velocity isn't quite zeroed out, the bias impulse should account for that. It may need to be stronger than if the regular velocity is zeroed out. I could calculate the bias impulse in complete isolation of the regular impulse but it seems like it should consider the regular velocity since it is not guaranteed to be zero along the collision normal.
Am I thinking about this correctly? Does what I've done here look reasonable?