Search in sources :

Example 1 with CircleShape

use of com.badlogic.gdx.physics.box2d.CircleShape 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 2 with CircleShape

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

the class KinematicBodyTest method create.

public void create() {
    cam = new OrthographicCamera(48, 32);
    cam.position.set(0, 15, 0);
    renderer = new Box2DDebugRenderer();
    world = new World(new Vector2(0, -10), true);
    Body body = world.createBody(new BodyDef());
    CircleShape shape = new CircleShape();
    shape.setRadius(1f);
    MassData mass = new MassData();
    mass.mass = 1f;
    body.setMassData(mass);
    body.setFixedRotation(true);
    body.setType(BodyType.KinematicBody);
    body.createFixture(shape, 1);
    body.setBullet(true);
    body.setTransform(new Vector2(0, 0), body.getAngle());
    body.setLinearVelocity(new Vector2(50f, 0));
}
Also used : Box2DDebugRenderer(com.badlogic.gdx.physics.box2d.Box2DDebugRenderer) Vector2(com.badlogic.gdx.math.Vector2) CircleShape(com.badlogic.gdx.physics.box2d.CircleShape) MassData(com.badlogic.gdx.physics.box2d.MassData) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) World(com.badlogic.gdx.physics.box2d.World) Body(com.badlogic.gdx.physics.box2d.Body) BodyDef(com.badlogic.gdx.physics.box2d.BodyDef)

Example 3 with CircleShape

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

the class Box2DCharacterControllerTest method createCircle.

Body createCircle(BodyType type, float radius, float density) {
    BodyDef def = new BodyDef();
    def.type = type;
    Body box = world.createBody(def);
    CircleShape poly = new CircleShape();
    poly.setRadius(radius);
    box.createFixture(poly, density);
    poly.dispose();
    return box;
}
Also used : CircleShape(com.badlogic.gdx.physics.box2d.CircleShape) BodyDef(com.badlogic.gdx.physics.box2d.BodyDef) Body(com.badlogic.gdx.physics.box2d.Body)

Example 4 with CircleShape

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

the class Box2dUtils method translateFixtures.

/**
 * Internally translates all the Body's fixtures the specified translation, without moving the Body's center. For now, it generates garbage so should be used only once.
 *
 * @param body
 *            The body to work on.
 * @param tx
 *            The translation in x coordinate.
 * @param ty
 *            The translation in y coordinate.
 */
public static void translateFixtures(ArrayList<Fixture> fixtures, float tx, float ty) {
    // TODO: should be in a Box2dUtils
    for (int i = 0; i < fixtures.size(); i++) {
        Fixture fixture = fixtures.get(i);
        Shape shape = fixture.getShape();
        if (shape.getType() == Type.Polygon)
            ShapeUtils.translatePolygonShape((PolygonShape) shape, tx, ty);
        else if (shape.getType() == Type.Circle)
            ShapeUtils.translateCircleShape((CircleShape) shape, tx, ty);
    }
}
Also used : PolygonShape(com.badlogic.gdx.physics.box2d.PolygonShape) Shape(com.badlogic.gdx.physics.box2d.Shape) CircleShape(com.badlogic.gdx.physics.box2d.CircleShape) PolygonShape(com.badlogic.gdx.physics.box2d.PolygonShape) Fixture(com.badlogic.gdx.physics.box2d.Fixture)

Example 5 with CircleShape

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

the class FixtureDefBuilder method circleShape.

public FixtureDefBuilder circleShape(float radius) {
    Shape shape = new CircleShape();
    shape.setRadius(radius);
    fixtureDef.shape = shape;
    return this;
}
Also used : Shape(com.badlogic.gdx.physics.box2d.Shape) CircleShape(com.badlogic.gdx.physics.box2d.CircleShape) PolygonShape(com.badlogic.gdx.physics.box2d.PolygonShape) CircleShape(com.badlogic.gdx.physics.box2d.CircleShape)

Aggregations

CircleShape (com.badlogic.gdx.physics.box2d.CircleShape)12 BodyDef (com.badlogic.gdx.physics.box2d.BodyDef)8 PolygonShape (com.badlogic.gdx.physics.box2d.PolygonShape)8 Body (com.badlogic.gdx.physics.box2d.Body)7 Vector2 (com.badlogic.gdx.math.Vector2)6 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)5 EdgeShape (com.badlogic.gdx.physics.box2d.EdgeShape)4 Fixture (com.badlogic.gdx.physics.box2d.Fixture)2 Shape (com.badlogic.gdx.physics.box2d.Shape)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 Box2DDebugRenderer (com.badlogic.gdx.physics.box2d.Box2DDebugRenderer)1 ChainShape (com.badlogic.gdx.physics.box2d.ChainShape)1 MassData (com.badlogic.gdx.physics.box2d.MassData)1 World (com.badlogic.gdx.physics.box2d.World)1 PrismaticJointDef (com.badlogic.gdx.physics.box2d.joints.PrismaticJointDef)1 RevoluteJointDef (com.badlogic.gdx.physics.box2d.joints.RevoluteJointDef)1 WeldJointDef (com.badlogic.gdx.physics.box2d.joints.WeldJointDef)1