public SuperAlienRifleBullet(
        Main applet,
        PVector position,
        String img,
        float angle,
        int color,
        float radius,
        float health,
        float maxSpeed,
        Weapon weapon,
        float weight,
        PVector startPos) {
      super(
          applet, position, img, angle, color, radius, health, maxSpeed, weapon, weight, startPos);
      start = applet.millis();

      ttl = 0;
      for (int i = 0; i < sprite.sprites.length; ++i) {
        ttl += sprite.sprites[i].getTime();
      }
    }
Example #2
0
  /**
   * Draws the vertices to the screen.
   *
   * @param inpAudioFrameIdx The audio frame to reference for height data.
   */
  public void drawSphere(int inpAudioFrameIdx) {
    _audioFrameDataVals = rtrvAudioFrameData(inpAudioFrameIdx);
    float prevAudioFrameLvlNbr, currAudioFrameLvlNbr;

    if (inpAudioFrameIdx > 0) {
      prevAudioFrameLvlNbr = rtrvAudioFrameData(inpAudioFrameIdx - 1)[0];
    } else {
      prevAudioFrameLvlNbr = 0;
    }

    currAudioFrameLvlNbr = rtrvAudioFrameData(inpAudioFrameIdx)[0];

    // _parApp.noStroke();
    _parApp.stroke(_fillClrNbr);
    _lerpClrAmt = _parApp.frameCount / (float) _musicData.length;
    _fillClrNbr = (int) PApplet.lerpColor(FROM_CLR_NBR, TO_CLR_NBR, _lerpClrAmt, PApplet.RGB);
    _parApp.fill(_fillClrNbr);

    float newVertexHghtNbr = 0,
        adjacentLatitudeLnLatitudeDegNbr = 0,
        adjacentLatitudeLnLongitudeDegNbr = 0,
        adjacentLatitudeLnRadiusLenNbr = 0,
        currLatitudeLnLatitudeDegNbr = 0,
        currLatitudeLnLongitudeDegNbr = 0;
    PVector adjacentVertex, currVertex;
    int adjacentLatitudeVertexIdx = 0, currLatitudeVertexIdx = 0;

    for (int latitudeDegNbr = -90; latitudeDegNbr <= 90; latitudeDegNbr += _resNbr) {

      if (PApplet.abs(latitudeDegNbr) == 90) {
        // Create Triangle Fans for each of the poles.
        _parApp.beginShape(PApplet.TRIANGLE_FAN);

        // Draw the pole vertex.
        currLatitudeVertexIdx = calcVertexIdx(latitudeDegNbr, 0);
        newVertexHghtNbr =
            calcAndStoreNewVertexHghtNbr(
                currLatitudeVertexIdx, prevAudioFrameLvlNbr, currAudioFrameLvlNbr);
        currVertex = Main.toCartesian(latitudeDegNbr, 0, newVertexHghtNbr);
        // _parApp.text("Lat: " + latitudeDegNbr, currVertex.x, currVertex.y, currVertex.z + 20);
        _parApp.vertex(currVertex.x, currVertex.y, currVertex.z);

        float adjacentLatitudeDegNbr;

        if (latitudeDegNbr == -90) {
          adjacentLatitudeDegNbr = latitudeDegNbr + _resNbr;
        } else {
          adjacentLatitudeDegNbr = latitudeDegNbr - _resNbr;
        }

        // In order to complete the sphere, you have to go completely around the circle (i.e.,
        // include both -180 and 180).
        for (int longitudeDegNbr = -180; longitudeDegNbr <= 180; longitudeDegNbr += _resNbr) {

          adjacentLatitudeVertexIdx = calcVertexIdx(adjacentLatitudeDegNbr, longitudeDegNbr);

          if (longitudeDegNbr == 180) {
            // When we complete the circle, use the heights that we used for longitude = -180 to
            // stitch the mesh together.
            newVertexHghtNbr = _radiusLenNbrs[calcVertexIdx(adjacentLatitudeDegNbr, -180)];
          } else {
            // If we're building the second pole, we need to stitch it to the previous ring.
            if (adjacentLatitudeDegNbr == latitudeDegNbr - _resNbr) {
              adjacentLatitudeVertexIdx = calcVertexIdx(adjacentLatitudeDegNbr, longitudeDegNbr);
              newVertexHghtNbr = _radiusLenNbrs[adjacentLatitudeVertexIdx];
            } else {
              newVertexHghtNbr =
                  calcAndStoreNewVertexHghtNbr(
                      adjacentLatitudeVertexIdx, prevAudioFrameLvlNbr, currAudioFrameLvlNbr);
            }
          }

          adjacentVertex =
              Main.toCartesian(adjacentLatitudeDegNbr, longitudeDegNbr, newVertexHghtNbr);
          _parApp.vertex(adjacentVertex.x, adjacentVertex.y, adjacentVertex.z);
        }

        _parApp.endShape();
      } else if (latitudeDegNbr - _resNbr != -90) {
        // We already built a triangle fan for the first pole, so we do not want to build a triangle
        // strip over it.
        _parApp.beginShape(PConstants.TRIANGLE_STRIP);

        // In order to complete the sphere, you have to go completely around the circle (i.e.,
        // include both -180 and 180).
        for (int longitudeDegNbr = -180; longitudeDegNbr <= 180; longitudeDegNbr += _resNbr) {

          if (PApplet.abs(latitudeDegNbr) < 90) {
            adjacentLatitudeVertexIdx = calcVertexIdx(latitudeDegNbr - _resNbr, longitudeDegNbr);
            adjacentLatitudeLnLatitudeDegNbr = _latitudeDegs[adjacentLatitudeVertexIdx];
            adjacentLatitudeLnLongitudeDegNbr = _longitudeDegs[adjacentLatitudeVertexIdx];
            adjacentLatitudeLnRadiusLenNbr = _radiusLenNbrs[adjacentLatitudeVertexIdx];

            adjacentVertex =
                Main.toCartesian(
                    adjacentLatitudeLnLatitudeDegNbr,
                    adjacentLatitudeLnLongitudeDegNbr,
                    adjacentLatitudeLnRadiusLenNbr);
            _parApp.vertex(adjacentVertex.x, adjacentVertex.y, adjacentVertex.z);
          }

          currLatitudeVertexIdx = calcVertexIdx(latitudeDegNbr, longitudeDegNbr);
          currLatitudeLnLatitudeDegNbr = _latitudeDegs[currLatitudeVertexIdx];
          currLatitudeLnLongitudeDegNbr = _longitudeDegs[currLatitudeVertexIdx];

          if (longitudeDegNbr == 180) {
            // When we complete the circle, use the heights that we used for longitude = -180 to
            // stitch the mesh together.
            newVertexHghtNbr = _radiusLenNbrs[calcVertexIdx(latitudeDegNbr, -180)];
          } else {
            newVertexHghtNbr =
                calcAndStoreNewVertexHghtNbr(
                    currLatitudeVertexIdx, prevAudioFrameLvlNbr, currAudioFrameLvlNbr);
          }

          currVertex =
              Main.toCartesian(
                  currLatitudeLnLatitudeDegNbr, currLatitudeLnLongitudeDegNbr, newVertexHghtNbr);
          _parApp.vertex(currVertex.x, currVertex.y, currVertex.z);
        }
        _parApp.endShape();
      }
    }
  }