Esempio n. 1
0
 /*Creates the equipment in all states to initiate the game */
 private void fillStates(int sAvail, int sRent, int sShop) {
   int[] statesSizes = {sAvail, sRent, sShop};
   int s = 1;
   for (int stateSize : statesSizes) {
     for (int t = 1; t <= TYPES; t++) {
       for (int i = 1; i <= stateSize; i++) {
         Equipment e = new Equipment();
         e.state = s;
         e.type = t;
         int sMax =
             Math.max(
                 s - 2, 0); /*formula to make sure identifiers resume counting and stay unique */
         int sMin =
             Math.min(
                 s - 1, 1); /*formula to make sure identifiers resume counting and stay unique */
         e.ident = i + (sMin) * sAvail + (sMax) * sRent;
         e.c = equipColor(e.type);
         switch (s) {
           case 1:
             availEquipment.add(e);
             break;
           case 2:
             rentEquipment.add(e);
             break;
           case 3:
             shopEquipment.add(e);
             break;
         }
       }
     }
     s++;
   }
   computeInitialTimes();
   assignShapes();
 }
Esempio n. 2
0
  // APPLY LIGHTING CALCULATIONS TO VERTEX USING ITS MATERIAL
  private void lightPoint(double[] vertex, Material material) {

    // NORMAL AT THE VERTEX
    double[] normal = {vertex[3], vertex[4], vertex[5]};

    // RESET TEMPORARY COLOR ARRAY
    for (int i = 0; i < tmpCol.length; i++) {
      tmpCol[i] = 0.0;
    }

    // FOR EACH LIGHT SOURCE
    for (int i = 0; i < lights.length; i++) {

      // LIGHT DIRECTION
      double[] lDir = lights[i][0];

      // REFLECTION DIRECTION
      for (int k = 0; k < lDir.length; k++) {
        tmpVec[k] = 2 * (dot(lDir, normal)) * normal[k] - lDir[k];
      }
      double[] rDir = tmpVec;
      normalize(rDir);

      // FOR EACH COLOR IN RGB
      for (int j = 0; j < 3; j++) {
        tmpCol[j] +=
            tmpMaterial.getAmbientColor()[j]
                + lights[i][1][j]
                    * (tmpMaterial.getDiffuseColor()[j] * Math.max(0.0, dot(lDir, normal))
                        + tmpMaterial.getSpecularColor()[j]
                            * Math.pow(
                                Math.max(0.0, dot(rDir, eyeDir)), tmpMaterial.getSpecularPower()));
      }
    }

    // GAMMA CORRECTION

    if (!showNormals) {
      vertex[6] = 255.0 * Math.pow(tmpCol[0], 0.45);
      vertex[7] = 255.0 * Math.pow(tmpCol[1], 0.45);
      vertex[8] = 255.0 * Math.pow(tmpCol[2], 0.45);
    } else {
      vertex[6] = mapRGB(normal[0]);
      vertex[7] = mapRGB(normal[1]);
      vertex[8] = mapRGB(normal[2]);
    }
  }
Esempio n. 3
0
  public static void main(String[] args) {
    double a = -191.635;
    double b = 43.74;
    int c = 16, d = 45;

    System.out.printf("The absolute value " + "of %.3f is %.3f%n", a, abs(a));

    System.out.printf("The ceiling of " + "%.2f is %.0f%n", b, Math.ceil(b));

    System.out.printf("The floor of " + "%.2f is %.0f%n", b, Math.floor(b));

    System.out.printf("The rint of %.2f " + "is %.0f%n", b, Math.rint(b));

    System.out.printf("The max of %d and " + "%d is %d%n", c, d, Math.max(c, d));

    System.out.printf("The min of of %d " + "and %d is %d%n", c, d, Math.min(c, d));
  }
Esempio n. 4
0
 private int getDistance(int x, int y) {
   return Math.max(Math.abs(CENTRE_OF_VISION - x), Math.abs(CENTRE_OF_VISION - y));
 }