use of com.badlogic.gdx.physics.box2d.Fixture in project commons-gdx by gemserk.
the class BodyBuilder method build.
public Body build(boolean disposeShapes) {
Body body = world.createBody(bodyDef);
for (int i = 0; i < fixtureDefs.size(); i++) {
FixtureDef fixtureDef = fixtureDefs.get(i);
Fixture fixture = body.createFixture(fixtureDef);
fixture.setUserData(fixtureUserDatas.get(i));
}
if (massSet) {
MassData bodyMassData = body.getMassData();
// massData.center.set(position);
massData.center.set(bodyMassData.center);
// massData.I = bodyMassData.I;
body.setMassData(massData);
}
// MassData massData = body.getMassData();
// massData.mass = mass;
// massData.I = 1f;
body.setUserData(userData);
body.setTransform(position, angle);
reset(disposeShapes);
return body;
}
use of com.badlogic.gdx.physics.box2d.Fixture in project commons-gdx by gemserk.
the class Contacts method addContact.
public void addContact(com.badlogic.gdx.physics.box2d.Contact contact, boolean AB) {
Vector2 normal = contact.getWorldManifold().getNormal();
Fixture myFixture;
Fixture otherFixture;
if (AB) {
myFixture = contact.getFixtureA();
otherFixture = contact.getFixtureB();
} else {
myFixture = contact.getFixtureB();
otherFixture = contact.getFixtureA();
// if the body in contact is the first one declared by the contact, then we have to invert the normal.
normal.mul(-1);
}
addContact(myFixture, otherFixture, normal);
}
use of com.badlogic.gdx.physics.box2d.Fixture in project commons-gdx by gemserk.
the class ContactsTest method removesSecondContactIfItMatches.
@Test
public void removesSecondContactIfItMatches() {
final Fixture fixtureC = mockery.mock(Fixture.class);
mockery.checking(new Expectations() {
{
ignoring(fixtureA);
ignoring(fixtureB);
ignoring(fixtureC);
}
});
contacts.addContact(fixtureA, fixtureC, new Vector2());
contacts.addContact(fixtureA, fixtureB, normal);
assertTrue(contacts.isInContact());
assertThat(2, IsEqual.equalTo(contacts.getContactCount()));
contacts.removeContact(fixtureA, fixtureB);
assertTrue(contacts.isInContact());
assertThat(1, IsEqual.equalTo(contacts.getContactCount()));
Contact stillValidContact = contacts.contacts.get(0);
assertTrue(stillValidContact.inContact);
assertSame(fixtureA, stillValidContact.myFixture);
assertSame(fixtureC, stillValidContact.otherFixture);
Contact removedContact = contacts.contacts.get(1);
assertFalse(removedContact.inContact);
assertNull(removedContact.myFixture);
assertNull(removedContact.otherFixture);
}
use of com.badlogic.gdx.physics.box2d.Fixture in project commons-gdx by gemserk.
the class ContactsTest method removesFirstOfTwoContactIfItMatches.
@Test
public void removesFirstOfTwoContactIfItMatches() {
final Fixture fixtureC = mockery.mock(Fixture.class);
mockery.checking(new Expectations() {
{
ignoring(fixtureA);
ignoring(fixtureB);
ignoring(fixtureC);
}
});
contacts.addContact(fixtureA, fixtureB, normal);
contacts.addContact(fixtureA, fixtureC, new Vector2());
assertTrue(contacts.isInContact());
assertThat(2, IsEqual.equalTo(contacts.getContactCount()));
contacts.removeContact(fixtureA, fixtureB);
assertTrue(contacts.isInContact());
assertThat(1, IsEqual.equalTo(contacts.getContactCount()));
Contact stillValidContact = contacts.contacts.get(0);
assertTrue(stillValidContact.inContact);
assertSame(fixtureA, stillValidContact.myFixture);
assertSame(fixtureC, stillValidContact.otherFixture);
Contact removedContact = contacts.contacts.get(1);
assertFalse(removedContact.inContact);
assertNull(removedContact.myFixture);
assertNull(removedContact.otherFixture);
}
use of com.badlogic.gdx.physics.box2d.Fixture in project RubeLoader by tescott.
the class RubeLoaderTest method endContact.
@Override
public void endContact(Contact contact) {
Fixture fixA = contact.getFixtureA();
Fixture fixB = contact.getFixtureB();
if ((fixA.isSensor()) && (fixA.getUserData() != null)) {
B2Controller b2c = (B2Controller) fixA.getUserData();
b2c.removeBody(fixB.getBody());
} else if ((fixB.isSensor()) && (fixB.getUserData() != null)) {
B2Controller b2c = (B2Controller) fixB.getUserData();
b2c.removeBody(fixA.getBody());
}
}
Aggregations