我正在尝试写一个方法,它将从一个开始的角度画一个弧线到一个结束角使用GL_TRIANGLE_STRIP。我编写了以下代码,但有以下问题:
我花了很多时间来尝试正确地处理这个问题,并认为让另一双眼睛看我的代码会很有帮助。下面的图片显示了我试图在两个角度之间创建的三角形条带。我会在弄清楚这个部分后再应用纹理。谢谢你的帮忙!

-(void) drawArcFrom:(CGFloat)startAngle to:(CGFloat)endAngle position:(CGFloat)position radius:(CGPoint)radius {
CGFloat segmentWidth = 10.0;
CGFloat increment = fabsf(endAngle - startAngle) / segmentWidth;
int numSegs = fabsf(endAngle - startAngle) / segmentWidth;
int direction = (endAngle - startAngle > 0) ? 1 : -1;
ccVertex2F vertices[numSegs * 2];
for (int i = 0; i < numSegs; i++) {
CGFloat angle = startAngle - (i * increment * direction);
CGPoint outsidePoint = ccpAdd(position, ccp(sinf(CC_DEGREES_TO_RADIANS(angle)) * (radius + 4), cosf(CC_DEGREES_TO_RADIANS(angle)) * (radius + 4)));
CGPoint insidePoint = ccpAdd(position, ccp(sinf(CC_DEGREES_TO_RADIANS(angle)) * (radius - 4), cosf(CC_DEGREES_TO_RADIANS(angle)) * (radius - 4)));
vertices[i * 2] = (ccVertex2F) {outsidePoint.x, outsidePoint.y };
vertices[i * 2 + 1] = (ccVertex2F) {insidePoint.x, insidePoint.y };
}
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei) numSegs * 2);
}发布于 2015-06-08 20:58:27
我的android代码是整圈的。段= 20;共弦x,y,z
float w2 = width / 2f;
float h2 = height / 2f;
double radius = Math.min(w2, h2);
double PI2 = Math.PI * 2d;
coords = new float[SEGMENTS * 2 * 3];
double angle;
int index = 0;
double min_radius = radius - circle_width;
double max_radius = radius + circle_width;
for (int i = 0; i < SEGMENTS; i++, index += 6) {
angle = (PI2 * (double) i) / (double) (SEGMENTS - 1);
double sin_angle = Math.sin(angle);
double cos_angle = Math.cos(angle);
coords[index + 0] = (float) (cos_angle * max_radius);
coords[index + 1] = (float) (sin_angle * max_radius);
coords[index + 2] = 0f;
coords[index + 3] = (float) (cos_angle * min_radius);
coords[index + 4] = (float) (sin_angle * min_radius);
coords[index + 5] = 0f;
}https://stackoverflow.com/questions/18166952
复制相似问题