Search in sources :

Example 66 with Vector2

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");
}
Also used : WorldManifold(com.badlogic.gdx.physics.box2d.WorldManifold) Vector2(com.badlogic.gdx.math.Vector2) Fixture(com.badlogic.gdx.physics.box2d.Fixture) Contact(com.gemserk.commons.gdx.box2d.Contacts.Contact) Before(org.junit.Before)

Example 67 with Vector2

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);
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) Fixture(com.badlogic.gdx.physics.box2d.Fixture)

Example 68 with Vector2

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);
}
Also used : Expectations(org.jmock.Expectations) Vector2(com.badlogic.gdx.math.Vector2) Fixture(com.badlogic.gdx.physics.box2d.Fixture) Contact(com.gemserk.commons.gdx.box2d.Contacts.Contact) Test(org.junit.Test)

Example 69 with Vector2

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);
}
Also used : Expectations(org.jmock.Expectations) Vector2(com.badlogic.gdx.math.Vector2) Fixture(com.badlogic.gdx.physics.box2d.Fixture) Contact(com.gemserk.commons.gdx.box2d.Contacts.Contact) Test(org.junit.Test)

Example 70 with Vector2

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));
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Vector2 (com.badlogic.gdx.math.Vector2)103 Body (com.badlogic.gdx.physics.box2d.Body)21 BodyDef (com.badlogic.gdx.physics.box2d.BodyDef)14 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)10 PolygonShape (com.badlogic.gdx.physics.box2d.PolygonShape)10 Texture (com.badlogic.gdx.graphics.Texture)7 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)7 EdgeShape (com.badlogic.gdx.physics.box2d.EdgeShape)7 Vector3 (com.badlogic.gdx.math.Vector3)6 Fixture (com.badlogic.gdx.physics.box2d.Fixture)6 World (com.badlogic.gdx.physics.box2d.World)6 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)6 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)5 CircleShape (com.badlogic.gdx.physics.box2d.CircleShape)5 Test (org.junit.Test)5 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)4 Box2DDebugRenderer (com.badlogic.gdx.physics.box2d.Box2DDebugRenderer)4 Contact (com.badlogic.gdx.physics.box2d.Contact)4 WorldManifold (com.badlogic.gdx.physics.box2d.WorldManifold)4