Remove IntegrationParameters::inv_dt and make dt pub
This commit is contained in:
@@ -3,9 +3,8 @@
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
pub struct IntegrationParameters {
|
pub struct IntegrationParameters {
|
||||||
/// The timestep length (default: `1.0 / 60.0`)
|
/// The timestep length (default: `1.0 / 60.0`)
|
||||||
dt: f32,
|
pub dt: f32,
|
||||||
/// The inverse of `dt` (default: `60.0` steps per second).
|
|
||||||
inv_dt: f32,
|
|
||||||
// /// If `true` and if rapier is compiled with the `parallel` feature, this will enable rayon-based multithreading (default: `true`).
|
// /// 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.
|
// /// This parameter is ignored if rapier is not compiled with is `parallel` feature.
|
||||||
@@ -110,7 +109,6 @@ impl IntegrationParameters {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
IntegrationParameters {
|
IntegrationParameters {
|
||||||
dt,
|
dt,
|
||||||
inv_dt: if dt == 0.0 { 0.0 } else { 1.0 / dt },
|
|
||||||
// multithreading_enabled,
|
// multithreading_enabled,
|
||||||
erp,
|
erp,
|
||||||
joint_erp,
|
joint_erp,
|
||||||
@@ -144,26 +142,23 @@ impl IntegrationParameters {
|
|||||||
self.dt
|
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.
|
/// This is zero if `self.dt` is zero.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn inv_dt(&self) -> f32 {
|
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.
|
/// Sets the time-stepping length.
|
||||||
///
|
|
||||||
/// This automatically recompute `self.inv_dt`.
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_dt(&mut self, dt: f32) {
|
pub fn set_dt(&mut self, dt: f32) {
|
||||||
assert!(dt >= 0.0, "The time-stepping length cannot be negative.");
|
assert!(dt >= 0.0, "The time-stepping length cannot be negative.");
|
||||||
self.dt = dt;
|
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).
|
/// Sets the inverse time-stepping length (i.e. the frequency).
|
||||||
@@ -171,7 +166,6 @@ impl IntegrationParameters {
|
|||||||
/// This automatically recompute `self.dt`.
|
/// This automatically recompute `self.dt`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_inv_dt(&mut self, inv_dt: f32) {
|
pub fn set_inv_dt(&mut self, inv_dt: f32) {
|
||||||
self.inv_dt = inv_dt;
|
|
||||||
if inv_dt == 0.0 {
|
if inv_dt == 0.0 {
|
||||||
self.dt = 0.0
|
self.dt = 0.0
|
||||||
} else {
|
} else {
|
||||||
@@ -184,7 +178,6 @@ impl Default for IntegrationParameters {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
dt: 1.0 / 60.0,
|
dt: 1.0 / 60.0,
|
||||||
inv_dt: 60.0,
|
|
||||||
// multithreading_enabled: true,
|
// multithreading_enabled: true,
|
||||||
return_after_ccd_substep: false,
|
return_after_ccd_substep: false,
|
||||||
erp: 0.2,
|
erp: 0.2,
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ impl VelocityConstraint {
|
|||||||
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
||||||
push: bool,
|
push: bool,
|
||||||
) {
|
) {
|
||||||
|
let inv_dt = params.inv_dt();
|
||||||
let rb1 = &bodies[manifold.body_pair.body1];
|
let rb1 = &bodies[manifold.body_pair.body1];
|
||||||
let rb2 = &bodies[manifold.body_pair.body2];
|
let rb2 = &bodies[manifold.body_pair.body2];
|
||||||
let mj_lambda1 = rb1.active_set_offset;
|
let mj_lambda1 = rb1.active_set_offset;
|
||||||
@@ -244,7 +245,7 @@ impl VelocityConstraint {
|
|||||||
rhs += manifold.restitution * rhs
|
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;
|
let impulse = manifold_points[k].impulse * warmstart_coeff;
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ impl VelocityGroundConstraint {
|
|||||||
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
||||||
push: bool,
|
push: bool,
|
||||||
) {
|
) {
|
||||||
|
let inv_dt = params.inv_dt();
|
||||||
let mut rb1 = &bodies[manifold.body_pair.body1];
|
let mut rb1 = &bodies[manifold.body_pair.body1];
|
||||||
let mut rb2 = &bodies[manifold.body_pair.body2];
|
let mut rb2 = &bodies[manifold.body_pair.body2];
|
||||||
let flipped = !rb2.is_dynamic();
|
let flipped = !rb2.is_dynamic();
|
||||||
@@ -176,7 +177,7 @@ impl VelocityGroundConstraint {
|
|||||||
rhs += manifold.restitution * rhs
|
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;
|
let impulse = manifold_points[k].impulse * warmstart_coeff;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user