public void setBounds(PVector i_topLeft, PVector i_bottomRight) {
    topLeftBound = i_topLeft.get();
    bottomRightBound = i_bottomRight.get();

    TL = topLeftBound.get();
    BR = bottomRightBound.get();
    BL = new PVector(TL.x, BR.y);
    TR = new PVector(BR.x, TL.y);
  }
예제 #2
0
  /*
  	Perform Simulation
  */
  public void simulate(float dt) {
    // Accelerate angular speed
    float requiredSpeed = targetAngularSpeed - angularSpeed;
    float angularAccel = requiredSpeed / dt;
    angularAccel = PApplet.constrain(angularAccel, -maxAngularAccel, maxAngularAccel);

    // Limit Angular speed
    angularSpeed += angularAccel * dt;
    angularSpeed = PApplet.constrain(angularSpeed, -maxAngularSpeed, maxAngularSpeed);

    // Orientation Simulation
    orientation += angularSpeed * dt;

    // Position simulation
    PVector worldRequiredSpeed = targetSpeed.get();
    worldRequiredSpeed.rotate(orientation);
    worldRequiredSpeed.sub(speed);

    // PVector worldRequiredSpeed = worldTargetSpeed.get();
    float dSpeed = worldRequiredSpeed.mag();
    float dAcell = dSpeed / dt;
    float dForce = Math.min(dAcell * getMass(), motorForce);

    worldRequiredSpeed.normalize();
    worldRequiredSpeed.mult(dForce);
    force.add(worldRequiredSpeed);

    super.simulate(dt);
  }
 // Constructor initialize all values
 Boid(PVector l, float ms, float mf) {
   loc = l.get();
   r = 4.0f;
   maxspeed = ms;
   maxforce = mf;
   acc = new PVector(0, 0);
   vel = new PVector(maxspeed, 0);
 }
    public void avoid(ArrayList obstacles) {

      // Make a vector that will be the position of the object
      // relative to the Boid rotated in the direction of boid's velocity
      PVector closestRotated = new PVector(sight + 1, sight + 1);
      float closestDistance = 99999;
      Obstacle avoid = null;

      // Let's look at each obstacle
      for (int i = 0; i < obstacles.size(); i++) {
        Obstacle o = (Obstacle) obstacles.get(i);

        float d = PVector.dist(loc, o.loc);
        PVector dir = vel.get();
        dir.normalize();
        PVector diff = PVector.sub(o.loc, loc);

        // Now we use the dot product to rotate the vector that points from boid to obstacle
        // Velocity is the new x-axis
        PVector rotated = new PVector(diff.dot(dir), diff.dot(getNormal(dir)));

        // Is the obstacle in our path?
        if (PApplet.abs(rotated.y) < (o.radius + r)) {
          // Is it the closest obstacle?
          if ((rotated.x > 0) && (rotated.x < closestRotated.x)) {
            closestRotated = rotated;
            avoid = o;
          }
        }
      }

      // Can we actually see the closest one?
      if (PApplet.abs(closestRotated.x) < sight) {

        // The desired vector should point away from the obstacle
        // The closer to the obstacle, the more it should steer
        PVector desired =
            new PVector(closestRotated.x, -closestRotated.y * sight / closestRotated.x);
        desired.normalize();
        desired.mult(closestDistance);
        desired.limit(maxspeed);
        // Rotate back to the regular coordinate system
        rotateVector(desired, vel.heading2D());

        // Draw some debugging stuff
        if (debug) {
          stroke(0);
          line(loc.x, loc.y, loc.x + desired.x * 10, loc.y + desired.y * 10);
          avoid.highlight(true);
        }

        // Apply Reynolds steering rules
        desired.sub(vel);
        desired.limit(maxforce);
        acc.add(desired);
      }
    }
  public MarqueeSelectionWidget(PVector i_position, PVector i_size) {
    super(i_position, i_size);
    TL = new PVector(0, 0);
    BR = i_size.get();
    BL = new PVector(TL.x, BR.y);
    TR = new PVector(BR.x, TL.y);

    setBounds(TL, BR);
  }
예제 #6
0
  public void setState(PVector position, float orientation, boolean resetAll) {
    this.position = position.get();
    this.orientation = orientation;

    if (resetAll) {
      this.force = new PVector();
      this.accel = new PVector();
      this.speed = new PVector();
    }
  }
예제 #7
0
  private PVector getLatticePos(String nodeName, String slotName) {

    PVector nodeLoc = lattice.getLocation(nodeName);
    Lattice<Void> slotLat = lattice.getContents(nodeName);

    if (slotLat == null) {
      log.warn("No slot lattice for node " + nodeName);
      return new PVector(0, 0, 0);
    }

    // Node position within the lattice, natural coordinates
    float nodeOffset = nodeSize + 2 * nodePadding;
    PVector nodePos = nodeLoc.get();
    nodePos.mult(nodeOffset);
    nodePos.add(nodePadding, nodePadding, nodePadding);

    PVector slotLoc = slotLat.getLocation(slotName);
    if (slotLoc == null) {
      log.warn("No slot location for slot " + slotName + " in node " + nodeName);
      return nodePos.get();
    }

    // TODO: cache these calculations

    // Slot position within the node, natural coordinates
    float slotOffset = jobSize + 2 * jobPadding;
    PVector slotPos = slotLoc.get();
    slotPos.mult(slotOffset);
    slotPos.add(jobPadding, jobPadding, jobPadding);

    // Combine node and slot position, natural coordinates
    PVector pos = slotPos.get();
    pos.add(nodePos);

    // Convert into central coordinate system
    float latticeWidth = lattice.size * nodeOffset;
    float t = latticeWidth / 2;
    pos.sub(t, t, t);

    return pos;
  }
  protected void addedToStage() {
    handles = new SelectionHandle[4];
    handles[0] = new SelectionHandle(TL.get(), new PVector(HANDLE_SIZE, HANDLE_SIZE));
    handles[1] = new SelectionHandle(TR.get(), new PVector(HANDLE_SIZE, HANDLE_SIZE));
    handles[2] = new SelectionHandle(BR.get(), new PVector(HANDLE_SIZE, HANDLE_SIZE));
    handles[3] = new SelectionHandle(BL.get(), new PVector(HANDLE_SIZE, HANDLE_SIZE));

    handles[0].setCornerVectors(TL, BL, TR, this);
    handles[0].setLabel(TOP_LEFT);
    handles[1].setCornerVectors(TR, BR, TL, this);
    handles[1].setLabel(TOP_RIGHT);
    handles[2].setCornerVectors(BR, TR, BL, this);
    handles[2].setLabel(BOTTOM_RIGHT);
    handles[3].setCornerVectors(BL, TL, BR, this);
    handles[3].setLabel(BOTTOM_LEFT);

    addChild(handles[0]);
    addChild(handles[2]);
    addChild(handles[1]);
    addChild(handles[3]);
  }
  public PVector[] getTexCoords() {
    PVector[] out = new PVector[4];

    float xSize = bottomRightBound.x - topLeftBound.x;
    float ySize = bottomRightBound.y - topLeftBound.y;

    out[0] = TL.get();
    out[0].x /= xSize;
    out[0].y /= ySize;

    out[1] = TR.get();
    out[1].x /= xSize;
    out[1].y /= ySize;

    out[2] = BR.get();
    out[2].x /= xSize;
    out[2].y /= ySize;

    out[3] = new PVector(ImageSelectionWidget.MARQUEE, ImageSelectionWidget.MARQUEE);

    return out;
  }
    // This constructor could be improved to allow a greater variety of pendulums
    Pendulum(PVector origin_, float r_) {
      // Fill all variables
      origin = origin_.get();
      r = r_;
      theta = 0.0f;

      // calculate the location of the ball using polar to cartesian conversion
      float x = r * sin(theta);
      float y = r * cos(theta);
      loc = new PVector(origin.x + x, origin.y + y);
      theta_vel = 0.0f;
      theta_acc = 0.0f;
      damping = 0.995f; // Arbitrary damping
      ballr = 16.0f; // Arbitrary ball radius
    }
  Particle(PApplet p_, PVector l) {
    p = p_;
    location = l.get();
    acceleration = new PVector(0, 0.5f);
    gen1 = new Random();
    gen2 = new Random();
    rand1 = gen1.nextDouble() * 1 + -1;
    rand2 = gen2.nextDouble() * -2;
    velocity = new PVector((float) rand1, (float) rand2);
    lifespan = 255;
    // getSingletonLoader = new SingletonLoader();
    // myImage = getSingletonLoader.getInstance(p, "particle2");
    mass = new PVector(0.5f, 0.5f);

    myImage = new ImageCreator(p, "particleLarge");
    // myImage.scaled(0.2f);

  }
 FontAgent(PVector l) {
   loc = l.get();
   // acc = new PVector (0, 0.1);
 }
예제 #13
0
 public PVector getTargetPos() {
   return camCenter.get();
 }
예제 #14
0
 public PVector getCamPos() {
   return camPos.get();
 }
예제 #15
0
 public void setTargetPos(PVector v) {
   camCenter = v.get();
 }
예제 #16
0
 public void setCamPos(PVector v) {
   camPos = v.get();
 }
예제 #17
0
 // deep copy
 public PositionRotation clone() {
   return new PositionRotation(position.get(), rotation.get());
 }