Package org.jbox2d.dynamics.joints

Examples of org.jbox2d.dynamics.joints.WeldJointDef


      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 20.0f;

      WeldJointDef jd = new WeldJointDef();

      Body prevBody = ground;
      for (int i = 0; i < e_count; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(-14.5f + 1.0f * i, 5.0f);
        Body body = getWorld().createBody(bd);
        body.createFixture(fd);

        Vec2 anchor = new Vec2(-15.0f + 1.0f * i, 5.0f);
        jd.initialize(prevBody, body, anchor);
        getWorld().createJoint(jd);

        prevBody = body;
      }
    }

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

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 20.0f;

      WeldJointDef jd = new WeldJointDef();
      jd.frequencyHz = 5f;
      jd.dampingRatio = .7f;

      Body prevBody = ground;
      for (int i = 0; i < 3; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(-14.0f + 2.0f * i, 15.0f);
        Body body = getWorld().createBody(bd);
        body.createFixture(fd);

        Vec2 anchor = new Vec2(-15.0f + 2.0f * i, 15.0f);
        jd.initialize(prevBody, body, anchor);
        getWorld().createJoint(jd);

        prevBody = body;
      }
    }

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

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 20.0f;

      WeldJointDef jd = new WeldJointDef();

      Body prevBody = ground;
      for (int i = 0; i < e_count; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(-4.5f + 1.0f * i, 5.0f);
        Body body = getWorld().createBody(bd);
        body.createFixture(fd);

        if (i > 0) {
          Vec2 anchor = new Vec2(-5.0f + 1.0f * i, 5.0f);
          jd.initialize(prevBody, body, anchor);
          getWorld().createJoint(jd);
        }

        prevBody = body;
      }
    }

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

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 20.0f;

      WeldJointDef jd = new WeldJointDef();
      jd.frequencyHz = 8f;
      jd.dampingRatio = .7f;

      Body prevBody = ground;
      for (int i = 0; i < e_count; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(5.5f + 1.0f * i, 10.0f);
        Body body = getWorld().createBody(bd);
        body.createFixture(fd);

        if (i > 0) {
          Vec2 anchor = new Vec2(5.0f + 1.0f * i, 10.0f);
          jd.initialize(prevBody, body, anchor);
          getWorld().createJoint(jd);
        }

        prevBody = body;
      }
View Full Code Here


        def.frequencyHz = joint.getFrequency();
        def.dampingRatio = joint.getDampingRatio();
        break;
      }
      case WELD: {
        WeldJointDef def = new WeldJointDef();
        jd = def;
        def.localAnchorA.set(pbToVec(joint.getLocalAnchorA()));
        def.localAnchorB.set(pbToVec(joint.getLocalAnchorB()));
        def.referenceAngle = joint.getRefAngle();
        def.frequencyHz = joint.getFrequency();
        def.dampingRatio = joint.getDampingRatio();
        break;
      }
      case FRICTION: {
        FrictionJointDef def = new FrictionJointDef();
        jd = def;
        def.localAnchorA.set(pbToVec(joint.getLocalAnchorA()));
        def.localAnchorB.set(pbToVec(joint.getLocalAnchorB()));
        def.maxForce = joint.getMaxForce();
        def.maxTorque = joint.getMaxTorque();
        break;
      }
      case ROPE: {
        RopeJointDef def = new RopeJointDef();
        jd = def;
        def.localAnchorA.set(pbToVec(joint.getLocalAnchorA()));
        def.localAnchorB.set(pbToVec(joint.getLocalAnchorB()));
        def.maxLength = joint.getMaxLength();
        return null;
      }
      case CONSTANT_VOLUME: {
        ConstantVolumeJointDef def = new ConstantVolumeJointDef();
        jd = def;
        def.dampingRatio = joint.getDampingRatio();
        def.frequencyHz = joint.getFrequency();
        if (joint.getBodiesCount() != joint.getJointsCount()) {
          throw new IllegalArgumentException(
              "Constant volume joint must have bodies and joints defined");
        }
        for (int i = 0; i < joint.getBodiesCount(); i++) {
          int body = joint.getBodies(i);
          if (!argBodyMap.containsKey(body)) {
            throw new IllegalArgumentException("Index " + body + " is not present in the body map");
          }
          int jointIndex = joint.getJoints(i);
          if (!jointMap.containsKey(jointIndex)) {
            throw new IllegalArgumentException("Index " + jointIndex
                + " is not present in the joint map");
          }
          Joint djoint = jointMap.get(jointIndex);
          if (!(djoint instanceof DistanceJoint)) {
            throw new IllegalArgumentException(
                "Joints for constant volume joint must be distance joints");
          }
          def.addBodyAndJoint(argBodyMap.get(body), (DistanceJoint) djoint);
        }
        break;
      }
      case LINE: {
        UnsupportedObjectException e =
View Full Code Here

TOP

Related Classes of org.jbox2d.dynamics.joints.WeldJointDef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.