WEB开发网
开发学院手机开发Android 开发 浅谈 Android 3D旋转 阅读

浅谈 Android 3D旋转

 2010-08-23 01:27:00 来源:WEB开发网   
核心提示:extends Animation { 66 private float mFromDegree; 67 private float mToDegree; 68 private float mCenterX; 69 private float mCenterY; 70 private float mLeft; 71 p
extends Animation { 66 private float mFromDegree; 67 private float mToDegree; 68 private float mCenterX; 69 private float mCenterY; 70 private float mLeft; 71 private float mTop; 72 private Camera mCamera; 73 private static final String TAG = "Rotate3d"; 74 75 public Rotate3d(float fromDegree, float toDegree, float left, float top, 76 float centerX, float centerY) { 77 this.mFromDegree = fromDegree; 78 this.mToDegree = toDegree; 79 this.mLeft = left; 80 this.mTop = top; 81 this.mCenterX = centerX; 82 this.mCenterY = centerY; 83 84 } 85 86 @Override 87 public void initialize(int width, int height, int parentWidth, 88 int parentHeight) { 89 super.initialize(width, height, parentWidth, parentHeight); 90 mCamera = new Camera(); 91 } 92 93 @Override 94 protected void applyTransformation(float interpolatedTime, Transformation t) { 95 final float FromDegree = mFromDegree; 96 float degrees = FromDegree + (mToDegree - mFromDegree) 97 * interpolatedTime; 98 final float centerX = mCenterX; 99 final float centerY = mCenterY;100 final Matrix matrix = t.getMatrix();101 102 if (degrees <= -76.0f) {103 degrees = -90.0f;104 mCamera.save();105 mCamera.rotateY(degrees);106 mCamera.getMatrix(matrix);107 mCamera.restore();108 } else if(degrees >=76.0f){109 degrees = 90.0f;110 mCamera.save();111 mCamera.rotateY(degrees);112 mCamera.getMatrix(matrix);113 mCamera.restore();114 }else{115 mCamera.save();116 //这里很重要哦。117 mCamera.translate(0, 0, centerX);118 mCamera.rotateY(degrees);119 mCamera.translate(0, 0, -centerX);120 mCamera.getMatrix(matrix);121 mCamera.restore();122 }123 124 matrix.preTranslate(-centerX, -centerY);125 matrix.postTranslate(centerX, centerY);126 }127 } 128 129

有了这个类一切都会变得简单的,接着只要在activity中写两个Rotate3d的对象,让两个view,分别做这两个对象的animation就好了;

1 //下面两句很关键哦, 2 Rotate3d leftAnimation = new Rotate3d(-0, -90, 0, 0, mCenterX, mCenterY); 3 Rotate3d rightAnimation = new Rotate3d(-0+90, -90+90,

Tags:Android 旋转

编辑录入:coldstar [复制链接] [打 印]
赞助商链接