Apply accelerations during velocity solver

Closes https://github.com/dimforge/rapier/issues/97

Instead of applying accelerations from gravity and external forces
as a separate step, this PR switches to applying them in the velocity solver.
This commit is contained in:
Emil Ernerfeldt
2021-02-03 18:18:03 +01:00
parent 17ef7e10f9
commit d999e0e8c6
5 changed files with 64 additions and 13 deletions

View File

@@ -32,6 +32,18 @@ impl VelocitySolver {
self.mj_lambdas
.resize(bodies.active_island(island_id).len(), DeltaVel::zero());
// Initialize delta-velocities (`mj_lambdas`) with external forces (gravity etc):
bodies.foreach_active_island_body_mut_internal(island_id, |_, rb| {
let dvel = &mut self.mj_lambdas[rb.active_set_offset];
dvel.linear += rb.force * (rb.effective_inv_mass * params.dt);
rb.force = na::zero();
// dvel.angular is actually storing angular velocity delta multiplied by the square root of the inertia tensor:
dvel.angular += rb.effective_world_inv_inertia_sqrt * rb.torque * params.dt;
rb.torque = na::zero();
});
/*
* Warmstart constraints.
*/