rename MapPosition.angle -> bearing

This commit is contained in:
Hannes Janetzek 2014-02-16 04:22:36 +01:00
parent 79b5a09ac8
commit 904360ff69
8 changed files with 37 additions and 37 deletions

@ -1 +1 @@
Subproject commit 0558c06ed068929a53897dc4ab6b98d4a79e0192 Subproject commit 873b964335364db5b524d505451aa1a68ca62b52

View File

@ -95,7 +95,7 @@ class GwtGdxMap extends GdxMap {
p.setPosition(lat, lon); p.setPosition(lat, lon);
log.debug("map position: " + p.x + "/" + p.y + " " + lat + "/" + lon); log.debug("map position: " + p.x + "/" + p.y + " " + lat + "/" + lon);
p.angle = rotation; p.bearing = rotation;
p.tilt = tilt; p.tilt = tilt;
mMap.setMapPosition(p); mMap.setMapPosition(p);
@ -124,12 +124,12 @@ class GwtGdxMap extends GdxMap {
mMap.viewport().getMapPosition(pos); mMap.viewport().getMapPosition(pos);
int lat = (int) (MercatorProjection.toLatitude(pos.y) * 1000); int lat = (int) (MercatorProjection.toLatitude(pos.y) * 1000);
int lon = (int) (MercatorProjection.toLongitude(pos.x) * 1000); int lon = (int) (MercatorProjection.toLongitude(pos.x) * 1000);
int rot = (int) (pos.angle); int rot = (int) (pos.bearing);
rot = (int) (pos.angle) % 360; rot = (int) (pos.bearing) % 360;
//rot = rot < 0 ? -rot : rot; //rot = rot < 0 ? -rot : rot;
if (curZoom != pos.zoomLevel || curLat != lat || curLon != lon if (curZoom != pos.zoomLevel || curLat != lat || curLon != lon
|| curTilt != rot || curRot != (int) (pos.angle)) { || curTilt != rot || curRot != (int) (pos.bearing)) {
curLat = lat; curLat = lat;
curLon = lon; curLon = lon;

View File

@ -29,7 +29,7 @@ public class MapPosition {
public double scale; public double scale;
/** rotation angle */ /** rotation angle */
public float angle; public float bearing;
/** perspective tile */ /** perspective tile */
public float tilt; public float tilt;
@ -41,7 +41,7 @@ public class MapPosition {
this.x = 0.5; this.x = 0.5;
this.y = 0.5; this.y = 0.5;
this.zoomLevel = 1; this.zoomLevel = 1;
this.angle = 0; this.bearing = 0;
} }
public MapPosition(double latitude, double longitude, double scale) { public MapPosition(double latitude, double longitude, double scale) {
@ -74,22 +74,22 @@ public class MapPosition {
this.x = other.x; this.x = other.x;
this.y = other.y; this.y = other.y;
this.angle = other.angle; this.bearing = other.bearing;
this.scale = other.scale; this.scale = other.scale;
this.tilt = other.tilt; this.tilt = other.tilt;
this.zoomLevel = other.zoomLevel; this.zoomLevel = other.zoomLevel;
} }
public void set(double x, double y, double scale, float rotation, float tilt) { public void set(double x, double y, double scale, float bearing, float tilt) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.scale = scale; this.scale = scale;
while (rotation > 180) while (bearing > 180)
rotation -= 360; bearing -= 360;
while (rotation < -180) while (bearing < -180)
rotation += 360; bearing += 360;
this.angle = rotation; this.bearing = bearing;
this.tilt = tilt; this.tilt = tilt;
this.zoomLevel = FastMath.log2((int) scale); this.zoomLevel = FastMath.log2((int) scale);
@ -127,7 +127,7 @@ public class MapPosition {
scale = Math.min(zx, zy); scale = Math.min(zx, zy);
x = minx + dx / 2; x = minx + dx / 2;
y = miny + dy / 2; y = miny + dy / 2;
angle = 0; bearing = 0;
tilt = 0; tilt = 0;
} }

View File

@ -97,7 +97,7 @@ public class MarkerRenderer extends ElementRenderer {
return; return;
} }
double angle = Math.toRadians(v.pos.angle); double angle = Math.toRadians(v.pos.bearing);
float cos = (float) Math.cos(angle); float cos = (float) Math.cos(angle);
float sin = (float) Math.sin(angle); float sin = (float) Math.sin(angle);
@ -143,7 +143,7 @@ public class MarkerRenderer extends ElementRenderer {
} }
/* keep position for current state */ /* keep position for current state */
mMapPosition.copy(v.pos); mMapPosition.copy(v.pos);
mMapPosition.angle = -mMapPosition.angle; mMapPosition.bearing = -mMapPosition.bearing;
sort(mItems, 0, mItems.length); sort(mItems, 0, mItems.length);
//log.debug(Arrays.toString(mItems)); //log.debug(Arrays.toString(mItems));

View File

@ -303,7 +303,7 @@ public class LabelPlacement {
/* scale of tiles zoom-level relative to current position */ /* scale of tiles zoom-level relative to current position */
double scale = pos.scale / (1 << zoom); double scale = pos.scale / (1 << zoom);
double angle = Math.toRadians(pos.angle); double angle = Math.toRadians(pos.bearing);
float cos = (float) Math.cos(angle); float cos = (float) Math.cos(angle);
float sin = (float) Math.sin(angle); float sin = (float) Math.sin(angle);

View File

@ -82,7 +82,7 @@ public class Animator {
mDeltaPos.set(longitudeToX(p.getLongitude()) - mStartPos.x, mDeltaPos.set(longitudeToX(p.getLongitude()) - mStartPos.x,
latitudeToY(p.getLatitude()) - mStartPos.y, latitudeToY(p.getLatitude()) - mStartPos.y,
newScale - mStartPos.scale, newScale - mStartPos.scale,
-mStartPos.angle, -mStartPos.bearing,
-mStartPos.tilt); -mStartPos.tilt);
animStart(duration, ANIM_MOVE | ANIM_SCALE | ANIM_ROTATE | ANIM_TILT); animStart(duration, ANIM_MOVE | ANIM_SCALE | ANIM_ROTATE | ANIM_TILT);
@ -123,7 +123,7 @@ public class Animator {
mDeltaPos.set(pos.x - mStartPos.x, mDeltaPos.set(pos.x - mStartPos.x,
pos.y - mStartPos.y, pos.y - mStartPos.y,
pos.scale - mStartPos.scale, pos.scale - mStartPos.scale,
mStartPos.angle - pos.angle, mStartPos.bearing - pos.bearing,
clamp(pos.tilt, 0, Viewport.MAX_TILT) - mStartPos.tilt); clamp(pos.tilt, 0, Viewport.MAX_TILT) - mStartPos.tilt);
animStart(duration, ANIM_MOVE | ANIM_SCALE | ANIM_ROTATE | ANIM_TILT); animStart(duration, ANIM_MOVE | ANIM_SCALE | ANIM_ROTATE | ANIM_TILT);
@ -229,7 +229,7 @@ public class Animator {
} }
} }
if ((mState & ANIM_ROTATE) != 0) { if ((mState & ANIM_ROTATE) != 0) {
v.setRotation(mStartPos.angle + mDeltaPos.angle * adv); v.setRotation(mStartPos.bearing + mDeltaPos.bearing * adv);
} }
if ((mState & ANIM_TILT) != 0) { if ((mState & ANIM_TILT) != 0) {

View File

@ -41,7 +41,7 @@ public class ViewController extends Viewport {
mTmpMatrix.setScale(1 / mWidth, 1 / mWidth, 1 / mWidth); mTmpMatrix.setScale(1 / mWidth, 1 / mWidth, 1 / mWidth);
mProjMatrix.multiplyRhs(mTmpMatrix); mProjMatrix.multiplyRhs(mTmpMatrix);
updateMatrix(); updateMatrices();
} }
/** /**
@ -72,11 +72,11 @@ public class ViewController extends Viewport {
} }
private Point applyRotation(double mx, double my) { private Point applyRotation(double mx, double my) {
if (mPos.angle == 0) { if (mPos.bearing == 0) {
mMovePoint.x = mx; mMovePoint.x = mx;
mMovePoint.y = my; mMovePoint.y = my;
} else { } else {
double rad = Math.toRadians(mPos.angle); double rad = Math.toRadians(mPos.bearing);
double rcos = Math.cos(rad); double rcos = Math.cos(rad);
double rsin = Math.sin(rad); double rsin = Math.sin(rad);
mMovePoint.x = mx * rcos + my * rsin; mMovePoint.x = mx * rcos + my * rsin;
@ -136,17 +136,17 @@ public class ViewController extends Viewport {
moveMap(x, y); moveMap(x, y);
setRotation(mPos.angle + Math.toDegrees(radians)); setRotation(mPos.bearing + Math.toDegrees(radians));
} }
public synchronized void setRotation(double degree) { public synchronized void setRotation(double degree) {
while (degree > 360) while (degree > 180)
degree -= 360; degree -= 360;
while (degree < 0) while (degree < -180)
degree += 360; degree += 360;
mPos.angle = (float) degree; mPos.bearing = (float) degree;
updateMatrix(); updateMatrices();
} }
public synchronized boolean tiltMap(float move) { public synchronized boolean tiltMap(float move) {
@ -158,7 +158,7 @@ public class ViewController extends Viewport {
if (tilt == mPos.tilt) if (tilt == mPos.tilt)
return false; return false;
mPos.tilt = tilt; mPos.tilt = tilt;
updateMatrix(); updateMatrices();
return true; return true;
} }
@ -167,16 +167,16 @@ public class ViewController extends Viewport {
mPos.x = mapPosition.x; mPos.x = mapPosition.x;
mPos.y = mapPosition.y; mPos.y = mapPosition.y;
mPos.tilt = mapPosition.tilt; mPos.tilt = mapPosition.tilt;
mPos.angle = mapPosition.angle; mPos.bearing = mapPosition.bearing;
updateMatrix(); updateMatrices();
} }
private void updateMatrix() { private void updateMatrices() {
/* - view matrix: /* - view matrix:
* 0. apply rotate * 0. apply rotate
* 1. apply tilt */ * 1. apply tilt */
mRotationMatrix.setRotation(mPos.angle, 0, 0, 1); mRotationMatrix.setRotation(mPos.bearing, 0, 0, 1);
mTmpMatrix.setRotation(mPos.tilt, 1, 0, 0); mTmpMatrix.setRotation(mPos.tilt, 1, 0, 0);
/* apply first rotation, then tilt */ /* apply first rotation, then tilt */

View File

@ -75,7 +75,7 @@ public class Viewport {
mPos.scale = MIN_SCALE; mPos.scale = MIN_SCALE;
mPos.x = 0.5; mPos.x = 0.5;
mPos.y = 0.5; mPos.y = 0.5;
mPos.angle = 0; mPos.bearing = 0;
mPos.tilt = 0; mPos.tilt = 0;
} }
@ -92,10 +92,10 @@ public class Viewport {
boolean changed = (pos.scale != mPos.scale boolean changed = (pos.scale != mPos.scale
|| pos.x != mPos.x || pos.x != mPos.x
|| pos.y != mPos.y || pos.y != mPos.y
|| pos.angle != mPos.angle || pos.bearing != mPos.bearing
|| pos.tilt != mPos.tilt); || pos.tilt != mPos.tilt);
pos.angle = mPos.angle; pos.bearing = mPos.bearing;
pos.tilt = mPos.tilt; pos.tilt = mPos.tilt;
pos.x = mPos.x; pos.x = mPos.x;