use of com.gemserk.commons.gdx.box2d.Contacts.Contact in project commons-gdx by gemserk.
the class ContactsTest method whenAddingOneContactBAItIsAdded.
@Test
public void whenAddingOneContactBAItIsAdded() {
mockery.checking(new Expectations() {
{
oneOf(box2dcontact).getWorldManifold();
will(returnValue(worldManifold));
oneOf(worldManifold).getNormal();
will(returnValue(normal));
oneOf(box2dcontact).getFixtureA();
will(returnValue(fixtureA));
oneOf(box2dcontact).getFixtureB();
will(returnValue(fixtureB));
ignoring(fixtureA);
ignoring(fixtureB);
}
});
contacts.addContact(box2dcontact, false);
assertTrue(contacts.isInContact());
assertThat(1, IsEqual.equalTo(contacts.getContactCount()));
Contact contact = contacts.getContact(0);
assertThat(contact.getNormal().dst(0, -1), OrderingComparisons.lessThan(0.1f));
assertSame(fixtureA, contact.getOtherFixture());
assertSame(fixtureB, contact.getMyFixture());
}
use of com.gemserk.commons.gdx.box2d.Contacts.Contact in project commons-gdx by gemserk.
the class PhysicsUtils method releaseContacts.
public static void releaseContacts(Contacts contacts) {
// removes contact from the other entity
for (int i = 0; i < contacts.getContactCount(); i++) {
Contact contact = contacts.getContact(i);
Fixture myFixture = contact.getMyFixture();
Fixture otherFixture = contact.getOtherFixture();
contactsToRemove.add(contact);
Body otherBody = otherFixture.getBody();
if (otherBody == null)
continue;
Entity otherEntity = (Entity) otherBody.getUserData();
if (otherEntity == null)
continue;
// entitiesInContact.add(otherEntity);
// removes the contact from the other entity.
PhysicsComponent otherPhyiscsComponent = Components.getPhysicsComponent(otherEntity);
otherPhyiscsComponent.getContact().removeContact(otherFixture, myFixture);
}
for (int i = 0; i < contactsToRemove.size; i++) {
Contact contact = contactsToRemove.get(i);
contacts.removeContact(contact.getMyFixture(), contact.getOtherFixture());
}
contactsToRemove.clear();
}
use of com.gemserk.commons.gdx.box2d.Contacts.Contact in project commons-gdx by gemserk.
the class ContactsTest method addingAContactReusesOneIfAvailable.
@Test
public void addingAContactReusesOneIfAvailable() {
mockery.checking(new Expectations() {
{
ignoring(fixtureA);
ignoring(fixtureB);
}
});
Contact reusedContact = new Contact();
contacts.contacts.add(reusedContact);
contacts.activeContacts = 0;
contacts.addContact(fixtureA, fixtureB, new Vector2());
assertTrue(contacts.isInContact());
assertThat(1, IsEqual.equalTo(contacts.getContactCount()));
Contact contact = contacts.contacts.get(0);
assertThat(true, IsEqual.equalTo(contact.inContact));
assertThat(contact.myFixture, same(fixtureA));
assertThat(contact.otherFixture, same(fixtureB));
}
use of com.gemserk.commons.gdx.box2d.Contacts.Contact in project commons-gdx by gemserk.
the class ContactsTest method removesFirstContactIfItMatches.
@Test
public void removesFirstContactIfItMatches() {
mockery.checking(new Expectations() {
{
ignoring(fixtureA);
ignoring(fixtureB);
}
});
contacts.addContact(fixtureA, fixtureB, normal);
assertTrue(contacts.isInContact());
assertThat(1, IsEqual.equalTo(contacts.getContactCount()));
contacts.removeContact(fixtureA, fixtureB);
assertFalse(contacts.isInContact());
assertThat(0, IsEqual.equalTo(contacts.getContactCount()));
Contact removedContact = contacts.contacts.get(0);
assertFalse(removedContact.inContact);
assertNull(removedContact.myFixture);
assertNull(removedContact.otherFixture);
}
use of com.gemserk.commons.gdx.box2d.Contacts.Contact in project commons-gdx by gemserk.
the class ContactsTest method whenAddingOneContactABItIsAdded.
@Test
public void whenAddingOneContactABItIsAdded() {
mockery.checking(new Expectations() {
{
oneOf(box2dcontact).getWorldManifold();
will(returnValue(worldManifold));
oneOf(worldManifold).getNormal();
will(returnValue(normal));
oneOf(box2dcontact).getFixtureA();
will(returnValue(fixtureA));
oneOf(box2dcontact).getFixtureB();
will(returnValue(fixtureB));
ignoring(fixtureA);
ignoring(fixtureB);
}
});
contacts.addContact(box2dcontact, true);
assertTrue(contacts.isInContact());
assertThat(1, IsEqual.equalTo(contacts.getContactCount()));
Contact contact = contacts.getContact(0);
assertThat(contact.getNormal().dst(0, 1), OrderingComparisons.lessThan(0.1f));
assertSame(fixtureA, contact.getMyFixture());
assertSame(fixtureB, contact.getOtherFixture());
}
Aggregations