internal void Initialize(Fixture fixtureA, int indexA, Fixture fixtureB, int indexB) { Flags = ContactFlag.EnabledFlag; FixtureA = fixtureA; FixtureB = fixtureB; NodeA = SimpleObjectPool <ContactEdge> .Shared.Get(); NodeB = SimpleObjectPool <ContactEdge> .Shared.Get(); ChildIndexA = indexA; ChildIndexB = indexB; ToiCount = 0; Friction = MixFriction(FixtureA.Friction, FixtureB.Friction); Restitution = MixRestitution(FixtureA.Restitution, FixtureB.Restitution); TangentSpeed = 0.0f; }
internal virtual void Reset() { FixtureA = default; FixtureB = default; Flags = default; Friction = default; ChildIndexA = default; ChildIndexB = default; Manifold = default; Node = default; SimpleObjectPool <ContactEdge> .Shared.Return(NodeA); SimpleObjectPool <ContactEdge> .Shared.Return(NodeB); NodeA = default; NodeB = default; Restitution = default; TangentSpeed = default; Toi = default; ToiCount = default; }
internal void Initialize(Fixture fixtureA, int indexA, Fixture fixtureB, int indexB) { Flags = ContactFlag.EnabledFlag; FixtureA = fixtureA; FixtureB = fixtureB; ChildIndexA = indexA; ChildIndexB = indexB; ToiCount = 0; Friction = MixFriction(FixtureA.Friction, FixtureB.Friction); Restitution = MixRestitution(FixtureA.Restitution, FixtureB.Restitution); TangentSpeed = 0.0f; Manifold = new Manifold() { Points = FixedArray2 <ManifoldPoint> .Create() }; }
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); } }
public void SetAsSensor(bool sensor) { if (sensor) { Flags |= ContactFlag.SensorFlag; } else { Flags &= ~ContactFlag.SensorFlag; } }
public void FlagForFiltering() { Flags |= ContactFlag.FilterFlag; }
public void Disable() { Flags |= ContactFlag.DisabledFlag; }
public Contact(Fixture fixtureA, Fixture fixtureB) { Flags = 0; if (fixtureA.IsSensor || fixtureB.IsSensor) { Flags |= ContactFlag.SensorFlag; } Body bodyA = fixtureA.GetBody(); Body bodyB = fixtureB.GetBody(); if (bodyA.IsStatic() || bodyA.IsBullet() || bodyB.IsStatic() || bodyB.IsBullet()) { Flags |= ContactFlag.ContinuousFlag; } else { Flags &= ~ContactFlag.ContinuousFlag; } _fixtureA = fixtureA; _fixtureB = fixtureB; Manifold = new Manifold(); Manifold.PointCount = 0; Prev = null; Next = null; NodeA = new ContactEdge(); NodeA.Contact = null; NodeA.Prev = null; NodeA.Next = null; NodeA.Other = null; NodeB = new ContactEdge(); NodeB.Contact = null; NodeB.Prev = null; NodeB.Next = null; NodeB.Other = null; }
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); } }
public void FlagForFiltering() { Flags |= ContactFlag.FilterFlag; }
public void Disable() { Flags |= ContactFlag.DisabledFlag; }