public override void PreSolve(Contact contact, Manifold oldManifold) { base.PreSolve(contact, oldManifold); Fixture fixtureA = contact.FixtureA; Fixture fixtureB = contact.FixtureB; if (fixtureA != m_platform && fixtureA != m_character) return; if (fixtureB != m_character && fixtureB != m_character) return; Vec2 position = m_character.Body.Position; if (position.Y < m_top + m_radius - 3.0f * Box2DSettings.b2_linearSlop) contact.Enabled = false; }
// Implement contact listener. public override void BeginContact(Contact contact) { Fixture fixtureA = contact.FixtureA; Fixture fixtureB = contact.FixtureB; if (fixtureA == m_sensor) { object userData = fixtureB.Body.UserData; if (userData != null && userData is int) m_touching[(int)fixtureB.Body.UserData] = true; } if (fixtureB == m_sensor) { object userData = fixtureA.Body.UserData; if (userData != null && userData is int) m_touching[(int)fixtureA.Body.UserData] = true; } }
public override void PreSolve(Contact contact, Manifold oldManifold) { Manifold manifold = contact.Manifold; if (manifold.PointCount == 0) return; Fixture fixtureA = contact.FixtureA; Fixture fixtureB = contact.FixtureB; PointState[] state1 = new PointState[Box2DSettings.b2_maxManifoldPoints], state2 = new PointState[Box2DSettings.b2_maxManifoldPoints]; Manifold.GetPointStates(ref state1, ref state2, ref oldManifold, ref manifold); WorldManifold worldManifold = contact.WorldManifold; for (int i = 0; i < manifold.PointCount && m_pointCount < ContactPoint.k_maxContactPoints; ++i) { m_points[m_pointCount].fixtureA = fixtureA; m_points[m_pointCount].fixtureB = fixtureB; m_points[m_pointCount].position = worldManifold.Points[i]; m_points[m_pointCount].normal = worldManifold.Normal; m_points[m_pointCount].state = state2[i]; ++m_pointCount; } }
public override void PostSolve(Contact contact, ContactImpulse impulse) { }
public override void EndContact(Contact contact) { }
public override void BeginContact(Contact contact) { }
public abstract void BeginContact(Contact contact);
public abstract void PreSolve(Contact contact, Manifold oldManifold);
public abstract void PostSolve(Contact contact, ContactImpulse impulse);
public abstract void EndContact(Contact contact);
public override void PostSolve(Contact contact, ContactImpulse impulse) { foreach (var x in m_breaks) { if (_jointsToRemove.Contains(x) || x.MaxForce == 0) { // The body already broke. continue; } bool hasAnyFixtures = false; foreach (var f in x.Joint.BodyA.Fixtures) { if (f == contact.FixtureA || f == contact.FixtureB) { hasAnyFixtures = true; break; } } if (!hasAnyFixtures) { foreach (var f in x.Joint.BodyB.Fixtures) { if (f == contact.FixtureA || f == contact.FixtureB) { hasAnyFixtures = true; break; } } if (!hasAnyFixtures) continue; } // Should the body break? int count = contact.Manifold.PointCount; float maxImpulse = 0.0f; for (int i = 0; i < count; ++i) maxImpulse = Math.Max(maxImpulse, impulse.GetNormalImpulse(i)); if (maxImpulse > x.MaxForce) { // Flag the body for breaking. _jointsToRemove.Add(x); } } }