Example usage for com.badlogic.gdx.physics.box2d.joints FrictionJointDef FrictionJointDef

List of usage examples for com.badlogic.gdx.physics.box2d.joints FrictionJointDef FrictionJointDef

Introduction

In this page you can find the example usage for com.badlogic.gdx.physics.box2d.joints FrictionJointDef FrictionJointDef.

Prototype

public FrictionJointDef() 

Source Link

Usage

From source file:com.badlogic.gdx.tests.box2d.ApplyForce.java

License:Apache License

@Override
protected void createWorld(World world) {
    world.setGravity(new Vector2(0, 0));

    float k_restitution = 0.4f;
    Body ground;//from  w  w  w.  j  av  a 2s.  c  om

    {
        BodyDef bd = new BodyDef();
        bd.position.set(0, 20);
        ground = world.createBody(bd);

        EdgeShape shape = new EdgeShape();

        FixtureDef sd = new FixtureDef();
        sd.shape = shape;
        sd.density = 0;
        sd.restitution = k_restitution;

        shape.set(new Vector2(-20, -20), new Vector2(-20, 20));
        ground.createFixture(sd);

        shape.set(new Vector2(20, -20), new Vector2(20, 20));
        ground.createFixture(sd);

        shape.set(new Vector2(-20, 20), new Vector2(20, 20));
        ground.createFixture(sd);

        shape.set(new Vector2(-20, -20), new Vector2(20, -20));
        ground.createFixture(sd);

        shape.dispose();
    }

    {
        Transform xf1 = new Transform(new Vector2(), 0.3524f * (float) Math.PI);
        xf1.setPosition(xf1.mul(new Vector2(1, 0)));

        Vector2[] vertices = new Vector2[3];
        vertices[0] = xf1.mul(new Vector2(-1, 0));
        vertices[1] = xf1.mul(new Vector2(1, 0));
        vertices[2] = xf1.mul(new Vector2(0, 0.5f));

        PolygonShape poly1 = new PolygonShape();
        poly1.set(vertices);

        FixtureDef sd1 = new FixtureDef();
        sd1.shape = poly1;
        sd1.density = 4.0f;

        Transform xf2 = new Transform(new Vector2(), -0.3524f * (float) Math.PI);
        xf2.setPosition(xf2.mul(new Vector2(-1, 0)));

        vertices[0] = xf2.mul(new Vector2(-1, 0));
        vertices[1] = xf2.mul(new Vector2(1, 0));
        vertices[2] = xf2.mul(new Vector2(0, 0.5f));

        PolygonShape poly2 = new PolygonShape();
        poly2.set(vertices);

        FixtureDef sd2 = new FixtureDef();
        sd2.shape = poly2;
        sd2.density = 2.0f;

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.angularDamping = 5.0f;
        bd.linearDamping = 0.1f;

        bd.position.set(0, 2);
        bd.angle = (float) Math.PI;
        bd.allowSleep = false;
        m_body = world.createBody(bd);
        m_body.createFixture(sd1);
        m_body.createFixture(sd2);
        poly1.dispose();
        poly2.dispose();
    }

    {
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(0.5f, 0.5f);

        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.density = 1.0f;
        fd.friction = 0.3f;

        for (int i = 0; i < 10; i++) {
            BodyDef bd = new BodyDef();
            bd.type = BodyType.DynamicBody;

            bd.position.set(0, 5 + 1.54f * i);
            Body body = world.createBody(bd);

            body.createFixture(fd);

            float gravity = 10.0f;
            float I = body.getInertia();
            float mass = body.getMass();

            float radius = (float) Math.sqrt(2 * I / mass);

            FrictionJointDef jd = new FrictionJointDef();
            jd.localAnchorA.set(0, 0);
            jd.localAnchorB.set(0, 0);
            jd.bodyA = ground;
            jd.bodyB = body;
            jd.collideConnected = true;
            jd.maxForce = mass * gravity;
            jd.maxTorque = mass * radius * gravity;

            world.createJoint(jd);
        }

        shape.dispose();
    }
}

From source file:com.cafeitvn.myballgame.screen.Box2DMapObjectParser.java

License:Apache License

/**
 * creates a {@link Joint} from a {@link MapObject}
 * @param mapObject the {@link Joint} which to parse
 * @return the parsed {@link Joint}/*from   w ww .  ja v a  2  s . com*/
 */
public Joint createJoint(MapObject mapObject) {
    MapProperties properties = mapObject.getProperties();

    JointDef jointDef = null;

    String type = properties.get("type", String.class);
    if (!type.equals(aliases.joint))
        throw new IllegalArgumentException(
                "type of " + mapObject + " is  \"" + type + "\" instead of \"" + aliases.joint + "\"");

    String jointType = properties.get(aliases.jointType, String.class);

    // get all possible values
    if (jointType.equals(aliases.distanceJoint)) {
        DistanceJointDef distanceJointDef = new DistanceJointDef();
        distanceJointDef.dampingRatio = (Float) getProperty(properties, aliases.dampingRatio,
                distanceJointDef.dampingRatio, Float.class);
        distanceJointDef.frequencyHz = (Float) getProperty(properties, aliases.frequencyHz,
                distanceJointDef.frequencyHz, Float.class);
        distanceJointDef.length = (Float) getProperty(properties, aliases.length, distanceJointDef.length,
                Float.class) * (tileWidth + tileHeight) / 2 * unitScale;
        distanceJointDef.localAnchorA.set(
                (Float) getProperty(properties, aliases.localAnchorAX, distanceJointDef.localAnchorA.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorAY, distanceJointDef.localAnchorA.y,
                        Float.class) * tileHeight * unitScale);
        distanceJointDef.localAnchorB.set(
                (Float) getProperty(properties, aliases.localAnchorBX, distanceJointDef.localAnchorB.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorBY, distanceJointDef.localAnchorB.y,
                        Float.class) * tileHeight * unitScale);

        jointDef = distanceJointDef;
    } else if (jointType.equals(aliases.frictionJoint)) {
        FrictionJointDef frictionJointDef = new FrictionJointDef();
        frictionJointDef.localAnchorA.set(
                (Float) getProperty(properties, aliases.localAnchorAX, frictionJointDef.localAnchorA.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorAY, frictionJointDef.localAnchorA.y,
                        Float.class) * tileHeight * unitScale);
        frictionJointDef.localAnchorB.set(
                (Float) getProperty(properties, aliases.localAnchorBX, frictionJointDef.localAnchorB.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorBY, frictionJointDef.localAnchorB.y,
                        Float.class) * tileHeight * unitScale);
        frictionJointDef.maxForce = (Float) getProperty(properties, aliases.maxForce, frictionJointDef.maxForce,
                Float.class);
        frictionJointDef.maxTorque = (Float) getProperty(properties, aliases.maxTorque,
                frictionJointDef.maxTorque, Float.class);

        jointDef = frictionJointDef;
    } else if (jointType.equals(aliases.gearJoint)) {
        GearJointDef gearJointDef = new GearJointDef();
        gearJointDef.joint1 = joints.get(properties.get(aliases.joint1, String.class));
        gearJointDef.joint2 = joints.get(properties.get(aliases.joint2, String.class));
        gearJointDef.ratio = (Float) getProperty(properties, aliases.ratio, gearJointDef.ratio, Float.class);

        jointDef = gearJointDef;
    } else if (jointType.equals(aliases.mouseJoint)) {
        MouseJointDef mouseJointDef = new MouseJointDef();
        mouseJointDef.dampingRatio = (Float) getProperty(properties, aliases.dampingRatio,
                mouseJointDef.dampingRatio, Float.class);
        mouseJointDef.frequencyHz = (Float) getProperty(properties, aliases.frequencyHz,
                mouseJointDef.frequencyHz, Float.class);
        mouseJointDef.maxForce = (Float) getProperty(properties, aliases.maxForce, mouseJointDef.maxForce,
                Float.class);
        mouseJointDef.target.set(
                (Float) getProperty(properties, aliases.targetX, mouseJointDef.target.x, Float.class)
                        * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.targetY, mouseJointDef.target.y, Float.class)
                        * tileHeight * unitScale);

        jointDef = mouseJointDef;
    } else if (jointType.equals(aliases.prismaticJoint)) {
        PrismaticJointDef prismaticJointDef = new PrismaticJointDef();
        prismaticJointDef.enableLimit = (Boolean) getProperty(properties, aliases.enableLimit,
                prismaticJointDef.enableLimit, Boolean.class);
        prismaticJointDef.enableMotor = (Boolean) getProperty(properties, aliases.enableMotor,
                prismaticJointDef.enableMotor, Boolean.class);
        prismaticJointDef.localAnchorA.set(
                (Float) getProperty(properties, aliases.localAnchorAX, prismaticJointDef.localAnchorA.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorAY, prismaticJointDef.localAnchorA.y,
                        Float.class) * tileHeight * unitScale);
        prismaticJointDef.localAnchorB.set(
                (Float) getProperty(properties, aliases.localAnchorBX, prismaticJointDef.localAnchorB.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorBY, prismaticJointDef.localAnchorB.y,
                        Float.class) * tileHeight * unitScale);
        prismaticJointDef.localAxisA.set(
                (Float) getProperty(properties, aliases.localAxisAX, prismaticJointDef.localAxisA.x,
                        Float.class),
                (Float) getProperty(properties, aliases.localAxisAY, prismaticJointDef.localAxisA.y,
                        Float.class));
        prismaticJointDef.lowerTranslation = (Float) getProperty(properties, aliases.lowerTranslation,
                prismaticJointDef.lowerTranslation, Float.class) * (tileWidth + tileHeight) / 2 * unitScale;
        prismaticJointDef.maxMotorForce = (Float) getProperty(properties, aliases.maxMotorForce,
                prismaticJointDef.maxMotorForce, Float.class);
        prismaticJointDef.motorSpeed = (Float) getProperty(properties, aliases.motorSpeed,
                prismaticJointDef.motorSpeed, Float.class);
        prismaticJointDef.referenceAngle = (Float) getProperty(properties, aliases.referenceAngle,
                prismaticJointDef.referenceAngle, Float.class);
        prismaticJointDef.upperTranslation = (Float) getProperty(properties, aliases.upperTranslation,
                prismaticJointDef.upperTranslation, Float.class) * (tileWidth + tileHeight) / 2 * unitScale;

        jointDef = prismaticJointDef;
    } else if (jointType.equals(aliases.pulleyJoint)) {
        PulleyJointDef pulleyJointDef = new PulleyJointDef();
        pulleyJointDef.groundAnchorA.set(
                (Float) getProperty(properties, aliases.groundAnchorAX, pulleyJointDef.groundAnchorA.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.groundAnchorAY, pulleyJointDef.groundAnchorA.y,
                        Float.class) * tileHeight * unitScale);
        pulleyJointDef.groundAnchorB.set(
                (Float) getProperty(properties, aliases.groundAnchorBX, pulleyJointDef.groundAnchorB.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.groundAnchorBY, pulleyJointDef.groundAnchorB.y,
                        Float.class) * tileHeight * unitScale);
        pulleyJointDef.lengthA = (Float) getProperty(properties, aliases.lengthA, pulleyJointDef.lengthA,
                Float.class) * (tileWidth + tileHeight) / 2 * unitScale;
        pulleyJointDef.lengthB = (Float) getProperty(properties, aliases.lengthB, pulleyJointDef.lengthB,
                Float.class) * (tileWidth + tileHeight) / 2 * unitScale;
        pulleyJointDef.localAnchorA.set(
                (Float) getProperty(properties, aliases.localAnchorAX, pulleyJointDef.localAnchorA.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorAY, pulleyJointDef.localAnchorA.y,
                        Float.class) * tileHeight * unitScale);
        pulleyJointDef.localAnchorB.set(
                (Float) getProperty(properties, aliases.localAnchorBX, pulleyJointDef.localAnchorB.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorBY, pulleyJointDef.localAnchorB.y,
                        Float.class) * tileHeight * unitScale);
        pulleyJointDef.ratio = (Float) getProperty(properties, aliases.ratio, pulleyJointDef.ratio,
                Float.class);

        jointDef = pulleyJointDef;
    } else if (jointType.equals(aliases.revoluteJoint)) {
        RevoluteJointDef revoluteJointDef = new RevoluteJointDef();
        revoluteJointDef.enableLimit = (Boolean) getProperty(properties, aliases.enableLimit,
                revoluteJointDef.enableLimit, Boolean.class);
        revoluteJointDef.enableMotor = (Boolean) getProperty(properties, aliases.enableMotor,
                revoluteJointDef.enableMotor, Boolean.class);
        revoluteJointDef.localAnchorA.set(
                (Float) getProperty(properties, aliases.localAnchorAX, revoluteJointDef.localAnchorA.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorAY, revoluteJointDef.localAnchorA.y,
                        Float.class) * tileHeight * unitScale);
        revoluteJointDef.localAnchorB.set(
                (Float) getProperty(properties, aliases.localAnchorBX, revoluteJointDef.localAnchorB.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorBY, revoluteJointDef.localAnchorB.y,
                        Float.class) * tileHeight * unitScale);
        revoluteJointDef.lowerAngle = (Float) getProperty(properties, aliases.lowerAngle,
                revoluteJointDef.lowerAngle, Float.class);
        revoluteJointDef.maxMotorTorque = (Float) getProperty(properties, aliases.maxMotorTorque,
                revoluteJointDef.maxMotorTorque, Float.class);
        revoluteJointDef.motorSpeed = (Float) getProperty(properties, aliases.motorSpeed,
                revoluteJointDef.motorSpeed, Float.class);
        revoluteJointDef.referenceAngle = (Float) getProperty(properties, aliases.referenceAngle,
                revoluteJointDef.referenceAngle, Float.class);
        revoluteJointDef.upperAngle = (Float) getProperty(properties, aliases.upperAngle,
                revoluteJointDef.upperAngle, Float.class);

        jointDef = revoluteJointDef;
    } else if (jointType.equals(aliases.ropeJoint)) {
        RopeJointDef ropeJointDef = new RopeJointDef();
        ropeJointDef.localAnchorA.set(
                (Float) getProperty(properties, aliases.localAnchorAX, ropeJointDef.localAnchorA.x, Float.class)
                        * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorAY, ropeJointDef.localAnchorA.y, Float.class)
                        * tileHeight * unitScale);
        ropeJointDef.localAnchorB.set(
                (Float) getProperty(properties, aliases.localAnchorBX, ropeJointDef.localAnchorB.x, Float.class)
                        * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorBY, ropeJointDef.localAnchorB.y, Float.class)
                        * tileHeight * unitScale);
        ropeJointDef.maxLength = (Float) getProperty(properties, aliases.maxLength, ropeJointDef.maxLength,
                Float.class) * (tileWidth + tileHeight) / 2 * unitScale;

        jointDef = ropeJointDef;
    } else if (jointType.equals(aliases.weldJoint)) {
        WeldJointDef weldJointDef = new WeldJointDef();
        weldJointDef.localAnchorA.set(
                (Float) getProperty(properties, aliases.localAnchorAX, weldJointDef.localAnchorA.x, Float.class)
                        * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorAY, weldJointDef.localAnchorA.y, Float.class)
                        * tileHeight * unitScale);
        weldJointDef.localAnchorB.set(
                (Float) getProperty(properties, aliases.localAnchorBX, weldJointDef.localAnchorB.x, Float.class)
                        * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorBY, weldJointDef.localAnchorB.y, Float.class)
                        * tileHeight * unitScale);
        weldJointDef.referenceAngle = (Float) getProperty(properties, aliases.referenceAngle,
                weldJointDef.referenceAngle, Float.class);

        jointDef = weldJointDef;
    } else if (jointType.equals(aliases.wheelJoint)) {
        WheelJointDef wheelJointDef = new WheelJointDef();
        wheelJointDef.dampingRatio = (Float) getProperty(properties, aliases.dampingRatio,
                wheelJointDef.dampingRatio, Float.class);
        wheelJointDef.enableMotor = (Boolean) getProperty(properties, aliases.enableMotor,
                wheelJointDef.enableMotor, Boolean.class);
        wheelJointDef.frequencyHz = (Float) getProperty(properties, aliases.frequencyHz,
                wheelJointDef.frequencyHz, Float.class);
        wheelJointDef.localAnchorA.set(
                (Float) getProperty(properties, aliases.localAnchorAX, wheelJointDef.localAnchorA.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorAY, wheelJointDef.localAnchorA.y,
                        Float.class) * tileHeight * unitScale);
        wheelJointDef.localAnchorB.set(
                (Float) getProperty(properties, aliases.localAnchorBX, wheelJointDef.localAnchorB.x,
                        Float.class) * tileWidth * unitScale,
                (Float) getProperty(properties, aliases.localAnchorBY, wheelJointDef.localAnchorB.y,
                        Float.class) * tileHeight * unitScale);
        wheelJointDef.localAxisA.set(
                (Float) getProperty(properties, aliases.localAxisAX, wheelJointDef.localAxisA.x, Float.class),
                (Float) getProperty(properties, aliases.localAxisAY, wheelJointDef.localAxisA.y, Float.class));
        wheelJointDef.maxMotorTorque = (Float) getProperty(properties, aliases.maxMotorTorque,
                wheelJointDef.maxMotorTorque, Float.class);
        wheelJointDef.motorSpeed = (Float) getProperty(properties, aliases.motorSpeed, wheelJointDef.motorSpeed,
                Float.class);

        jointDef = wheelJointDef;
    }

    jointDef.bodyA = bodies.get(properties.get(aliases.bodyA, String.class));
    jointDef.bodyB = bodies.get(properties.get(aliases.bodyB, String.class));
    jointDef.collideConnected = (Boolean) getProperty(properties, aliases.collideConnected,
            jointDef.collideConnected, Boolean.class);

    Joint joint = jointDef.bodyA.getWorld().createJoint(jointDef);

    String name = mapObject.getName();
    if (joints.containsKey(name)) {
        int duplicate = 1;
        while (joints.containsKey(name + duplicate))
            duplicate++;
        name += duplicate;
    }

    joints.put(name, joint);

    return joint;
}

From source file:com.laex.cg2d.render.util.ProtoBufTypeConversionUtil.java

License:Open Source License

/**
 * As friction joint def.//from w  w  w  .ja  va  2  s  .c  o  m
 *
 * @param bodyA the body a
 * @param bodyB the body b
 * @param _j the _j
 * @return the friction joint def
 */
public static FrictionJointDef asFrictionJointDef(Body bodyA, Body bodyB, CGJoint _j) {
    FrictionJointDef jdef = new FrictionJointDef();
    jdef.collideConnected = _j.getFrictionJointDef().getCollideConnected();
    jdef.maxForce = _j.getFrictionJointDef().getMaxForce();
    jdef.maxTorque = _j.getFrictionJointDef().getMaxTorque();
    jdef.initialize(bodyA, bodyB, bodyA.getWorldCenter());

    if (_j.getUseLocalAnchors()) {
        jdef.localAnchorA.set(Vector2Adapter.asVector2(_j.getLocalAnchorA()));
        jdef.localAnchorB.set(Vector2Adapter.asVector2(_j.getLocalAnchorB()));
    }

    return jdef;
}

From source file:com.rubentxu.juegos.core.utils.dermetfan.box2d.Box2DMapObjectParser.java

License:Apache License

/**
 * creates a {@link Joint} from a {@link MapObject}
 *
 * @param mapObject the {@link Joint} to parse
 * @return the parsed {@link Joint}//from  ww  w  . j a  v  a  2 s .co m
 */
public Joint createJoint(MapObject mapObject) {
    MapProperties properties = mapObject.getProperties();

    JointDef jointDef = null;

    String type = properties.get("type", String.class);
    if (!type.equals(aliases.joint))
        throw new IllegalArgumentException(
                "type of " + mapObject + " is  \"" + type + "\" instead of \"" + aliases.joint + "\"");

    String jointType = properties.get(aliases.jointType, String.class);

    // get all possible values
    if (jointType.equals(aliases.distanceJoint)) {
        DistanceJointDef distanceJointDef = new DistanceJointDef();
        distanceJointDef.dampingRatio = getProperty(properties, aliases.dampingRatio,
                distanceJointDef.dampingRatio);
        distanceJointDef.frequencyHz = getProperty(properties, aliases.frequencyHz,
                distanceJointDef.frequencyHz);
        distanceJointDef.length = getProperty(properties, aliases.length, distanceJointDef.length)
                * (tileWidth + tileHeight) / 2 * unitScale;
        distanceJointDef.localAnchorA.set(
                getProperty(properties, aliases.localAnchorAX, distanceJointDef.localAnchorA.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorAY, distanceJointDef.localAnchorA.y) * tileHeight
                        * unitScale);
        distanceJointDef.localAnchorB.set(
                getProperty(properties, aliases.localAnchorBX, distanceJointDef.localAnchorB.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorBY, distanceJointDef.localAnchorB.y) * tileHeight
                        * unitScale);

        jointDef = distanceJointDef;
    } else if (jointType.equals(aliases.frictionJoint)) {
        FrictionJointDef frictionJointDef = new FrictionJointDef();
        frictionJointDef.localAnchorA.set(
                getProperty(properties, aliases.localAnchorAX, frictionJointDef.localAnchorA.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorAY, frictionJointDef.localAnchorA.y) * tileHeight
                        * unitScale);
        frictionJointDef.localAnchorB.set(
                getProperty(properties, aliases.localAnchorBX, frictionJointDef.localAnchorB.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorBY, frictionJointDef.localAnchorB.y) * tileHeight
                        * unitScale);
        frictionJointDef.maxForce = getProperty(properties, aliases.maxForce, frictionJointDef.maxForce);
        frictionJointDef.maxTorque = getProperty(properties, aliases.maxTorque, frictionJointDef.maxTorque);

        jointDef = frictionJointDef;
    } else if (jointType.equals(aliases.gearJoint)) {
        GearJointDef gearJointDef = new GearJointDef();
        gearJointDef.joint1 = joints.get(properties.get(aliases.joint1, String.class));
        gearJointDef.joint2 = joints.get(properties.get(aliases.joint2, String.class));
        gearJointDef.ratio = getProperty(properties, aliases.ratio, gearJointDef.ratio);

        jointDef = gearJointDef;
    } else if (jointType.equals(aliases.mouseJoint)) {
        MouseJointDef mouseJointDef = new MouseJointDef();
        mouseJointDef.dampingRatio = getProperty(properties, aliases.dampingRatio, mouseJointDef.dampingRatio);
        mouseJointDef.frequencyHz = getProperty(properties, aliases.frequencyHz, mouseJointDef.frequencyHz);
        mouseJointDef.maxForce = getProperty(properties, aliases.maxForce, mouseJointDef.maxForce);
        mouseJointDef.target.set(
                getProperty(properties, aliases.targetX, mouseJointDef.target.x) * tileWidth * unitScale,
                getProperty(properties, aliases.targetY, mouseJointDef.target.y) * tileHeight * unitScale);

        jointDef = mouseJointDef;
    } else if (jointType.equals(aliases.prismaticJoint)) {
        PrismaticJointDef prismaticJointDef = new PrismaticJointDef();
        prismaticJointDef.enableLimit = getProperty(properties, aliases.enableLimit,
                prismaticJointDef.enableLimit);
        prismaticJointDef.enableMotor = getProperty(properties, aliases.enableMotor,
                prismaticJointDef.enableMotor);
        prismaticJointDef.localAnchorA.set(
                getProperty(properties, aliases.localAnchorAX, prismaticJointDef.localAnchorA.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorAY, prismaticJointDef.localAnchorA.y) * tileHeight
                        * unitScale);
        prismaticJointDef.localAnchorB.set(
                getProperty(properties, aliases.localAnchorBX, prismaticJointDef.localAnchorB.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorBY, prismaticJointDef.localAnchorB.y) * tileHeight
                        * unitScale);
        prismaticJointDef.localAxisA.set(
                getProperty(properties, aliases.localAxisAX, prismaticJointDef.localAxisA.x),
                getProperty(properties, aliases.localAxisAY, prismaticJointDef.localAxisA.y));
        prismaticJointDef.lowerTranslation = getProperty(properties, aliases.lowerTranslation,
                prismaticJointDef.lowerTranslation) * (tileWidth + tileHeight) / 2 * unitScale;
        prismaticJointDef.maxMotorForce = getProperty(properties, aliases.maxMotorForce,
                prismaticJointDef.maxMotorForce);
        prismaticJointDef.motorSpeed = getProperty(properties, aliases.motorSpeed,
                prismaticJointDef.motorSpeed);
        prismaticJointDef.referenceAngle = getProperty(properties, aliases.referenceAngle,
                prismaticJointDef.referenceAngle);
        prismaticJointDef.upperTranslation = getProperty(properties, aliases.upperTranslation,
                prismaticJointDef.upperTranslation) * (tileWidth + tileHeight) / 2 * unitScale;

        jointDef = prismaticJointDef;
    } else if (jointType.equals(aliases.pulleyJoint)) {
        PulleyJointDef pulleyJointDef = new PulleyJointDef();
        pulleyJointDef.groundAnchorA.set(
                getProperty(properties, aliases.groundAnchorAX, pulleyJointDef.groundAnchorA.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.groundAnchorAY, pulleyJointDef.groundAnchorA.y) * tileHeight
                        * unitScale);
        pulleyJointDef.groundAnchorB.set(
                getProperty(properties, aliases.groundAnchorBX, pulleyJointDef.groundAnchorB.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.groundAnchorBY, pulleyJointDef.groundAnchorB.y) * tileHeight
                        * unitScale);
        pulleyJointDef.lengthA = getProperty(properties, aliases.lengthA, pulleyJointDef.lengthA)
                * (tileWidth + tileHeight) / 2 * unitScale;
        pulleyJointDef.lengthB = getProperty(properties, aliases.lengthB, pulleyJointDef.lengthB)
                * (tileWidth + tileHeight) / 2 * unitScale;
        pulleyJointDef.localAnchorA.set(
                getProperty(properties, aliases.localAnchorAX, pulleyJointDef.localAnchorA.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorAY, pulleyJointDef.localAnchorA.y) * tileHeight
                        * unitScale);
        pulleyJointDef.localAnchorB.set(
                getProperty(properties, aliases.localAnchorBX, pulleyJointDef.localAnchorB.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorBY, pulleyJointDef.localAnchorB.y) * tileHeight
                        * unitScale);
        pulleyJointDef.ratio = getProperty(properties, aliases.ratio, pulleyJointDef.ratio);

        jointDef = pulleyJointDef;
    } else if (jointType.equals(aliases.revoluteJoint)) {
        RevoluteJointDef revoluteJointDef = new RevoluteJointDef();
        revoluteJointDef.enableLimit = getProperty(properties, aliases.enableLimit,
                revoluteJointDef.enableLimit);
        revoluteJointDef.enableMotor = getProperty(properties, aliases.enableMotor,
                revoluteJointDef.enableMotor);
        revoluteJointDef.localAnchorA.set(
                getProperty(properties, aliases.localAnchorAX, revoluteJointDef.localAnchorA.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorAY, revoluteJointDef.localAnchorA.y) * tileHeight
                        * unitScale);
        revoluteJointDef.localAnchorB.set(
                getProperty(properties, aliases.localAnchorBX, revoluteJointDef.localAnchorB.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorBY, revoluteJointDef.localAnchorB.y) * tileHeight
                        * unitScale);
        revoluteJointDef.lowerAngle = getProperty(properties, aliases.lowerAngle, revoluteJointDef.lowerAngle);
        revoluteJointDef.maxMotorTorque = getProperty(properties, aliases.maxMotorTorque,
                revoluteJointDef.maxMotorTorque);
        revoluteJointDef.motorSpeed = getProperty(properties, aliases.motorSpeed, revoluteJointDef.motorSpeed);
        revoluteJointDef.referenceAngle = getProperty(properties, aliases.referenceAngle,
                revoluteJointDef.referenceAngle);
        revoluteJointDef.upperAngle = getProperty(properties, aliases.upperAngle, revoluteJointDef.upperAngle);

        jointDef = revoluteJointDef;
    } else if (jointType.equals(aliases.ropeJoint)) {
        RopeJointDef ropeJointDef = new RopeJointDef();
        ropeJointDef.localAnchorA.set(
                getProperty(properties, aliases.localAnchorAX, ropeJointDef.localAnchorA.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorAY, ropeJointDef.localAnchorA.y) * tileHeight
                        * unitScale);
        ropeJointDef.localAnchorB.set(
                getProperty(properties, aliases.localAnchorBX, ropeJointDef.localAnchorB.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorBY, ropeJointDef.localAnchorB.y) * tileHeight
                        * unitScale);
        ropeJointDef.maxLength = getProperty(properties, aliases.maxLength, ropeJointDef.maxLength)
                * (tileWidth + tileHeight) / 2 * unitScale;

        jointDef = ropeJointDef;
    } else if (jointType.equals(aliases.weldJoint)) {
        WeldJointDef weldJointDef = new WeldJointDef();
        weldJointDef.localAnchorA.set(
                getProperty(properties, aliases.localAnchorAX, weldJointDef.localAnchorA.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorAY, weldJointDef.localAnchorA.y) * tileHeight
                        * unitScale);
        weldJointDef.localAnchorB.set(
                getProperty(properties, aliases.localAnchorBX, weldJointDef.localAnchorB.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorBY, weldJointDef.localAnchorB.y) * tileHeight
                        * unitScale);
        weldJointDef.referenceAngle = getProperty(properties, aliases.referenceAngle,
                weldJointDef.referenceAngle);

        jointDef = weldJointDef;
    } else if (jointType.equals(aliases.wheelJoint)) {
        WheelJointDef wheelJointDef = new WheelJointDef();
        wheelJointDef.dampingRatio = getProperty(properties, aliases.dampingRatio, wheelJointDef.dampingRatio);
        wheelJointDef.enableMotor = getProperty(properties, aliases.enableMotor, wheelJointDef.enableMotor);
        wheelJointDef.frequencyHz = getProperty(properties, aliases.frequencyHz, wheelJointDef.frequencyHz);
        wheelJointDef.localAnchorA.set(
                getProperty(properties, aliases.localAnchorAX, wheelJointDef.localAnchorA.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorAY, wheelJointDef.localAnchorA.y) * tileHeight
                        * unitScale);
        wheelJointDef.localAnchorB.set(
                getProperty(properties, aliases.localAnchorBX, wheelJointDef.localAnchorB.x) * tileWidth
                        * unitScale,
                getProperty(properties, aliases.localAnchorBY, wheelJointDef.localAnchorB.y) * tileHeight
                        * unitScale);
        wheelJointDef.localAxisA.set(getProperty(properties, aliases.localAxisAX, wheelJointDef.localAxisA.x),
                getProperty(properties, aliases.localAxisAY, wheelJointDef.localAxisA.y));
        wheelJointDef.maxMotorTorque = getProperty(properties, aliases.maxMotorTorque,
                wheelJointDef.maxMotorTorque);
        wheelJointDef.motorSpeed = getProperty(properties, aliases.motorSpeed, wheelJointDef.motorSpeed);

        jointDef = wheelJointDef;
    }

    jointDef.bodyA = bodies.get(properties.get(aliases.bodyA, String.class));
    jointDef.bodyB = bodies.get(properties.get(aliases.bodyB, String.class));
    jointDef.collideConnected = getProperty(properties, aliases.collideConnected, jointDef.collideConnected);

    Joint joint = jointDef.bodyA.getWorld().createJoint(jointDef);

    String name = mapObject.getName();
    if (joints.containsKey(name)) {
        int duplicate = 1;
        while (joints.containsKey(name + duplicate))
            duplicate++;
        name += duplicate;
    }

    joints.put(name, joint);

    return joint;
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java

License:Apache License

/** creates a {@link Joint} from a {@link MapObject}
 *  @param mapObject the {@link Joint} to parse
 *  @return the parsed {@link Joint} */
public Joint createJoint(MapObject mapObject) {
    if ((mapObject = listener.createJoint(mapObject)) == null)
        return null;

    MapProperties properties = mapObject.getProperties();

    JointDef jointDef;//  ww w  .  j a v  a 2s.co  m

    String jointType = getProperty(properties, aliases.jointType, "");
    if (jointType.equals(aliases.distanceJoint)) {
        DistanceJointDef distanceJointDef = new DistanceJointDef();
        assignProperties(distanceJointDef, heritage);
        assignProperties(distanceJointDef, mapProperties);
        assignProperties(distanceJointDef, layerProperties);
        assignProperties(distanceJointDef, properties);
        jointDef = distanceJointDef;
    } else if (jointType.equals(aliases.frictionJoint)) {
        FrictionJointDef frictionJointDef = new FrictionJointDef();
        assignProperties(frictionJointDef, heritage);
        assignProperties(frictionJointDef, mapProperties);
        assignProperties(frictionJointDef, layerProperties);
        assignProperties(frictionJointDef, properties);
        jointDef = frictionJointDef;
    } else if (jointType.equals(aliases.gearJoint)) {
        GearJointDef gearJointDef = new GearJointDef();
        assignProperties(gearJointDef, heritage);
        assignProperties(gearJointDef, mapProperties);
        assignProperties(gearJointDef, layerProperties);
        assignProperties(gearJointDef, properties);
        jointDef = gearJointDef;
    } else if (jointType.equals(aliases.mouseJoint)) {
        MouseJointDef mouseJointDef = new MouseJointDef();
        assignProperties(mouseJointDef, heritage);
        assignProperties(mouseJointDef, mapProperties);
        assignProperties(mouseJointDef, layerProperties);
        assignProperties(mouseJointDef, properties);
        jointDef = mouseJointDef;
    } else if (jointType.equals(aliases.prismaticJoint)) {
        PrismaticJointDef prismaticJointDef = new PrismaticJointDef();
        assignProperties(prismaticJointDef, heritage);
        assignProperties(prismaticJointDef, mapProperties);
        assignProperties(prismaticJointDef, layerProperties);
        assignProperties(prismaticJointDef, properties);
        jointDef = prismaticJointDef;
    } else if (jointType.equals(aliases.pulleyJoint)) {
        PulleyJointDef pulleyJointDef = new PulleyJointDef();
        assignProperties(pulleyJointDef, heritage);
        assignProperties(pulleyJointDef, mapProperties);
        assignProperties(pulleyJointDef, layerProperties);
        assignProperties(pulleyJointDef, properties);
        jointDef = pulleyJointDef;
    } else if (jointType.equals(aliases.revoluteJoint)) {
        RevoluteJointDef revoluteJointDef = new RevoluteJointDef();
        assignProperties(revoluteJointDef, heritage);
        assignProperties(revoluteJointDef, mapProperties);
        assignProperties(revoluteJointDef, layerProperties);
        assignProperties(revoluteJointDef, properties);
        jointDef = revoluteJointDef;
    } else if (jointType.equals(aliases.ropeJoint)) {
        RopeJointDef ropeJointDef = new RopeJointDef();
        assignProperties(ropeJointDef, heritage);
        assignProperties(ropeJointDef, mapProperties);
        assignProperties(ropeJointDef, layerProperties);
        assignProperties(ropeJointDef, properties);
        jointDef = ropeJointDef;
    } else if (jointType.equals(aliases.weldJoint)) {
        WeldJointDef weldJointDef = new WeldJointDef();
        assignProperties(weldJointDef, heritage);
        assignProperties(weldJointDef, mapProperties);
        assignProperties(weldJointDef, layerProperties);
        assignProperties(weldJointDef, properties);
        jointDef = weldJointDef;
    } else if (jointType.equals(aliases.wheelJoint)) {
        WheelJointDef wheelJointDef = new WheelJointDef();
        assignProperties(wheelJointDef, heritage);
        assignProperties(wheelJointDef, mapProperties);
        assignProperties(wheelJointDef, layerProperties);
        assignProperties(wheelJointDef, properties);
        jointDef = wheelJointDef;
    } else
        throw new IllegalArgumentException(
                ClassReflection.getSimpleName(JointType.class) + " " + jointType + " is unknown");

    assignProperties(jointDef, properties);

    Joint joint = jointDef.bodyA.getWorld().createJoint(jointDef);
    joint.setUserData(getProperty(properties, aliases.userData, joint.getUserData()));

    joints.put(findAvailableName(mapObject.getName(), joints), joint);
    listener.created(joint, mapObject);

    return joint;
}

From source file:de.fhkoeln.game.utils.Box2DMapObjectParser.java

License:Apache License

/** creates a {@link com.badlogic.gdx.physics.box2d.Joint} from a {@link com.badlogic.gdx.maps.MapObject}
 *  @param mapObject the {@link com.badlogic.gdx.physics.box2d.Joint} to parse
 *  @return the parsed {@link com.badlogic.gdx.physics.box2d.Joint} */
public Joint createJoint(MapObject mapObject) {
    if ((mapObject = listener.createJoint(mapObject)) == null)
        return null;

    MapProperties properties = mapObject.getProperties();

    JointDef jointDef;// w w  w  .  j  a v  a  2  s  .c  om

    String jointType = getProperty(properties, aliases.jointType, "");
    if (jointType.equals(aliases.distanceJoint)) {
        DistanceJointDef distanceJointDef = new DistanceJointDef();
        assignProperties(distanceJointDef, heritage);
        assignProperties(distanceJointDef, mapProperties);
        assignProperties(distanceJointDef, layerProperties);
        assignProperties(distanceJointDef, properties);
        jointDef = distanceJointDef;
    } else if (jointType.equals(aliases.frictionJoint)) {
        FrictionJointDef frictionJointDef = new FrictionJointDef();
        assignProperties(frictionJointDef, heritage);
        assignProperties(frictionJointDef, mapProperties);
        assignProperties(frictionJointDef, layerProperties);
        assignProperties(frictionJointDef, properties);
        jointDef = frictionJointDef;
    } else if (jointType.equals(aliases.gearJoint)) {
        GearJointDef gearJointDef = new GearJointDef();
        assignProperties(gearJointDef, heritage);
        assignProperties(gearJointDef, mapProperties);
        assignProperties(gearJointDef, layerProperties);
        assignProperties(gearJointDef, properties);
        jointDef = gearJointDef;
    } else if (jointType.equals(aliases.mouseJoint)) {
        MouseJointDef mouseJointDef = new MouseJointDef();
        assignProperties(mouseJointDef, heritage);
        assignProperties(mouseJointDef, mapProperties);
        assignProperties(mouseJointDef, layerProperties);
        assignProperties(mouseJointDef, properties);
        jointDef = mouseJointDef;
    } else if (jointType.equals(aliases.prismaticJoint)) {
        PrismaticJointDef prismaticJointDef = new PrismaticJointDef();
        assignProperties(prismaticJointDef, heritage);
        assignProperties(prismaticJointDef, mapProperties);
        assignProperties(prismaticJointDef, layerProperties);
        assignProperties(prismaticJointDef, properties);
        jointDef = prismaticJointDef;
    } else if (jointType.equals(aliases.pulleyJoint)) {
        PulleyJointDef pulleyJointDef = new PulleyJointDef();
        assignProperties(pulleyJointDef, heritage);
        assignProperties(pulleyJointDef, mapProperties);
        assignProperties(pulleyJointDef, layerProperties);
        assignProperties(pulleyJointDef, properties);
        jointDef = pulleyJointDef;
    } else if (jointType.equals(aliases.revoluteJoint)) {
        RevoluteJointDef revoluteJointDef = new RevoluteJointDef();
        assignProperties(revoluteJointDef, heritage);
        assignProperties(revoluteJointDef, mapProperties);
        assignProperties(revoluteJointDef, layerProperties);
        assignProperties(revoluteJointDef, properties);
        jointDef = revoluteJointDef;
    } else if (jointType.equals(aliases.ropeJoint)) {
        RopeJointDef ropeJointDef = new RopeJointDef();
        assignProperties(ropeJointDef, heritage);
        assignProperties(ropeJointDef, mapProperties);
        assignProperties(ropeJointDef, layerProperties);
        assignProperties(ropeJointDef, properties);
        jointDef = ropeJointDef;
    } else if (jointType.equals(aliases.weldJoint)) {
        WeldJointDef weldJointDef = new WeldJointDef();
        assignProperties(weldJointDef, heritage);
        assignProperties(weldJointDef, mapProperties);
        assignProperties(weldJointDef, layerProperties);
        assignProperties(weldJointDef, properties);
        jointDef = weldJointDef;
    } else if (jointType.equals(aliases.wheelJoint)) {
        WheelJointDef wheelJointDef = new WheelJointDef();
        assignProperties(wheelJointDef, heritage);
        assignProperties(wheelJointDef, mapProperties);
        assignProperties(wheelJointDef, layerProperties);
        assignProperties(wheelJointDef, properties);
        jointDef = wheelJointDef;
    } else
        throw new IllegalArgumentException(JointType.class.getSimpleName() + " " + jointType + " is unknown");

    assignProperties(jointDef, properties);

    Joint joint = jointDef.bodyA.getWorld().createJoint(jointDef);
    joint.setUserData(getProperty(properties, aliases.userData, joint.getUserData()));

    joints.put(findAvailableName(mapObject.getName(), joints), joint);
    listener.created(joint, mapObject);

    return joint;
}

From source file:net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java

License:Apache License

/** creates a {@link Joint} from a {@link MapObject}
 *  @param mapObject the {@link Joint} to parse
 *  @return the parsed {@link Joint} */
public Joint createJoint(MapObject mapObject) {
    MapProperties properties = mapObject.getProperties();

    JointDef jointDef = null;//from  w  w w  .j  av  a 2  s.  com

    String jointType = getProperty(properties, aliases.jointType, "");
    if (jointType.equals(aliases.distanceJoint)) {
        DistanceJointDef distanceJointDef = new DistanceJointDef();
        assignProperties(distanceJointDef, heritage);
        assignProperties(distanceJointDef, mapProperties);
        assignProperties(distanceJointDef, layerProperties);
        assignProperties(distanceJointDef, properties);
        jointDef = distanceJointDef;
    } else if (jointType.equals(aliases.frictionJoint)) {
        FrictionJointDef frictionJointDef = new FrictionJointDef();
        assignProperties(frictionJointDef, heritage);
        assignProperties(frictionJointDef, mapProperties);
        assignProperties(frictionJointDef, layerProperties);
        assignProperties(frictionJointDef, properties);
        jointDef = frictionJointDef;
    } else if (jointType.equals(aliases.gearJoint)) {
        GearJointDef gearJointDef = new GearJointDef();
        assignProperties(gearJointDef, heritage);
        assignProperties(gearJointDef, mapProperties);
        assignProperties(gearJointDef, layerProperties);
        assignProperties(gearJointDef, properties);
        jointDef = gearJointDef;
    } else if (jointType.equals(aliases.mouseJoint)) {
        MouseJointDef mouseJointDef = new MouseJointDef();
        assignProperties(mouseJointDef, heritage);
        assignProperties(mouseJointDef, mapProperties);
        assignProperties(mouseJointDef, layerProperties);
        assignProperties(mouseJointDef, properties);
        jointDef = mouseJointDef;
    } else if (jointType.equals(aliases.prismaticJoint)) {
        PrismaticJointDef prismaticJointDef = new PrismaticJointDef();
        assignProperties(prismaticJointDef, heritage);
        assignProperties(prismaticJointDef, mapProperties);
        assignProperties(prismaticJointDef, layerProperties);
        assignProperties(prismaticJointDef, properties);
        jointDef = prismaticJointDef;
    } else if (jointType.equals(aliases.pulleyJoint)) {
        PulleyJointDef pulleyJointDef = new PulleyJointDef();
        assignProperties(pulleyJointDef, heritage);
        assignProperties(pulleyJointDef, mapProperties);
        assignProperties(pulleyJointDef, layerProperties);
        assignProperties(pulleyJointDef, properties);
        jointDef = pulleyJointDef;
    } else if (jointType.equals(aliases.revoluteJoint)) {
        RevoluteJointDef revoluteJointDef = new RevoluteJointDef();
        assignProperties(revoluteJointDef, heritage);
        assignProperties(revoluteJointDef, mapProperties);
        assignProperties(revoluteJointDef, layerProperties);
        assignProperties(revoluteJointDef, properties);
        jointDef = revoluteJointDef;
    } else if (jointType.equals(aliases.ropeJoint)) {
        RopeJointDef ropeJointDef = new RopeJointDef();
        assignProperties(ropeJointDef, heritage);
        assignProperties(ropeJointDef, mapProperties);
        assignProperties(ropeJointDef, layerProperties);
        assignProperties(ropeJointDef, properties);
        jointDef = ropeJointDef;
    } else if (jointType.equals(aliases.weldJoint)) {
        WeldJointDef weldJointDef = new WeldJointDef();
        assignProperties(weldJointDef, heritage);
        assignProperties(weldJointDef, mapProperties);
        assignProperties(weldJointDef, layerProperties);
        assignProperties(weldJointDef, properties);
        jointDef = weldJointDef;
    } else if (jointType.equals(aliases.wheelJoint)) {
        WheelJointDef wheelJointDef = new WheelJointDef();
        assignProperties(wheelJointDef, heritage);
        assignProperties(wheelJointDef, mapProperties);
        assignProperties(wheelJointDef, layerProperties);
        assignProperties(wheelJointDef, properties);
        jointDef = wheelJointDef;
    }

    jointDef.bodyA = bodies.get(getProperty(properties, aliases.bodyA, ""));
    jointDef.bodyB = bodies.get(getProperty(properties, aliases.bodyB, ""));
    jointDef.collideConnected = getProperty(properties, aliases.collideConnected, jointDef.collideConnected);

    Joint joint = jointDef.bodyA.getWorld().createJoint(jointDef);
    joint.setUserData(getProperty(properties, aliases.userData, joint.getUserData()));

    joints.put(findAvailableName(mapObject.getName(), joints), joint);

    return joint;
}

From source file:zzz.box2dtest.ApplyForce.java

License:Apache License

@Override
protected void createWorld(World world) {
    world.setGravity(new Vector2(0, 0));
    Gdx.input.setInputProcessor(this);

    float k_restitution = 0.4f;
    Body ground;//from  w w  w .ja v a2 s.c  o m

    {
        BodyDef bd = new BodyDef();
        bd.position.set(0, 20);
        ground = world.createBody(bd);

        EdgeShape shape = new EdgeShape();

        FixtureDef sd = new FixtureDef();
        sd.shape = shape;
        sd.density = 0;
        sd.restitution = k_restitution;

        shape.set(new Vector2(-20, -20), new Vector2(-20, 20));
        ground.createFixture(sd);

        shape.set(new Vector2(20, -20), new Vector2(20, 20));
        ground.createFixture(sd);

        shape.set(new Vector2(-20, 20), new Vector2(20, 20));
        ground.createFixture(sd);

        shape.set(new Vector2(-20, -20), new Vector2(20, -20));
        ground.createFixture(sd);

        shape.dispose();
    }

    {
        Transform xf1 = new Transform(new Vector2(), 0.3524f * (float) Math.PI);
        xf1.setPosition(xf1.mul(new Vector2(1, 0)));

        Vector2[] vertices = new Vector2[3];
        vertices[0] = xf1.mul(new Vector2(-1, 0));
        vertices[1] = xf1.mul(new Vector2(1, 0));
        vertices[2] = xf1.mul(new Vector2(0, 0.5f));

        PolygonShape poly1 = new PolygonShape();
        poly1.set(vertices);

        FixtureDef sd1 = new FixtureDef();
        sd1.shape = poly1;
        sd1.density = 4.0f;

        Transform xf2 = new Transform(new Vector2(), -0.3524f * (float) Math.PI);
        xf2.setPosition(xf2.mul(new Vector2(-1, 0)));

        vertices[0] = xf2.mul(new Vector2(-1, 0));
        vertices[1] = xf2.mul(new Vector2(1, 0));
        vertices[2] = xf2.mul(new Vector2(0, 0.5f));

        PolygonShape poly2 = new PolygonShape();
        poly2.set(vertices);

        FixtureDef sd2 = new FixtureDef();
        sd2.shape = poly2;
        sd2.density = 2.0f;

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.angularDamping = 5.0f;
        bd.linearDamping = 0.1f;

        bd.position.set(0, 2);
        bd.angle = (float) Math.PI;
        bd.allowSleep = false;
        m_body = world.createBody(bd);
        m_body.createFixture(sd1);
        m_body.createFixture(sd2);
        poly1.dispose();
        poly2.dispose();
    }

    {
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(0.5f, 0.5f);

        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.density = 1.0f;
        fd.friction = 0.3f;

        for (int i = 0; i < 10; i++) {
            BodyDef bd = new BodyDef();
            bd.type = BodyType.DynamicBody;

            bd.position.set(0, 5 + 1.54f * i);
            Body body = world.createBody(bd);

            body.createFixture(fd);

            float gravity = 10.0f;
            float I = body.getInertia();
            float mass = body.getMass();

            float radius = (float) Math.sqrt(2 * I / mass);

            FrictionJointDef jd = new FrictionJointDef();
            jd.localAnchorA.set(0, 0);
            jd.localAnchorB.set(0, 0);
            jd.bodyA = ground;
            jd.bodyB = body;
            jd.collideConnected = true;
            jd.maxForce = mass * gravity;
            jd.maxTorque = mass * radius * gravity;

            world.createJoint(jd);
        }

        shape.dispose();
    }
}