Package org.jbox2d.dynamics.joints

Examples of org.jbox2d.dynamics.joints.RevoluteJointDef


      shape.setAsBox(20.0f, 0.5f, new Vec2(0.0f, 10.0f), 0.0f);
      body.createFixture(shape, 5.0f);
      shape.setAsBox(20.0f, 0.5f, new Vec2(0.0f, -10.0f), 0.0f);
      body.createFixture(shape, 5.0f);

      RevoluteJointDef jd = new RevoluteJointDef();
      jd.bodyA = getGroundBody();
      jd.bodyB = body;
      jd.localAnchorA.set(0.0f, 10.0f);
      jd.localAnchorB.set(0.0f, 0.0f);
      jd.referenceAngle = 0.0f;
View Full Code Here


        def.referenceAngle = joint.getRefAngle();
        def.upperTranslation = joint.getUpperLimit();
        break;
      }
      case REVOLUTE: {
        RevoluteJointDef def = new RevoluteJointDef();
        jd = def;
        def.enableLimit = joint.getEnableLimit();
        def.enableMotor = joint.getEnableMotor();
        def.localAnchorA.set(pbToVec(joint.getLocalAnchorA()));
        def.localAnchorB.set(pbToVec(joint.getLocalAnchorB()));
        def.lowerAngle = joint.getLowerLimit();
        def.maxMotorTorque = joint.getMaxMotorTorque();
        def.motorSpeed = joint.getMotorSpeed();
        def.referenceAngle = joint.getRefAngle();
        def.upperAngle = joint.getUpperLimit();
        break;
      }
      case DISTANCE: {
        DistanceJointDef def = new DistanceJointDef();
        jd = def;
        def.localAnchorA.set(pbToVec(joint.getLocalAnchorA()));
        def.localAnchorB.set(pbToVec(joint.getLocalAnchorB()));
        def.dampingRatio = joint.getDampingRatio();
        def.frequencyHz = joint.getFrequency();
        def.length = joint.getLength();
        break;
      }
      case PULLEY: {
        PulleyJointDef def = new PulleyJointDef();
        jd = def;
        def.localAnchorA.set(pbToVec(joint.getLocalAnchorA()));
        def.localAnchorB.set(pbToVec(joint.getLocalAnchorB()));
        def.groundAnchorA.set(pbToVec(joint.getGroundAnchorA()));
        def.groundAnchorB.set(pbToVec(joint.getGroundAnchorB()));
        def.lengthA = joint.getLengthA();
        def.lengthB = joint.getLengthB();
        def.ratio = joint.getRatio();
        break;
      }
      case MOUSE: {
        MouseJointDef def = new MouseJointDef();
        jd = def;
        def.dampingRatio = joint.getDampingRatio();
        def.frequencyHz = joint.getFrequency();
        def.maxForce = joint.getMaxForce();
        def.target.set(pbToVec(joint.getTarget()));
        break;
      }
      case GEAR: {
        GearJointDef def = new GearJointDef();
        jd = def;
        if (!jointMap.containsKey(joint.getJoint1())) {
          throw new IllegalArgumentException("Index " + joint.getJoint1()
              + " is not present in the joint map.");
        }
        def.joint1 = jointMap.get(joint.getJoint1());
        if (!jointMap.containsKey(joint.getJoint2())) {
          throw new IllegalArgumentException("Index " + joint.getJoint2()
              + " is not present in the joint map.");
        }
        def.joint2 = jointMap.get(joint.getJoint2());
        def.ratio = joint.getRatio();
        break;
      }
      case WHEEL: {
        WheelJointDef def = new WheelJointDef();
        jd = def;
        def.localAnchorA.set(pbToVec(joint.getLocalAnchorA()));
        def.localAnchorB.set(pbToVec(joint.getLocalAnchorB()));
        def.localAxisA.set(pbToVec(joint.getLocalAxisA()));
        def.enableMotor = joint.getEnableMotor();
        def.maxMotorTorque = joint.getMaxMotorTorque();
        def.motorSpeed = joint.getMotorSpeed();
        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

      m_wheel = getWorld().createBody(bd);
      m_wheel.createFixture(sd);
    }

    {
      RevoluteJointDef jd = new RevoluteJointDef();

      jd.initialize(m_wheel, m_chassis, pivot.add(m_offset));
      jd.collideConnected = false;
      jd.motorSpeed = m_motorSpeed;
      jd.maxMotorTorque = 400.0f;
      jd.enableMotor = m_motorOn;
      m_motorJoint = (RevoluteJoint) getWorld().createJoint(jd);
View Full Code Here

    getWorld().createJoint(djd);

    djd.initialize(body2, m_wheel, p6.add(m_offset), wheelAnchor.add(m_offset));
    getWorld().createJoint(djd);

    RevoluteJointDef rjd = new RevoluteJointDef();

    rjd.initialize(body2, m_chassis, p4.add(m_offset));
    getWorld().createJoint(rjd);
  }
View Full Code Here

      bodyDef.type = BodyType.STATIC;
      ground = getWorld().createBody(bodyDef);
      ground.createFixture(shape, 0);
    }

    RevoluteJointDef jointDef = new RevoluteJointDef();

    if (switchBodiesInJoint)
      jointDef.initialize(pendulum, base, new Vec2(0, 0));
    else
      jointDef.initialize(base, pendulum, new Vec2(0, 0));

    getWorld().createJoint(jointDef);
  }
View Full Code Here

      fd.shape = shape;
      fd.friction = 0.6f;
      fd.density = 2.0f;
      m_platform.createFixture(fd);

      RevoluteJointDef rjd = new RevoluteJointDef();
      rjd.initialize(m_attachment, m_platform, new Vec2(0.0f, 5.0f));
      rjd.maxMotorTorque = 50.0f;
      rjd.enableMotor = true;
      getWorld().createJoint(rjd);

      PrismaticJointDef pjd = new PrismaticJointDef();
View Full Code Here

        cd.m_p.set(xPos, yPos);

        body.createFixture(fd);
      }

      RevoluteJointDef rjd = new RevoluteJointDef();
      rjd.initialize(body, getGroundBody(), body.getPosition());
      rjd.motorSpeed = MathUtils.PI;
      rjd.maxMotorTorque = 1000000.0f;
      rjd.enableMotor = true;
      getWorld().createJoint(rjd);
    }


    {
      Body prevBody = ground;

      // Define crank.
      {
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(0.5f, 2.0f);

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(0.0f, 7.0f);
        Body body = getWorld().createBody(bd);
        body.createFixture(shape, 2.0f);

        RevoluteJointDef rjd = new RevoluteJointDef();
        rjd.initialize(prevBody, body, new Vec2(0.0f, 5.0f));
        rjd.motorSpeed = 1.0f * MathUtils.PI;
        rjd.maxMotorTorque = 20000;
        rjd.enableMotor = true;
        getWorld().createJoint(rjd);

        prevBody = body;
      }

      // Define follower.
      {
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(0.5f, 4.0f);

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(0.0f, 13.0f);
        Body body = getWorld().createBody(bd);
        body.createFixture(shape, 2.0f);

        RevoluteJointDef rjd = new RevoluteJointDef();
        rjd.initialize(prevBody, body, new Vec2(0.0f, 9.0f));
        rjd.enableMotor = false;
        getWorld().createJoint(rjd);

        prevBody = body;
      }

      // Define piston
      {
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(7f, 2f);

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(0.0f, 17.0f);
        Body body = getWorld().createBody(bd);
        FixtureDef piston = new FixtureDef();
        piston.shape = shape;
        piston.density = 2;
        piston.filter.categoryBits = 1;
        piston.filter.maskBits = 2;
        body.createFixture(piston);
        body.setBullet(false);
       
        RevoluteJointDef rjd = new RevoluteJointDef();
        rjd.initialize(prevBody, body, new Vec2(0.0f, 17.0f));
        getWorld().createJoint(rjd);

        PrismaticJointDef pjd = new PrismaticJointDef();
        pjd.initialize(ground, body, new Vec2(0.0f, 17.0f), new Vec2(0.0f, 1.0f));

View Full Code Here

      bd3.type = BodyType.DYNAMIC;
      bd3.position.set(10.0f, 6.0f);
      Body body3 = m_world.createBody(bd3);
      body3.createFixture(circle2, 5.0f);

      RevoluteJointDef jd1 = new RevoluteJointDef();
      jd1.initialize(body2, body1, bd1.position);
      Joint joint1 = m_world.createJoint(jd1);

      RevoluteJointDef jd2 = new RevoluteJointDef();
      jd2.initialize(body2, body3, bd3.position);
      Joint joint2 = m_world.createJoint(jd2);

      GearJointDef jd4 = new GearJointDef();
      jd4.bodyA = body1;
      jd4.bodyB = body3;
      jd4.joint1 = joint1;
      jd4.joint2 = joint2;
      jd4.ratio = circle2.m_radius / circle1.m_radius;
      m_world.createJoint(jd4);
    }

    {
      CircleShape circle1 = new CircleShape();
      circle1.m_radius = 1.0f;

      CircleShape circle2 = new CircleShape();
      circle2.m_radius = 2.0f;

      PolygonShape box = new PolygonShape();
      box.setAsBox(0.5f, 5.0f);

      BodyDef bd1 = new BodyDef();
      bd1.type = BodyType.DYNAMIC;
      bd1.position.set(-3.0f, 12.0f);
      Body body1 = m_world.createBody(bd1);
      body1.createFixture(circle1, 5.0f);

      RevoluteJointDef jd1 = new RevoluteJointDef();
      jd1.bodyA = ground;
      jd1.bodyB = body1;
      ground.getLocalPointToOut(bd1.position, jd1.localAnchorA);
      body1.getLocalPointToOut(bd1.position, jd1.localAnchorB);
      jd1.referenceAngle = body1.getAngle() - ground.getAngle();
      m_joint1 = (RevoluteJoint) m_world.createJoint(jd1);

      BodyDef bd2 = new BodyDef();
      bd2.type = BodyType.DYNAMIC;
      bd2.position.set(0.0f, 12.0f);
      Body body2 = m_world.createBody(bd2);
      body2.createFixture(circle2, 5.0f);

      RevoluteJointDef jd2 = new RevoluteJointDef();
      jd2.initialize(ground, body2, bd2.position);
      m_joint2 = (RevoluteJoint) m_world.createJoint(jd2);

      BodyDef bd3 = new BodyDef();
      bd3.type = BodyType.DYNAMIC;
      bd3.position.set(2.5f, 12.0f);
View Full Code Here

      fd.density = 20.0f;
      fd.friction = 0.2f;
      fd.filter.categoryBits = 0x0001;
      fd.filter.maskBits = 0xFFFF & ~0x0002;

      RevoluteJointDef jd = new RevoluteJointDef();
      jd.collideConnected = false;

      final int N = 10;
      final float y = 15.0f;
      m_ropeDef = new RopeJointDef();
      m_ropeDef.localAnchorA.set(0.0f, y);

      Body prevBody = ground;
      for (int i = 0; i < N; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(0.5f + 1.0f * i, y);
        if (i == N - 1) {
          shape.setAsBox(1.5f, 1.5f);
          fd.density = 100.0f;
          fd.filter.categoryBits = 0x0002;
          bd.position.set(1.0f * i, y);
          bd.angularDamping = 0.4f;
        }

        Body body = getWorld().createBody(bd);

        body.createFixture(fd);

        Vec2 anchor = new Vec2(i, y);
        jd.initialize(prevBody, body, anchor);
        getWorld().createJoint(jd);

        prevBody = body;
      }

View Full Code Here

      shape.setAsBox(10.0f, 0.5f, new Vec2(0.0f, 10.0f), 0.0f);
      body.createFixture(shape, 5.0f);
      shape.setAsBox(10.0f, 0.5f, new Vec2(0.0f, -10.0f), 0.0f);
      body.createFixture(shape, 5.0f);

      RevoluteJointDef jd = new RevoluteJointDef();
      jd.bodyA = getGroundBody();
      jd.bodyB = body;
      jd.localAnchorA.set(0.0f, 10.0f);
      jd.localAnchorB.set(0.0f, 0.0f);
      jd.referenceAngle = 0.0f;
View Full Code Here

TOP

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

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.