aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2021-01-22 16:10:24 +0100
committerCrozet Sébastien <developer@crozet.re>2021-01-22 16:10:24 +0100
commitcf52e01308cefcce71b9914c539641cb7530b22c (patch)
tree8e12a108d040d2b287957bec2b611c569b530bc7 /src
parent800b35b103c60a3f13dffdfe1c20561074041cea (diff)
parente6fc8f67faf3e37afe38d683cbd930d457f289be (diff)
downloadrapier-cf52e01308cefcce71b9914c539641cb7530b22c.tar.gz
rapier-cf52e01308cefcce71b9914c539641cb7530b22c.tar.bz2
rapier-cf52e01308cefcce71b9914c539641cb7530b22c.zip
Merge branch 'master' into split_geom
# Conflicts: # examples2d/sensor2.rs # examples3d/sensor3.rs # src/dynamics/integration_parameters.rs # src/dynamics/solver/parallel_island_solver.rs # src/dynamics/solver/velocity_constraint.rs # src/dynamics/solver/velocity_ground_constraint.rs # src_testbed/nphysics_backend.rs # src_testbed/physx_backend.rs # src_testbed/testbed.rs
Diffstat (limited to 'src')
-rw-r--r--src/dynamics/integration_parameters.rs75
-rw-r--r--src/dynamics/solver/island_solver.rs3
-rw-r--r--src/dynamics/solver/parallel_island_solver.rs2
-rw-r--r--src/dynamics/solver/velocity_constraint.rs3
-rw-r--r--src/dynamics/solver/velocity_ground_constraint.rs3
-rw-r--r--src/pipeline/physics_pipeline.rs5
6 files changed, 48 insertions, 43 deletions
diff --git a/src/dynamics/integration_parameters.rs b/src/dynamics/integration_parameters.rs
index 706fb3f..0d4d3b6 100644
--- a/src/dynamics/integration_parameters.rs
+++ b/src/dynamics/integration_parameters.rs
@@ -5,9 +5,8 @@ use crate::math::Real;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
pub struct IntegrationParameters {
/// The timestep length (default: `1.0 / 60.0`)
- dt: Real,
- /// The inverse of `dt`.
- inv_dt: Real,
+ pub dt: Real,
+
// /// 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.
@@ -31,7 +30,7 @@ pub struct IntegrationParameters {
/// Contacts at points where the involved bodies have a relative
/// velocity smaller than this threshold wont be affected by the restitution force (default: `1.0`).
pub restitution_velocity_threshold: Real,
- /// Amount of penetration the engine wont attempt to correct (default: `0.001m`).
+ /// Amount of penetration the engine wont attempt to correct (default: `0.005m`).
pub allowed_linear_error: Real,
/// The maximal distance separating two objects that will generate predictive contacts (default: `0.002`).
pub prediction_distance: Real,
@@ -89,6 +88,7 @@ pub struct IntegrationParameters {
impl IntegrationParameters {
/// Creates a set of integration parameters with the given values.
+ #[deprecated = "Use `IntegrationParameters { dt: 60.0, ..Default::default() }` instead"]
pub fn new(
dt: Real,
// multithreading_enabled: bool,
@@ -112,7 +112,6 @@ impl IntegrationParameters {
) -> Self {
IntegrationParameters {
dt,
- inv_dt: if dt == 0.0 { 0.0 } else { 1.0 / dt },
// multithreading_enabled,
erp,
joint_erp,
@@ -142,30 +141,29 @@ impl IntegrationParameters {
/// The current time-stepping length.
#[inline(always)]
+ #[deprecated = "You can just read the `IntegrationParams::dt` value directly"]
pub fn dt(&self) -> Real {
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) -> Real {
- 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]
+ #[deprecated = "You can just set the `IntegrationParams::dt` value directly"]
pub fn set_dt(&mut self, dt: Real) {
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).
@@ -173,7 +171,6 @@ impl IntegrationParameters {
/// This automatically recompute `self.dt`.
#[inline]
pub fn set_inv_dt(&mut self, inv_dt: Real) {
- self.inv_dt = inv_dt;
if inv_dt == 0.0 {
self.dt = 0.0
} else {
@@ -184,26 +181,32 @@ impl IntegrationParameters {
impl Default for IntegrationParameters {
fn default() -> Self {
- Self::new(
- 1.0 / 60.0,
- // true,
- 0.2,
- 0.2,
- 1.0,
- 1.0,
- 0.005,
- 0.001,
- 0.2,
- 0.2,
- 0.002,
- 0.2,
- 4,
- 1,
- 10,
- 1,
- false,
- false,
- false,
- )
+ Self {
+ dt: 1.0 / 60.0,
+ // multithreading_enabled: true,
+ return_after_ccd_substep: false,
+ erp: 0.2,
+ joint_erp: 0.2,
+ warmstart_coeff: 1.0,
+ restitution_velocity_threshold: 1.0,
+ allowed_linear_error: 0.005,
+ prediction_distance: 0.002,
+ allowed_angular_error: 0.001,
+ max_linear_correction: 0.2,
+ max_angular_correction: 0.2,
+ max_stabilization_multiplier: 0.2,
+ max_velocity_iterations: 4,
+ max_position_iterations: 1,
+ // FIXME: what is the optimal value for min_island_size?
+ // It should not be too big so that we don't end up with
+ // huge islands that don't fit in cache.
+ // However we don't want it to be too small and end up with
+ // tons of islands, reducing SIMD parallelism opportunities.
+ min_island_size: 128,
+ max_ccd_position_iterations: 10,
+ max_ccd_substeps: 1,
+ multiple_ccd_substep_sensor_events_enabled: false,
+ ccd_on_penetration_enabled: false,
+ }
}
}
diff --git a/src/dynamics/solver/island_solver.rs b/src/dynamics/solver/island_solver.rs
index 46d6b75..deed8c2 100644
--- a/src/dynamics/solver/island_solver.rs
+++ b/src/dynamics/solver/island_solver.rs
@@ -57,8 +57,7 @@ impl IslandSolver {
}
counters.solver.velocity_update_time.resume();
- bodies
- .foreach_active_island_body_mut_internal(island_id, |_, rb| rb.integrate(params.dt()));
+ bodies.foreach_active_island_body_mut_internal(island_id, |_, rb| rb.integrate(params.dt));
counters.solver.velocity_update_time.pause();
if manifold_indices.len() != 0 || joint_indices.len() != 0 {
diff --git a/src/dynamics/solver/parallel_island_solver.rs b/src/dynamics/solver/parallel_island_solver.rs
index 389b6e6..24435db 100644
--- a/src/dynamics/solver/parallel_island_solver.rs
+++ b/src/dynamics/solver/parallel_island_solver.rs
@@ -251,7 +251,7 @@ impl ParallelIslandSolver {
let dvel = mj_lambdas[rb.active_set_offset];
rb.linvel += dvel.linear;
rb.angvel += rb.effective_world_inv_inertia_sqrt.transform_vector(dvel.angular);
- rb.integrate(params.dt());
+ rb.integrate(params.dt));
positions[rb.active_set_offset] = rb.position;
}
}
diff --git a/src/dynamics/solver/velocity_constraint.rs b/src/dynamics/solver/velocity_constraint.rs
index c2aa6f5..9d75830 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.data.body_pair.body1];
let rb2 = &bodies[manifold.data.body_pair.body2];
let mj_lambda1 = rb1.active_set_offset;
@@ -244,7 +245,7 @@ impl VelocityConstraint {
rhs += manifold_point.restitution * rhs
}
- rhs += manifold_point.dist.max(0.0) * params.inv_dt();
+ rhs += manifold_point.dist.max(0.0) * inv_dt;
let impulse = manifold_point.data.impulse * warmstart_coeff;
diff --git a/src/dynamics/solver/velocity_ground_constraint.rs b/src/dynamics/solver/velocity_ground_constraint.rs
index 7ea4fbb..49bb465 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.data.body_pair.body1];
let mut rb2 = &bodies[manifold.data.body_pair.body2];
let flipped = !rb2.is_dynamic();
@@ -159,7 +160,7 @@ impl VelocityGroundConstraint {
rhs += manifold_point.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].data.impulse * warmstart_coeff;
diff --git a/src/pipeline/physics_pipeline.rs b/src/pipeline/physics_pipeline.rs
index 718dd10..d59a534 100644
--- a/src/pipeline/physics_pipeline.rs
+++ b/src/pipeline/physics_pipeline.rs
@@ -154,7 +154,7 @@ impl PhysicsPipeline {
self.counters.stages.update_time.start();
bodies.foreach_active_dynamic_body_mut_internal(|_, b| {
b.update_world_mass_properties();
- b.integrate_accelerations(integration_parameters.dt(), *gravity)
+ b.integrate_accelerations(integration_parameters.dt, *gravity)
});
self.counters.stages.update_time.pause();
@@ -233,7 +233,7 @@ impl PhysicsPipeline {
rb.linvel = na::zero();
rb.angvel = na::zero();
} else {
- rb.update_predicted_position(integration_parameters.dt());
+ rb.update_predicted_position(integration_parameters.dt);
}
rb.update_colliders_positions(colliders);
@@ -330,6 +330,7 @@ mod test {
);
}
+ #[cfg(feature = "serde")]
#[test]
fn rigid_body_removal_snapshot_handle_determinism() {
let mut colliders = ColliderSet::new();