use of spacegraph.space2d.phys.collision.ContactID in project narchy by automenta.
the class Contact method update.
public void update(ContactListener listener) {
oldManifold.set(m_manifold);
// Re-enable this contact.
m_flags |= ENABLED_FLAG;
boolean touching = false;
boolean wasTouching = (m_flags & TOUCHING_FLAG) == TOUCHING_FLAG;
boolean sensorA = aFixture.isSensor();
boolean sensorB = bFixture.isSensor();
boolean sensor = sensorA || sensorB;
Body2D bodyA = aFixture.getBody();
Body2D bodyB = bFixture.getBody();
Transform xfA = bodyA;
Transform xfB = bodyB;
if (sensor) {
Shape shapeA = aFixture.shape();
Shape shapeB = bFixture.shape();
touching = pool.getCollision().testOverlap(shapeA, aIndex, shapeB, bIndex, xfA, xfB);
// Sensors don't generate manifolds.
m_manifold.pointCount = 0;
} else {
evaluate(m_manifold, xfA, xfB);
touching = m_manifold.pointCount > 0;
// stored impulses to warm start the solver.
for (int i = 0; i < m_manifold.pointCount; ++i) {
ManifoldPoint mp2 = m_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.setAwake(true);
bodyB.setAwake(true);
}
}
if (touching) {
m_flags |= TOUCHING_FLAG;
} else {
m_flags &= ~TOUCHING_FLAG;
}
if (!sensor && touching) {
m_angularVelocity_bodyA = aFixture.body.velAngular;
m_linearVelocity_bodyA.set(aFixture.body.vel);
m_angularVelocity_bodyB = bFixture.body.velAngular;
m_linearVelocity_bodyB.set(bFixture.body.vel);
}
if (listener == null) {
return;
}
if (!wasTouching && touching) {
if (!listener.beginContact(this))
touching = false;
}
if (wasTouching && !touching) {
listener.endContact(this);
}
if (!sensor && touching) {
listener.preSolve(this, oldManifold);
}
}
Aggregations