use matrix utilities

This commit is contained in:
Hannes Janetzek 2013-01-11 20:05:30 +01:00
parent 4acd9a492f
commit a7790537f2
2 changed files with 14 additions and 32 deletions

View File

@ -25,6 +25,7 @@ import org.oscim.renderer.TextureRenderer;
import org.oscim.renderer.layer.Layer; import org.oscim.renderer.layer.Layer;
import org.oscim.renderer.layer.Layers; import org.oscim.renderer.layer.Layers;
import org.oscim.utils.FastMath; import org.oscim.utils.FastMath;
import org.oscim.utils.GlUtils;
import org.oscim.view.MapView; import org.oscim.view.MapView;
import android.opengl.GLES20; import android.opengl.GLES20;
@ -128,36 +129,30 @@ public abstract class RenderOverlay {
* @param matrix ... * @param matrix ...
*/ */
protected void setMatrix(MapPosition curPos, float[] matrix) { protected void setMatrix(MapPosition curPos, float[] matrix) {
// TODO if oPos == curPos this could be simplified
MapPosition oPos = mMapPosition; MapPosition oPos = mMapPosition;
byte z = oPos.zoomLevel; float div = FastMath.pow(oPos.zoomLevel - curPos.zoomLevel);
float div = FastMath.pow(z - curPos.zoomLevel); // translate relative to map center
float x = (float) (oPos.x - curPos.x * div); float x = (float) (oPos.x - curPos.x * div);
float y = (float) (oPos.y - curPos.y * div); float y = (float) (oPos.y - curPos.y * div);
// flip around date-line // flip around date-line
float max = (Tile.TILE_SIZE << z); // FIXME not sure if this is correct!
float max = (Tile.TILE_SIZE << oPos.zoomLevel);
if (x < -max / 2) if (x < -max / 2)
x = max + x; x = max + x;
else if (x > max / 2) else if (x > max / 2)
x = x - max; x = x - max;
// scale to current tile world coordinates
float scale = curPos.scale / div; float scale = curPos.scale / div;
Matrix.setIdentityM(matrix, 0); // set scale to be relative to current scale
float s = (curPos.scale / oPos.scale) / div;
// translate relative to map center GlUtils.setMatrix(matrix, x * scale, y * scale,
matrix[12] = x * scale; s / GLRenderer.COORD_MULTIPLIER);
matrix[13] = y * scale;
// scale to current tile world coordinates
scale = (curPos.scale / oPos.scale) / div;
scale /= GLRenderer.COORD_MULTIPLIER;
matrix[0] = scale;
matrix[5] = scale;
Matrix.multiplyMM(matrix, 0, curPos.viewMatrix, 0, matrix, 0); Matrix.multiplyMM(matrix, 0, curPos.viewMatrix, 0, matrix, 0);
} }

View File

@ -25,6 +25,7 @@ import org.oscim.renderer.layer.TextItem;
import org.oscim.renderer.layer.TextLayer; import org.oscim.renderer.layer.TextLayer;
import org.oscim.utils.FastMath; import org.oscim.utils.FastMath;
import org.oscim.utils.GeometryUtils; import org.oscim.utils.GeometryUtils;
import org.oscim.utils.GlUtils;
import org.oscim.utils.PausableThread; import org.oscim.utils.PausableThread;
import org.oscim.view.MapView; import org.oscim.view.MapView;
@ -291,30 +292,16 @@ public class TextOverlay extends RenderOverlay {
@Override @Override
protected void setMatrix(MapPosition curPos, float[] matrix) { protected void setMatrix(MapPosition curPos, float[] matrix) {
// TODO if oPos == curPos this could be simplified
MapPosition oPos = mMapPosition; MapPosition oPos = mMapPosition;
byte z = oPos.zoomLevel; float div = FastMath.pow(oPos.zoomLevel - curPos.zoomLevel);
float div = FastMath.pow(z - curPos.zoomLevel);
float x = (float) (oPos.x - curPos.x * div); float x = (float) (oPos.x - curPos.x * div);
float y = (float) (oPos.y - curPos.y * div); float y = (float) (oPos.y - curPos.y * div);
float scale = curPos.scale / div; float scale = curPos.scale / div;
Matrix.setIdentityM(matrix, 0); GlUtils.setMatrix(matrix, x * scale, y * scale,
scale / GLRenderer.COORD_MULTIPLIER);
// translate relative to map center
matrix[12] = x * scale;
matrix[13] = y * scale;
// scale to current tile world coordinates
scale = curPos.scale / div; // oPos.scale / div;
scale /= GLRenderer.COORD_MULTIPLIER;
matrix[0] = scale;
matrix[5] = scale;
Matrix.multiplyMM(matrix, 0, curPos.viewMatrix, 0, matrix, 0); Matrix.multiplyMM(matrix, 0, curPos.viewMatrix, 0, matrix, 0);
} }