使用Camera实现三维动画
2015-04-04 12:57
148 查看
package test.example.lxm.test; import android.app.Activity; import android.graphics.Camera; import android.graphics.Matrix; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.Display; import android.view.Window; import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.LinearInterpolator; import android.view.animation.Transformation; import android.widget.ImageView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //设置全屏 requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); //获取屏幕大小 WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); DisplayMetrics displayMetrics = new DisplayMetrics(); display.getMetrics(displayMetrics); int windowWidth = displayMetrics.widthPixels; int windowHeight = displayMetrics.heightPixels; //开始动画 int centerX = windowWidth /2; int centerY = windowHeight/2; MyAnimation myAnimation = new MyAnimation(centerX,centerY,4000); ImageView iv = (ImageView)findViewById(R.id.iv_test); iv.startAnimation(myAnimation); } class MyAnimation extends Animation{ //中心点 int centerX; int centerY; int duration; //进行三维变动 Camera camera = new Camera(); //各方向的位移变化量 final float TRANS_X = 100f; final float TRANS_Y = -150f; final float TRANS_Z = 80f; //旋转度数 final int ROTATE_X = 360; final int ROTATE_Y = 360; final int ROTATE_Z = 360; public MyAnimation(int centerX,int centerY, int duration){ this.centerX = centerX; this.centerY = centerY; this.duration = duration; } /** * @param width Width of the object being animated * @param height Height of the object being animated * @param parentWidth Width of the animated object's parent * @param parentHeight Height of the animated object's parent */ public void initialize(int width, int height, int parentWidth, int parentHeight) { super.initialize(width,height,parentWidth,parentHeight); setDuration(duration); //设置持续时间 setFillAfter(true); //设置保留动画结果 setInterpolator(new LinearInterpolator()); } /** * 设置动画在每一进度所做的事情 * @param interpolatedTime 动画行进时间比(如:动画进行到一半,interpolatedTime=0.5即1/2) * @param t 变化 */ protected void applyTransformation(float interpolatedTime, Transformation t) { super.applyTransformation(interpolatedTime,t); camera.save(); //位移 camera.translate(TRANS_X - TRANS_X * interpolatedTime,TRANS_Y - TRANS_Y*interpolatedTime, TRANS_Z-TRANS_Z*interpolatedTime); //旋转 camera.rotateX(ROTATE_X *interpolatedTime ); camera.rotateY(ROTATE_Y * interpolatedTime); camera.rotateZ(ROTATE_Z * interpolatedTime); //应用 Matrix matrix = t.getMatrix(); camera.getMatrix(matrix); //位移中心 matrix.preTranslate(-centerX,-centerY); matrix.postTranslate(centerX,centerY); camera.restore(); } } }
相关文章推荐
- 使用Eclipse实现USB Camera的ROS Publisher
- Android使用MediaRecorder和Camera实现视频录制及播放功能整理
- Android使用MediaRecorder和Camera实现视频录制及播放功能整理
- 使用surfaceview实现camera时,出现拍照后照片花屏问题
- Android中使用Opencv自带JavaCameraView实现高帧率竖屏显示
- Camera使用-实现简单的自定义相机
- 60.自定义View练习(五)高仿小米时钟 - 使用Camera和Matrix实现3D效果
- 安卓使用Camera实现拍照并保存到内存卡中
- Android实现拍照功能,使用SurfaceView+camera
- Opencv使用自带的CameraGLSurfaceView实现相机帧处理
- 高仿小米时钟 - 使用Camera和Matrix实现3D效果
- 使用Camera与SurfaceView实现自定义拍照功能
- Android使用MediaRecorder和Camera实现视频录制及播放功能整理
- 安卓使用Camera实现拍照并保存到内存卡中
- 60.自己定义View练习(五)高仿小米时钟 - 使用Camera和Matrix实现3D效果
- 使用自定义Camera实现简单拍照功能
- 安卓使用surfaceview+Camera+MediaRecorder实现视频录制
- 使用Camera和Matrix实现3D效果
- unity中camera怎么生成使用深度图 Camera Depth Texture 实现Image Effect
- android高仿小米时钟(使用Camera和Matrix实现3D效果)