コード例 #1
0
ファイル: Area.java プロジェクト: route-a-lot/route-a-lot
 @Override
 public boolean isInBounds(Bounds bounds) {
   // TODO there is no float polygon, so I have to think about s.th. else (or leave it the way it
   // is now)
   int x[] = new int[nodes.length];
   int y[] = new int[nodes.length];
   int i = 0;
   for (Node node : nodes) {
     x[i] = (int) (node.getPos().getLongitude() * 1000); // 1000 is a random factor, can be changed
     i++;
   }
   i = 0;
   for (Node node : nodes) {
     y[i] = (int) (node.getPos().getLatitude() * 1000);
     i++;
   }
   Polygon area = new Polygon(x, y, nodes.length);
   Rectangle2D.Double box =
       new Rectangle2D.Double(
           bounds.getLeft() * 1000 - 1,
           bounds.getTop() * 1000 - 1,
           bounds.getWidth() * 1000 + 1,
           bounds.getHeight() * 1000 + 1);
   boolean inside = false;
   for (Node node : nodes) {
     if (node.isInBounds(bounds)) {
       inside = true;
     }
   }
   return inside || area.contains(box) || area.intersects(box);
 }
コード例 #2
0
ファイル: Tile3D.java プロジェクト: route-a-lot/route-a-lot
 private void drawLine(GL gl, float size, Node[] line) {
   gl.glLineWidth(size);
   gl.glPointSize(size);
   gl.glBegin(GL.GL_LINE_STRIP);
   for (Node pos : line) {
     drawVertex(gl, getLocalCoordinates(pos.getPos()));
   }
   gl.glEnd();
   gl.glBegin(GL.GL_POINTS);
   for (Node pos : line) {
     drawVertex(gl, getLocalCoordinates(pos.getPos()));
   }
   gl.glEnd();
 }
コード例 #3
0
ファイル: Area.java プロジェクト: route-a-lot/route-a-lot
 @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));
 }
コード例 #4
0
ファイル: Tile3D.java プロジェクト: route-a-lot/route-a-lot
  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);
  }