Search in sources :

Example 31 with Vector2

use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.

the class MovementSystem method processEntities.

@Override
protected void processEntities() {
    RandomAccessMap<Entity, EntityComponents> allTheEntityComponents = componentsHolder.entityComponents;
    int entitiesSize = allTheEntityComponents.size();
    float delta = GlobalTime.getDelta();
    for (int entityIndex = 0; entityIndex < entitiesSize; entityIndex++) {
        EntityComponents entityComponents = allTheEntityComponents.get(entityIndex);
        MovementComponent movementComponent = entityComponents.movementComponent;
        Spatial spatial = entityComponents.spatialComponent.getSpatial();
        Vector2 velocity = movementComponent.getVelocity();
        tmpVelocity.set(velocity).mul(delta);
        tmpPosition.set(spatial.getX(), spatial.getY()).add(tmpVelocity);
        float newAngle = spatial.getAngle() + delta * movementComponent.getAngularVelocity();
        spatial.setAngle(newAngle);
        spatial.setPosition(tmpPosition.x, tmpPosition.y);
    }
}
Also used : Entity(com.artemis.Entity) Spatial(com.gemserk.commons.gdx.games.Spatial) Vector2(com.badlogic.gdx.math.Vector2) MovementComponent(com.gemserk.commons.artemis.components.MovementComponent)

Example 32 with Vector2

use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.

the class ShapeUtils method calculateBounds.

public static void calculateBounds(Vector2[] vertices, Rectangle bounds) {
    bounds.x = Float.MAX_VALUE;
    bounds.y = Float.MAX_VALUE;
    bounds.width = -Float.MAX_VALUE;
    bounds.height = -Float.MAX_VALUE;
    for (int i = 0; i < vertices.length; i++) {
        Vector2 v = vertices[i];
        if (v.x < bounds.x)
            bounds.x = v.x;
        if (v.y < bounds.y)
            bounds.y = v.y;
        if (v.x > bounds.x + bounds.width)
            bounds.width = v.x - bounds.x;
        if (v.y > bounds.y + bounds.height)
            bounds.height = v.y - bounds.y;
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2)

Example 33 with Vector2

use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.

the class EfficientPolygonTriangulator method area.

static float area(Array<Vector2> contour) {
    int n = contour.size;
    float A = 0.0f;
    for (int p = n - 1, q = 0; q < n; p = q++) {
        Vector2 p0 = contour.get(p);
        Vector2 p1 = contour.get(q);
        A += p0.x * p1.y - p1.x * p0.y;
    }
    return A * 0.5f;
}
Also used : Vector2(com.badlogic.gdx.math.Vector2)

Example 34 with Vector2

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

Example 35 with Vector2

use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.

the class Libgdx2dCameraTransformImplTest method shouldReturnProjectedVectorWhenCameraMoved.

@Ignore
@Test
public void shouldReturnProjectedVectorWhenCameraMoved() {
    Libgdx2dCameraTransformImpl camera = new Libgdx2dCameraTransformImpl();
    camera.move(100, 0);
    camera.zoom(32f);
    Vector2 position = new Vector2(10f, 10f);
    camera.project(position);
    assertThat(position.x, IsEqual.equalTo(-2880f));
    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