This commit is contained in:
Hannes Janetzek 2013-01-06 06:33:25 +01:00
parent a61d2d4804
commit 05e6490d3a
3 changed files with 23 additions and 20 deletions

View File

@ -168,6 +168,8 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
// TODO: building with non simple holes (Berlin): // TODO: building with non simple holes (Berlin):
//if ((tile.zoomLevel != 17) || (tile.tileX == 70428 && tile.tileY == 43009)), //if ((tile.zoomLevel != 17) || (tile.tileX == 70428 && tile.tileY == 43009)),
//if ((tile.zoomLevel != 17) || (tile.tileX == 70463 && tile.tileY == 42990)) //if ((tile.zoomLevel != 17) || (tile.tileX == 70463 && tile.tileY == 42990))
// FIXME 180 degree angle in building
//if ((tile.zoomLevel != 17) || (tile.tileX == 68728 && tile.tileY == 42634))
if (mMapDatabase.executeQuery(tile, this) != QueryResult.SUCCESS) { if (mMapDatabase.executeQuery(tile, this) != QueryResult.SUCCESS) {
//Log.d(TAG, "Failed loading: " + tile); //Log.d(TAG, "Failed loading: " + tile);
@ -198,9 +200,6 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
mLayers = null; mLayers = null;
mLabels = null; mLabels = null;
if (tile.layers.extrusionLayers != null)
((ExtrusionLayer) tile.layers.extrusionLayers).ready = true;
return true; return true;
} }

View File

@ -30,6 +30,8 @@ import android.util.Log;
/** /**
* @author Hannes Janetzek * @author Hannes Janetzek
* FIXME check if polygon has self intersections or 0/180 degree
* angles!!!
*/ */
public class ExtrusionLayer extends Layer { public class ExtrusionLayer extends Layer {
private final static String TAG = ExtrusionLayer.class.getName(); private final static String TAG = ExtrusionLayer.class.getName();
@ -51,6 +53,9 @@ public class ExtrusionLayer extends Layer {
private final static int IND_ROOF = 2; private final static int IND_ROOF = 2;
private final static int IND_OUTLINE = 3; private final static int IND_OUTLINE = 3;
public boolean compiled = false;
private int[] mVboIds;
public ExtrusionLayer(int level) { public ExtrusionLayer(int level) {
this.type = Layer.EXTRUSION; this.type = Layer.EXTRUSION;
this.layer = level; this.layer = level;
@ -182,8 +187,7 @@ public class ExtrusionLayer extends Layer {
} }
} }
private static short getColor(float vx, float vy) { private static short getColor(float vx, float a) {
float a = (float) Math.sqrt(vx * vx + vy * vy);
float vlight = vx > 0 ? (vx / a) : -(vx / a); float vlight = vx > 0 ? (vx / a) : -(vx / a);
return (short) (220 + (35 * vlight)); return (short) (220 + (35 * vlight));
} }
@ -207,7 +211,8 @@ public class ExtrusionLayer extends Layer {
// vector from previous point // vector from previous point
float ux, uy; float ux, uy;
short color1 = getColor(vx, vy); float a = (float) Math.sqrt(vx * vx + vy * vy);
short color1 = getColor(vx, a);
short fcolor = color1; short fcolor = color1;
short color2 = 0; short color2 = 0;
@ -245,7 +250,7 @@ public class ExtrusionLayer extends Layer {
vertices[v + 2] = 0; vertices[v + 2] = 0;
vertices[v + 6] = h; vertices[v + 6] = h;
// calculate direction to next point // get direction to next point
if (i < len) { if (i < len) {
nx = points[pos + i + 0]; nx = points[pos + i + 0];
ny = points[pos + i + 1]; ny = points[pos + i + 1];
@ -259,11 +264,12 @@ public class ExtrusionLayer extends Layer {
break; break;
} }
// vector to next point
vx = nx - cx; vx = nx - cx;
vy = ny - cy; vy = ny - cy;
color2 = getColor(vx, vy); // set lighting (by direction)
a = (float) Math.sqrt(vx * vx + vy * vy);
color2 = getColor(vx, a);
short c; short c;
if (even == 0) if (even == 0)
@ -271,7 +277,6 @@ public class ExtrusionLayer extends Layer {
else else
c = (short) (color2 | color1 << 8); c = (short) (color2 | color1 << 8);
// set lighting (direction)
vertices[v + 3] = vertices[v + 7] = c; vertices[v + 3] = vertices[v + 7] = c;
color1 = color2; color1 = color2;
@ -395,12 +400,6 @@ public class ExtrusionLayer extends Layer {
compiled = true; compiled = true;
} }
public boolean compiled = false;
int[] mVboIds;
public boolean ready;
@Override @Override
protected void clear() { protected void clear() {
if (compiled) { if (compiled) {

View File

@ -19,6 +19,7 @@ import java.nio.ByteOrder;
import java.nio.ShortBuffer; import java.nio.ShortBuffer;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.generator.JobTile;
import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer;
import org.oscim.renderer.GLState; import org.oscim.renderer.GLState;
import org.oscim.renderer.MapTile; import org.oscim.renderer.MapTile;
@ -105,7 +106,7 @@ public class ExtrusionOverlay extends RenderOverlay {
if (el == null) if (el == null)
continue; continue;
if (el.ready && !el.compiled) { if (!el.compiled) {
el.compile(mShortBuffer); el.compile(mShortBuffer);
GlUtils.checkGlError("..."); GlUtils.checkGlError("...");
} }
@ -139,7 +140,8 @@ public class ExtrusionOverlay extends RenderOverlay {
} }
private static ExtrusionLayer getLayer(MapTile t) { private static ExtrusionLayer getLayer(MapTile t) {
if (t.layers != null && t.layers.extrusionLayers != null) if (t.layers != null && t.layers.extrusionLayers != null
&& t.state == JobTile.STATE_READY)
return (ExtrusionLayer) t.layers.extrusionLayers; return (ExtrusionLayer) t.layers.extrusionLayers;
return null; return null;
} }
@ -162,6 +164,8 @@ public class ExtrusionOverlay extends RenderOverlay {
GLES20.glUniform1i(hExtrusionMode, 0); GLES20.glUniform1i(hExtrusionMode, 0);
GLES20.glUniform4f(hExtrusionColor, 0.6f, 0.6f, 0.6f, 0.8f); GLES20.glUniform4f(hExtrusionColor, 0.6f, 0.6f, 0.6f, 0.8f);
GLState.test(false, false);
for (int i = 0; i < mTileCnt; i++) { for (int i = 0; i < mTileCnt; i++) {
ExtrusionLayer el = (ExtrusionLayer) tiles[i].layers.extrusionLayers; ExtrusionLayer el = (ExtrusionLayer) tiles[i].layers.extrusionLayers;
@ -182,7 +186,6 @@ public class ExtrusionOverlay extends RenderOverlay {
(el.mIndiceCnt[0] + el.mIndiceCnt[1] + el.mIndiceCnt[2]), (el.mIndiceCnt[0] + el.mIndiceCnt[1] + el.mIndiceCnt[2]),
GLES20.GL_UNSIGNED_SHORT, 0); GLES20.GL_UNSIGNED_SHORT, 0);
GLES20.glUniform1i(hExtrusionMode, 0);
GLES20.glUniform4f(hExtrusionColor, 1.0f, 0.5f, 0.5f, 0.9f); GLES20.glUniform4f(hExtrusionColor, 1.0f, 0.5f, 0.5f, 0.9f);
GLES20.glDrawElements(GLES20.GL_LINES, el.mIndiceCnt[3], GLES20.glDrawElements(GLES20.GL_LINES, el.mIndiceCnt[3],
@ -317,7 +320,9 @@ public class ExtrusionOverlay extends RenderOverlay {
float mColor[] = { 201 / 255f, 200 / 255f, 198 / 255f, 0.8f }; float mColor[] = { 201 / 255f, 200 / 255f, 198 / 255f, 0.8f };
float mColor2[] = { 201 / 255f, 200 / 255f, 199 / 255f, 0.8f }; float mColor2[] = { 201 / 255f, 200 / 255f, 199 / 255f, 0.8f };
float mRoofColor[] = { 0.895f, 0.89f, 0.88f, 0.9f }; //float mRoofColor[] = { 0.895f, 0.89f, 0.88f, 0.9f };
float _a = 0.8f;
float mRoofColor[] = { 236 / 255f * _a, 235 / 255f * _a, 234 / 255f * _a, _a };
final static String extrusionVertexShader = "" final static String extrusionVertexShader = ""
+ "precision mediump float;" + "precision mediump float;"