Improve fling animation (#489)

Easing: add Sin in and out
Animator: Smooth Fling
MapEventLayer: note for changing initial rotation position
This commit is contained in:
Gustl22 2018-01-23 00:59:31 +01:00 committed by Emux
parent a1cfd80853
commit 5ff9abca1a
No known key found for this signature in database
GPG Key ID: 89C6921D7AF2BDD0
4 changed files with 27 additions and 3 deletions

View File

@ -342,6 +342,7 @@ public class MapEventLayer extends AbstractMapEventLayer implements InputListene
mCanTilt = false;
mTwoFingersDone = true;
/*start from recognized position (smoother rotation)*/
mAngle = rad;
} else if (!mDoScale) {
/* reduce pinch trigger by the amount of rotation */
@ -359,8 +360,10 @@ public class MapEventLayer extends AbstractMapEventLayer implements InputListene
/* start rotate again */
mDoRotate = true;
mCanRotate = true;
mAngle = rad;
mTwoFingersDone = true;
/*start from recognized position (smoother rotation)*/
mAngle = rad;
}
}

View File

@ -426,6 +426,7 @@ public class MapEventLayer2 extends AbstractMapEventLayer implements InputListen
mCanTilt = false;
mTwoFingersDone = true;
/*start from recognized position (smoother rotation)*/
mAngle = rad;
} else if (!mDoScale) {
/* reduce pinch trigger by the amount of rotation */
@ -443,8 +444,10 @@ public class MapEventLayer2 extends AbstractMapEventLayer implements InputListen
/* start rotate again */
mDoRotate = true;
mCanRotate = true;
mAngle = rad;
mTwoFingersDone = true;
/*start from recognized position (smoother rotation)*/
mAngle = rad;
}
}

View File

@ -4,6 +4,7 @@
* Copyright 2016 devemux86
* Copyright 2016 Izumi Kawashima
* Copyright 2017 Wolfgang Schramm
* Copyright 2018 Gustl22
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -247,7 +248,7 @@ public class Animator {
return;
}
animStart(duration, ANIM_FLING, Easing.Type.LINEAR);
animStart(duration, ANIM_FLING, Easing.Type.SINE_OUT);
}
private void animStart(float duration, int state, Easing.Type easingType) {

View File

@ -1,5 +1,6 @@
/*
* Copyright 2016 Izumi Kawashima
* Copyright 2018 Gustl22
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -22,6 +23,8 @@ public class Easing {
public enum Type {
LINEAR,
SINE_INOUT,
SINE_IN,
SINE_OUT,
EXPO_OUT,
QUAD_INOUT,
CUBIC_INOUT,
@ -48,6 +51,12 @@ public class Easing {
case SINE_INOUT:
adv = sineInout(x, t, b, c, d);
break;
case SINE_IN:
adv = sineIn(x, t, b, c, d);
break;
case SINE_OUT:
adv = sineOut(x, t, b, c, d);
break;
case EXPO_OUT:
adv = expoOut(x, t, b, c, d);
break;
@ -78,6 +87,14 @@ public class Easing {
return -c / 2 * (float) (Math.cos(Math.PI * t / d) - 1) + b;
}
static private float sineIn(float x, float t, float b, float c, float d) {
return -c * (float) Math.cos(t / d * (Math.PI / 2)) + c + b;
}
static private float sineOut(float x, float t, float b, float c, float d) {
return c * (float) Math.sin(t / d * (Math.PI / 2)) + b;
}
static private float expoOut(float x, float t, float b, float c, float d) {
return (t == d) ? b + c : c * (float) (-Math.pow(2, -10 * x) + 1) + b;
}