private ChainAndCircleContact(Fixture fixtureA, int indexA, Fixture fixtureB, int indexB) : base( fixtureA, indexA, fixtureB, indexB) { Debug.Assert(FixtureA.GetShapeType() == ShapeType.Chain); Debug.Assert(FixtureB.GetShapeType() == ShapeType.Circle); }
/// <summary> /// Computes the toi using the specified sweep a /// </summary> /// <param name="sweepA">The sweep</param> /// <param name="sweepB">The sweep</param> /// <returns>The float</returns> public float ComputeToi(Sweep sweepA, Sweep sweepB) { ToiInput input = new ToiInput(); input.SweepA = sweepA; input.SweepB = sweepB; input.SweepRadiusA = FixtureA.ComputeSweepRadius(sweepA.LocalCenter); input.SweepRadiusB = FixtureB.ComputeSweepRadius(sweepB.LocalCenter); input.Tolerance = Settings.LinearSlop; return(Collision.Collision.TimeOfImpact(input, FixtureA.Shape, FixtureB.Shape)); }
/// <summary> /// Update the contact manifold and touching status. /// Note: do not assume the fixture AABBs are overlapping or are valid. /// </summary> /// <param name="contactManager">The contact manager.</param> internal void Update(ContactManager contactManager) { Body bodyA = FixtureA.Body; Body bodyB = FixtureB.Body; if (FixtureA == null || FixtureB == null) { return; } Manifold oldManifold = Manifold; // Re-enable this contact. Enabled = true; bool touching; bool wasTouching = IsTouching; bool sensor = FixtureA.IsSensor || FixtureB.IsSensor; // Is this contact a sensor? if (sensor) { Shape shapeA = FixtureA.Shape; Shape shapeB = FixtureB.Shape; touching = Collision.Collision.TestOverlap(shapeA, ChildIndexA, shapeB, ChildIndexB, ref bodyA._xf, ref bodyB._xf); // Sensors don't generate manifolds. Manifold.PointCount = 0; } else { Evaluate(ref Manifold, ref bodyA._xf, ref bodyB._xf); touching = Manifold.PointCount > 0; // Match old contact ids to new contact ids and copy the // stored impulses to warm start the solver. for (int i = 0; i < Manifold.PointCount; ++i) { ManifoldPoint mp2 = Manifold.Points[i]; mp2.NormalImpulse = 0.0f; mp2.TangentImpulse = 0.0f; ContactID id2 = mp2.Id; for (int j = 0; j < oldManifold.PointCount; ++j) { ManifoldPoint mp1 = oldManifold.Points[j]; if (mp1.Id.Key == id2.Key) { mp2.NormalImpulse = mp1.NormalImpulse; mp2.TangentImpulse = mp1.TangentImpulse; break; } } Manifold.Points[i] = mp2; } if (touching != wasTouching) { bodyA.Awake = true; bodyB.Awake = true; } } IsTouching = touching; if (wasTouching == false) { if (touching) { bool enabledA = true, enabledB = true; // Report the collision to both participants. Track which ones returned true so we can // later call OnSeparation if the contact is disabled for a different reason. if (FixtureA.OnCollision != null) { foreach (OnCollisionEventHandler handler in FixtureA.OnCollision.GetInvocationList()) { enabledA = handler(FixtureA, FixtureB, this) && enabledA; } } // Reverse the order of the reported fixtures. The first fixture is always the one that the // user subscribed to. if (FixtureB.OnCollision != null) { foreach (OnCollisionEventHandler handler in FixtureB.OnCollision.GetInvocationList()) { enabledB = handler(FixtureB, FixtureA, this) && enabledB; } } // Report the collision to both bodies: if (FixtureA.Body != null && FixtureA.Body.onCollisionEventHandler != null) { foreach (OnCollisionEventHandler handler in FixtureA.Body.onCollisionEventHandler.GetInvocationList()) { enabledA = handler(FixtureA, FixtureB, this) && enabledA; } } // Reverse the order of the reported fixtures. The first fixture is always the one that the // user subscribed to. if (FixtureB.Body != null && FixtureB.Body.onCollisionEventHandler != null) { foreach (OnCollisionEventHandler handler in FixtureB.Body.onCollisionEventHandler.GetInvocationList()) { enabledB = handler(FixtureB, FixtureA, this) && enabledB; } } Enabled = enabledA && enabledB; // BeginContact can also return false and disable the contact if (enabledA && enabledB && contactManager.BeginContact != null) { Enabled = contactManager.BeginContact(this); } // If the user disabled the contact (needed to exclude it in TOI solver) at any point by // any of the callbacks, we need to mark it as not touching and call any separation // callbacks for fixtures that didn't explicitly disable the collision. if (!Enabled) { IsTouching = false; } } } else { if (touching == false) { //Report the separation to both participants: if (FixtureA != null && FixtureA.OnSeparation != null) { FixtureA.OnSeparation(FixtureA, FixtureB, this); } //Reverse the order of the reported fixtures. The first fixture is always the one that the //user subscribed to. if (FixtureB != null && FixtureB.OnSeparation != null) { FixtureB.OnSeparation(FixtureB, FixtureA, this); } //Report the separation to both bodies: if (FixtureA != null && FixtureA.Body != null && FixtureA.Body.onSeparationEventHandler != null) { FixtureA.Body.onSeparationEventHandler(FixtureA, FixtureB, this); } //Reverse the order of the reported fixtures. The first fixture is always the one that the //user subscribed to. if (FixtureB != null && FixtureB.Body != null && FixtureB.Body.onSeparationEventHandler != null) { FixtureB.Body.onSeparationEventHandler(FixtureB, FixtureA, this); } if (contactManager.EndContact != null) { contactManager.EndContact(this); } } } if (sensor) { return; } if (contactManager.PreSolve != null) { contactManager.PreSolve(this, ref oldManifold); } }
private EdgeAndPolygonContact(Fixture fixtureA, Fixture fixtureB) : base(fixtureA, 0, fixtureB, 0) { Debug.Assert(FixtureA.GetShapeType() == ShapeType.Edge); Debug.Assert(FixtureB.GetShapeType() == ShapeType.Polygon); }
private PolygonAndCircleContact(Fixture fixtureA, Fixture fixtureB) : base(fixtureA, 0, fixtureB, 0) { Debug.Assert(FixtureA.GetShapeType() == ShapeType.Polygon); Debug.Assert(FixtureB.GetShapeType() == ShapeType.Circle); }