Ejemplo n.º 1
0
 @Override
 public Selection getSelection() {
   Coordinates center = new Coordinates();
   for (Node node : nodes) {
     center.add(node.getPos());
   }
   return State.getInstance().getMapInfo().select(center.scale(1f / nodes.length));
 }
Ejemplo n.º 2
0
  /**
   * Renders the tile to the given context, in the process building all needed resources.
   *
   * @param gl
   */
  public void render(GL gl) {
    projection = ProjectionFactory.getCurrentProjection();
    heightmap = State.getInstance().getLoadedHeightmap();

    // BUILD TEXTURES IF NECESSARY
    if (!gl.glIsTexture(textureID)) {
      textureID = createTexture(gl, getImage(), false);
      // prerenderToTexture(gl);
    }
    if (!gl.glIsTexture(grainTextureID)) {
      createGrainTexture(gl);
    }
    // RENDER TILE FROM DISPLAY LIST, OR ELSE BUILD DISPLAY LIST
    if (gl.glIsList(displaylistID)) {
      gl.glCallList(displaylistID);
    } else {
      displaylistID = gl.glGenLists(1);
      gl.glNewList(displaylistID, GL_COMPILE_AND_EXECUTE);
      gl.glActiveTexture(GL_TEXTURE0);
      gl.glEnable(GL_TEXTURE_2D);
      gl.glBindTexture(GL_TEXTURE_2D, grainTextureID);
      gl.glActiveTexture(GL_TEXTURE1);
      gl.glEnable(GL_TEXTURE_2D);
      gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
      gl.glBindTexture(GL_TEXTURE_2D, textureID);

      gl.glColor3f(1, 1, 1);
      float[] color = new float[3];
      float hRes = HEIGHT_RESOLUTION - 1;
      float stepSize = bounds.getWidth() / hRes;
      Coordinates pos = new Coordinates();
      for (int x = 0; x < hRes; x++) {
        gl.glBegin(GL_TRIANGLE_STRIP);
        for (int y = 0; y <= hRes; y++) {
          for (int i = 0; i < 2; i++) {
            pos.setLatitude(bounds.getTop() + y * stepSize);
            pos.setLongitude(bounds.getLeft() + (x + i) * stepSize);
            gl.glMultiTexCoord2f(
                GL_TEXTURE0, (x + i) / (float) GRAIN_RESOLUTION, y / (float) GRAIN_RESOLUTION);
            gl.glMultiTexCoord2f(GL_TEXTURE1, (x + i) / hRes, y / hRes);
            float height = heights[x + HEIGHT_BORDER + i][y + HEIGHT_BORDER];
            getHeightColor(color, height);
            float shade = getShade(x + i, y, stepSize);
            gl.glColor3f(color[0] * shade, color[1] * shade, color[2] * shade);
            gl.glVertex3f(pos.getLongitude(), pos.getLatitude(), height);
          }
        }
        gl.glEnd();
      }
      gl.glDisable(GL_TEXTURE_2D);
      gl.glActiveTexture(GL_TEXTURE0);
      renderPOIs(gl);
      gl.glEndList();
    }
  }
Ejemplo n.º 3
0
 @Override
 public void queryElements(Bounds area, Set<MapElement> target, boolean exact) {
   if (isInBounds(area)) {
     if (QTGeographicalOperator.drawFrames) {
       State.getInstance().getActiveRenderer().addFrameToDraw(bounds, Color.black);
     }
     for (QuadTree qt : children) {
       qt.queryElements(area, target, exact);
     }
   }
 }
Ejemplo n.º 4
0
 @Override
 protected void load(MappedByteBuffer mmap) throws IOException {
   String name = Util.readUTFString(mmap);
   this.name = EMPTY.equals(name) ? null : name;
   int len = mmap.getInt();
   this.nodes = new Node[len];
   MapInfo mapInfo = State.getInstance().getMapInfo();
   for (int i = 0; i < len; i++) {
     this.nodes[i] = mapInfo.getNode(mmap.getInt());
   }
   this.wayInfo = WayInfo.loadFromInput(mmap);
 }
Ejemplo n.º 5
0
 @Override
 protected void load(DataInput input) throws IOException {
   String name = input.readUTF();
   this.name = EMPTY.equals(name) ? null : name;
   int len = input.readInt();
   this.nodes = new Node[len];
   MapInfo mapInfo = State.getInstance().getMapInfo();
   for (int i = 0; i < len; i++) {
     this.nodes[i] = mapInfo.getNode(input.readInt());
   }
   this.wayInfo = WayInfo.loadFromInput(input);
 }
Ejemplo n.º 6
0
 private void renderPOIs(GL gl) {
   Collection<MapElement> elements =
       State.getInstance().getMapInfo().queryElements(detailLevel, bounds, false);
   if (elements.size() == 0) {
     return;
   }
   for (MapElement element : elements) {
     if (!element.isInBounds(bounds)) {
       continue;
     }
     if (element instanceof POINode) {
       POINode poi = (POINode) element;
       if ((poi.getInfo().getName() != null)
           && (poi.getInfo().getName().length() > 0)
           && (poi.getInfo().getCategory() != OSMType.FAVOURITE)) {
         renderPin(gl, poi.getPos(), COLOR_POI, 1);
       }
     }
   }
 }
Ejemplo n.º 7
0
 @Override
 public void prerender() {
   super.prerender();
   projection = ProjectionFactory.getCurrentProjection();
   Bounds geoBounds =
       new Bounds(
           projection.getGeoCoordinates(bounds.getTopLeft()),
           projection.getGeoCoordinates(bounds.getBottomRight()),
           true);
   State.getInstance().getLoadedHeightmap().reduceSection(geoBounds, getHeights(), HEIGHT_BORDER);
   minHeight = heights[0][0];
   maxHeight = heights[0][0];
   for (int x = 0; x < heights.length; x++) {
     for (int y = 0; y < heights[x].length; y++) {
       if (heights[x][y] < minHeight) {
         minHeight = heights[x][y];
       }
       if (heights[x][y] > maxHeight) {
         maxHeight = heights[x][y];
       }
     }
   }
 }
Ejemplo n.º 8
0
  public void prerenderToTexture(GL gl) {
    int texSize = 256;
    final int[] tmp = new int[1];
    gl.glGenTextures(1, tmp, 0);
    textureID = tmp[0];
    gl.glBindTexture(GL_TEXTURE_2D, textureID);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    gl.glTexImage2D(
        GL_TEXTURE_2D, 0, GL_RGBA, texSize, texSize, 0, GL_BGRA, GL_UNSIGNED_BYTE, null);

    final int[] fbo = new int[1];
    gl.glGenFramebuffersEXT(1, IntBuffer.wrap(fbo));
    gl.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo[0]);
    gl.glFramebufferTexture2DEXT(
        GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureID, 0);

    gl.glDrawBuffers(1, IntBuffer.wrap(new int[] {GL_COLOR_ATTACHMENT0_EXT}));

    final int[] rba = new int[1];
    gl.glGenRenderbuffersEXT(1, IntBuffer.wrap(rba));
    gl.glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rba[0]);
    gl.glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, texSize, texSize);
    gl.glFramebufferRenderbufferEXT(
        GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rba[0]);

    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glPushAttrib(GL_VIEWPORT_BIT);
    gl.glViewport(0, 0, texSize, texSize);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glOrtho(0, texSize, 0, texSize, 0, 10);
    gl.glMatrixMode(GL.GL_MODELVIEW);

    Set<MapElement> map = State.getInstance().getMapInfo().queryElements(detailLevel, bounds, true);

    gl.glDisable(GL_TEXTURE_2D);
    gl.glColor3f(1, 1, 1);
    for (MapElement element : map) {
      if (element instanceof Street) {
        drawLine(
            gl,
            ((Street) element).getDrawingSize() / (float) Projection.getZoomFactor(detailLevel),
            ((Street) element).getNodes());
      }
    }
    gl.glColor3f(0.3f, 0.3f, 0.3f);
    for (MapElement element : map) {
      if ((element instanceof Area) && (((Area) element).getWayInfo().isBuilding())) {
        gl.glBegin(GL_POLYGON);
        for (Node node : ((Area) element).getNodes()) {
          Coordinates pos = getLocalCoordinates(node.getPos());
          gl.glVertex3f(pos.getLongitude(), pos.getLatitude(), 0f);
        }
        gl.glEnd();
      }
    }

    gl.glEnable(GL_TEXTURE_2D);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopAttrib();
    gl.glPopMatrix();

    gl.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    gl.glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
    gl.glDeleteFramebuffersEXT(1, fbo, 0);
    gl.glDeleteRenderbuffersEXT(1, rba, 0);
  }