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

@@ -135,16 +135,20 @@ impl RigidBody {
self.active_set_timestamp = 0;
}
pub(crate) fn integrate_accelerations(&mut self, dt: Real, gravity: Vector<Real>) {
pub(crate) fn add_gravity(&mut self, gravity: Vector<Real>) {
if self.effective_inv_mass != 0.0 {
let acceleration = self.force * self.effective_inv_mass;
self.linvel += (gravity * self.gravity_scale + acceleration) * dt;
self.force = na::zero();
self.force += gravity * self.gravity_scale * self.mass();
}
}
let angular_acceleration = self.effective_world_inv_inertia_sqrt
pub(crate) fn integrate_accelerations(&mut self, dt: Real) {
let linear_acc = self.force * self.effective_inv_mass;
let angular_acc = self.effective_world_inv_inertia_sqrt
* (self.effective_world_inv_inertia_sqrt * self.torque);
self.angvel += angular_acceleration * dt;
self.linvel += linear_acc * dt;
self.angvel += angular_acc * dt;
self.force = na::zero();
self.torque = na::zero();
}