cover Flow

  • A8_606314
    了解作者
  • 2.5MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-08 01:21
    上传日期
cover flow使用openGL实现android图片的倒影效果
AlexCoverFlow.zip
内容介绍
package com.alex.Sample_CoverFlow; import static com.alex.Sample_CoverFlow.Constant.ratio; import java.io.IOException; import java.io.InputStream; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.PixelFormat; import android.opengl.GLES20; import android.opengl.GLSurfaceView; import android.opengl.GLUtils; import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.util.Log; import android.view.MotionEvent; import com.alex.CoverFlow.R; public class MySurfaceView extends GLSurfaceView { final int TexturesCount = Constant.MAX_TEXTURES_COUNT; private SceneRenderer mRenderer;//场景渲染器 int[] textureIds =new int[TexturesCount]; //系统分配的纹理id private HandlerThread ht = new HandlerThread("MyGLSurfaceView"); private Handler handler; private float ox; private int next = 1; private int front = 2; private int slideIndex = 0;/*旋转次数索引*/ private boolean leftToRightDirection = true;/*向右为正*/ private Context mContext; private ImageLoader imageLoader; public MySurfaceView(Context context) { super(context); mContext = context; //设置背景是否透明 /* this.setZOrderOnTop(true); this.setEGLConfigChooser(8, 8, 8, 8, 16, 0); this.getHolder().setFormat(PixelFormat.TRANSLUCENT); */ imageLoader = new ImageLoader(mContext); ht.start(); this.setEGLContextClientVersion(2); //设置使用OPENGL ES2.0 mRenderer = new SceneRenderer(); //创建场景渲染器 setRenderer(mRenderer); //设置渲染器 //setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);//设置渲染模式为主动渲染 setRenderMode(RENDERMODE_WHEN_DIRTY); handler = new Handler(ht.getLooper()){ public void handleMessage(Message msg){ if(msg.what == next){ mRenderer.next(false); }else{ mRenderer.next(true); } } }; //计算GLSurfaceView的宽高比 Constant.pic_ratio = (float)186/275; } //触摸事件回调方法 @Override public boolean onTouchEvent(MotionEvent e) { float x = e.getX(); switch(e.getAction()){ case MotionEvent.ACTION_DOWN: ox = x; break; case MotionEvent.ACTION_UP: float length = x - ox; if(length < -Constant.slide_length){ Message msg = handler.obtainMessage(next); handler.sendMessage(msg); }else if(length > Constant.slide_length){ Message msg = handler.obtainMessage(front); handler.sendMessage(msg); } } return true; } private class SceneRenderer implements GLSurfaceView.Renderer { ImageRect imgRect[] = new ImageRect[Constant.MAX_IMG_COUNT]; private Object lock = new Object(); public void onDrawFrame(GL10 gl) { //清除深度缓冲与颜色缓冲 GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); //初始化光源方向 MatrixState.setLightLocation(0f, 5f, 5f); DrawPics(); } public void onSurfaceChanged(GL10 gl, int width, int height) { //设置视窗大小及位置 GLES20.glViewport(0, 0, width, height); //计算GLSurfaceView的宽高比 ratio = (float) width / height; //调用此方法计算产生透视投影矩阵 MatrixState.setProjectFrustum(-ratio, ratio, -1, 1, 4f, 100); //调用此方法产生摄像机9参数位置矩阵 MatrixState.setCamera(0f,0f,10.0f,0f,0f,0f,0f,1.0f,0.0f); //初始化变换矩阵 MatrixState.setInitStack(); //加载纹理 /* * start mgao test */ int drawableIDs[] = new int[] { R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d, R.drawable.e, R.drawable.f, }; /* String drawableIDs[] = new String[] { "http://61.58.63.25:80/cms/upload/vod/1400751021.jpg", "http://61.58.63.25:80/cms/upload/vod/1400751021.jpg", "http://61.58.63.25:80/cms/upload/vod/1400751021.jpg", "http://61.58.63.25:80/cms/upload/vod/1400751021.jpg", "http://61.58.63.25:80/cms/upload/vod/1400751021.jpg", "http://61.58.63.25:80/cms/upload/vod/1400751021.jpg", };*/ /* * end mgao test */ /*drawableIDs[0] = R.drawable.android_robot0; drawableIDs[1] = R.drawable.android_robot0; drawableIDs[2] = R.drawable.android_robot0; drawableIDs[3] = R.drawable.android_robot0; drawableIDs[4] = R.drawable.android_robot0; drawableIDs[5] = R.drawable.android_robot0;*/ for (int i=0;i<TexturesCount; i++) textureIds[i] = initTexture(drawableIDs[i]); } public void onSurfaceCreated(GL10 gl, EGLConfig config) { //设置屏幕背景色RGBA GLES20.glClearColor(0.0f,0.0f,0.0f, 1.0f); //创建img对象 for (int i=0; i<Constant.MAX_IMG_COUNT; i++) imgRect[i] =new ImageRect(MySurfaceView.this); //打开深度检测 GLES20.glEnable(GLES20.GL_DEPTH_TEST); //打开背面剪裁 GLES20.glEnable(GLES20.GL_CULL_FACE); } //将标准图片向远处偏移 public void originTransformPic(int picIndex) { //计算偏移后的x和z坐标 int factor = picIndex -(Constant.MAX_IMG_COUNT-1)/2;//介于-2~+2之间 float xOffset, zOffset; xOffset = factor*Constant.xDistance; zOffset = -Math.abs(factor*Constant.zDistance); MatrixState.translate(xOffset, 0, zOffset); } public void AnimationTransform(int picIndex, int rotateIndex/*旋转次数索引*/, boolean leftToRightDirection/*向右为正*/) { //先进行原始偏移 originTransformPic(picIndex); if (rotateIndex == 0)//不需要动画 return; //再进行动画偏移 int factor = picIndex -(Constant.MAX_IMG_COUNT-1)/2;//介于-2~+2之间 float xOffset, zOffset; xOffset = Constant.xFrameStep*rotateIndex; zOffset = -Constant.zFrameStep*rotateIndex; if (!leftToRightDirection) xOffset = -xOffset; if ((leftToRightDirection && (factor < 0)) || (!leftToRightDirection && (factor > 0))) zOffset = -zOffset; MatrixState.translate(xOffset, 0, zOffset); //对中间一张进行旋转,让下面一张露出来时候不挡住视线 /*if (0 == factor) { int count = Constant.slideFrames; float rotateAngel; rotateAngel = (count/2 - Math.abs(rotateIndex - count/2))*Constant.frameRotateAngel; if (!leftToRightDirection) rotateAngel = -rotateAngel; //MatrixState.rotate((float)Math.toRadians(rotateAngel), 1, 1, 1); MatrixState.rotate(rotateAngel, 0, 1, 0); }*/ } public void DrawPics() { float iAlphoaValue = 1.0f; //从左到右按顺序绘制照片(最中间一张暂时不绘制,最后再绘) int mediaIndex = (Constant.MAX_IMG_COUNT-1)/2; for (int i=0; i<Constant.MAX_IMG_COUNT; i++) { iAlphoaValue = 1.0f; if (i != mediaIndex) { //给最后一张照片加上淡出的效果 if (((i == 0) && (!leftToRightDirection)) || ((i == Constant.MAX_IMG_COU
评论
    相关推荐
    • Android学习
      Android学习Android学习Android学习Android学习Android学习Android学习
    • Android678
      Android678Android678Android678Android678Android678Android678Android678Android678Android678Android678
    • android 例子
      android 例子android 例子android 例子android 例子android 例子
    • android图片
      android精美小图片android精美小图片android精美小图片android精美小图片
    • android课件
      清华老师上课的android课件。ch_01android概述ch_02android开发基础ch_03资源的访问ch_04android用户界面ch_05Ativity和Intent。其他自己看。
    • AndroidKiller
      安卓App反编译工具AndroidKiller\AndroidKiller\AndroidKiller
    • AndroidSample
      Android示例 这是一个示例Android应用,用于降低Google Play服务和Android Volley的使用率。 有关更多详细信息,请参阅以下链接: Google Play服务: Android凌空抽射:
    • android source
      android 源代码 source android 源代码 source android 源代码 source android 源代码 source android 源代码 source android 源代码 source android 源代码 source
    • Android 教程
      Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android ...
    • android资料
      Android程序员指南 Android_UI开发专题 Android程序开发初级教程 android的五大类各种常用类的资料整理 Android高手进阶教程