Map view roll (#474)

This commit is contained in:
Izumi Kawashima
2018-01-08 06:08:03 +09:00
committed by Emux
parent 4d7078e861
commit 49476e17bb
10 changed files with 187 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
/*
* Copyright 2012 Hannes Janetzek
* Copyright 2016-2018 devemux86
* Copyright 2018 Izumi Kawashima
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@@ -47,6 +48,11 @@ public class MapPosition {
*/
public float tilt;
/**
* Perspective roll
*/
public float roll;
/**
* Zoom-level for current scale.
* - To be removed: FastMath.log2(scale)
@@ -61,6 +67,7 @@ public class MapPosition {
this.zoomLevel = 0;
this.bearing = 0;
this.tilt = 0;
this.roll = 0;
}
public MapPosition(double latitude, double longitude, double scale) {
@@ -95,6 +102,15 @@ public class MapPosition {
return this;
}
public float getRoll() {
return roll;
}
public MapPosition setRoll(float roll) {
this.roll = clampRoll(roll);
return this;
}
public float getTilt() {
return tilt;
}
@@ -157,6 +173,7 @@ public class MapPosition {
this.scale = other.scale;
this.tilt = other.tilt;
this.zoomLevel = other.zoomLevel;
this.roll = other.roll;
}
public void set(double x, double y, double scale, float bearing, float tilt) {
@@ -169,6 +186,11 @@ public class MapPosition {
this.zoomLevel = FastMath.log2((int) scale);
}
public void set(double x, double y, double scale, float bearing, float tilt, float roll) {
set(x, y, scale, bearing, tilt);
this.roll = clampRoll(roll);
}
private static float clampBearing(float bearing) {
while (bearing > 180)
bearing -= 360;
@@ -177,6 +199,10 @@ public class MapPosition {
return bearing;
}
private static float clampRoll(float roll) {
return clampBearing(roll); // Uses the same logic
}
/**
* @return scale relative to zoom-level.
*/
@@ -212,6 +238,7 @@ public class MapPosition {
y = miny + dy / 2;
bearing = 0;
tilt = 0;
roll = 0;
}
@Override

View File

@@ -1,6 +1,7 @@
/*
* Copyright 2016 devemux86
* Copyright 2016-2018 devemux86
* Copyright 2017 Luca Osten
* Copyright 2018 Izumi Kawashima
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@@ -200,6 +201,23 @@ public class ViewController extends Viewport {
updateMatrices();
}
public void rollMap(float move) {
setRoll(mPos.roll + move);
}
public void setRoll(double degree) {
ThreadUtils.assertMainThread();
while (degree > 360)
degree -= 360;
while (degree < 0)
degree += 360;
mPos.roll = (float) degree;
updateMatrices();
}
public boolean tiltMap(float move) {
return setTilt(mPos.tilt + move);
}
@@ -233,13 +251,16 @@ public class ViewController extends Viewport {
private void updateMatrices() {
/* - view matrix:
* 0. apply rotate
* 1. apply tilt */
* 0. apply yaw
* 1. apply pitch
* 2. apply roll */
mRotationMatrix.setRotation(mPos.bearing, 0, 0, 1);
mTmpMatrix.setRotation(mPos.tilt, 1, 0, 0);
/* apply first rotation, then tilt */
mTmpMatrix.setRotation(mPos.tilt, 1, 0, 0);
mRotationMatrix.multiplyLhs(mTmpMatrix);
mTmpMatrix.setRotation(mPos.roll, 0, 1, 0);
mRotationMatrix.multiplyLhs(mTmpMatrix);
mViewMatrix.copy(mRotationMatrix);

View File

@@ -1,8 +1,9 @@
/*
* Copyright 2012 Hannes Janetzek
* Copyright 2016 devemux86
* Copyright 2016-2018 devemux86
* Copyright 2016 Erik Duisters
* Copyright 2017 Luca Osten
* Copyright 2018 Izumi Kawashima
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@@ -52,6 +53,9 @@ public class Viewport {
protected float mMinBearing = -180;
protected float mMaxBearing = 180;
protected float mMinRoll = -180;
protected float mMaxRoll = 180;
protected double mMinX = 0;
protected double mMaxX = 1;
protected double mMinY = 0;
@@ -90,6 +94,7 @@ public class Viewport {
mPos.y = 0.5;
mPos.bearing = 0;
mPos.tilt = 0;
mPos.roll = 0;
}
public double limitScale(double scale) {
@@ -136,6 +141,14 @@ public class Viewport {
changed = true;
}
if (pos.roll > mMaxRoll) {
pos.roll = mMaxRoll;
changed = true;
} else if (pos.roll < mMinRoll) {
pos.roll = mMinRoll;
changed = true;
}
if (pos.x > mMaxX) {
pos.x = mMaxX;
changed = true;
@@ -168,10 +181,12 @@ public class Viewport {
|| pos.x != mPos.x
|| pos.y != mPos.y
|| pos.bearing != mPos.bearing
|| pos.tilt != mPos.tilt);
|| pos.tilt != mPos.tilt
|| pos.roll != mPos.roll);
pos.bearing = mPos.bearing;
pos.tilt = mPos.tilt;
pos.roll = mPos.roll;
pos.x = mPos.x;
pos.y = mPos.y;
@@ -471,6 +486,22 @@ public class Viewport {
this.mMinBearing = minBearing;
}
public float getMaxRoll() {
return mMaxRoll;
}
public void setMaxRoll(float maxRoll) {
this.mMaxRoll = maxRoll;
}
public float getMinRoll() {
return mMinRoll;
}
public void setMinRoll(float minRoll) {
this.mMinRoll = minRoll;
}
public double getMaxX() {
return mMaxX;
}