public void Update(ContactListener listener) { Manifold oldManifold = _manifold.Clone(); Evaluate(); Body bodyA = _fixtureA.Body; Body bodyB = _fixtureB.Body; int oldCount = oldManifold.PointCount; int newCount = _manifold.PointCount; if (newCount == 0 && oldCount > 0) { bodyA.WakeUp(); bodyB.WakeUp(); } // Slow contacts don't generate TOI events. if (bodyA.IsStatic() || bodyA.IsBullet() || bodyB.IsStatic() || bodyB.IsBullet()) { _flags &= ~CollisionFlags.Slow; } else { _flags |= CollisionFlags.Slow; } // 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; } } } if (oldCount == 0 && newCount > 0) { _flags |= CollisionFlags.Touch; if (listener != null) { listener.BeginContact(this); } } if (oldCount > 0 && newCount == 0) { _flags &= ~CollisionFlags.Touch; if (listener != null) { listener.EndContact(this); } } if ((_flags & CollisionFlags.NonSolid) == 0) { if (listener != null) { listener.PreSolve(this, oldManifold); } // The user may have disabled contact. if (_manifold.PointCount == 0) { _flags &= ~CollisionFlags.Touch; } } }
public void Destroy(Contact c) { Fixture fixtureA = c.GetFixtureA(); Fixture fixtureB = c.GetFixtureB(); Body body1 = fixtureA.GetBody(); Body body2 = fixtureB.GetBody(); if (c.Manifold.PointCount > 0) { _contactListener.EndContact(c); } // Remove from the world. if (c.Prev != null) { c.Prev.Next = c.Next; } if (c.Next != null) { c.Next.Prev = c.Prev; } if (c == _contactList) { _contactList = c.Next; } // Remove from body 1 if (c.NodeA.Prev != null) { c.NodeA.Prev.Next = c.NodeA.Next; } if (c.NodeA.Next != null) { c.NodeA.Next.Prev = c.NodeA.Prev; } if (c.NodeA == body1._contactList) { body1._contactList = c.NodeA.Next; } // Remove from body 2 if (c.NodeB.Prev != null) { c.NodeB.Prev.Next = c.NodeB.Next; } if (c.NodeB.Next != null) { c.NodeB.Next.Prev = c.NodeB.Prev; } if (c.NodeB == body2._contactList) { body2._contactList = c.NodeB.Next; } // Call the factory. Contact.Destroy(c); --_contactCount; }
public void Update(ContactListener listener) { Manifold oldManifold = _manifold.Clone(); Evaluate(); Body bodyA = _fixtureA.Body; Body bodyB = _fixtureB.Body; int oldCount = oldManifold.PointCount; int newCount = _manifold.PointCount; if (newCount == 0 && oldCount > 0) { bodyA.WakeUp(); bodyB.WakeUp(); } // Slow contacts don't generate TOI events. if (bodyA.IsStatic() || bodyA.IsBullet() || bodyB.IsStatic() || bodyB.IsBullet()) { _flags &= ~CollisionFlags.Slow; } else { _flags |= CollisionFlags.Slow; } // 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; } } } if (oldCount == 0 && newCount > 0) { _flags |= CollisionFlags.Touch; if(listener!=null) listener.BeginContact(this); } if (oldCount > 0 && newCount == 0) { _flags &= ~CollisionFlags.Touch; if (listener != null) listener.EndContact(this); } if ((_flags & CollisionFlags.NonSolid) == 0) { if (listener != null) listener.PreSolve(this, oldManifold); // The user may have disabled contact. if (_manifold.PointCount == 0) { _flags &= ~CollisionFlags.Touch; } } }
public void Update(ContactListener listener) { //Note: Manifold is a class, not a struct. It will reference the old manifest, not copy it - DONE Manifold oldManifold = new Manifold(); oldManifold.LocalPlaneNormal = Manifold.LocalPlaneNormal; oldManifold.LocalPoint = Manifold.LocalPoint; oldManifold.PointCount = Manifold.PointCount; oldManifold.Points = Manifold.Points; oldManifold.Type = Manifold.Type; // Re-enable this contact. Flags &= ~ContactFlag.DisabledFlag; if (Collision.Collision.TestOverlap(_fixtureA.Aabb, _fixtureB.Aabb)) { Evaluate(); } else { Manifold.PointCount = 0; } Body bodyA = _fixtureA.GetBody(); Body bodyB = _fixtureB.GetBody(); int oldCount = oldManifold.PointCount; int newCount = Manifold.PointCount; if (newCount == 0 && oldCount > 0) { bodyA.WakeUp(); bodyB.WakeUp(); } // Slow contacts don't generate TOI events. if (bodyA.IsStatic() || bodyA.IsBullet() || bodyB.IsStatic() || bodyB.IsBullet()) { Flags |= ContactFlag.ContinuousFlag; } else { Flags &= ~ContactFlag.ContinuousFlag; } // 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; } } } if (newCount > 0) { Flags |= ContactFlag.TouchingFlag; } else { Flags &= ~ContactFlag.TouchingFlag; } if (oldCount == 0 && newCount > 0) { listener.BeginContact(this); } if (oldCount > 0 && newCount == 0) { listener.EndContact(this); } if ((Flags & ContactFlag.SensorFlag) == 0) { listener.PreSolve(this, oldManifold); } }