- no need for double precision in visible tile calculation
This commit is contained in:
parent
5c36bd7c46
commit
525af0e2a4
@ -66,12 +66,17 @@ public class MapViewPosition {
|
||||
private float[] mTmpMatrix = new float[16];
|
||||
|
||||
private int mHeight, mWidth;
|
||||
public final static float VIEW_SCALE = 1f / 2;
|
||||
public final static float VIEW_DISTANCE = 1;
|
||||
|
||||
void setViewport(int width, int height) {
|
||||
Matrix.frustumM(mProjMatrix, 0, -0.5f * width, 0.5f * width,
|
||||
0.5f * height, -0.5f * height, 1, 2);
|
||||
float sw = VIEW_SCALE;
|
||||
float sh = VIEW_SCALE;
|
||||
|
||||
Matrix.translateM(mProjMatrix, 0, 0, 0, -1);
|
||||
Matrix.frustumM(mProjMatrix, 0, -sw * width, sw * width,
|
||||
sh * height, -sh * height, 1, 2);
|
||||
|
||||
Matrix.translateM(mProjMatrix, 0, 0, 0, -VIEW_DISTANCE);
|
||||
|
||||
Matrix.invertM(mProjMatrixI, 0, mProjMatrix, 0);
|
||||
Matrix.invertM(mUnprojMatrix, 0, mProjMatrix, 0);
|
||||
@ -132,7 +137,7 @@ 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 - 1;
|
||||
mv[2] = z - VIEW_DISTANCE;
|
||||
mv[3] = 1;
|
||||
|
||||
Matrix.multiplyMV(mv, 0, mUnprojMatrix, 0, mv, 0);
|
||||
@ -160,6 +165,8 @@ public class MapViewPosition {
|
||||
// get unproject matrix:
|
||||
// (transpose of rotation is its inverse)
|
||||
Matrix.transposeM(mTmpMatrix, 0, mRotateMatrix, 0);
|
||||
// Matrix.invertM(mTmpMatrix, 0, mRotateMatrix, 0);
|
||||
|
||||
// (AB)^-1 = B^-1*A^-1
|
||||
Matrix.multiplyMM(mUnprojMatrix, 0, mTmpMatrix, 0, mProjMatrixI, 0);
|
||||
|
||||
|
@ -453,6 +453,7 @@ public class GLRenderer implements GLSurfaceView.Renderer {
|
||||
|
||||
if (project)
|
||||
Matrix.multiplyMM(matrix, 0, mProjMatrix, 0, matrix, 0);
|
||||
|
||||
}
|
||||
|
||||
private static float scaleDiv(MapTile t) {
|
||||
@ -528,17 +529,33 @@ public class GLRenderer implements GLSurfaceView.Renderer {
|
||||
|
||||
float s = Tile.TILE_SIZE;
|
||||
float scale = mapPosition.scale / div;
|
||||
double px = mapPosition.x * div;
|
||||
double py = mapPosition.y * div;
|
||||
float px = (float) mapPosition.x * div;
|
||||
float py = (float) mapPosition.y * div;
|
||||
|
||||
for (int i = 0; i < 8; i += 2) {
|
||||
coords[i + 0] = (float) ((px + coords[i + 0] / scale) / s);
|
||||
coords[i + 1] = (float) ((py + coords[i + 1] / scale) / s);
|
||||
coords[i + 0] = (px + coords[i + 0] / scale) / s;
|
||||
coords[i + 1] = (py + coords[i + 1] / scale) / s;
|
||||
}
|
||||
|
||||
mHolderCount = 0;
|
||||
mScanBox.scan(coords, tiles[0].zoomLevel);
|
||||
tileCnt += mHolderCount;
|
||||
|
||||
// // TODO get the right function: trying to accomodate for the
|
||||
// y-stretching introduced by the perspective transformation...
|
||||
// float sw, sh;
|
||||
// sw = MapViewPosition.VIEW_SCALE;
|
||||
// sh = MapViewPosition.VIEW_SCALE;
|
||||
// sh += (mMapViewPosition.mTilt / 150);
|
||||
//
|
||||
// Matrix.frustumM(mProjMatrix, 0, -sw * mWidth, sw * mWidth,
|
||||
// sh * mHeight, -sh * mHeight, 1, 2);
|
||||
//
|
||||
// Matrix.translateM(mProjMatrix, 0, 0, 0,
|
||||
// -MapViewPosition.VIEW_DISTANCE);
|
||||
//
|
||||
// mProjMatrix[10] = 0;
|
||||
// mProjMatrix[14] = 0;
|
||||
}
|
||||
|
||||
uploadCnt = 0;
|
||||
@ -795,13 +812,13 @@ public class GLRenderer implements GLSurfaceView.Renderer {
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
|
||||
float s = 0.5f;
|
||||
// use this to scale only the view to see better which tiles are
|
||||
// rendered
|
||||
// s = 1.0f;
|
||||
float s = MapViewPosition.VIEW_SCALE;
|
||||
Matrix.frustumM(mProjMatrix, 0, -s * width, s * width,
|
||||
s * height, -s * height, 1, 2);
|
||||
Matrix.translateM(mProjMatrix, 0, 0, 0, -1);
|
||||
|
||||
Matrix.translateM(mProjMatrix, 0, 0, 0, -MapViewPosition.VIEW_DISTANCE);
|
||||
|
||||
// set to zero: we modify the z value with polygon-offset for clipping
|
||||
mProjMatrix[10] = 0;
|
||||
|
@ -208,14 +208,14 @@ public class MapRenderer extends GLSurfaceView {
|
||||
float s = Tile.TILE_SIZE;
|
||||
// load some additional tiles more than currently visible
|
||||
float scale = mapPosition.scale * 0.75f;
|
||||
double px = mapPosition.x;
|
||||
double py = mapPosition.y;
|
||||
float px = (float) mapPosition.x;
|
||||
float py = (float) mapPosition.y;
|
||||
float[] coords = mTileCoords;
|
||||
int zdir = 0;
|
||||
|
||||
for (int i = 0; i < 8; i += 2) {
|
||||
coords[i + 0] = (float) ((px + coords[i + 0] / scale) / s);
|
||||
coords[i + 1] = (float) ((py + coords[i + 1] / scale) / s);
|
||||
coords[i + 0] = (px + coords[i + 0] / scale) / s;
|
||||
coords[i + 1] = (py + coords[i + 1] / scale) / s;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user