use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.
the class ContactsTest method setUp.
@Before
public void setUp() {
contacts = new Contacts();
box2dcontact = mockery.mock(com.badlogic.gdx.physics.box2d.Contact.class);
worldManifold = mockery.mock(WorldManifold.class);
normal = new Vector2(0, 1);
fixtureA = mockery.mock(Fixture.class, "fixtureA");
fixtureB = mockery.mock(Fixture.class, "fixtureB");
}
use of com.badlogic.gdx.math.Vector2 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.math.Vector2 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.math.Vector2 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.math.Vector2 in project commons-gdx by gemserk.
the class Libgdx2dCameraTransformImplTest method shouldReturnProjectedVectorWhenCameraNotMoved.
@Ignore
@Test
public void shouldReturnProjectedVectorWhenCameraNotMoved() {
Libgdx2dCameraTransformImpl camera = new Libgdx2dCameraTransformImpl();
camera.move(0, 0);
camera.zoom(32f);
Vector2 position = new Vector2(10f, 10f);
camera.project(position);
assertThat(position.x, IsEqual.equalTo(320f));
assertThat(position.y, IsEqual.equalTo(320f));
}
Aggregations