Skip to content

Commit

Permalink
parent testing at the same place a interaction group check, to avoid …
Browse files Browse the repository at this point in the history
…missing parent change
  • Loading branch information
Vrixyz committed Dec 16, 2024
1 parent b5ffbba commit e139e8c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/geometry/contact_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl IntersectionPair {
events: &dyn EventHandler,
) {
self.start_event_emitted = true;
println!("start");
events.handle_collision_event(
bodies,
colliders,
Expand All @@ -99,6 +100,7 @@ impl IntersectionPair {
events: &dyn EventHandler,
) {
self.start_event_emitted = false;
println!("stop");
events.handle_collision_event(
bodies,
colliders,
Expand Down
70 changes: 50 additions & 20 deletions src/geometry/narrow_phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,6 @@ impl NarrowPhase {
if let (Some(co1), Some(co2)) =
(colliders.get(pair.collider1), colliders.get(pair.collider2))
{
if co1.parent.map(|p| p.handle) == co2.parent.map(|p| p.handle) && co1.parent.is_some()
{
// Same parents. Ignore collisions.
return;
}

// These colliders have no parents - continue.

let (gid1, gid2) = self.graph_indices.ensure_pair_exists(
Expand Down Expand Up @@ -745,7 +739,13 @@ impl NarrowPhase {
// No update needed for these colliders.
return;
}

if co1.parent.map(|p| p.handle) == co2.parent.map(|p| p.handle)
&& co1.parent.is_some()
{
// Same parents. Ignore collisions.
edge.weight.intersecting = false;
break 'emit_events;
}
// TODO: avoid lookup into bodies.
let mut rb_type1 = RigidBodyType::Fixed;
let mut rb_type2 = RigidBodyType::Fixed;
Expand Down Expand Up @@ -846,6 +846,12 @@ impl NarrowPhase {
// No update needed for these colliders.
return;
}
if co1.parent.map(|p| p.handle) == co2.parent.map(|p| p.handle) && co1.parent.is_some()
{
// Same parents. Ignore collisions.
pair.clear();
break 'emit_events;
}

let rb1 = co1.parent.map(|co_parent1| &bodies[co_parent1.handle]);
let rb2 = co2.parent.map(|co_parent2| &bodies[co_parent2.handle]);
Expand Down Expand Up @@ -1270,15 +1276,43 @@ mod test {
< 0.5f32
);

let contact_pair = narrow_phase
.contact_pair(collider_1_handle, collider_2_handle)
.expect("The contact pair should exist.");
assert_eq!(contact_pair.manifolds.len(), 0);
assert!(matches!(
narrow_phase.intersection_pair(collider_1_handle, collider_2_handle),
None,
));
/* Parent collider 2 to body 2. */
collider_set.set_parent(collider_2_handle, Some(body_2_handle), &mut rigid_body_set);
narrow_phase.add_pair(
&collider_set,
&ColliderPair {
collider1: collider_2_handle,
collider2: collider_1_handle,
},

physics_pipeline.step(
&gravity,
&integration_parameters,
&mut island_manager,
&mut broad_phase,
&mut narrow_phase,
&mut rigid_body_set,
&mut collider_set,
&mut impulse_joint_set,
&mut multibody_joint_set,
&mut ccd_solver,
Some(&mut query_pipeline),
&physics_hooks,
&event_handler,
);

let contact_pair = narrow_phase
.contact_pair(collider_1_handle, collider_2_handle)
.expect("The contact pair should exist.");
assert_eq!(contact_pair.manifolds.len(), 1);
assert!(matches!(
narrow_phase.intersection_pair(collider_1_handle, collider_2_handle),
// FIXME: I believe this is expected because we've not enabled intersection detection?
None,
));

/* Run the game loop, stepping the simulation once per frame. */
for _ in 0..200 {
physics_pipeline.step(
Expand All @@ -1305,6 +1339,7 @@ mod test {

let collider_1_position = collider_set.get(collider_1_handle).unwrap().pos;
let collider_2_position = collider_set.get(collider_2_handle).unwrap().pos;
println!("collider 2 position: {}", collider_2_position.translation);
assert!(
(collider_1_position.translation.vector - collider_2_position.translation.vector)
.magnitude()
Expand Down Expand Up @@ -1338,11 +1373,7 @@ mod test {
.build();
let body_2_handle = rigid_body_set.insert(rigid_body_2);

/* Create collider 2. Parent it to rigid body 1. */
//let collider_2_handle =
// collider_set.insert_with_parent(collider.build(), body_2_handle, &mut rigid_body_set);

/* Create collider 2. Parent it to rigid body 1. */
/* Create collider 2. Parent it to rigid body 2. */
let collider_2_handle =
collider_set.insert_with_parent(collider.build(), body_2_handle, &mut rigid_body_set);

Expand Down Expand Up @@ -1406,12 +1437,11 @@ mod test {

let collider_1_position = collider_set.get(collider_1_handle).unwrap().pos;
let collider_2_position = collider_set.get(collider_2_handle).unwrap().pos;
println!("collider 1 position: {}", collider_1_position.translation);
println!("collider 2 position: {}", collider_2_position.translation);
}

let collider_1_position = collider_set.get(collider_1_handle).unwrap().pos;
let collider_2_position = collider_set.get(collider_2_handle).unwrap().pos;
println!("collider 2 position: {}", collider_2_position.translation);
assert!(
(collider_1_position.translation.vector - collider_2_position.translation.vector)
.magnitude()
Expand Down

0 comments on commit e139e8c

Please sign in to comment.