-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathRotateView.java
65 lines (53 loc) · 1.48 KB
/
RotateView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package su.levenetc.android.draggableview;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.view.VelocityTracker;
/**
* Created by Eugene Levenetc.
*/
public class RotateView extends DraggableView {
protected static final float ROT_MULT = 10f;
public RotateView(
Context context,
Bitmap bitmap,
VelocityTracker velocityTracker,
PointF selectedViewPoint,
PointF downEventPoint,
DragController.IDragViewGroup viewGroup) {
super(
context,
bitmap,
velocityTracker,
selectedViewPoint,
downEventPoint,
viewGroup
);
}
@Override protected boolean render(Canvas canvas) {
float rotY = 0;
float rotX = 0;
if (motionEvent != null) {
velocityVector.addMovement(motionEvent);
rotY = ROT_MULT * velocityVector.getXVelocity();
rotX = ROT_MULT * velocityVector.getYVelocity() * -1;
}
canvas.save();
canvas.translate(xCanvasTranslation, yCanvasTranslation);
final float translateX = bitmap.getWidth() / 2;
final float translateY = bitmap.getHeight() / 2;
camera.getMatrix(cameraMatrix);
camera.save();
camera.rotateY(rotY);
camera.rotateX(rotX);
camera.getMatrix(cameraMatrix);
cameraMatrix.preTranslate(-translateX, -translateY);
cameraMatrix.postTranslate(translateX, translateY);
camera.restore();
canvas.concat(cameraMatrix);
canvas.drawBitmap(bitmap, 0, 0, paint);
canvas.restore();
return !(rotX == 0) || !(rotY == 0);
}
}