diff options
| author | Emil Ernerfeldt <emil.ernerfeldt@gmail.com> | 2021-01-22 13:32:18 +0100 |
|---|---|---|
| committer | Emil Ernerfeldt <emil.ernerfeldt@gmail.com> | 2021-01-22 13:32:18 +0100 |
| commit | 95c6199a9a66c50cc244f58a0de4773c7ad70623 (patch) | |
| tree | e929e9f0f11518c2bb4f3d6dd7e1b671b07740d0 /src/dynamics | |
| parent | 97031a68519bcab188415f78975639cce5daba57 (diff) | |
| download | rapier-95c6199a9a66c50cc244f58a0de4773c7ad70623.tar.gz rapier-95c6199a9a66c50cc244f58a0de4773c7ad70623.tar.bz2 rapier-95c6199a9a66c50cc244f58a0de4773c7ad70623.zip | |
Remove IntegrationParameters::inv_dt and make dt pub
Diffstat (limited to 'src/dynamics')
| -rw-r--r-- | src/dynamics/integration_parameters.rs | 23 | ||||
| -rw-r--r-- | src/dynamics/solver/velocity_constraint.rs | 3 | ||||
| -rw-r--r-- | src/dynamics/solver/velocity_ground_constraint.rs | 3 |
3 files changed, 12 insertions, 17 deletions
diff --git a/src/dynamics/integration_parameters.rs b/src/dynamics/integration_parameters.rs index cd78893..c1c7dc6 100644 --- a/src/dynamics/integration_parameters.rs +++ b/src/dynamics/integration_parameters.rs @@ -3,9 +3,8 @@ #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] pub struct IntegrationParameters { /// The timestep length (default: `1.0 / 60.0`) - dt: f32, - /// The inverse of `dt` (default: `60.0` steps per second). - inv_dt: f32, + pub dt: f32, + // /// If `true` and if rapier is compiled with the `parallel` feature, this will enable rayon-based multithreading (default: `true`). // /// // /// This parameter is ignored if rapier is not compiled with is `parallel` feature. @@ -110,7 +109,6 @@ impl IntegrationParameters { ) -> Self { IntegrationParameters { dt, - inv_dt: if dt == 0.0 { 0.0 } else { 1.0 / dt }, // multithreading_enabled, erp, joint_erp, @@ -144,26 +142,23 @@ impl IntegrationParameters { self.dt } - /// The inverse of the time-stepping length. + /// The inverse of the time-stepping length, i.e. the steps per seconds (Hz). /// /// This is zero if `self.dt` is zero. #[inline(always)] pub fn inv_dt(&self) -> f32 { - self.inv_dt + if self.dt == 0.0 { + 0.0 + } else { + 1.0 / self.dt + } } /// Sets the time-stepping length. - /// - /// This automatically recompute `self.inv_dt`. #[inline] pub fn set_dt(&mut self, dt: f32) { assert!(dt >= 0.0, "The time-stepping length cannot be negative."); self.dt = dt; - if dt == 0.0 { - self.inv_dt = 0.0 - } else { - self.inv_dt = 1.0 / dt - } } /// Sets the inverse time-stepping length (i.e. the frequency). @@ -171,7 +166,6 @@ impl IntegrationParameters { /// This automatically recompute `self.dt`. #[inline] pub fn set_inv_dt(&mut self, inv_dt: f32) { - self.inv_dt = inv_dt; if inv_dt == 0.0 { self.dt = 0.0 } else { @@ -184,7 +178,6 @@ impl Default for IntegrationParameters { fn default() -> Self { Self { dt: 1.0 / 60.0, - inv_dt: 60.0, // multithreading_enabled: true, return_after_ccd_substep: false, erp: 0.2, diff --git a/src/dynamics/solver/velocity_constraint.rs b/src/dynamics/solver/velocity_constraint.rs index 948081d..f9e38ac 100644 --- a/src/dynamics/solver/velocity_constraint.rs +++ b/src/dynamics/solver/velocity_constraint.rs @@ -144,6 +144,7 @@ impl VelocityConstraint { out_constraints: &mut Vec<AnyVelocityConstraint>, push: bool, ) { + let inv_dt = params.inv_dt(); let rb1 = &bodies[manifold.body_pair.body1]; let rb2 = &bodies[manifold.body_pair.body2]; let mj_lambda1 = rb1.active_set_offset; @@ -244,7 +245,7 @@ impl VelocityConstraint { rhs += manifold.restitution * rhs } - rhs += manifold_point.dist.max(0.0) * params.inv_dt(); + rhs += manifold_point.dist.max(0.0) * inv_dt; let impulse = manifold_points[k].impulse * warmstart_coeff; diff --git a/src/dynamics/solver/velocity_ground_constraint.rs b/src/dynamics/solver/velocity_ground_constraint.rs index d8ef8be..23b41c1 100644 --- a/src/dynamics/solver/velocity_ground_constraint.rs +++ b/src/dynamics/solver/velocity_ground_constraint.rs @@ -63,6 +63,7 @@ impl VelocityGroundConstraint { out_constraints: &mut Vec<AnyVelocityConstraint>, push: bool, ) { + let inv_dt = params.inv_dt(); let mut rb1 = &bodies[manifold.body_pair.body1]; let mut rb2 = &bodies[manifold.body_pair.body2]; let flipped = !rb2.is_dynamic(); @@ -176,7 +177,7 @@ impl VelocityGroundConstraint { rhs += manifold.restitution * rhs } - rhs += manifold_point.dist.max(0.0) * params.inv_dt(); + rhs += manifold_point.dist.max(0.0) * inv_dt; let impulse = manifold_points[k].impulse * warmstart_coeff; |
