Exemple #1
0
 /**
  * Minimal constructor.
  *
  * <p>Creates a fixed distance {@link Joint} where the joined {@link Body}s do not participate in
  * collision detection and resolution.
  *
  * @param body1 the first {@link Body}
  * @param body2 the second {@link Body}
  * @param anchor1 in world coordinates
  * @param anchor2 in world coordinates
  * @throws NullPointerException if body1, body2, anchor1, or anchor2 is null
  * @throws IllegalArgumentException if body1 == body2
  */
 public DistanceJoint(Body body1, Body body2, Vector2 anchor1, Vector2 anchor2) {
   super(body1, body2, false);
   // verify the bodies are not the same instance
   if (body1 == body2)
     throw new IllegalArgumentException(Messages.getString("dynamics.joint.sameBody"));
   // verify the anchor points are not null
   if (anchor1 == null)
     throw new NullPointerException(Messages.getString("dynamics.joint.nullAnchor1"));
   if (anchor2 == null)
     throw new NullPointerException(Messages.getString("dynamics.joint.nullAnchor2"));
   // get the local anchor points
   this.localAnchor1 = body1.getLocalPoint(anchor1);
   this.localAnchor2 = body2.getLocalPoint(anchor2);
   // compute the initial distance
   this.distance = anchor1.distance(anchor2);
 }
Exemple #2
0
 /**
  * Minimal constructor.
  *
  * @param body1 the first {@link Body}
  * @param body2 the second {@link Body}
  * @throws NullPointerException if body1 or body2 is null
  * @throws IllegalArgumentException if body1 == body2
  */
 public AngleJoint(Body body1, Body body2) {
   // default no collision allowed
   super(body1, body2, false);
   // verify the bodies are not the same instance
   if (body1 == body2)
     throw new IllegalArgumentException(Messages.getString("dynamics.joint.sameBody"));
   // initialize
   this.ratio = 1.0;
   this.impulse = 0.0;
   // compute the reference angle
   this.referenceAngle = body1.getTransform().getRotation() - body2.getTransform().getRotation();
   // set both limits
   this.upperLimit = this.referenceAngle;
   this.lowerLimit = this.referenceAngle;
   // set enabled
   this.limitEnabled = true;
   // default the limit state
   this.limitState = LimitState.EQUAL;
 }