Beispiel #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);
  }
  /** Render all 'layers' */
  @Override
  public synchronized void render(MapPosition curPos, Matrices m) {
    MapPosition pos = mMapPosition;

    float div = FastMath.pow(pos.zoomLevel - curPos.zoomLevel);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, layers.vbo.id);
    GLState.test(false, false);
    GLState.blend(true);
    int simple = (curPos.tilt < 1 ? 1 : 0);

    if (layers.baseLayers != null) {
      setMatrix(curPos, m, true);

      for (Layer l = layers.baseLayers; l != null; ) {
        switch (l.type) {
          case Layer.POLYGON:
            l = PolygonRenderer.draw(curPos, l, m, true, 1, false);
            break;

          case Layer.LINE:
            l = LineRenderer.draw(layers, l, curPos, m, div, simple);
            break;

          case Layer.TEXLINE:
            l = LineTexRenderer.draw(layers, l, curPos, m, div);
            break;
        }
      }
    }

    if (layers.textureLayers != null) {
      setMatrix(curPos, m, false);

      float scale = (float) (pos.scale / curPos.scale);

      for (Layer l = layers.textureLayers; l != null; ) {
        switch (l.type) {
          case Layer.BITMAP:
            l = BitmapRenderer.draw(l, 1, m);
            break;

            //					case Layer.SYMBOL:
            //						l = BitmapRenderer.draw(l, 1, m);
            //						break;

          default:
            l = TextureRenderer.draw(l, scale, m);
        }
      }
    }
  }
Beispiel #3
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;
  }
Beispiel #4
0
  /**
   * Get the current MapPosition.
   *
   * @param pos MapPosition to be updated.
   * @return true iff current position is different from passed position.
   */
  public boolean getMapPosition(MapPosition pos) {

    boolean changed =
        (pos.scale != mPos.scale
            || pos.x != mPos.x
            || pos.y != mPos.y
            || pos.bearing != mPos.bearing
            || pos.tilt != mPos.tilt);

    pos.bearing = mPos.bearing;
    pos.tilt = mPos.tilt;

    pos.x = mPos.x;
    pos.y = mPos.y;
    pos.scale = mPos.scale;
    pos.zoomLevel = FastMath.log2((int) mPos.scale);

    return changed;
  }
Beispiel #5
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;
  }
Beispiel #6
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);
 }