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

浅谈 Android 3D旋转

 2010-08-23 01:27:00 来源:WEB开发网   
核心提示:最近和一哥们在聊Android的3D旋转效果的技术实现的事情,今天正好有点时间就把技术细节写了出来在ANDROID中实现3D旋转直接使用animation配合camera就可以实现,浅谈 Android 3D旋转,在apidemo里就有这样的实例我们首先做一个继承animation的类Rotate3d.java1 pu

最近和一哥们在聊Android的3D旋转效果的技术实现的事情,今天正好有点时间就把技术细节写了出来

ANDROID中实现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; 35 final float centerY = mCenterY; 36 final Matrix matrix = t.getMatrix(); 37 38 if (degrees <= -76.0f) { 39 degrees = -90.0f; 40 mCamera.save(); 41 mCamera.rotateY(degrees); 42 mCamera.getMatrix(matrix); 43 mCamera.restore(); 44 } else if(degrees >=76.0f){ 45 degrees = 90.0f; 46 mCamera.save(); 47 mCamera.rotateY(degrees); 48 mCamera.getMatrix(matrix); 49 mCamera.restore(); 50 }else{ 51 mCamera.save(); 52 //这里很重要哦。 53 mCamera.translate(0, 0, centerX); 54 mCamera.rotateY(degrees); 55 mCamera.translate(0, 0, -centerX); 56 mCamera.getMatrix(matrix); 57 mCamera.restore(); 58 } 59 60 matrix.preTranslate(-centerX, -centerY); 61 matrix.postTranslate(centerX, centerY); 62 } 63 } 64 65 public class Rotate3d

1 2 3  下一页

Tags:Android 旋转

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