def PreSolve(self, contact, old_manifold): """ This is a critical function when there are many contacts in the world. It should be optimized as much as possible. """ if not (self.settings.drawContactPoints or self.settings.drawContactNormals or self.using_contacts): return elif len(self.points) > self.settings.maxContactPoints: return manifold = contact.manifold if manifold.pointCount == 0: return _, state2 = b2.b2GetPointStates(old_manifold, manifold) if not state2: return worldManifold = contact.worldManifold for i, _ in enumerate(state2): self.points.append({ 'fixtureA': contact.fixtureA, 'fixtureB': contact.fixtureB, 'position': worldManifold.points[i], 'normal': worldManifold.normal, 'state': state2[i] })
def PreSolve(self, contact, old_manifold): """ This is a critical function when there are many contacts in the world. It should be optimized as much as possible. """ if not (self.settings.drawContactPoints or self.settings.drawContactNormals or self.using_contacts): return elif len(self.points) > self.settings.maxContactPoints: return manifold = contact.manifold if manifold.pointCount == 0: return _, state2 = b2.b2GetPointStates(old_manifold, manifold) if not state2: return worldManifold = contact.worldManifold for i, _ in enumerate(state2): point = worldManifold.points[0] bodyA = contact.fixtureA.body bodyB = contact.fixtureB.body vA = bodyA.GetLinearVelocityFromWorldPoint(point) vB = bodyB.GetLinearVelocityFromWorldPoint(point) approachVelocity = b2.b2Dot(vB - vA, worldManifold.normal) # print("approachVelocity", approachVelocity) if abs(approachVelocity) > 1.0: self.collision = True self.points.append({ 'fixtureA': contact.fixtureA, 'fixtureB': contact.fixtureB, 'bodyA': bodyA, 'bodyB': bodyB, 'position': worldManifold.points[i], 'normal': worldManifold.normal, 'state': state2[i] })