示例#1
0
 /**
  * Sets the spring frequency.
  *
  * @param frequency the spring frequency in hz; must be greater than or equal to zero
  * @throws IllegalArgumentException if frequency is less than zero
  */
 public void setFrequency(double frequency) {
   // check for valid value
   if (frequency < 0)
     throw new IllegalArgumentException(Messages.getString("dynamics.joint.invalidFrequency"));
   // set the new value
   this.frequency = frequency;
 }
示例#2
0
 /**
  * Sets the damping ratio.
  *
  * @param dampingRatio the damping ratio; in the range [0, 1]
  * @throws IllegalArgumentException if damping ration is less than zero or greater than 1
  */
 public void setDampingRatio(double dampingRatio) {
   // make sure its within range
   if (dampingRatio < 0 || dampingRatio > 1)
     throw new IllegalArgumentException(Messages.getString("dynamics.joint.invalidDampingRatio"));
   // set the new value
   this.dampingRatio = dampingRatio;
 }
示例#3
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);
 }
示例#4
0
 /**
  * Sets the lower limit in radians.
  *
  * <p>See the class documentation for more details on the limit ranges.
  *
  * @param lowerLimit the lower limit in radians
  * @throws IllegalArgumentException if lowerLimit is greater than the current upper limit
  */
 public void setLowerLimit(double lowerLimit) {
   // make sure the minimum is less than or equal to the maximum
   if (lowerLimit > this.upperLimit)
     throw new IllegalArgumentException(Messages.getString("dynamics.joint.invalidLowerLimit"));
   // wake up both bodies
   this.body1.setAsleep(false);
   this.body2.setAsleep(false);
   // set the new target angle
   this.lowerLimit = lowerLimit;
 }
示例#5
0
 /**
  * Sets both the lower and upper limits.
  *
  * <p>See the class documentation for more details on the limit ranges.
  *
  * @param lowerLimit the lower limit in radians
  * @param upperLimit the upper limit in radians
  * @throws IllegalArgumentException if lowerLimit is greater than upperLimit
  */
 public void setLimits(double lowerLimit, double upperLimit) {
   // make sure the min < max
   if (lowerLimit > upperLimit)
     throw new IllegalArgumentException(Messages.getString("dynamics.joint.invalidLimits"));
   // wake up the bodies
   this.body1.setAsleep(false);
   this.body2.setAsleep(false);
   // set the limits
   this.upperLimit = upperLimit;
   this.lowerLimit = lowerLimit;
 }
示例#6
0
 /**
  * Sets the rest distance between the two constrained {@link Body}s in meters.
  *
  * @param distance the distance in meters
  * @throws IllegalArgumentException if distance is less than zero
  */
 public void setDistance(double distance) {
   // make sure the distance is greater than zero
   if (distance < 0.0)
     throw new IllegalArgumentException(
         Messages.getString("dynamics.joint.distance.invalidDistance"));
   // wake up both bodies
   this.body1.setAsleep(false);
   this.body2.setAsleep(false);
   // set the new target distance
   this.distance = distance;
 }
示例#7
0
 /**
  * Full constructor.
  *
  * @param comparable the comparable object
  * @param parent the parent node
  * @param left the left node
  * @param right the right node
  * @throws NullPointerException if comparable is null
  */
 public BinarySearchTreeNode(
     E comparable,
     BinarySearchTreeNode<E> parent,
     BinarySearchTreeNode<E> left,
     BinarySearchTreeNode<E> right) {
   if (comparable == null)
     throw new NullPointerException(Messages.getString("binarySearchTree.nullComparable"));
   this.comparable = comparable;
   this.parent = parent;
   this.left = left;
   this.right = right;
 }
示例#8
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;
 }
 /**
  * Full constructor.
  *
  * @param transform the transform for the bounds
  * @throws NullPointerException if transform is null
  */
 public AbstractBounds(Transform transform) {
   // check for a null transform
   if (transform == null)
     throw new NullPointerException(Messages.getString("collision.bounds.abstract.nullTransform"));
   this.transform = transform;
 }
示例#10
0
 /**
  * Full constructor.
  *
  * <p>Creates a new {@link Polygon} using the given vertices. The center of the polygon is
  * calculated using an area weighted method.
  *
  * <p>A polygon must have 3 or more vertices, of which one is not colinear with the other two.
  *
  * <p>A polygon must also be convex and have anti-clockwise winding.
  *
  * @param vertices the array of vertices
  * @throws NullPointerException if vertices is null or contains a null element
  * @throws IllegalArgumentException if vertices contains less than 3 points, contains coincident
  *     points, is not convex, or has clockwise winding
  */
 public Polygon(Vector2... vertices) {
   super();
   // check the vertex array
   if (vertices == null)
     throw new NullPointerException(Messages.getString("geometry.polygon.nullArray"));
   // get the size
   int size = vertices.length;
   // check the size
   if (size < 3)
     throw new IllegalArgumentException(Messages.getString("geometry.polygon.lessThan3Vertices"));
   // check for null vertices
   for (int i = 0; i < size; i++) {
     if (vertices[i] == null)
       throw new NullPointerException(Messages.getString("geometry.polygon.nullVertices"));
   }
   // check for convex
   double area = 0.0;
   double sign = 0.0;
   for (int i = 0; i < size; i++) {
     Vector2 p0 = (i - 1 < 0) ? vertices[size - 1] : vertices[i - 1];
     Vector2 p1 = vertices[i];
     Vector2 p2 = (i + 1 == size) ? vertices[0] : vertices[i + 1];
     // check for coincident vertices
     if (p1.equals(p2)) {
       throw new IllegalArgumentException(
           Messages.getString("geometry.polygon.coincidentVertices"));
     }
     // check the cross product for CCW winding
     double cross = p0.to(p1).cross(p1.to(p2));
     double tsign = Math.signum(cross);
     area += cross;
     // check for colinear points (for now its allowed)
     if (Math.abs(cross) > Epsilon.E) {
       // check for convexity
       if (sign != 0.0 && tsign != sign) {
         throw new IllegalArgumentException(Messages.getString("geometry.polygon.nonConvex"));
       }
     }
     sign = tsign;
   }
   // check for CCW
   if (area < 0.0) {
     throw new IllegalArgumentException(Messages.getString("geometry.polygon.invalidWinding"));
   }
   // set the vertices
   this.vertices = vertices;
   // create the normals
   this.normals = new Vector2[size];
   for (int i = 0; i < size; i++) {
     // get the edge points
     Vector2 p1 = vertices[i];
     Vector2 p2 = (i + 1 == size) ? vertices[0] : vertices[i + 1];
     // create the edge and get its left perpedicular vector
     Vector2 n = p1.to(p2).left();
     // normalize it
     n.normalize();
     this.normals[i] = n;
   }
   // perform the area weighted center to otain the center
   this.center = Geometry.getAreaWeightedCenter(this.vertices);
   // find the maximum radius from the center
   double r2 = 0.0;
   for (int i = 0; i < size; i++) {
     double r2t = this.center.distanceSquared(vertices[i]);
     // keep the largest
     r2 = Math.max(r2, r2t);
   }
   // set the radius
   this.radius = Math.sqrt(r2);
 }