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

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

Introduction

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

Prototype

public WheelJointDef() 

Source Link

Usage

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   ww  w .  jav  a  2s  . c  o 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 = (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.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 w w w . jav a2s . 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;//from   w  ww  .  j  av  a2  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;
    } 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.cwclan.gdxtest.core.entities.Car.java

public Car(World world, FixtureDef chassisFixtureDef, FixtureDef wheelFixtureDef, float x, float y, float width,
        float height) {
    this.world = world;
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(x, y);//from ww w . ja  v  a 2s . c o m

    //chassis
    PolygonShape chassisShape = new PolygonShape();
    chassisShape.set(new float[] { -width / 2, -height / 2, width / 2, -height / 2, width / 2 * .4f, height / 2,
            -width / 2 * .8f, height / 2 * .8f });
    chassisFixtureDef.shape = chassisShape;
    chassis = world.createBody(bodyDef);
    chassis.createFixture(chassisFixtureDef);

    CircleShape wheelShape = new CircleShape();
    wheelShape.setRadius(height / 3.5f);
    wheelFixtureDef.shape = wheelShape;

    //left wheel
    leftWheel = world.createBody(bodyDef);
    leftWheel.createFixture(wheelFixtureDef);

    //right wheel
    rightWheel = world.createBody(bodyDef);
    rightWheel.createFixture(wheelFixtureDef);

    //left axis
    WheelJointDef axisDef = new WheelJointDef();
    axisDef.bodyA = chassis;
    axisDef.bodyB = leftWheel;
    axisDef.localAnchorA.set(-width / 2 * .75f + wheelShape.getRadius(), -height / 2 * 1.25f);
    axisDef.frequencyHz = chassisFixtureDef.density;
    axisDef.localAxisA.set(Vector2.Y);
    axisDef.maxMotorTorque = chassisFixtureDef.density * 10;

    leftAxis = (WheelJoint) world.createJoint(axisDef);

    //right axis
    axisDef.bodyB = rightWheel;
    axisDef.localAnchorA.x *= -1;

    rightAxis = (WheelJoint) world.createJoint(axisDef);
}

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;/*from w  w w  .j  a  v a2 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   www  .j  a v  a 2s  .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;
    }

    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;
}