1 |
torben |
1217 |
package dk.thoerup.side9.anim; |
2 |
|
|
|
3 |
|
|
import android.graphics.Camera; |
4 |
|
|
import android.graphics.Matrix; |
5 |
|
|
import android.view.animation.Animation; |
6 |
|
|
import android.view.animation.Transformation; |
7 |
|
|
|
8 |
|
|
public class Flip3dAnimation extends Animation { |
9 |
|
|
private final float mFromDegrees; |
10 |
|
|
private final float mToDegrees; |
11 |
|
|
private final float mCenterX; |
12 |
|
|
private final float mCenterY; |
13 |
|
|
private Camera mCamera; |
14 |
|
|
|
15 |
|
|
public Flip3dAnimation(float fromDegrees, float toDegrees, float centerX, float centerY) { |
16 |
|
|
mFromDegrees = fromDegrees; |
17 |
|
|
mToDegrees = toDegrees; |
18 |
|
|
mCenterX = centerX; |
19 |
|
|
mCenterY = centerY; |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
@Override |
23 |
|
|
public void initialize(int width, int height, int parentWidth, int parentHeight) { |
24 |
|
|
super.initialize(width, height, parentWidth, parentHeight); |
25 |
|
|
mCamera = new Camera(); |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
@Override |
29 |
|
|
protected void applyTransformation(float interpolatedTime, Transformation t) { |
30 |
|
|
final float fromDegrees = mFromDegrees; |
31 |
|
|
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime); |
32 |
|
|
|
33 |
|
|
final float centerX = mCenterX; |
34 |
|
|
final float centerY = mCenterY; |
35 |
|
|
final Camera camera = mCamera; |
36 |
|
|
|
37 |
|
|
final Matrix matrix = t.getMatrix(); |
38 |
|
|
|
39 |
|
|
camera.save(); |
40 |
|
|
|
41 |
|
|
camera.rotateY(degrees); |
42 |
|
|
|
43 |
|
|
camera.getMatrix(matrix); |
44 |
|
|
camera.restore(); |
45 |
|
|
|
46 |
|
|
matrix.preTranslate(-centerX, -centerY); |
47 |
|
|
matrix.postTranslate(centerX, centerY); |
48 |
|
|
|
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
} |