diff options
| author | Thierry Berger <contact@thierryberger.com> | 2024-06-23 18:18:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-23 18:18:54 +0200 |
| commit | 3e8650f3a761422f0926300dc98f9870e5d92776 (patch) | |
| tree | 91b95ae4cffd09f993733f2326010867f15205cc /src/pipeline | |
| parent | 8a592e458e45c2896c52a931ca04a69868efdd53 (diff) | |
| download | rapier-3e8650f3a761422f0926300dc98f9870e5d92776.tar.gz rapier-3e8650f3a761422f0926300dc98f9870e5d92776.tar.bz2 rapier-3e8650f3a761422f0926300dc98f9870e5d92776.zip | |
Fix delta_time being 0 resulting in incorrect simulation (#660)
* Add failing test
* fix tests
* better fix
* add changelog
* fix propagated to `contact_cfm_factor`
* PR feedback
* more PR feedbacks
Diffstat (limited to 'src/pipeline')
| -rw-r--r-- | src/pipeline/physics_pipeline.rs | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/src/pipeline/physics_pipeline.rs b/src/pipeline/physics_pipeline.rs index 95e408f..7723fc3 100644 --- a/src/pipeline/physics_pipeline.rs +++ b/src/pipeline/physics_pipeline.rs @@ -662,6 +662,8 @@ impl PhysicsPipeline { #[cfg(test)] mod test { + use na::point; + use crate::dynamics::{ CCDSolver, ImpulseJointSet, IntegrationParameters, IslandManager, RigidBodyBuilder, RigidBodySet, @@ -669,7 +671,7 @@ mod test { use crate::geometry::{BroadPhaseMultiSap, ColliderBuilder, ColliderSet, NarrowPhase}; use crate::math::Vector; use crate::pipeline::PhysicsPipeline; - use crate::prelude::{MultibodyJointSet, RigidBodyType}; + use crate::prelude::{MultibodyJointSet, RevoluteJointBuilder, RigidBodyType}; #[test] fn kinematic_and_fixed_contact_crash() { @@ -937,4 +939,68 @@ mod test { // Expect body to now be in active_dynamic_set assert!(islands.active_dynamic_set.contains(&h)); } + + #[test] + fn joint_step_delta_time_0() { + let mut colliders = ColliderSet::new(); + let mut impulse_joints = ImpulseJointSet::new(); + let mut multibody_joints = MultibodyJointSet::new(); + let mut pipeline = PhysicsPipeline::new(); + let mut bf = BroadPhaseMultiSap::new(); + let mut nf = NarrowPhase::new(); + let mut islands = IslandManager::new(); + + let mut bodies = RigidBodySet::new(); + + // Initialize bodies + let rb = RigidBodyBuilder::fixed().additional_mass(1.0).build(); + let h = bodies.insert(rb.clone()); + let rb_dynamic = RigidBodyBuilder::dynamic().additional_mass(1.0).build(); + let h_dynamic = bodies.insert(rb_dynamic.clone()); + + // Add joint + #[cfg(feature = "dim2")] + let joint = RevoluteJointBuilder::new() + .local_anchor1(point![0.0, 1.0]) + .local_anchor2(point![0.0, -3.0]); + #[cfg(feature = "dim3")] + let joint = RevoluteJointBuilder::new(Vector::z_axis()) + .local_anchor1(point![0.0, 1.0, 0.0]) + .local_anchor2(point![0.0, -3.0, 0.0]); + impulse_joints.insert(h, h_dynamic, joint, true); + + let mut parameters = IntegrationParameters::default(); + parameters.dt = 0.0; + // Step once + let gravity = Vector::y() * -9.81; + pipeline.step( + &gravity, + ¶meters, + &mut islands, + &mut bf, + &mut nf, + &mut bodies, + &mut colliders, + &mut impulse_joints, + &mut multibody_joints, + &mut CCDSolver::new(), + None, + &(), + &(), + ); + let translation = bodies[h_dynamic].translation(); + let rotation = bodies[h_dynamic].rotation(); + assert!(translation.x.is_finite()); + assert!(translation.y.is_finite()); + #[cfg(feature = "dim2")] + assert!(rotation.is_finite()); + #[cfg(feature = "dim3")] + { + assert!(translation.z.is_finite()); + assert!(rotation.i.is_finite()); + assert!(rotation.j.is_finite()); + assert!(rotation.k.is_finite()); + assert!(rotation.w.is_finite()); + } + } } |
