OpenGL ES 绘制圆环
2015-08-12 21:00
459 查看
1、新建 MyRingRenderer.h
2、运行效果
/* * 圆环 */ public class MyRingRenderer extends MyAbstractRenderer { private float r_inner =0.2f; //内环 半径 private float r_ring =0.3f; //圆环 环半径 public void onSurfaceCreated(GL10 gl, EGLConfig arg1) { //设置清屏色(背景) gl.glClearColor(0, 0, 0, 1); //启用顶点缓冲区 gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); } protected void drawBefore(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT); } protected void draw(GL10 gl) { int ringCount =20;//把圆环 切成20块 int blockCount =20;//把圆 切成20块 float alpha =0; float beta =0; float alphaStep =(float) ((2*Math.PI) /ringCount); float betaStep =(float) ((2*Math.PI) /blockCount); List<Float> pos =new ArrayList<Float>(); for(int i =0;i <ringCount;i++){ //一次画两个相邻的圆 alpha =i *alphaStep; for(int j =0; j <blockCount; j++){ beta =j *betaStep; // z值为0的 以(0,0)点线段长度 float lineD =(float) (r_inner +r_ring +r_ring *Math.cos(beta)); // 投影到 x,y轴 float x0 =(float) (Math.cos(alpha) *lineD); float y0 =(float) (Math.sin(alpha) *lineD); //由于 z轴靠近人的为正方向 +Math.PI float z0 =(float) (Math.sin(beta +Math.PI) *r_ring); float x1 =(float) (Math.cos(alpha +alphaStep) *lineD); float y1 =(float) (Math.sin(alpha +alphaStep) *lineD); float z1 =z0; pos.add(x0); pos.add(y0); pos.add(z0); pos.add(x1); pos.add(y1); pos.add(z1); } } ByteBuffer bb =BufferUtil.list2ByteBuffer(pos); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, bb); gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, pos.size()/3); } }
2、运行效果
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories