- keep screen-to-map-plane projection in Matrices so that this stays consistent for a frame

- dont modify map-plane coord array that is passed to ScanBox
This commit is contained in:
Hannes Janetzek 2013-05-07 08:02:45 +02:00
parent 9bbfef02ad
commit 0174c0229d
3 changed files with 93 additions and 98 deletions

View File

@ -26,15 +26,15 @@ import org.oscim.utils.ScanBox;
import org.oscim.view.MapView; import org.oscim.view.MapView;
import android.util.Log; import android.util.Log;
public class TileRenderLayer extends RenderLayer { public class TileRenderLayer extends RenderLayer {
private final static String TAG = TileRenderLayer.class.getName(); private final static String TAG = TileRenderLayer.class.getName();
private final float[] mBoxCoords;
private final TileManager mTileManager; private final TileManager mTileManager;
public TileRenderLayer(MapView mapView, TileManager tileManager) { public TileRenderLayer(MapView mapView, TileManager tileManager) {
super(mapView); super(mapView);
mTileManager = tileManager; mTileManager = tileManager;
mBoxCoords = new float[8];
} }
boolean mFaded; boolean mFaded;
@ -45,10 +45,10 @@ public class TileRenderLayer extends RenderLayer {
@Override @Override
public void update(MapPosition pos, boolean positionChanged, Matrices m) { public void update(MapPosition pos, boolean positionChanged, Matrices m) {
int serial = 0;
mMapPosition.copy(pos); mMapPosition.copy(pos);
int serial = 0;
if (mDrawTiles != null) if (mDrawTiles != null)
serial = mDrawTiles.getSerial(); serial = mDrawTiles.getSerial();
@ -60,25 +60,18 @@ public class TileRenderLayer extends RenderLayer {
if (mDrawTiles == null || mDrawTiles.cnt == 0) if (mDrawTiles == null || mDrawTiles.cnt == 0)
return; return;
boolean changed = false; boolean tilesChanged = false;
//boolean positionChanged = false;
// check if the tiles have changed... // check if tiles have changed.
if (serial != mDrawTiles.getSerial()) { if (serial != mDrawTiles.getSerial())
changed = true; tilesChanged = true;
// FIXME needed?
//positionChanged = true;
}
int tileCnt = mDrawTiles.cnt; int tileCnt = mDrawTiles.cnt;
MapTile[] tiles = mDrawTiles.tiles; MapTile[] tiles = mDrawTiles.tiles;
if (changed || positionChanged){ if (tilesChanged || positionChanged)
float[] box = mBoxCoords; updateTileVisibility(m.mapPlane);
mMapView.getMapViewPosition().getMapViewProjection(box);
updateTileVisibility(box);
}
tileCnt += mNumTileHolder; tileCnt += mNumTileHolder;
/* prepare tile for rendering */ /* prepare tile for rendering */
@ -95,7 +88,6 @@ public class TileRenderLayer extends RenderLayer {
@Override @Override
public void render(MapPosition pos, Matrices m) { public void render(MapPosition pos, Matrices m) {
} }
/** compile tile layer data and upload to VBOs */ /** compile tile layer data and upload to VBOs */
@ -236,12 +228,11 @@ public class TileRenderLayer extends RenderLayer {
td.cnt = 0; td.cnt = 0;
} }
// Add additional tiles that serve as placeholer when flipping // Add additional tiles that serve as placeholer when flipping
// over date-line. // over date-line.
// I dont really like this but cannot think of a better solution: // I dont really like this but cannot think of a better solution:
// the other option would be to run scanbox each time for upload, // The other option would be to run scanbox each time for upload,
// drawing, proxies and text layer. needing to add placeholder only // drawing, proxies and text layer. Adding placeholder only
// happens rarely, unless you live on Fidschi // happens rarely, unless you live on Fidschi
/* package */int mNumTileHolder; /* package */int mNumTileHolder;

View File

@ -74,13 +74,12 @@ public class GLRenderer implements GLSurfaceView.Renderer {
// bytes currently loaded in VBOs // bytes currently loaded in VBOs
private static int mBufferMemoryUsage; private static int mBufferMemoryUsage;
private static float[] mBoxCoords;
public class Matrices { public class Matrices {
// do not modify any of these // do not modify any of these
public final Matrix4 viewproj = new Matrix4(); public final Matrix4 viewproj = new Matrix4();
public final Matrix4 proj = new Matrix4(); public final Matrix4 proj = new Matrix4();
public final Matrix4 view = new Matrix4(); public final Matrix4 view = new Matrix4();
public final float[] mapPlane = new float[8];
// for temporary use by callee // for temporary use by callee
public final Matrix4 mvp = new Matrix4(); public final Matrix4 mvp = new Matrix4();
@ -132,7 +131,6 @@ public class GLRenderer implements GLSurfaceView.Renderer {
mMapPosition = new MapPosition(); mMapPosition = new MapPosition();
mMatrices = new Matrices(); mMatrices = new Matrices();
mBoxCoords = new float[8];
// tile fill coords // tile fill coords
short min = 0; short min = 0;
@ -291,7 +289,7 @@ public class GLRenderer implements GLSurfaceView.Renderer {
| GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT
| GLES20.GL_STENCIL_BUFFER_BIT); | GLES20.GL_STENCIL_BUFFER_BIT);
boolean positionChanged = false; boolean changed = false;
// get current MapPosition, set mBoxCoords (mapping of screen to model // get current MapPosition, set mBoxCoords (mapping of screen to model
// coordinates) // coordinates)
@ -300,10 +298,10 @@ public class GLRenderer implements GLSurfaceView.Renderer {
synchronized (mMapViewPosition) { synchronized (mMapViewPosition) {
mMapViewPosition.updateAnimation(); mMapViewPosition.updateAnimation();
positionChanged = mMapViewPosition.getMapPosition(pos); changed = mMapViewPosition.getMapPosition(pos);
if (positionChanged) if (changed)
mMapViewPosition.getMapViewProjection(mBoxCoords); mMapViewPosition.getMapViewProjection(mMatrices.mapPlane);
mMapViewPosition.getMatrix(mMatrices.view, null, mMatrices.viewproj); mMapViewPosition.getMatrix(mMatrices.view, null, mMatrices.viewproj);
@ -317,7 +315,7 @@ public class GLRenderer implements GLSurfaceView.Renderer {
RenderLayer[] overlays = mMapView.getLayerManager().getRenderLayers(); RenderLayer[] overlays = mMapView.getLayerManager().getRenderLayers();
for (int i = 0, n = overlays.length; i < n; i++) for (int i = 0, n = overlays.length; i < n; i++)
overlays[i].update(mMapPosition, positionChanged, mMatrices); overlays[i].update(pos, changed, mMatrices);
/* draw layers */ /* draw layers */
for (int i = 0, n = overlays.length; i < n; i++) { for (int i = 0, n = overlays.length; i < n; i++) {

View File

@ -33,7 +33,9 @@ import org.oscim.core.Tile;
* */ * */
public abstract class ScanBox { public abstract class ScanBox {
public static void transScale(double x, double y, double scale, int zoom, float[] box){ private final float[] mBox = new float[8];
private float[] transScale(double x, double y, double scale, int zoom, float[] box){
scale *= Tile.SIZE; scale *= Tile.SIZE;
//double curScale = Tile.SIZE * scale; //double curScale = Tile.SIZE * scale;
@ -43,10 +45,12 @@ public abstract class ScanBox {
y *= scale; y *= scale;
for (int i = 0; i < 8; i += 2) { for (int i = 0; i < 8; i += 2) {
box[i + 0] = (float) ((x + box[i + 0]) / div); mBox[i + 0] = (float) ((x + box[i + 0]) / div);
box[i + 1] = (float) ((y + box[i + 1]) / div); mBox[i + 1] = (float) ((y + box[i + 1]) / div);
} }
return mBox;
} }
/* /*
* ported from Polymaps: Layer.js * ported from Polymaps: Layer.js
*/ */
@ -74,6 +78,7 @@ public abstract class ScanBox {
private Edge ab = new Edge(); private Edge ab = new Edge();
private Edge bc = new Edge(); private Edge bc = new Edge();
private Edge ca = new Edge(); private Edge ca = new Edge();
private int minX, maxX; private int minX, maxX;
protected int mZoom; protected int mZoom;
@ -82,7 +87,8 @@ public abstract class ScanBox {
public void scan(double x, double y, double scale, int zoom, float[] box) { public void scan(double x, double y, double scale, int zoom, float[] box) {
mZoom = zoom; mZoom = zoom;
transScale(x, y, scale, zoom, box); // this does not modify 'box' parameter
box = transScale(x, y, scale, zoom, box);
// clip result to min/max as steep angles // clip result to min/max as steep angles
// cause overshooting in x direction. // cause overshooting in x direction.