public void Update(IContactListener listener)
{
oldManifold.Set(Manifold);
// Re-enable this contact.
Flags |= ContactFlags.Enabled;
bool touching;
bool wasTouching = (Flags & ContactFlags.Touching) == ContactFlags.Touching;
bool sensorA = FixtureA.Sensor;
bool sensorB = FixtureB.Sensor;
bool sensor = sensorA || sensorB;
Body bodyA = FixtureA.Body;
Body bodyB = FixtureB.Body;
Transform xfA = bodyA.GetTransform();
Transform xfB = bodyB.GetTransform();
// log.debug("TransformA: "+xfA);
// log.debug("TransformB: "+xfB);
if (sensor)
{
Shape shapeA = FixtureA.Shape;
Shape shapeB = FixtureB.Shape;
touching = Pool.GetCollision().TestOverlap(shapeA, ChildIndexA, shapeB, ChildIndexB, xfA, xfB);
// Sensors don't generate manifolds.
Manifold.PointCount = 0;
}
else
{
Evaluate(Manifold, xfA, xfB);
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.IsEqual(id2))
{
mp2.NormalImpulse = mp1.NormalImpulse;
mp2.TangentImpulse = mp1.TangentImpulse;
break;
}
}
}
if (touching != wasTouching)
{
bodyA.Awake = true;
bodyB.Awake = true;
}
}
if (touching)
{
Flags |= ContactFlags.Touching;
}
else
{
Flags &= ~ContactFlags.Touching;
}
if (listener == null)
{
return;
}
if (!wasTouching && touching)
{
listener.BeginContact(this);
}
if (wasTouching && !touching)
{
listener.EndContact(this);
}
if (!sensor && touching)
{
listener.PreSolve(this, oldManifold);
}
}