// check for move out of bounds
  private Vector getBounce(Dimension bounds) {
    final double IMPULSE_MAGNITUDE = 2;
    int tolerance = 10;

    Vector impulse = new Vector();
    if (getLeft() < tolerance) {
      impulse = new Vector(RIGHT_DIRECTION, IMPULSE_MAGNITUDE);
    } else if (getRight() - tolerance > bounds.width) {
      impulse = new Vector(LEFT_DIRECTION, IMPULSE_MAGNITUDE);
    }
    if (getTop() < tolerance) {
      impulse = new Vector(DOWN_DIRECTION, IMPULSE_MAGNITUDE);
    } else if (getBottom() - tolerance > bounds.height) {
      impulse = new Vector(UP_DIRECTION, IMPULSE_MAGNITUDE);
    }
    impulse.scale(getMyMass());
    impulse.scale(getVelocity().getRelativeMagnitude(impulse));
    return impulse;
  }
示例#2
0
  /**
   * ******************************************************************************* addMarker
   *
   * <p>This method is responsible for adding crumbs to the handler and determining when crumbs
   * should become invisible. Right now, crumbs are removed once there are more than 20 markers in
   * the handler. Crumbs are removed according to when they were placed on the manifold by the user.
   * *******************************************************************************
   */
  public void addMarker(ManifoldPosition mp) {
    ManifoldPosition pos = new ManifoldPosition(mp);
    Vector vec = new Vector(pos.getDirectionForward());
    vec.scale(-.25);
    pos.move(vec);
    Marker m = new Marker(pos, crumb, Marker.MarkerType.FIXED);
    trail.add(m);
    markers.addMarker(m);
    counter++;

    int numMarkers = trail.size() - 1;
    if (numMarkers >= 5) {
      Marker toRemove = trail.poll();
      toRemove.flagForRemoval();
    }
  }
 /** Use the given force to change this mass's acceleration. */
 public void applyForce(Vector force) {
   Vector scaled = new Vector(force);
   scaled.scale(1 / myMass);
   myAcceleration.sum(scaled);
 }
 public void applyVescosity(Mass m) {
   Vector vescoForce = new Vector(m.getVelocity());
   vescoForce.scale(myViscosity);
   vescoForce.negate();
   m.applyForce(vescoForce);
 }
 public void applyGravity(Mass m) {
   Vector g = new Vector(getMyGravity());
   g.scale(m.getMyMass());
   m.applyForce(g);
 }