先看效果图
圆面的绘制:
package test.com.opengles8_1;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import android.opengl.GLES20;
/**
* Created by hbin on 2016/9/5.
* 圆面
*/
public class Circle {
int mProgram;//自定义渲染管线着色器程序id
int muMVPMatrixHandle;//总变换矩阵引用
int maPositionHandle; //顶点位置属性引用
int maTexCoorHandle; //顶点纹理坐标属性引用
int muMMatrixHandle;
int maCameraHandle; //摄像机位置属性引用
int maNormalHandle; //顶点法向量属性引用
int maLightLocationHandle;//光源位置属性引用
String mVertexShader;//顶点着色器代码脚本
String mFragmentShader;//片元着色器代码脚本
FloatBuffer mVertexBuffer;//顶点坐标数据缓冲
FloatBuffer mTexCoorBuffer;//顶点纹理坐标数据缓冲
FloatBuffer mNormalBuffer;//顶点法向量数据缓冲
int vCount=0;
float xAngle=0;//绕x轴旋转的角度
float yAngle=0;//绕y轴旋转的角度
float zAngle=0;//绕z轴旋转的角度
public Circle(MySurfaceView mv,float scale,float r,int n)
{
//调用初始化顶点数据的initVertexData方法
initVertexData(scale,r,n);
//调用初始化着色器的intShader方法
initShader(mv);
}
public void initVertexData(
float scale,//大小
float r,//半径
int n //切分的份数
){
r=r*scale;
float angdegSpan=360.0f/n;//顶角的读书
vCount=3*n;//顶点个数,共有n个三角形,每个三角形都有3个顶点
float[] vertices=new float[vCount*3];//顶点坐标数据
float[] textures=new float[vCount*2];//顶点纹理S,T坐标值数组
//坐标数据初始化
int count=0;
int stCount=0;
for (float angdeg=0;Math.ceil(angdeg)<360;angdeg+=angdegSpan){
double angrad=Math.toRadians(angdeg);//当前弧度
double angradNext=Math.toRadians(angdeg+angdegSpan);//下一弧度
//中心点
vertices[count++]=0;//顶点坐标
vertices[count++]=0;
vertices[count++]=0;
textures[stCount++]=0.5F;//ST坐标
textures[stCount++]=0.5f;
//当前点
vertices[count++]=(float)(-r*Math.sin(angrad));//顶点坐标
vertices[count++]=(float)(r*Math.cos(angrad));
vertices[count++]=0;
textures[stCount++]=(float)(0.5-0.5*Math.sin(angrad));//st坐标
textures[stCount++]=(float)(0.5-0.5*Math.cos(angrad));
//下一点
vertices[count++]=(float)(-r*Math.sin(angradNext));//顶点坐标
vertices[count++]&#