android 3d 旋转
2010-10-12 02:45:00 来源:本站整理在javaeye里看到了关于3d旋转的文章,可是博主没有透入什么技术细节。由于一直想做出那种旋转效果,所以就想啊想,终于想出来了(我是个小菜鸟)。呵呵,不管怎样,希望对想做还没做出来的朋友一些帮助。
先上一个效果图:
这是你想要的吗?如果是就继续往下看吧。
其实,这个效果是用animation配合camera做出来的,相信大家在apidemo里面看过类似的。
那么先写一个继承animation的类:Rotate3d
Java代码
1. public class Rotate3d extends Animation {
2. private float mFromDegree;
3. private float mToDegree;
4. private float mCenterX;
5. private float mCenterY;
6. private float mLeft;
7. private float mTop;
8. private Camera mCamera;
9. private static final String TAG = "Rotate3d";
10.
11. public Rotate3d(float fromDegree, float toDegree, float left, float top,
12. float centerX, float centerY) {
13. this.mFromDegree = fromDegree;
14. this.mToDegree = toDegree;
15. this.mLeft = left;
16. this.mTop = top;
17. this.mCenterX = centerX;
18. this.mCenterY = centerY;
19.
20. }
21.
22. @Override
23. public void initialize(int width, int height, int parentWidth,
24. int parentHeight) {
25. super.initialize(width, height, parentWidth, parentHeight);
26. mCamera = new Camera();
27. }
28.
29. @Override
30. protected void applyTransformation(float interpolatedTime, Transformation t) {
31. final float FromDegree = mFromDegree;
32. float degrees = FromDegree + (mToDegree - mFromDegree)
33. * interpolatedTime;
34. final float centerX = mCenterX;
更多精彩
赞助商链接