private void renderPin(GL gl, Coordinates position, float[] color, float size) { float height = heightmap.getHeight(projection.getGeoCoordinates(position)); gl.glPushMatrix(); double[] model = new double[16]; gl.glGetDoublev(GL_MODELVIEW_MATRIX, model, 0); double zoomH = 0.1 / Math.sqrt((model[0] * model[0]) + (model[1] * model[1]) + (model[2] * model[2])); double zoomZ = 0.1 / Math.sqrt((model[8] * model[8]) + (model[9] * model[9]) + (model[10] * model[10])); gl.glTranslatef(position.getLongitude(), position.getLatitude(), height); gl.glScaled(zoomH * size, zoomH * size, zoomZ * size); gl.glDisable(GL_TEXTURE_2D); gl.glRotatef(20, 0.3f, 1, 0); GLU glu = new GLU(); GLUquadric quadric = glu.gluNewQuadric(); // glu.gluQuadricNormals(quadric, GLU.GLU_FLAT); gl.glColor3f(0.5f, 0.5f, 0.5f); gl.glEnable(GL_LIGHTING); glu.gluCylinder(quadric, 0.03, 0.03, 0.6f, 5, 1); gl.glTranslatef(0, 0, 0.6f); gl.glColor3f(color[0], color[1], color[2]); gl.glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glu.gluSphere(quadric, 0.12, 8, 8); // glu.gluCylinder(quadric, 0.2, 0.1, 0.5, 8, 1); gl.glDisable(GL_LIGHTING); glu.gluDeleteQuadric(quadric); gl.glPopMatrix(); }
@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)); }
public void createChildren() { children = new DividerTree[4]; float width = bounds.getWidth() / 2; float height = bounds.getHeight() / 2; for (int i = 0; i < 4; i++) { Coordinates topLeft = bounds.getTopLeft().add(height * (i % 2), width * (i / 2)); children[i] = new DividerTree(new Bounds(topLeft, topLeft.clone().add(height, width))); } };
/** * 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(); } }
/** * Tests whether this tile is in the given view frustum. If the tile was not loaded so far, the * test will assume a minimum height of -500 and a maximum height of 8000. * * @param frustum the current view frustum * @return whether the tile is in the frustum */ boolean isInFrustum(Frustum frustum) { Coordinates center = bounds.getCenter(); return (frustum == null) || frustum.isBoxWithin( new float[] { center.getLongitude(), center.getLatitude(), 0.5f * (minHeight + maxHeight) }, new float[] { center.getLongitude() - bounds.getLeft(), center.getLatitude() - bounds.getTop(), 0.5f * (maxHeight - minHeight) }); }
private void drawVertex(GL gl, Coordinates point) { gl.glVertex3f(point.getLongitude(), point.getLatitude(), 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); }