@Override public void createBodies(World world) { this.anchorBody = Box2DFactory.createCircle(world, this.cx, this.cy, 0.05f, true); // Joint angle is 0 when flipper is horizontal. // The flipper needs to be slightly extended past anchorBody to rotate correctly. float ext = (this.flipperLength > 0) ? -0.05f : +0.05f; // Width larger than 0.12 slows rotation? this.flipperBody = Box2DFactory.createWall(world, cx+ext, cy-0.12f, cx+flipperLength, cy+0.12f, 0f); flipperBody.setType(BodyDef.BodyType.DynamicBody); flipperBody.setBullet(true); flipperBody.getFixtureList().get(0).setDensity(5.0f); jointDef = new RevoluteJointDef(); jointDef.initialize(anchorBody, flipperBody, new Vector2(this.cx, this.cy)); jointDef.enableLimit = true; jointDef.enableMotor = true; // counterclockwise rotations are positive, so flip angles for flippers extending left jointDef.lowerAngle = (this.flipperLength>0) ? this.minangle : -this.maxangle; jointDef.upperAngle = (this.flipperLength>0) ? this.maxangle : -this.minangle; jointDef.maxMotorTorque = 1000f; this.joint = (RevoluteJoint)world.createJoint(jointDef); flipperBodySet = Collections.singletonList(flipperBody); this.setEffectiveMotorSpeed(-this.downspeed); // Force flipper to bottom when field is first created. }
/** * create Revolute Joint */ public RevoluteJoint createRevoluteJoint(Body bodyA, Body bodyB, Vector2 jointPositionA, Vector2 jointPositionB, boolean enabledMotor, int maxMotorTorque, int motorSpeed) { RevoluteJointDef rJoint = new RevoluteJointDef(); rJoint.bodyA = bodyA; rJoint.bodyB = bodyB; rJoint.localAnchorA.set(jointPositionA.x * WORLD_TO_BOX, jointPositionA.y * WORLD_TO_BOX); rJoint.localAnchorB.set(jointPositionB.x * WORLD_TO_BOX, jointPositionB.y * WORLD_TO_BOX); rJoint.enableMotor = enabledMotor; rJoint.maxMotorTorque = maxMotorTorque; rJoint.motorSpeed = motorSpeed; RevoluteJoint joint = (RevoluteJoint) world.createJoint(rJoint); return joint; }
public RevoluteJoint createRevoluteJoint(Body bodyA, Body bodyB, Vector2 jointPositionA, Vector2 jointPositionB) { RevoluteJointDef rJoint = new RevoluteJointDef(); rJoint.bodyA = bodyA; rJoint.bodyB = bodyB; rJoint.localAnchorA.set(jointPositionA.x * WORLD_TO_BOX, jointPositionA.y * WORLD_TO_BOX); rJoint.localAnchorB.set(jointPositionB.x * WORLD_TO_BOX, jointPositionB.y * WORLD_TO_BOX); RevoluteJoint joint = (RevoluteJoint) world.createJoint(rJoint); return joint; }
@Override public void finishCreate (Map params, World world) { List pos = (List)params.get("position"); this.cx = asFloat(pos.get(0)); this.cy = asFloat(pos.get(1)); this.flipperLength = asFloat(params.get("length")); this.minangle = toRadians(asFloat(params.get("minangle"))); this.maxangle = toRadians(asFloat(params.get("maxangle"))); this.upspeed = asFloat(params.get("upspeed")); this.downspeed = asFloat(params.get("downspeed")); this.anchorBody = Box2DFactory.createCircle(world, this.cx, this.cy, 0.05f, true); // joint angle is 0 when flipper is horizontal // flipper needs to be slightly extended past anchorBody to rotate correctly float ext = (this.flipperLength > 0) ? -0.05f : +0.05f; // width larger than 0.12 slows rotation? this.flipperBody = Box2DFactory.createWall(world, cx + ext, cy - 0.12f, cx + flipperLength, cy + 0.12f, 0f); flipperBody.setType(BodyDef.BodyType.DynamicBody); flipperBody.setBullet(true); flipperBody.getFixtureList().get(0).setDensity(5.0f); jointDef = new RevoluteJointDef(); jointDef.initialize(anchorBody, flipperBody, new Vector2(this.cx, this.cy)); jointDef.enableLimit = true; jointDef.enableMotor = true; // counterclockwise rotations are positive, so flip angles for flippers extending left jointDef.lowerAngle = (this.flipperLength > 0) ? this.minangle : -this.maxangle; jointDef.upperAngle = (this.flipperLength > 0) ? this.maxangle : -this.minangle; jointDef.maxMotorTorque = 1000f; this.joint = (RevoluteJoint)world.createJoint(jointDef); flipperBodySet = Collections.singleton(flipperBody); this.setEffectiveMotorSpeed(-this.downspeed); // force flipper to bottom when field is first created }
@Override public void finishCreate (Map params, World world) { List pos = (List)params.get("position"); this.cx = asFloat(pos.get(0)); this.cy = asFloat(pos.get(1)); this.flipperLength = asFloat(params.get("length")); this.minangle = toRadians(asFloat(params.get("minangle"))); this.maxangle = toRadians(asFloat(params.get("maxangle"))); this.upspeed = asFloat(params.get("upspeed")); this.downspeed = asFloat(params.get("downspeed")); this.anchorBody = Box2DFactory.createCircle(world, this.cx, this.cy, 0.05f, true, 1); // joint angle is 0 when flipper is horizontal // flipper needs to be slightly extended past anchorBody to rotate correctly float ext = (this.flipperLength > 0) ? -0.05f : +0.05f; // width larger than 0.12 slows rotation? this.flipperBody = Box2DFactory.createWall(world, cx + ext, cy - 0.12f, cx + flipperLength, cy + 0.12f, 0f); flipperBody.setType(BodyDef.BodyType.DynamicBody); flipperBody.setBullet(true); flipperBody.getFixtureList().get(0).setDensity(5.0f); jointDef = new RevoluteJointDef(); jointDef.initialize(anchorBody, flipperBody, new Vector2(this.cx, this.cy)); jointDef.enableLimit = true; jointDef.enableMotor = true; // counterclockwise rotations are positive, so flip angles for flippers extending left jointDef.lowerAngle = (this.flipperLength > 0) ? this.minangle : -this.maxangle; jointDef.upperAngle = (this.flipperLength > 0) ? this.maxangle : -this.minangle; jointDef.maxMotorTorque = 1000f; this.joint = (RevoluteJoint)world.createJoint(jointDef); flipperBodySet = Collections.singleton(flipperBody); this.setEffectiveMotorSpeed(-this.downspeed); // force flipper to bottom when field is first created }
public RevoluteJoint getJoint() { return joint; }
public RevoluteJoint getJoint () { return joint; }
@Override public RevoluteJoint getJoint(){return (RevoluteJoint)joint;}
private void enableMotor(Mill mill) { ((RevoluteJoint) mill.getJoint()).enableMotor(true); }
private void disableMotor(Mill mill) { ((RevoluteJoint) mill.getJoint()).enableMotor(false); }
private long createProperJoint(JointDef paramJointDef) { if (paramJointDef.type == JointDef.JointType.DistanceJoint) { DistanceJointDef localDistanceJointDef = (DistanceJointDef)paramJointDef; return jniCreateDistanceJoint(this.addr, localDistanceJointDef.bodyA.addr, localDistanceJointDef.bodyB.addr, localDistanceJointDef.collideConnected, localDistanceJointDef.localAnchorA.x, localDistanceJointDef.localAnchorA.y, localDistanceJointDef.localAnchorB.x, localDistanceJointDef.localAnchorB.y, localDistanceJointDef.length, localDistanceJointDef.frequencyHz, localDistanceJointDef.dampingRatio); } if (paramJointDef.type == JointDef.JointType.FrictionJoint) { FrictionJointDef localFrictionJointDef = (FrictionJointDef)paramJointDef; return jniCreateFrictionJoint(this.addr, localFrictionJointDef.bodyA.addr, localFrictionJointDef.bodyB.addr, localFrictionJointDef.collideConnected, localFrictionJointDef.localAnchorA.x, localFrictionJointDef.localAnchorA.y, localFrictionJointDef.localAnchorB.x, localFrictionJointDef.localAnchorB.y, localFrictionJointDef.maxForce, localFrictionJointDef.maxTorque); } if (paramJointDef.type == JointDef.JointType.GearJoint) { GearJointDef localGearJointDef = (GearJointDef)paramJointDef; return jniCreateGearJoint(this.addr, localGearJointDef.bodyA.addr, localGearJointDef.bodyB.addr, localGearJointDef.collideConnected, localGearJointDef.joint1.addr, localGearJointDef.joint2.addr, localGearJointDef.ratio); } if (paramJointDef.type == JointDef.JointType.MouseJoint) { MouseJointDef localMouseJointDef = (MouseJointDef)paramJointDef; return jniCreateMouseJoint(this.addr, localMouseJointDef.bodyA.addr, localMouseJointDef.bodyB.addr, localMouseJointDef.collideConnected, localMouseJointDef.target.x, localMouseJointDef.target.y, localMouseJointDef.maxForce, localMouseJointDef.frequencyHz, localMouseJointDef.dampingRatio); } if (paramJointDef.type == JointDef.JointType.PrismaticJoint) { PrismaticJointDef localPrismaticJointDef = (PrismaticJointDef)paramJointDef; return jniCreatePrismaticJoint(this.addr, localPrismaticJointDef.bodyA.addr, localPrismaticJointDef.bodyB.addr, localPrismaticJointDef.collideConnected, localPrismaticJointDef.localAnchorA.x, localPrismaticJointDef.localAnchorA.y, localPrismaticJointDef.localAnchorB.x, localPrismaticJointDef.localAnchorB.y, localPrismaticJointDef.localAxisA.x, localPrismaticJointDef.localAxisA.y, localPrismaticJointDef.referenceAngle, localPrismaticJointDef.enableLimit, localPrismaticJointDef.lowerTranslation, localPrismaticJointDef.upperTranslation, localPrismaticJointDef.enableMotor, localPrismaticJointDef.maxMotorForce, localPrismaticJointDef.motorSpeed); } if (paramJointDef.type == JointDef.JointType.PulleyJoint) { PulleyJointDef localPulleyJointDef = (PulleyJointDef)paramJointDef; return jniCreatePulleyJoint(this.addr, localPulleyJointDef.bodyA.addr, localPulleyJointDef.bodyB.addr, localPulleyJointDef.collideConnected, localPulleyJointDef.groundAnchorA.x, localPulleyJointDef.groundAnchorA.y, localPulleyJointDef.groundAnchorB.x, localPulleyJointDef.groundAnchorB.y, localPulleyJointDef.localAnchorA.x, localPulleyJointDef.localAnchorA.y, localPulleyJointDef.localAnchorB.x, localPulleyJointDef.localAnchorB.y, localPulleyJointDef.lengthA, localPulleyJointDef.lengthB, localPulleyJointDef.ratio); } if (paramJointDef.type == JointDef.JointType.RevoluteJoint) { RevoluteJointDef localRevoluteJointDef = (RevoluteJointDef)paramJointDef; return jniCreateRevoluteJoint(this.addr, localRevoluteJointDef.bodyA.addr, localRevoluteJointDef.bodyB.addr, localRevoluteJointDef.collideConnected, localRevoluteJointDef.localAnchorA.x, localRevoluteJointDef.localAnchorA.y, localRevoluteJointDef.localAnchorB.x, localRevoluteJointDef.localAnchorB.y, localRevoluteJointDef.referenceAngle, localRevoluteJointDef.enableLimit, localRevoluteJointDef.lowerAngle, localRevoluteJointDef.upperAngle, localRevoluteJointDef.enableMotor, localRevoluteJointDef.motorSpeed, localRevoluteJointDef.maxMotorTorque); } if (paramJointDef.type == JointDef.JointType.WeldJoint) { WeldJointDef localWeldJointDef = (WeldJointDef)paramJointDef; return jniCreateWeldJoint(this.addr, localWeldJointDef.bodyA.addr, localWeldJointDef.bodyB.addr, localWeldJointDef.collideConnected, localWeldJointDef.localAnchorA.x, localWeldJointDef.localAnchorA.y, localWeldJointDef.localAnchorB.x, localWeldJointDef.localAnchorB.y, localWeldJointDef.referenceAngle); } if (paramJointDef.type == JointDef.JointType.RopeJoint) { RopeJointDef localRopeJointDef = (RopeJointDef)paramJointDef; return jniCreateRopeJoint(this.addr, localRopeJointDef.bodyA.addr, localRopeJointDef.bodyB.addr, localRopeJointDef.collideConnected, localRopeJointDef.localAnchorA.x, localRopeJointDef.localAnchorA.y, localRopeJointDef.localAnchorB.x, localRopeJointDef.localAnchorB.y, localRopeJointDef.maxLength); } if (paramJointDef.type == JointDef.JointType.WheelJoint) { WheelJointDef localWheelJointDef = (WheelJointDef)paramJointDef; return jniCreateWheelJoint(this.addr, localWheelJointDef.bodyA.addr, localWheelJointDef.bodyB.addr, localWheelJointDef.collideConnected, localWheelJointDef.localAnchorA.x, localWheelJointDef.localAnchorA.y, localWheelJointDef.localAnchorB.x, localWheelJointDef.localAnchorB.y, localWheelJointDef.localAxisA.x, localWheelJointDef.localAxisA.y, localWheelJointDef.enableMotor, localWheelJointDef.maxMotorTorque, localWheelJointDef.motorSpeed, localWheelJointDef.frequencyHz, localWheelJointDef.dampingRatio); } return 0L; }