コード例 #1
0
  /**
   * Tethers the given node to its location with the given strength.
   *
   * @param node The node to be tethered.
   * @param strength Strength of the tether.
   * @return True if the viewer contains the given node and it was tethered successfully.
   */
  public boolean tether(N node, float strength) {
    Particle p1 = nodes.get(node);
    if (p1 == null) {
      return false;
    }

    // Grab the tethering stake if it has already been created, otherwise create a new one.
    Particle stake = stakes.get(node);
    if (stake == null) {
      stake = physics.makeParticle(1, node.getLocation().x, node.getLocation().y, 0);
      stake.makeFixed();
      stakes.put(node, stake);
    }

    // Grab the tether if it has already been created, otherwise create a new one.
    Spring tether = tethers.get(stake);
    if (tether == null) {
      tether = physics.makeSpring(stake, p1, strength, DAMPING, Float.MIN_VALUE);
      tethers.put(stake, tether);
    } else {
      tether.setStrength(strength);
    }
    return true;
  }
コード例 #2
0
 /**
  * Adds a node to those to be displayed in the viewer.
  *
  * @param node Node to add to the viewer.
  */
 public void addNode(N node) {
   Particle p = physics.makeParticle(1, node.getLocation().x, node.getLocation().y, 0);
   nodes.put(node, p);
 }