|
onDrawFrame: 定义实际的绘图操作。onSurfaceChanged: 如果设备支持屏幕横向和纵向切换,这个方法将发生在横向纵向互换时。此时可以重新设置绘制的纵横比率。以上内容是建立一个opengl es工程的基础。3.2.3顶点坐标的定义xt, yt, zt,// 0a+xt,yt,zt,//1xt, yt, zt,// 0a+xt,yt,zt,//1a+xt,a+yt,zt,//2xt,a+yt,zt,//3xt,yt,-a+zt,//4a+xt,yt,-a+zt,//5a+xt,a+yt,-a+zt,//6xt,a+yt,-a+zt,//70 ,0, 0,// 00 ,0, 0,// 0a,0,0,//1a,a,0,//20a,0,//30,0,-a,//4a,0,-a,//5a,a,-a,//60,a,-a,//7相当于按照向量(xt,yt,zt)平移3.2.4线程控制魔方的旋转一共三个状态,循环往复new Thread() {public void run() {// 省去一些属性的定义while (true) {while (i = t) && (i = 2 * t && i = 3* t) {i = i - 3 * t;//返回第一个状态}}}}.start();3.2.5加载纹理(0,0(0,0)(1,1)(0,1)(1,0)图片区域定义纹理坐标:float[] texST = new float[] { 0, 0, 0, 1, 1, 0, 1, 1, };将坐标值存放到Buffer中:ByteBuffer tbb = ByteBuffer.allocateDirect(texST.length * 4);tbb.order(ByteOrder.nativeOrder());// 设置字节顺序mTextureBuffer = tbb.asFloatBuffer();// 转换为int型缓冲mTextureBuffer.put(texST);// 向缓冲区中放入顶点着色数据mTextureBuffer.position(0);// 设置缓冲区起始位置开启并绑定纹理gl.glEnable(GL10.GL_TEXTURE_2D); // 开启纹理gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);// 允许使用纹理ST坐标缓冲gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer);// 为画笔指定纹理ST坐标缓冲gl.glBindTexture(GL10.GL_TEXTURE_2D, MySurfaceView.frontId);// 绑定纹理图片过大或过小的纹理映射方式://当图片过小时的纹理映射方法gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);//当图片过大时的纹理映射方法gl.glTexParameterf(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR_MIPMAP_LINEAR);四、程序清单4.1 资源清单资源名大小(KB)像素用途up.bmp32128*128三阶魔方上面贴图down.bmp32128*128三阶魔方下面贴图left.bmp32128*128三阶魔方左面贴图right.bmp32128*128三阶魔方右面贴图back.bmp32128*128三阶魔方后面贴图front.bmp32128*128三阶魔方前面贴图background.jpg171586*950程序主界面背景图片ic_launcher.png751512*1134程序图标up2.bmp16128*128二阶魔方上面贴图down2.bmp16128*128二阶魔方下面贴图left2.bmp16128*128二阶魔方左面贴图right2.bmp16128*128二阶魔方右面贴图back2.bmp16128*128二阶魔方后面贴图front2.bmp16128*128二阶魔方前面贴图Three.mp32.44MB/三阶魔方背景音乐4.2 类图RotateCube.classMySurfaceView myGLSurfaceView;private SeekBar mSeekBarx;RotateCube.classMySurfaceView myGLSurfaceView;private SeekBar mSeekBarx;private SeekBar mSeekBary ;private SeekBar mSeekBarz ;MediaPlayer mediaPlayer;onCreate()onResume()onPause()Main.classMenuInflater mInflater;onCreate()onCreateOptionsMenu()onOptionsItemSelected()exitAler()Setting.classonCreateySetting.classonCreatey()RotateCubeTwo.classMySurfaceViewTwo myGLSurfaceView2;onCreate()onResume()onPause()CubeVertex.classprivate FloatBuffer mVertexBuffer;CubeVertex.classprivate FloatBuffer mVertexBuffer;private FloatBuffer mVertexBuffer1;private FloatBuffer mVertexBuffer2;private FloatBuffer mVertexBuffer3;private FloatBuffer mVertexBuffer4;private FloatBuffer mVertexBuffer5;private FloatBuffer mTextureBuffer;int vCountpublic float mAngleX;public float mAngleY;public float mAngleZ;float a = 0.9f;CubeVertex()drawSelf()MySurfaceView.classprivate SceneRenderer mRenderer;float cx = 10;float cy = 10;float cz = 40;float tx = 0;float ty = 0;float tz = 0;static int upId;static int downId;static int leftId;static int rightId;static int backId;static int frontId;public float size = 5;public long time = 10;public float seekx;public float seeky;public float seekz;MySurfaceView()initTexture()SceneRenderer.class CubeVertexTwo.classCubeVertexTwo.classprivate FloatBuffer mVertexBuffer;private FloatBuffer mVertexBuffer1;private FloatBuffer mVertexBuffer2;private FloatBuffer mVertexBuffer3;private FloatBuffer mVertexBuffer4;private FloatBuffer mVertexBuffer5;private FloatBuffer mTextureBuffer;int vCountpublic float mAngleX2;public float mAngleY2;public float mAngleZ2;float a = 1.8f;CubeVertexTwo()drawSelfTwo()MySurfaceView.classMySurfaceView.classprivate SceneRenderer mRenderer;float cx = 10;float cy = 10;float cz = 40;float tx = 0;float ty = 0;float tz = 0;static int upId2;static int downId2;static int leftId2;static int rightId2;static int backId2;static int frontId2;MySurfaceView2()initTexture()SceneRenderer2.classSky.classSky.classfinal float R=11.0f;Private FloatBuffer mVertexBuffer;private IntBuffer mColorBuffer;int vCount=0;float yAngle;int xOffset;int zOffset;float scale;Sky()drawSelf()五、调试过程出现的问题及解决办法5.1 只能加载一面纹理 加载一个面的纹理较简单,只需在CubeVertex里面定义一个纹理坐标,然后将其存放进纹理缓冲器buffer里面,在绘制时,将纹理坐标与顶点坐标绑定。
以上内容就是[3d旋转魔方]基于opengl的3d旋转魔方.doc的相关内容介绍,喜欢侠外游戏论坛的朋友可以关注我们。
上一页12345下一页 |
|