diff --git a/src/org/oscim/renderer/GLRenderer.java b/src/org/oscim/renderer/GLRenderer.java index c02cba8a..9324a134 100644 --- a/src/org/oscim/renderer/GLRenderer.java +++ b/src/org/oscim/renderer/GLRenderer.java @@ -77,6 +77,8 @@ public class GLRenderer implements GLSurfaceView.Renderer { private static float[] mMVPMatrix = new float[16]; private static float[] mProjMatrix = new float[16]; + // 'flat' projection used for clipping by depth buffer + private static float[] mfProjMatrix = new float[16]; private static float[] mTmpMatrix = new float[16]; private static float[] mTileCoords = new float[8]; private static float[] mDebugCoords = new float[8]; @@ -351,7 +353,7 @@ public class GLRenderer implements GLSurfaceView.Renderer { Matrix.multiplyMM(matrix, 0, mapPosition.viewMatrix, 0, matrix, 0); if (project) - Matrix.multiplyMM(matrix, 0, mProjMatrix, 0, matrix, 0); + Matrix.multiplyMM(matrix, 0, mfProjMatrix, 0, matrix, 0); } private static float scaleDiv(MapTile t) { @@ -577,6 +579,7 @@ public class GLRenderer implements GLSurfaceView.Renderer { mMapViewPosition.getMapPosition(mapPosition, mDebugCoords); Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mapPosition.viewMatrix, 0); + PolygonRenderer.debugDraw(mMVPMatrix, mDebugCoords, 1); } @@ -644,14 +647,14 @@ public class GLRenderer implements GLSurfaceView.Renderer { } } - if (tile.layers.textureLayers != null) { - setMatrix(mvp, tile, div, false); - - for (Layer l = tile.layers.textureLayers; l != null;) { - l = TextureRenderer.draw(l, 1, mProjMatrix, mvp, - tile.layers.texOffset); - } - } + // if (tile.layers.textureLayers != null) { + // setMatrix(mvp, tile, div, false); + // + // for (Layer l = tile.layers.textureLayers; l != null;) { + // l = TextureRenderer.draw(l, 1, mProjMatrix, mvp, + // tile.layers.texOffset); + // } + // } } private static boolean drawProxyChild(MapTile tile) { @@ -730,7 +733,7 @@ public class GLRenderer implements GLSurfaceView.Renderer { MapViewPosition.VIEW_FAR); Matrix.setIdentityM(mTmpMatrix, 0); - Matrix.translateM(mTmpMatrix, 0, 0, 0, -MapViewPosition.VIEW_DISTANCE); + Matrix.translateM(mTmpMatrix, 0, 0, 0, -MapViewPosition.VIEW_DISTANCE * 2); Matrix.multiplyMM(mProjMatrix, 0, mProjMatrix, 0, mTmpMatrix, 0); if (debugView) { @@ -741,9 +744,10 @@ public class GLRenderer implements GLSurfaceView.Renderer { Matrix.multiplyMM(mProjMatrix, 0, mMVPMatrix, 0, mProjMatrix, 0); } + System.arraycopy(mProjMatrix, 0, mfProjMatrix, 0, 16); // set to zero: we modify the z value with polygon-offset for clipping - mProjMatrix[10] = 0; - mProjMatrix[14] = 0; + mfProjMatrix[10] = 0; + mfProjMatrix[14] = 0; GLES20.glViewport(0, 0, width, height); diff --git a/src/org/oscim/renderer/overlays/OverlayText.java b/src/org/oscim/renderer/overlays/OverlayText.java index 2b272163..b8b3c4a8 100644 --- a/src/org/oscim/renderer/overlays/OverlayText.java +++ b/src/org/oscim/renderer/overlays/OverlayText.java @@ -274,7 +274,7 @@ public class OverlayText extends RenderOverlay { } @Override - protected float setMatrix(MapPosition curPos, float[] matrix) { + protected void setMatrix(MapPosition curPos, float[] matrix) { // TODO if oPos == curPos this could be simplified MapPosition oPos = mMapPosition; @@ -301,7 +301,5 @@ public class OverlayText extends RenderOverlay { matrix[5] = scale; Matrix.multiplyMM(matrix, 0, curPos.viewMatrix, 0, matrix, 0); - - return div; } } diff --git a/src/org/oscim/renderer/overlays/RenderOverlay.java b/src/org/oscim/renderer/overlays/RenderOverlay.java index ea845dee..8b519e6d 100644 --- a/src/org/oscim/renderer/overlays/RenderOverlay.java +++ b/src/org/oscim/renderer/overlays/RenderOverlay.java @@ -98,7 +98,8 @@ public abstract class RenderOverlay { * current projection matrix */ public synchronized void render(MapPosition pos, float[] mv, float[] proj) { - float div = setMatrix(pos, mv); + setMatrix(pos, mv); + float div = FastMath.pow(mMapPosition.zoomLevel - pos.zoomLevel); Matrix.multiplyMM(mvp, 0, proj, 0, mv, 0); @@ -121,8 +122,12 @@ public abstract class RenderOverlay { } } - // set matrix to scale relative to zoomlevel - protected float setMatrix(MapPosition curPos, float[] matrix) { + /** + * Utility: set matrix to scale relative to zoomlevel + * @param curPos ... + * @param matrix ... + */ + protected void setMatrix(MapPosition curPos, float[] matrix) { // TODO if oPos == curPos this could be simplified MapPosition oPos = mMapPosition; @@ -155,7 +160,5 @@ public abstract class RenderOverlay { matrix[5] = scale; Matrix.multiplyMM(matrix, 0, curPos.viewMatrix, 0, matrix, 0); - - return div; } } diff --git a/src/org/oscim/view/MapViewPosition.java b/src/org/oscim/view/MapViewPosition.java index c139381f..96de9f46 100644 --- a/src/org/oscim/view/MapViewPosition.java +++ b/src/org/oscim/view/MapViewPosition.java @@ -15,6 +15,9 @@ */ package org.oscim.view; +// TODO: +// - fix ray intersection for unproject, see getZ() + import java.lang.ref.WeakReference; import org.oscim.core.BoundingBox; @@ -28,7 +31,6 @@ import android.opengl.Matrix; import android.os.Handler; import android.os.Message; import android.os.SystemClock; -import android.util.FloatMath; import android.util.Log; /** @@ -84,10 +86,10 @@ public class MapViewPosition { private float[] mTmpMatrix = new float[16]; private static int mHeight, mWidth; - public final static float VIEW_SCALE = 1f / 2; - public final static float VIEW_DISTANCE = 2; + public final static float VIEW_SCALE = 1f / 4; + public final static float VIEW_DISTANCE = 1; public final static float VIEW_NEAR = VIEW_DISTANCE; - public final static float VIEW_FAR = VIEW_DISTANCE * 2; + public final static float VIEW_FAR = VIEW_DISTANCE * 4; void setViewport(int width, int height) { float sw = VIEW_SCALE; @@ -98,7 +100,7 @@ public class MapViewPosition { aspect * sh, -aspect * sh, VIEW_NEAR, VIEW_FAR); Matrix.setIdentityM(mTmpMatrix, 0); - Matrix.translateM(mTmpMatrix, 0, 0, 0, -VIEW_DISTANCE); + Matrix.translateM(mTmpMatrix, 0, 0, 0, -VIEW_DISTANCE * 2); Matrix.multiplyMM(mProjMatrix, 0, mProjMatrix, 0, mTmpMatrix, 0); Matrix.invertM(mProjMatrixI, 0, mProjMatrix, 0); @@ -229,10 +231,11 @@ public class MapViewPosition { * needed to un-project a point on screen to the position on the map. not * so sure about this, but at least somehow works. */ private float getZ(float y) { - return FloatMath.sin((float) Math.toRadians(mTilt)) - // * 2.2f // for dist = 1 - * 1.3f // for dist = 2 - // * 0.8f // for dist = 4 + return (float) Math.sin(Math.toRadians(mTilt)) + //* 2.2f // for dist = 1 + //* 1.3f // for dist = 2 + //* 0.8f // for dist = 4 + * 0.5f * ((float) mHeight / mWidth) * y; } @@ -335,7 +338,8 @@ public class MapViewPosition { private void unproject(float x, float y, float z, float[] coords, int position) { mv[0] = x; mv[1] = y; - mv[2] = z - 1f; + // -1f when near plane is 1 and map is on near plane.. + mv[2] = z + 0.4f; mv[3] = 1; Matrix.multiplyMV(mv, 0, mUnprojMatrix, 0, mv, 0);