List of usage examples for com.badlogic.gdx.physics.box2d.joints DistanceJointDef DistanceJointDef
public DistanceJointDef()
From source file:com.badlogic.gdx.tests.box2d.PhysicalCell.java
private void join(Body b1, Body b2, float length) { DistanceJointDef jd = new DistanceJointDef(); jd.localAnchorA.set(0, 0);/*from w w w . j a v a 2s . c o m*/ jd.localAnchorB.set(0, 0); jd.bodyA = b1; jd.bodyB = b2; jd.collideConnected = true; //jd.maxLength = 10 + 2 * i; jd.length = length; //jd.maxForce = mass * gravity; //jd.maxTorque = mass * radius * gravity; jd.dampingRatio = 0f; jd.frequencyHz = 6; world.createJoint(jd); }
From source file:com.badlogic.gdx.tests.box2d.PhysicalCell.java
void merge(PhysicalCell peer, int dir) { DistanceJointDef jd = new DistanceJointDef(); jd.length = 0.95f * (physicalSize.x / 3); jd.collideConnected = false;//from w ww. ja va 2 s. c o m //jd.dampingRatio = 0.5f; //jd.frequencyHz = 6; jd.localAnchorA.set(0, 0); jd.localAnchorB.set(0, 0); if (dir == 1) { // right TODO: fix it jd.bodyA = this.bodies[2][0]; jd.bodyB = peer.bodies[0][0]; world.createJoint(jd); jd.bodyA = this.bodies[2][1]; jd.bodyB = peer.bodies[0][1]; world.createJoint(jd); jd.bodyA = this.bodies[2][2]; jd.bodyB = peer.bodies[0][2]; world.createJoint(jd); } }
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 w w .j a va 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 = (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 distance joint def.//from w w w. j a v a 2s . c om * * @param bodyA the body a * @param bodyB the body b * @param _j the _j * @return the distance joint def */ public static DistanceJointDef asDistanceJointDef(Body bodyA, Body bodyB, CGJoint _j) { DistanceJointDef jdef = new DistanceJointDef(); jdef.collideConnected = _j.getDistanceJointDef().getCollideConnected(); jdef.dampingRatio = _j.getDistanceJointDef().getDampingRatio(); jdef.frequencyHz = _j.getDistanceJointDef().getFreqencyHz(); jdef.initialize(bodyA, bodyB, bodyA.getWorldCenter(), bodyB.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 w w w . ja v a 2 s.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 = 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 w w .j a va 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; } 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;/*from w w w.j a v a 2s.c o 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(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:edu.lehigh.cse.lol.Actor.java
License:Open Source License
/** * Create a distance joint between this actor and some other actor * * @param anchor The actor to which this actor is connected * @param anchorX The X coordinate (relative to the center of the actor) where * the joint fuses to the anchor * @param anchorY The Y coordinate (relative to the center of the actor) where * the joint fuses to the anchor * @param localAnchorX The X coordinate (relative to the center of the actor) where * the joint fuses to this actor * @param localAnchorY The Y coordinate (relative to the center of the actor) where * the joint fuses to this actor *//* w ww .j a v a 2 s . c om*/ public void setDistanceJoint(Actor anchor, float anchorX, float anchorY, float localAnchorX, float localAnchorY) { // make the body dynamic setCanFall(); // set up a joint so the head can't move too far mDistJointDef = new DistanceJointDef(); mDistJointDef.bodyA = anchor.mBody; mDistJointDef.bodyB = mBody; mDistJointDef.localAnchorA.set(anchorX, anchorY); mDistJointDef.localAnchorB.set(localAnchorX, localAnchorY); mDistJointDef.collideConnected = false; mDistJointDef.dampingRatio = 0.1f; mDistJointDef.frequencyHz = 2; mDistJoint = Lol.sGame.mCurrentLevel.mWorld.createJoint(mDistJointDef); }
From source file:edu.lehigh.cse.lol.Physics.java
License:Open Source License
/** * When a hero collides with a "sticky" obstacle, this is the code we run to * figure out what to do//from www . j a va 2s . com * * @param sticky The sticky actor... it should always be an obstacle for now * @param other The other actor... it should always be a hero for now * @param contact A description of the contact event */ static void handleSticky(final Actor sticky, final Actor other, Contact contact) { // don't create a joint if we've already got one if (other.mDJoint != null) return; // don't create a joint if we're supposed to wait if (System.currentTimeMillis() < other.mStickyDelay) return; // handle sticky obstacles... only do something if we're hitting the // obstacle from the correct direction if ((sticky.mIsSticky[0] && other.getYPosition() >= sticky.getYPosition() + sticky.mSize.y) || (sticky.mIsSticky[1] && other.getXPosition() + other.mSize.x <= sticky.getXPosition()) || (sticky.mIsSticky[3] && other.getXPosition() >= sticky.getXPosition() + sticky.mSize.x) || (sticky.mIsSticky[2] && other.getYPosition() + other.mSize.y <= sticky.getYPosition())) { // create distance and weld joints... somehow, the combination is // needed to get this to work. Note that this function runs during // the box2d step, so we need to make the joint in a callback that // runs later final Vector2 v = contact.getWorldManifold().getPoints()[0]; Lol.sGame.mCurrentLevel.mOneTimeEvents.add(new LolAction() { @Override public void go() { other.mBody.setLinearVelocity(0, 0); DistanceJointDef d = new DistanceJointDef(); d.initialize(sticky.mBody, other.mBody, v, v); d.collideConnected = true; other.mDJoint = (DistanceJoint) Lol.sGame.mCurrentLevel.mWorld.createJoint(d); WeldJointDef w = new WeldJointDef(); w.initialize(sticky.mBody, other.mBody, v); w.collideConnected = true; other.mWJoint = (WeldJoint) Lol.sGame.mCurrentLevel.mWorld.createJoint(w); } }); } }
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;// w w w .ja va2 s . c o 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; } 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; }