ViewController: pivotX, pivotY in map view center (#625)
This commit is contained in:
parent
1efed2bef8
commit
69421c0381
@ -2,6 +2,7 @@
|
|||||||
* Copyright 2016-2018 devemux86
|
* Copyright 2016-2018 devemux86
|
||||||
* Copyright 2017 Luca Osten
|
* Copyright 2017 Luca Osten
|
||||||
* Copyright 2018 Izumi Kawashima
|
* Copyright 2018 Izumi Kawashima
|
||||||
|
* Copyright 2018 Mathieu De Brito
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* 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 {
|
public class ViewController extends Viewport {
|
||||||
|
|
||||||
|
private float mPivotX = 0.0f;
|
||||||
private float mPivotY = 0.0f;
|
private float mPivotY = 0.0f;
|
||||||
|
|
||||||
private final float[] mat = new float[16];
|
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
|
* Get pivot horizontal / vertical relative to view center.
|
||||||
* for navigation, moving the center to 25% of the view height.
|
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
|
||||||
* Range is [-1, 1].
|
* Range is [-1, 1].
|
||||||
*/
|
*/
|
||||||
public float getMapViewCenter() {
|
public float[] getMapViewCenter() {
|
||||||
return mPivotY;
|
return new float[]{mPivotX, mPivotY};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set pivot height relative to view center. E.g. 0.5 is usually preferred
|
* Set pivot horizontal / vertical relative to view center.
|
||||||
* for navigation, moving the center to 25% of the view height.
|
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
|
||||||
* Range is [-1, 1].
|
* 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;
|
mPivotY = FastMath.clamp(pivotY, -1, 1) * 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,6 +180,7 @@ public class ViewController extends Viewport {
|
|||||||
mPos.scale = newScale;
|
mPos.scale = newScale;
|
||||||
|
|
||||||
if (pivotX != 0 || pivotY != 0) {
|
if (pivotX != 0 || pivotY != 0) {
|
||||||
|
pivotX -= mWidth * mPivotX;
|
||||||
pivotY -= mHeight * mPivotY;
|
pivotY -= mHeight * mPivotY;
|
||||||
|
|
||||||
moveMap(pivotX * (1.0f - scale),
|
moveMap(pivotX * (1.0f - scale),
|
||||||
@ -195,6 +199,7 @@ public class ViewController extends Viewport {
|
|||||||
double rsin = Math.sin(radians);
|
double rsin = Math.sin(radians);
|
||||||
double rcos = Math.cos(radians);
|
double rcos = Math.cos(radians);
|
||||||
|
|
||||||
|
pivotX -= mWidth * mPivotX;
|
||||||
pivotY -= mHeight * mPivotY;
|
pivotY -= mHeight * mPivotY;
|
||||||
|
|
||||||
float x = (float) (pivotX - pivotX * rcos + pivotY * rsin);
|
float x = (float) (pivotX - pivotX * rcos + pivotY * rsin);
|
||||||
@ -276,7 +281,7 @@ public class ViewController extends Viewport {
|
|||||||
|
|
||||||
mViewMatrix.copy(mRotationMatrix);
|
mViewMatrix.copy(mRotationMatrix);
|
||||||
|
|
||||||
mTmpMatrix.setTranslation(0, mPivotY * mHeight, 0);
|
mTmpMatrix.setTranslation(mPivotX * mWidth, mPivotY * mHeight, 0);
|
||||||
mViewMatrix.multiplyLhs(mTmpMatrix);
|
mViewMatrix.multiplyLhs(mTmpMatrix);
|
||||||
|
|
||||||
mViewProjMatrix.multiplyMM(mProjMatrix, mViewMatrix);
|
mViewProjMatrix.multiplyMM(mProjMatrix, mViewMatrix);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user