Skip to content

Commit 591d0e8

Browse files
committed
added test for fix
1 parent 25a3fbe commit 591d0e8

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/pipeline/collision_pipeline.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::geometry::{
77
};
88
use crate::math::Real;
99
use crate::pipeline::{EventHandler, PhysicsHooks, QueryPipeline};
10-
use crate::prelude::{ModifiedRigidBodies, RigidBodyChanges, RigidBodyHandle};
10+
use crate::prelude::{ModifiedRigidBodies, RigidBodyChanges};
1111
use crate::{dynamics::RigidBodySet, geometry::ColliderSet};
1212

1313
/// The collision pipeline, responsible for performing collision detection between colliders.
@@ -290,4 +290,50 @@ mod tests {
290290

291291
assert!(hit, "No hit found");
292292
}
293+
294+
#[cfg(feature = "dim2")]
295+
#[test]
296+
fn test_collider_move_with_parent_body_updates_collissions() {
297+
use na::{Isometry2, Rotation2, Translation2};
298+
299+
use crate::prelude::*;
300+
let mut rigid_body_set = RigidBodySet::new();
301+
let mut collider_set = ColliderSet::new();
302+
303+
let body = RigidBodyBuilder::fixed().build();
304+
let body_handle = rigid_body_set.insert(body);
305+
306+
let collider = ColliderBuilder::ball(1.).build();
307+
let collider_handle =
308+
collider_set.insert_with_parent(collider, body_handle, &mut rigid_body_set);
309+
310+
let integration_parameters = IntegrationParameters::default();
311+
let mut broad_phase = BroadPhaseMultiSap::new();
312+
let mut narrow_phase = NarrowPhase::new();
313+
let mut collision_pipeline = CollisionPipeline::default();
314+
315+
for i in 1..3 {
316+
let next_position = Translation2::new(i as Real, 0.).vector;
317+
rigid_body_set.get_mut(body_handle).unwrap().set_translation(next_position, false);
318+
319+
collision_pipeline.step(
320+
integration_parameters.prediction_distance(),
321+
&mut broad_phase,
322+
&mut narrow_phase,
323+
&mut rigid_body_set,
324+
&mut collider_set,
325+
None,
326+
&(),
327+
&(),
328+
);
329+
330+
assert_eq!(
331+
collider_set.get(collider_handle).unwrap().position(),
332+
rigid_body_set.get(body_handle).unwrap().position(),
333+
"Collider should be at the same position as the parent body after {i} step"
334+
);
335+
assert_eq!(collider_set.get(collider_handle).unwrap().position(), &Isometry2::new(next_position, Rotation2::identity().angle()));
336+
}
337+
338+
}
293339
}

0 commit comments

Comments
 (0)