Skip to content

Commit

Permalink
Fix the behavior of BroadPhaseCollisionFilter (#58)
Browse files Browse the repository at this point in the history
* Fix the behavior of the BroadPhaseCollisionFilter

* Adjust documentation
  • Loading branch information
notgiven688 authored Dec 9, 2023
1 parent 1a8f6a5 commit 9ed6ebd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/docs/02_documentation/04contact-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class TeamFilter : IBroadPhaseFilter
}

// There is no collision between team red and team blue.
return shapeA.RigidBody.Tag == shapeB.RigidBody.Tag;
return shapeA.RigidBody.Tag != shapeB.RigidBody.Tag;
}
}
```
Expand Down
16 changes: 8 additions & 8 deletions src/Jitter2/SoftBodies/BroadPhaseCollisionFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public BroadPhaseCollisionFilter(World world)

public bool Filter(Shape shapeA, Shape shapeB)
{
if (!world.Shapes.IsActive(shapeA) && !world.Shapes.IsActive(shapeB)) return true;
if (!world.Shapes.IsActive(shapeA) && !world.Shapes.IsActive(shapeB)) return false;

ISoftBodyShape? i1 = shapeA as ISoftBodyShape;
ISoftBodyShape? i2 = shapeB as ISoftBodyShape;
Expand All @@ -49,47 +49,47 @@ public bool Filter(Shape shapeA, Shape shapeB)
JMatrix.Identity, JVector.Zero,
out JVector pA, out JVector pB, out JVector normal, out float penetration);

if (!colliding) return true;
if (!colliding) return false;

var closestA = i1.GetClosest(pA);
var closestB = i2.GetClosest(pB);

world.RegisterContact(closestA.RigidBodyId, closestB.RigidBodyId, closestA, closestB,
pA, pB, normal, penetration);

return true;
return false;
}

if (i1 != null)
{
bool colliding = NarrowPhase.MPREPA(shapeA, shapeB, shapeB.RigidBody!.Orientation, shapeB.RigidBody.Position,
out JVector pA, out JVector pB, out JVector normal, out float penetration);

if (!colliding) return true;
if (!colliding) return false;

var closest = i1.GetClosest(pA);

world.RegisterContact(closest.RigidBodyId, shapeB.RigidBody.RigidBodyId, closest, shapeB.RigidBody,
pA, pB, normal, penetration);

return true;
return false;
}

if (i2 != null)
{
bool colliding = NarrowPhase.MPREPA(shapeB, shapeA, shapeA.RigidBody!.Orientation, shapeA.RigidBody.Position,
out JVector pA, out JVector pB, out JVector normal, out float penetration);

if (!colliding) return true;
if (!colliding) return false;

var closest = i2.GetClosest(pA);

world.RegisterContact(closest.RigidBodyId, shapeA.RigidBody.RigidBodyId, closest, shapeA.RigidBody,
pA, pB, normal, penetration);

return true;
return false;
}

return false;
return true;
}
}
2 changes: 1 addition & 1 deletion src/Jitter2/World.Detect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private void Detect(Shape sA, Shape sB)

if (BroadPhaseFilter != null)
{
if (BroadPhaseFilter.Filter(sA, sB))
if (!BroadPhaseFilter.Filter(sA, sB))
{
return;
}
Expand Down

0 comments on commit 9ed6ebd

Please sign in to comment.