Search in sources :

Example 1 with Fixture

use of com.badlogic.gdx.physics.box2d.Fixture in project libgdx by libgdx.

the class ContactListenerTest method endContact.

@Override
public void endContact(Contact contact) {
    System.out.println(String.format("  endContact() addr=%d", getContactAddr(contact)));
    System.out.println(String.format("  endContact() addrA=%d, addrB=%d", getFixtureAddrA(contact), getFixtureAddrB(contact)));
    System.out.println(String.format("  endContact() fixA=%s, fixB=%s", contact.getFixtureA(), contact.getFixtureB()));
    final Fixture fixtureA = contact.getFixtureA();
    final Fixture fixtureB = contact.getFixtureB();
    if (fixtureA == null || fixtureB == null) {
        throw new RuntimeException("No fixture found.");
    }
}
Also used : Fixture(com.badlogic.gdx.physics.box2d.Fixture)

Example 2 with Fixture

use of com.badlogic.gdx.physics.box2d.Fixture in project libgdx by libgdx.

the class ConveyorBelt method preSolve.

public void preSolve(Contact contact, Manifold oldManifold) {
    Fixture fixtureA = contact.getFixtureA();
    Fixture fixtureB = contact.getFixtureB();
    if (fixtureA == m_platform || fixtureB == m_platform) {
        contact.setTangentSpeed(5.0f);
    }
}
Also used : Fixture(com.badlogic.gdx.physics.box2d.Fixture)

Example 3 with Fixture

use of com.badlogic.gdx.physics.box2d.Fixture in project RubeLoader by tescott.

the class BodySerializer method read.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Body read(Json json, JsonValue jsonData, Class type) {
    if (world == null)
        return null;
    BodyDef defaults = RubeDefaults.Body.definition;
    int bodyType = json.readValue("type", int.class, defaults.type.getValue(), jsonData);
    if (bodyType == BodyType.DynamicBody.getValue())
        def.type = BodyType.DynamicBody;
    else if (bodyType == BodyType.KinematicBody.getValue())
        def.type = BodyType.KinematicBody;
    else
        def.type = BodyType.StaticBody;
    def.position.set(json.readValue("position", Vector2.class, defaults.position, jsonData));
    def.linearVelocity.set(json.readValue("linearVelocity", Vector2.class, defaults.linearVelocity, jsonData));
    def.angle = json.readValue("angle", float.class, defaults.angle, jsonData);
    def.angularVelocity = json.readValue("angularVelocity", float.class, defaults.angularVelocity, jsonData);
    def.linearDamping = json.readValue("linearDamping", float.class, defaults.linearDamping, jsonData);
    def.angularDamping = json.readValue("angularDamping", float.class, defaults.angularDamping, jsonData);
    def.gravityScale = json.readValue("gravityScale", float.class, defaults.gravityScale, jsonData);
    def.allowSleep = json.readValue("allowSleep", boolean.class, defaults.allowSleep, jsonData);
    def.awake = json.readValue("awake", boolean.class, defaults.awake, jsonData);
    def.fixedRotation = json.readValue("fixedRotation", boolean.class, defaults.fixedRotation, jsonData);
    def.bullet = json.readValue("bullet", boolean.class, defaults.bullet, jsonData);
    def.active = json.readValue("active", boolean.class, defaults.active, jsonData);
    Body body = world.createBody(def);
    if (def.type == BodyType.DynamicBody) {
        Vector2 center = json.readValue("massData-center", Vector2.class, jsonData);
        float mass = json.readValue("massData-mass", float.class, 0.0f, jsonData);
        float I = json.readValue("massData-I", float.class, 0.0f, jsonData);
        if (center != null) {
            MassData massData = new MassData();
            massData.center.set(center);
            massData.mass = mass;
            massData.I = I;
            if (massData.mass != 0.0f || massData.I != 0.0f || massData.center.x != 0.0f || massData.center.y != 0.0f)
                body.setMassData(massData);
        }
    }
    scene.parseCustomProperties(json, body, jsonData);
    String name = json.readValue("name", String.class, jsonData);
    if (name != null) {
        scene.putNamed(name, body);
    }
    fixtureSerializer.setBody(body);
    scene.addFixtures(json.readValue("fixture", Array.class, Fixture.class, jsonData));
    return body;
}
Also used : Array(com.badlogic.gdx.utils.Array) Vector2(com.badlogic.gdx.math.Vector2) MassData(com.badlogic.gdx.physics.box2d.MassData) Fixture(com.badlogic.gdx.physics.box2d.Fixture) BodyDef(com.badlogic.gdx.physics.box2d.BodyDef) Body(com.badlogic.gdx.physics.box2d.Body)

Example 4 with Fixture

use of com.badlogic.gdx.physics.box2d.Fixture in project RubeLoader by tescott.

the class FixtureSerializer method read.

@SuppressWarnings("rawtypes")
@Override
public Fixture read(Json json, JsonValue jsonData, Class type) {
    if (body == null)
        return null;
    json.setIgnoreUnknownFields(true);
    FixtureDef defaults = RubeDefaults.Fixture.definition;
    FixtureDef def = new FixtureDef();
    json.readFields(def, jsonData);
    def.friction = json.readValue("friction", float.class, defaults.friction, jsonData);
    def.density = json.readValue("density", float.class, defaults.density, jsonData);
    def.restitution = json.readValue("restitution", float.class, defaults.restitution, jsonData);
    def.isSensor = json.readValue("sensor", boolean.class, defaults.isSensor, jsonData);
    def.filter.maskBits = json.readValue("filter-maskBits", short.class, defaults.filter.maskBits, jsonData);
    def.filter.categoryBits = json.readValue("filter-categoryBits", short.class, defaults.filter.categoryBits, jsonData);
    def.filter.groupIndex = json.readValue("filter-groupIndex", short.class, defaults.filter.groupIndex, jsonData);
    CircleShape circle = json.readValue("circle", CircleShape.class, jsonData);
    if (circle != null) {
        def.shape = circle;
    } else {
        EdgeShape edge = json.readValue("edge", EdgeShape.class, jsonData);
        if (edge != null) {
            def.shape = edge;
        } else {
            chainShapeSerializer.setReadLoop(false);
            ChainShape chain = json.readValue("chain", ChainShape.class, jsonData);
            if (chain != null) {
                def.shape = chain;
            } else {
                chainShapeSerializer.setReadLoop(true);
                chain = json.readValue("loop", ChainShape.class, jsonData);
                if (chain != null) {
                    def.shape = chain;
                } else {
                    PolygonShape polygon = json.readValue("polygon", PolygonShape.class, jsonData);
                    if (polygon != null) {
                        def.shape = polygon;
                    } else {
                        edge = json.readValue("polygon", EdgeShape.class, jsonData);
                        if (edge != null) {
                            def.shape = edge;
                        }
                    }
                }
            }
        }
    }
    Fixture fixture = body.createFixture(def);
    def.shape.dispose();
    scene.parseCustomProperties(json, fixture, jsonData);
    String name = json.readValue("name", String.class, jsonData);
    if (name != null) {
        scene.putNamed(name, fixture);
    }
    return fixture;
}
Also used : EdgeShape(com.badlogic.gdx.physics.box2d.EdgeShape) PolygonShape(com.badlogic.gdx.physics.box2d.PolygonShape) CircleShape(com.badlogic.gdx.physics.box2d.CircleShape) Fixture(com.badlogic.gdx.physics.box2d.Fixture) ChainShape(com.badlogic.gdx.physics.box2d.ChainShape) FixtureDef(com.badlogic.gdx.physics.box2d.FixtureDef)

Example 5 with Fixture

use of com.badlogic.gdx.physics.box2d.Fixture in project commons-gdx by gemserk.

the class Box2dUtils method getFixture.

/**
	 * Returns a Fixture from a Body given the fixtureUserData.
	 * 
	 * @param body
	 *            The Body to get the Fixture from.
	 * @param fixtureUserData
	 *            The Fixture userData to identify the Fixture.
	 */
public static Fixture getFixture(Body body, Object fixtureUserData) {
    ArrayList<Fixture> fixtureList = body.getFixtureList();
    for (int i = 0; i < fixtureList.size(); i++) {
        Fixture fixture = fixtureList.get(i);
        Object userData = fixture.getUserData();
        if (userData == fixtureUserData || fixtureUserData.equals(userData))
            return fixture;
    }
    return null;
}
Also used : Fixture(com.badlogic.gdx.physics.box2d.Fixture)

Aggregations

Fixture (com.badlogic.gdx.physics.box2d.Fixture)18 Body (com.badlogic.gdx.physics.box2d.Body)6 Vector2 (com.badlogic.gdx.math.Vector2)5 PolygonShape (com.badlogic.gdx.physics.box2d.PolygonShape)4 Contact (com.gemserk.commons.gdx.box2d.Contacts.Contact)3 B2Controller (com.gushikustudios.box2d.controllers.B2Controller)3 Texture (com.badlogic.gdx.graphics.Texture)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 CircleShape (com.badlogic.gdx.physics.box2d.CircleShape)2 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)2 MassData (com.badlogic.gdx.physics.box2d.MassData)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 Entity (com.artemis.Entity)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 PolygonRegion (com.badlogic.gdx.graphics.g2d.PolygonRegion)1 PolygonSpriteBatch (com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 EarClippingTriangulator (com.badlogic.gdx.math.EarClippingTriangulator)1 Vector3 (com.badlogic.gdx.math.Vector3)1