Example #1
0
  public static int fade(int color, double alpha) {
    alpha = FastMath.clamp(alpha, 0, 1);

    alpha *= (color >>> 24) & 0xff;
    int c = (((int) alpha) & 0xff) << 24;

    return c | (color & 0x00ffffff);
  }
Example #2
0
  public static int fadePremul(int color, double alpha) {
    alpha = FastMath.clamp(alpha, 0, 1);

    alpha *= (color >>> 24) & 0xff;
    int c = (((int) alpha) & 0xff) << 24;

    alpha /= 255;

    c |= ((int) (alpha * ((color >>> 16) & 0xff))) << 16;
    c |= ((int) (alpha * ((color >>> 8) & 0xff))) << 8;
    c |= ((int) (alpha * (color & 0xff)));

    return c;
  }
Example #3
0
  public void add(MapElement element) {
    if (element.type != GeometryType.TRIS) return;

    short[] index = element.index;
    float[] points = element.points;

    int vertexCnt = sumVertices;

    Vertex key = vertexPool.get();
    double scale = S * Tile.SIZE / 4096;

    for (int k = 0, n = index.length; k < n; ) {
      if (index[k] < 0) break;

      /* FIXME: workaround: dont overflow max index id. */
      if (vertexCnt >= 1 << 16) break;

      int vtx1 = index[k++] * 3;
      int vtx2 = index[k++] * 3;
      int vtx3 = index[k++] * 3;

      float vx1 = points[vtx1 + 0];
      float vy1 = points[vtx1 + 1];
      float vz1 = points[vtx1 + 2];

      float vx2 = points[vtx2 + 0];
      float vy2 = points[vtx2 + 1];
      float vz2 = points[vtx2 + 2];

      float vx3 = points[vtx3 + 0];
      float vy3 = points[vtx3 + 1];
      float vz3 = points[vtx3 + 2];

      float ax = vx2 - vx1;
      float ay = vy2 - vy1;
      float az = vz2 - vz1;

      float bx = vx3 - vx1;
      float by = vy3 - vy1;
      float bz = vz3 - vz1;

      float cx = ay * bz - az * by;
      float cy = az * bx - ax * bz;
      float cz = ax * by - ay * bx;

      double len = Math.sqrt(cx * cx + cy * cy + cz * cz);

      // packing the normal in two bytes
      //	int mx = FastMath.clamp(127 + (int) ((cx / len) * 128), 0, 0xff);
      //	int my = FastMath.clamp(127 + (int) ((cy / len) * 128), 0, 0xff);
      //	short normal = (short) ((my << 8) | (mx & NORMAL_DIR_MASK) | (cz > 0 ? 1 : 0));

      double p = Math.sqrt((cz / len) * 8.0 + 8.0);
      int mx = FastMath.clamp(127 + (int) ((cx / len / p) * 128), 0, 255);
      int my = FastMath.clamp(127 + (int) ((cy / len / p) * 128), 0, 255);
      short normal = (short) ((my << 8) | mx);

      if (key == null) key = vertexPool.get();

      key.set((short) (vx1 * scale), (short) (vy1 * scale), (short) (vz1 * scale), normal);

      Vertex vertex = mVertexMap.put(key, false);

      if (vertex == null) {
        key.id = vertexCnt++;
        addVertex(key);
        addIndex(key);
        key = vertexPool.get();
      } else {
        // numIndexHits++;
        addIndex(vertex);
      }

      key.set((short) (vx2 * scale), (short) (vy2 * scale), (short) (vz2 * scale), normal);

      vertex = mVertexMap.put(key, false);

      if (vertex == null) {
        key.id = vertexCnt++;
        addVertex(key);
        addIndex(key);
        key = vertexPool.get();
      } else {
        // numIndexHits++;
        addIndex(vertex);
      }

      key.set((short) (vx3 * scale), (short) (vy3 * scale), (short) (vz3 * scale), (short) normal);

      vertex = mVertexMap.put(key, false);
      if (vertex == null) {
        key.id = vertexCnt++;
        addVertex(key);
        addIndex(key);
        key = vertexPool.get();
      } else {
        // numIndexHits++;
        addIndex(vertex);
      }
    }

    vertexPool.release(key);

    sumVertices = vertexCnt;
  }
Example #4
0
 /**
  * @param lat the latitude in degrees, will be limited to the possible latitude range.
  * @param lon the longitude in degrees, will be limited to the possible longitude range.
  */
 public GeoPoint(double lat, double lon) {
   lat = FastMath.clamp(lat, MercatorProjection.LATITUDE_MIN, MercatorProjection.LATITUDE_MAX);
   this.latitudeE6 = (int) (lat * CONVERSION_FACTOR);
   lon = FastMath.clamp(lon, MercatorProjection.LONGITUDE_MIN, MercatorProjection.LONGITUDE_MAX);
   this.longitudeE6 = (int) (lon * CONVERSION_FACTOR);
 }