use setTileMatrix utility function
This commit is contained in:
parent
5b3b299217
commit
bfe8cf2889
@ -22,6 +22,7 @@ import static org.oscim.generator.JobTile.STATE_READY;
|
|||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.renderer.layer.Layer;
|
import org.oscim.renderer.layer.Layer;
|
||||||
import org.oscim.utils.FastMath;
|
import org.oscim.utils.FastMath;
|
||||||
|
import org.oscim.utils.GlUtils;
|
||||||
|
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.opengl.Matrix;
|
import android.opengl.Matrix;
|
||||||
@ -78,28 +79,39 @@ public class BaseLayer {
|
|||||||
if (tile.lastDraw == mDrawSerial)
|
if (tile.lastDraw == mDrawSerial)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float div = FastMath.pow(tile.zoomLevel - pos.zoomLevel);
|
|
||||||
|
|
||||||
tile.lastDraw = mDrawSerial;
|
tile.lastDraw = mDrawSerial;
|
||||||
|
|
||||||
float[] mvp = mMVPMatrix;
|
float[] mvp = mMVPMatrix;
|
||||||
setMatrix(mvp, tile, div, pos);
|
|
||||||
|
|
||||||
if (tile.holder != null)
|
//setMatrix(mvp, tile, div, pos);
|
||||||
tile = tile.holder;
|
|
||||||
|
|
||||||
if (tile.layers == null)
|
MapTile t = tile;
|
||||||
|
if (t.holder != null)
|
||||||
|
t = t.holder;
|
||||||
|
|
||||||
|
if (t.layers == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// set depth offset (used for clipping to tile boundaries)
|
// set Model matrix for tile
|
||||||
GLES20.glPolygonOffset(-1, -GLRenderer.depthOffset(tile));
|
float div = FastMath.pow(tile.zoomLevel - pos.zoomLevel);
|
||||||
|
float x = (float) (tile.pixelX - pos.x * div);
|
||||||
|
float y = (float) (tile.pixelY - pos.y * div);
|
||||||
|
float scale = pos.scale / div;
|
||||||
|
GlUtils.setTileMatrix(mvp, x, y, scale);
|
||||||
|
|
||||||
GLES20.glBindBuffer(GL_ARRAY_BUFFER, tile.vbo.id);
|
// add view-projection matrix
|
||||||
|
Matrix.multiplyMM(mvp, 0, mVPMatrix, 0, mvp, 0);
|
||||||
|
|
||||||
|
// set depth offset (used for clipping to tile boundaries)
|
||||||
|
GLES20.glPolygonOffset(-1, -GLRenderer.depthOffset(t));
|
||||||
|
|
||||||
|
GLES20.glBindBuffer(GL_ARRAY_BUFFER, t.vbo.id);
|
||||||
|
|
||||||
boolean clipped = false;
|
boolean clipped = false;
|
||||||
int simpleShader = (pos.tilt == 0 ? 1 : 0);
|
// simple line shader does not take forward shortening into account
|
||||||
|
int simpleShader = (pos.tilt < 1 ? 1 : 0);
|
||||||
|
|
||||||
for (Layer l = tile.layers.layers; l != null;) {
|
for (Layer l = t.layers.layers; l != null;) {
|
||||||
|
|
||||||
switch (l.type) {
|
switch (l.type) {
|
||||||
case Layer.POLYGON:
|
case Layer.POLYGON:
|
||||||
@ -118,7 +130,7 @@ public class BaseLayer {
|
|||||||
|
|
||||||
GLES20.glEnable(GL_BLEND);
|
GLES20.glEnable(GL_BLEND);
|
||||||
l = LineRenderer.draw(pos, l, mvp, div, simpleShader,
|
l = LineRenderer.draw(pos, l, mvp, div, simpleShader,
|
||||||
tile.layers.lineOffset);
|
t.layers.lineOffset);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,30 +145,6 @@ public class BaseLayer {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setMatrix(float[] matrix, MapTile tile,
|
|
||||||
float div, MapPosition pos) {
|
|
||||||
|
|
||||||
float x = (float) (tile.pixelX - pos.x * div);
|
|
||||||
float y = (float) (tile.pixelY - pos.y * div);
|
|
||||||
float scale = pos.scale / div;
|
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++)
|
|
||||||
matrix[i] = 0;
|
|
||||||
|
|
||||||
// translate relative to map center
|
|
||||||
matrix[12] = x * scale;
|
|
||||||
matrix[13] = y * scale;
|
|
||||||
|
|
||||||
// scale to tile to world coordinates
|
|
||||||
scale /= GLRenderer.COORD_MULTIPLIER;
|
|
||||||
matrix[0] = scale;
|
|
||||||
matrix[5] = scale;
|
|
||||||
matrix[10] = 1;
|
|
||||||
matrix[15] = 1;
|
|
||||||
|
|
||||||
Matrix.multiplyMM(matrix, 0, mVPMatrix, 0, matrix, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean drawProxyChild(MapTile tile, MapPosition pos) {
|
private static boolean drawProxyChild(MapTile tile, MapPosition pos) {
|
||||||
int drawn = 0;
|
int drawn = 0;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
|
@ -54,7 +54,7 @@ public class ExtrusionOverlay extends RenderOverlay {
|
|||||||
|
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
// TODO sum up size used while filling layer only up to:
|
// FIXME sum up size used while filling layer only up to:
|
||||||
private int BUFFERSIZE = 65536 * 2;
|
private int BUFFERSIZE = 65536 * 2;
|
||||||
private TileSet mTileSet;
|
private TileSet mTileSet;
|
||||||
private ShortBuffer mShortBuffer;
|
private ShortBuffer mShortBuffer;
|
||||||
@ -104,8 +104,8 @@ public class ExtrusionOverlay extends RenderOverlay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// keep a list of tiles available for rendering
|
// keep a list of tiles available for rendering
|
||||||
if (mTiles == null || mTiles.length != tiles.length)
|
if (mTiles == null || mTiles.length < mTileSet.cnt * 4)
|
||||||
mTiles = new MapTile[tiles.length];
|
mTiles = new MapTile[mTileSet.cnt * 4];
|
||||||
|
|
||||||
ExtrusionLayer el;
|
ExtrusionLayer el;
|
||||||
if (curPos.zoomLevel >= 17) {
|
if (curPos.zoomLevel >= 17) {
|
||||||
@ -139,7 +139,6 @@ public class ExtrusionOverlay extends RenderOverlay {
|
|||||||
if (el == null || !el.compiled)
|
if (el == null || !el.compiled)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// TODO check overflow, even if very unlikely...
|
|
||||||
mTiles[ready++] = c;
|
mTiles[ready++] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -317,19 +316,9 @@ public class ExtrusionOverlay extends RenderOverlay {
|
|||||||
float y = (float) (tile.pixelY - mapPosition.y * div);
|
float y = (float) (tile.pixelY - mapPosition.y * div);
|
||||||
float scale = mapPosition.scale / div;
|
float scale = mapPosition.scale / div;
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++)
|
GlUtils.setTileMatrix(matrix, x, y, scale);
|
||||||
matrix[i] = 0;
|
// scale height
|
||||||
|
matrix[10] = scale / (1000f * GLRenderer.COORD_MULTIPLIER);
|
||||||
// translate relative to map center
|
|
||||||
matrix[12] = x * scale;
|
|
||||||
matrix[13] = y * scale;
|
|
||||||
|
|
||||||
// scale to tile to world coordinates
|
|
||||||
scale /= GLRenderer.COORD_MULTIPLIER;
|
|
||||||
matrix[0] = scale;
|
|
||||||
matrix[5] = scale;
|
|
||||||
matrix[10] = scale / 1000f;
|
|
||||||
matrix[15] = 1;
|
|
||||||
|
|
||||||
Matrix.multiplyMM(matrix, 0, proj, 0, matrix, 0);
|
Matrix.multiplyMM(matrix, 0, proj, 0, matrix, 0);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.utils;
|
package org.oscim.utils;
|
||||||
|
|
||||||
|
import org.oscim.renderer.GLRenderer;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.opengl.GLUtils;
|
import android.opengl.GLUtils;
|
||||||
@ -186,4 +188,25 @@ public class GlUtils {
|
|||||||
c[2] = (color >> 0 & 0xff) / 255.0f * c[3];
|
c[2] = (color >> 0 & 0xff) / 255.0f * c[3];
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setTileMatrix(float[] matrix, float tx, float ty, float s) {
|
||||||
|
// scale tile relative to map scale
|
||||||
|
matrix[0] = matrix[5] = s / GLRenderer.COORD_MULTIPLIER;
|
||||||
|
matrix[1] = 0;
|
||||||
|
matrix[2] = 0;
|
||||||
|
matrix[3] = 0;
|
||||||
|
matrix[4] = 0;
|
||||||
|
|
||||||
|
matrix[6] = 0;
|
||||||
|
matrix[7] = 0;
|
||||||
|
matrix[8] = 0;
|
||||||
|
matrix[9] = 0;
|
||||||
|
matrix[10] = 1;
|
||||||
|
matrix[11] = 0;
|
||||||
|
// translate relative to map center
|
||||||
|
matrix[12] = tx * s;
|
||||||
|
matrix[13] = ty * s;
|
||||||
|
matrix[14] = 0;
|
||||||
|
matrix[15] = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user