首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

OpenGL ES课程V之更多3D模型(原文对照)

2012-07-05 
OpenGL ES教程V之更多3D模型(原文对照)The one to the left shows the segments and the one to the right

OpenGL ES教程V之更多3D模型(原文对照)


The one to the left shows the segments and the one to the right show us the faces we need to create.

public Cone(float baseRadius, float topRadius, float height,int numberOfSides) {int degree = 360 / numberOfSides;//ry = -degree / 2;float r = baseRadius;float vertices[] = new float[numberOfSides * 6];int current = 0;double part = ((2 * Math.PI) / 360);float y = (float)(r / Math.sin(degree/2 * part) * height / 2 );int halfTotal = numberOfSides * 3;// 算出基面和底面的顶点for (int i = 0; i < numberOfSides; i++) {float x = (float)Math.cos((degree * i * part));float z = -(float)Math.sin((degree * i * part));// X轴坐标值vertices[current] = (float) (r * x);vertices[current+ halfTotal] = topRadius * x;// Y轴,固定的vertices[current + 1] = -y ;vertices[current + 1 + halfTotal] = y;// Z轴,角度是逆时针等价分布,投影到Z轴,实际方向是向下,刚好相反vertices[current + 2] = (float) (r * z);vertices[current + 2 + halfTotal] = topRadius * z;current += 3;}current = 0;short incides[] = new short[(numberOfSides * 2 + (numberOfSides - 2) * 2) * 3];for (int i = 0; i < numberOfSides; i++) {incides[current + 0] = (short) i;incides[current + 1] = (short) ((i + 1) % numberOfSides);incides[current + 2] = (short) (incides[current + 1] + numberOfSides);incides[current + 3] = (short) (i);incides[current + 4] = (short) incides[current + 2];incides[current + 5] = (short) (i + numberOfSides);current += 6;}for (int i = 0; i < numberOfSides - 2; i++) {incides[current + 0] = (short) (numberOfSides);incides[current + 1] = (short) (numberOfSides + i + 1);incides[current + 2] = (short) ((numberOfSides + i + 2));current += 3;}for (int i = 0; i < numberOfSides - 2; i++) {incides[current + 0] = (short) (numberOfSides - 1);incides[current + 1] = (short) (i);incides[current + 2] = (short) (i + 1);current += 3;} }?

?

热点排行