ViewController: pivotX, pivotY in map view center (#625)

This commit is contained in:
mathieudebrito 2018-12-21 10:51:20 +01:00 committed by Emux
parent 1efed2bef8
commit 69421c0381
No known key found for this signature in database
GPG Key ID: 64ED9980896038C3

View File

@ -2,6 +2,7 @@
* Copyright 2016-2018 devemux86
* Copyright 2017 Luca Osten
* Copyright 2018 Izumi Kawashima
* Copyright 2018 Mathieu De Brito
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -29,6 +30,7 @@ import static org.oscim.utils.FastMath.clamp;
public class ViewController extends Viewport {
private float mPivotX = 0.0f;
private float mPivotY = 0.0f;
private final float[] mat = new float[16];
@ -72,20 +74,21 @@ public class ViewController extends Viewport {
}
/**
* Get pivot height relative to view center. E.g. 0.5 is usually preferred
* for navigation, moving the center to 25% of the view height.
* Get pivot horizontal / vertical relative to view center.
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
* Range is [-1, 1].
*/
public float getMapViewCenter() {
return mPivotY;
public float[] getMapViewCenter() {
return new float[]{mPivotX, mPivotY};
}
/**
* Set pivot height relative to view center. E.g. 0.5 is usually preferred
* for navigation, moving the center to 25% of the view height.
* Set pivot horizontal / vertical relative to view center.
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
* Range is [-1, 1].
*/
public void setMapViewCenter(float pivotY) {
public void setMapViewCenter(float pivotX, float pivotY) {
mPivotX = FastMath.clamp(pivotX, -1, 1) * 0.5f;
mPivotY = FastMath.clamp(pivotY, -1, 1) * 0.5f;
}
@ -177,6 +180,7 @@ public class ViewController extends Viewport {
mPos.scale = newScale;
if (pivotX != 0 || pivotY != 0) {
pivotX -= mWidth * mPivotX;
pivotY -= mHeight * mPivotY;
moveMap(pivotX * (1.0f - scale),
@ -195,6 +199,7 @@ public class ViewController extends Viewport {
double rsin = Math.sin(radians);
double rcos = Math.cos(radians);
pivotX -= mWidth * mPivotX;
pivotY -= mHeight * mPivotY;
float x = (float) (pivotX - pivotX * rcos + pivotY * rsin);
@ -276,7 +281,7 @@ public class ViewController extends Viewport {
mViewMatrix.copy(mRotationMatrix);
mTmpMatrix.setTranslation(0, mPivotY * mHeight, 0);
mTmpMatrix.setTranslation(mPivotX * mWidth, mPivotY * mHeight, 0);
mViewMatrix.multiplyLhs(mTmpMatrix);
mViewProjMatrix.multiplyMM(mProjMatrix, mViewMatrix);