Beispiel #1
0
    // --------------------------------------------------------
    private void calculPositionAndAngle() {

      PVector prev = new PVector(0, 0);
      PVector next;

      for (int i = 0; i < n; i++) {

        next = new PVector();

        // Position
        if (i == 0) {
          next = new PVector(0, 0);
        } else {
          next.x = prev.x + cos(random(angleMini - HALF_PI, angleMax - HALF_PI)) * distance;
          next.y = prev.y + sin(random(angleMini - HALF_PI, angleMax - HALF_PI)) * distance;

          // Angle
          float a = atan2(prev.y - next.y, prev.x - next.x) - HALF_PI;
          angle.append(a);
          if (i == n - 1) lastAngle = a;
        }

        // Add position
        position.add(next);

        distance *= 1.01f;
        prev.set(next);
      }
    }
    public void display() {
      location.x = (sin(radians(angle)) * r) + 5;
      location.y = cos(radians(angle)) * r;

      pushMatrix();
      translate(location.x, location.y, 0);
      fill(220);
      noStroke();
      sphere(size);
      popMatrix();

      angle += speed;
    }
Beispiel #3
0
    Background(float _sizeX, float _sizeY, Repulseur[] _r) {

      sizeX = _sizeX;
      sizeY = _sizeY;
      repulseurPoint = _r;

      for (int i = 0; i < 20000; i++) {

        PVector p = new PVector();
        p.x = random(sizeX);
        p.y = random(sizeY);

        points.add(p);
      }
    }
  public void mousePressed() {
    if (game.screen == 1) { // see above
      velocity =
          PVector.fromAngle(
              radians(
                  (float)
                      angledegrees)); // uses PVector to make a vector from the angle of the shooter
      if (canfire == true) { // checks if user is able to fire (if ball is active)
        game.shooterlist[0] = game.shooterlist[1]; // sets active ball to the next ball
        game.shooterlist[0].setVelocity(
            velocity.x, velocity.y); // adjusts velocity for ball depending on type
        game.shooterlist[1] =
            new Ball(
                game
                    .createNewBall()); // creates new ball with random type as generated by the
                                       // createNewBall function
        canfire = false; // disables firing while ball is active
      }
    }

    if (game.screen == 0) { // see above
      if (button.pressed()) { // checks if button is pressed
        game.gotoGame(); // loads game
      }
    }

    if (game.screen == 2) {
      if (button.pressed()) {
        game.reset(); // resets game
      }
    }
  }
Beispiel #5
0
    // ------------------------------------------------------
    public PVector updatedPointPosition(float _x, float _y) {

      p = new PVector(_x, _y);
      distance = dist(p.x, p.y, x, y);

      if (distance < radius) {

        angle = atan2(p.y - y, p.x - x);
        force = map(distance, 0, radius, maxForce, 0);

        p.x += cos(angle) * force;
        p.y += sin(angle) * force;
      }

      return p;
    }
  public void draw() {
    /*---Update---*/
    world.update();
    worm.update();
    for (int i = 0; i < extraNum; i++) {
      extraWorms[i].update();
    }

    /*---Draw--*/
    // Lights
    lights();
    /*
    ambientLight(128f, 128f, 128f);
    directionalLight(128f, 128f, 128f, 0f, 0f, -1f);
    lightFalloff(1f, 0f, 0f);
    lightSpecular(0f, 0f, 0f);
    */

    // Camera
    perspective(fov, aspect, near, far);
    // Calculate camera position
    if (PVector.dist(worm.getPosition(), eye) > eyeDist) {
      eye = PVector.sub(eye, worm.getPosition());
      eye.normalize();
      eye.mult(eyeDist);
      eye.add(worm.getPosition());
    }
    camera(
        eye.x,
        eye.y,
        eye.z, // eyeX, eyeY, eyeZ (camera position)
        worm.getPosition().x,
        worm.getPosition().y,
        worm.getPosition().z, // centerX, centerY, centerZ (look at)
        0f,
        1f,
        0f); // upX, upY, upZ

    // Action
    world.draw();
    worm.draw();
    for (int i = 0; i < extraNum; i++) {
      extraWorms[i].draw();
    }
    // Drama!
  }
Beispiel #7
0
    // -------------------------------------------
    public void calcul() {

      // UP - left side
      for (int i = 0; i < position.size(); i++) {

        PVector p = position.get(i);
        PVector pp = new PVector();

        pp.x = cos(angles.get(i) + HALF_PI) * radius[i] + p.x + initPosition.x;
        pp.y = sin(angles.get(i) + HALF_PI) * radius[i] + p.y + initPosition.y;
        pointForm.add(pp);
      }

      // DOWN - right side
      for (int i = position.size() - 1; i >= 0; i--) {

        PVector p = position.get(i);
        PVector pp = new PVector();

        pp.x = cos(angles.get(i) - HALF_PI) * radius[i] + p.x + initPosition.x;
        pp.y = sin(angles.get(i) - HALF_PI) * radius[i] + p.y + initPosition.y;
        pointForm.add(pp);
      }
    }
 public void motion() {
   xMove += random(-6, 6);
   theta = radians(xMove);
   loc.x += cos(theta);
   lifespan -= 0.29f;
 }
 FontAgent(PVector l) {
   loc = l.get();
   // acc = new PVector (0, 0.1);
 }
Beispiel #10
0
    // --------------------------------------------------------
    private void calculPositionAndAngle() {

      PVector prev = new PVector(0, 0);
      PVector next = new PVector(0, 0);
      float lastAngle = 0, randomAngle, tempAmplitude;

      // Position
      for (int i = 0; i < n; i++) {

        if (i == 0) {

          position.add(next);

        } else {

          tempAmplitude = amplitude;
          next = new PVector(0, 0);

          do {

            randomAngle = random(-tempAmplitude, tempAmplitude) + lastAngle;
            next.x = prev.x + cos(randomAngle + beginAngle) * distance;
            next.y = prev.y + sin(randomAngle + beginAngle) * distance;
            tempAmplitude += radians(1);
          } while (outside(next, border));

          // Angle
          float a = atan2(prev.y - next.y, prev.x - next.x);
          lastAngle = randomAngle;

          // Add position
          position.add(next);

          // Set prev to next
          prev.set(next);
        }
      }

      // Angle
      for (int i = 0; i < n; i++) {

        float a;

        if (i == 0) {

          // a = atan2(position.get(0).y-position.get(1).y,position.get(0).x-position.get(1).x);
          angle.append(beginAngle - PI);

        } else if (i == n - 1) {

          a =
              atan2(
                  position.get(n - 2).y - position.get(n - 1).y,
                  position.get(n - 2).x - position.get(n - 1).x);
          angle.append(a);

        } else {

          a =
              atan2(
                  position.get(i - 1).y - position.get(i + 1).y,
                  position.get(i - 1).x - position.get(i + 1).x);
          angle.append(a);
        }
      }
    }
Beispiel #11
0
    public void checkThirtyDegreeRule(
        ArrayList<Cam> cameras, ArrayList<Character> characters, int selectedIdx) {
      if (cameras == null || cameras.isEmpty()) {
        println("No cameras in the scene!");
      }

      if (characters.size() != 2) {
        println("Only two characters supported for now");
        // TODO (sanjeet): Hack! Fix this once more characters are allowed
      }

      Cam selectedCamera = cameras.get(selectedIdx);

      // TODO The characters.get results in a runtime error because there aren't currently any
      // characters allocated in the input file.
      Character ch1 = characters.get(0);
      Character ch2 = characters.get(1);

      // Obtaining (x,y,z) for characters and selected camera
      PVector ch1Location = ch1.getTranslation();
      PVector ch2Location = ch2.getTranslation();
      PVector selectedCameraLocation = selectedCamera.getTranslation();

      PVector cameraPoint = new PVector();
      cameraPoint.add(selectedCameraLocation);
      for (int i = 0; i < 100; i++) {
        cameraPoint.add(selectedCamera.getZAxis());
      }
      PVector intersection =
          getTwoLinesIntersection(
              new PVector(ch1Location.x, ch1Location.z),
              new PVector(ch2Location.x, ch2Location.z),
              new PVector(selectedCameraLocation.x, selectedCameraLocation.z),
              new PVector(cameraPoint.x, cameraPoint.z));

      PVector diff = PVector.sub(selectedCameraLocation, intersection);
      diff.normalize();
      FloatBuffer fb = selectedCamera.modelViewMatrix;
      float[] mat = fb.array();
      float[] fbMatrix = new float[mat.length];
      for (int i = 0; i < fbMatrix.length; i++) {
        fbMatrix[i] = mat[i];
      }
      fbMatrix[0] = -diff.x;
      fbMatrix[1] = diff.y;
      fbMatrix[2] = -diff.z;
      fbMatrix[9] = diff.x;
      fbMatrix[10] = diff.y;
      fbMatrix[11] = diff.z;
      fbMatrix[13] = intersection.x;
      fbMatrix[14] = intersection.y;
      fbMatrix[15] = intersection.z;
      PMatrix3D matrix = new PMatrix3D();
      matrix.set(fbMatrix);
      matrix.transpose();
      pushMatrix();
      applyMatrix(matrix);
      rotateY(radians(30));
      line(0, 0, 0, 0, 0, 1000);
      rotateY(radians(-2 * 30));
      line(0, 0, 0, 0, 0, 1000);
      popMatrix();

      for (int i = 0; i < cameras.size(); i++) {
        if (i == selectedIdx) {
          continue;
        }

        if (!cameras.get(i).isInView(ch1Location) && !cameras.get(i).isInView(ch2Location)) {
          continue;
        }
        PVector currCamLocation = cameras.get(i).getTranslation();
        PVector vect1 = PVector.sub(currCamLocation, intersection);
        PVector vect2 = PVector.sub(selectedCameraLocation, intersection);
        float dotP = vect1.dot(vect2) / (vect1.mag() * vect2.mag());
        if (acos(dotP) <= PI / 6) {
          cameras.get(i).setColor(255, 0, 0);
        } else {
          cameras.get(i).setColor(0, 0, 255);
        }
      }
    }
Beispiel #12
0
 /**
  * Given two points p1, p2 and a line passing through a,b check whether p1 and p2 are on the
  * same side of the line. In our case a,b are characters and p1, p2 are cameras
  */
 public boolean isInSameHalfPlane(PVector p1, PVector p2, PVector a, PVector b) {
   PVector copyP1 = new PVector(p1.x, p1.y, p1.z);
   PVector copyP2 = new PVector(p2.x, p2.y, p2.z);
   PVector copyA = new PVector(a.x, a.y, a.z);
   PVector copyB = new PVector(b.x, b.y, b.z);
   copyB.sub(copyA);
   copyP1.sub(copyA);
   copyP2.sub(copyA);
   PVector p1a = copyB.cross(copyP1);
   PVector p2a = copyB.cross(copyP2);
   if (p1a.dot(p2a) > 0) {
     return true;
   }
   return false;
 }
Beispiel #13
0
 public boolean isInView(PVector vect) {
   PVector z = getZAxis();
   PVector v1 = PVector.sub(vect, getTranslation());
   float dotP = PVector.dot(v1, z) / (z.mag() * v1.mag());
   if ((acos(dotP) * 180 / PI) <= fov) {
     return true;
   }
   return false;
 }