From a6a729244fe38bbd4ca165f22c62987f31446d7c Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Sat, 6 Apr 2013 17:44:57 +0200 Subject: [PATCH] added MapLensOverlay --- src/org/oscim/core/MapPosition.java | 6 +- src/org/oscim/renderer/PolygonRenderer.java | 16 +++-- src/org/oscim/renderer/TileRenderer.java | 14 +++- src/org/oscim/view/MapView.java | 7 +- src/org/oscim/view/MapViewPosition.java | 79 ++++++++++++--------- 5 files changed, 74 insertions(+), 48 deletions(-) diff --git a/src/org/oscim/core/MapPosition.java b/src/org/oscim/core/MapPosition.java index d518236a..7bf9ab82 100644 --- a/src/org/oscim/core/MapPosition.java +++ b/src/org/oscim/core/MapPosition.java @@ -21,7 +21,10 @@ public class MapPosition { public double lon; public double lat; - public int zoomLevel; + public double absX; + public double absY; + public double absScale; + public float scale; public float angle; public float tilt; @@ -29,6 +32,7 @@ public class MapPosition { // map center in tile coordinates of current zoom-level public double x; public double y; + public int zoomLevel; public MapPosition() { this.zoomLevel = (byte) 1; diff --git a/src/org/oscim/renderer/PolygonRenderer.java b/src/org/oscim/renderer/PolygonRenderer.java index 4a5cee2e..fdb611d1 100644 --- a/src/org/oscim/renderer/PolygonRenderer.java +++ b/src/org/oscim/renderer/PolygonRenderer.java @@ -294,7 +294,7 @@ public final class PolygonRenderer { } } - public static void drawOver(Matrices m) { + public static void drawOver(Matrices m, boolean drawColor, int color) { if (GLState.useProgram(polygonProgram)) { GLState.enableVertexArrays(hPolygonVertexPosition, -1); @@ -310,9 +310,13 @@ public final class PolygonRenderer { * a quad with func 'always' and op 'zero' */ - // disable drawing to framebuffer (will be re-enabled in fill) - glColorMask(false, false, false, false); - + if (drawColor) { + GlUtils.setColor(hPolygonColor, color, 1); + GLState.blend(true); + } else { + // disable drawing to framebuffer (will be re-enabled in fill) + glColorMask(false, false, false, false); + } // always pass stencil test: glStencilFunc(GL_ALWAYS, 0x00, 0x00); // write to all bits @@ -321,7 +325,9 @@ public final class PolygonRenderer { glStencilOp(GLES20.GL_KEEP, GLES20.GL_KEEP, GLES20.GL_ZERO); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glColorMask(true, true, true, true); + + if (!drawColor) + glColorMask(true, true, true, true); } private static float[] debugFillColor = { 0.3f, 0.0f, 0.0f, 0.3f }; diff --git a/src/org/oscim/renderer/TileRenderer.java b/src/org/oscim/renderer/TileRenderer.java index 55b9e6d1..1ed30337 100644 --- a/src/org/oscim/renderer/TileRenderer.java +++ b/src/org/oscim/renderer/TileRenderer.java @@ -22,6 +22,7 @@ import org.oscim.core.MapPosition; import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.layer.Layer; import org.oscim.utils.FastMath; +import org.oscim.utils.Matrix4; import android.opengl.GLES20; @@ -44,10 +45,17 @@ public class TileRenderer { private static Matrices mMatrices; + private static final Matrix4 mProjMatrix = new Matrix4(); + static void draw(MapTile[] tiles, int tileCnt, MapPosition pos, Matrices m) { mDrawCnt = 0; mMatrices = m; + mProjMatrix.copy(m.viewproj); + // discard z projection from tilt + mProjMatrix.setValue(10, 0); + mProjMatrix.setValue(14, 0); + GLES20.glDepthFunc(GLES20.GL_LESS); // load texture for line caps @@ -116,11 +124,11 @@ public class TileRenderer { Matrices m = mMatrices; m.mvp.setTransScale(x * scale, y * scale, scale / GLRenderer.COORD_SCALE); - m.mvp.multiplyMM(m.viewproj, m.mvp); + m.mvp.multiplyMM(mProjMatrix, m.mvp); // set depth offset (used for clipping to tile boundaries) GLES20.glPolygonOffset(1, mDrawCnt++); - if (mDrawCnt > 20) + if (mDrawCnt == 100) mDrawCnt = 0; // simple line shader does not take forward shortening into account @@ -160,7 +168,7 @@ public class TileRenderer { } // clear clip-region and could also draw 'fade-effect' - PolygonRenderer.drawOver(m); + PolygonRenderer.drawOver(m, true, 0x22000000); } private static int drawProxyChild(MapTile tile, MapPosition pos) { diff --git a/src/org/oscim/view/MapView.java b/src/org/oscim/view/MapView.java index 6af5906f..8383d7ba 100644 --- a/src/org/oscim/view/MapView.java +++ b/src/org/oscim/view/MapView.java @@ -38,14 +38,13 @@ import org.oscim.generator.JobTile; import org.oscim.generator.MapWorker; import org.oscim.generator.TileGenerator; import org.oscim.overlay.BuildingOverlay; -import org.oscim.overlay.GenericOverlay; import org.oscim.overlay.LabelingOverlay; +import org.oscim.overlay.MapLensOverlay; import org.oscim.overlay.Overlay; import org.oscim.overlay.OverlayManager; import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLView; import org.oscim.renderer.TileManager; -import org.oscim.renderer.overlays.TileOverlay; import org.oscim.theme.ExternalRenderTheme; import org.oscim.theme.InternalRenderTheme; import org.oscim.theme.RenderTheme; @@ -197,8 +196,8 @@ public class MapView extends RelativeLayout { mOverlayManager.add(new LabelingOverlay(this)); - mOverlayManager.add(new GenericOverlay(this, new TileOverlay(this))); - + //mOverlayManager.add(new GenericOverlay(this, new TileOverlay(this))); + mOverlayManager.add(new MapLensOverlay(this)); //mOverlayManager.add(new GenericOverlay(this, new CustomOverlay(this))); diff --git a/src/org/oscim/view/MapViewPosition.java b/src/org/oscim/view/MapViewPosition.java index a9b3602b..ea66e355 100644 --- a/src/org/oscim/view/MapViewPosition.java +++ b/src/org/oscim/view/MapViewPosition.java @@ -157,6 +157,10 @@ public class MapViewPosition { pos.angle = mRotation; pos.tilt = mTilt; + pos.absX = mAbsX; + pos.absY = mAbsY; + pos.absScale = mAbsScale; + // for tiling pos.scale = scale; pos.zoomLevel = (byte) z; @@ -312,28 +316,33 @@ public class MapViewPosition { return bbox; } -// /** -// * For x, y in screen coordinates set Point to map-tile -// * coordinates at returned scale. -// * -// * @param x screen coordinate -// * @param y screen coordinate -// * @param out Point coords will be set -// * @return current map scale -// */ -// public synchronized float getScreenPointOnMap(float x, float y, PointD out) { -// -// // scale to -1..1 -// float mx = 1 - (x / mWidth * 2); -// float my = 1 - (y / mHeight * 2); -// -// unproject(-mx, my, getZ(-my), mu, 0); -// -// out.x = mCurX + mu[0]; -// out.y = mCurY + mu[1]; -// -// return (float) mAbsScale; -// } + /** + * For x, y in screen coordinates set Point to map-tile + * coordinates at returned scale. + * + * @param x screen coordinate + * @param y screen coordinate + * @param out Point coords will be set + */ + public synchronized void getScreenPointOnMap(float x, float y, double scale, PointD out) { + + // scale to -1..1 + float mx = 1 - (x / mWidth * 2); + float my = 1 - (y / mHeight * 2); + + unproject(-mx, my, getZ(-my), mu, 0); + + //out.x = mCurX + mu[0]; + //out.y = mCurY + mu[1]; + + out.x = mu[0]; + out.y = mu[1]; + + if (scale != 0) { + out.x *= scale / mAbsScale; + out.y *= scale / mAbsScale; + } + } /** * Get the GeoPoint for x,y in screen coordinates. @@ -729,23 +738,23 @@ public class MapViewPosition { mHandler.start(mDuration); } + synchronized boolean fling(float adv) { - synchronized boolean fling(float adv){ + //float delta = (mDuration - millisLeft) / mDuration; + adv = (float) Math.sqrt(adv); + float dx = mVelocityX * adv; + float dy = mVelocityY * adv; - //float delta = (mDuration - millisLeft) / mDuration; - adv = (float)Math.sqrt(adv); - float dx = mVelocityX * adv; - float dy = mVelocityY * adv; + if (dx != 0 || dy != 0) { + moveMap((float) (dx - mScrollX), (float) (dy - mScrollY)); - if (dx != 0 || dy != 0){ - moveMap((float)(dx - mScrollX), (float)(dy - mScrollY)); - - mMapView.redrawMap(true); - mScrollX = dx; - mScrollY = dy; + mMapView.redrawMap(true); + mScrollX = dx; + mScrollY = dy; + } + return true; } - return true; -} + private float mVelocityX; private float mVelocityY;