3

我正在尝试生成多个五边形,但由于某种原因,五边形相互连接。有什么建议么?

GLfloat arr[] = {100,200,340,230,130,190,200,190,260,120,200};

glColor3f(1.0, 1.0, 1.0);
GLfloat angle2, r2, r_big_circle2, r_small_circle2, step2 = 3.14 / 5.0;
r_big_circle2 = 25;
r_small_circle2 = 20;

glPushMatrix();

glBegin(GL_LINE_LOOP);
for (int n = 0; n < 5; n++){
    for (int i = 0; i < 10; i++)
    {
        r2 = (i % 2 == 0 ? r_small_circle2 : r_big_circle2);
        angle2 = step2 * i;
        glVertex3f(r2 * cos(angle2)-arr[n], r2 * sin(angle2)-arr[n], -500);
    }

}
glEnd();
glPopMatrix();
4

1 回答 1

5

移动glBeginglEnd进入第一个for循环。此外GL_LINE_LOOP,对于 5 边多边形,应该只指定 5 个点glVertex3f- 您将每个五边形绘制两次,一次在其自身顶部。尝试:

for (int n = 0; n < 5; n++) {
    glBegin(GL_LINE_LOOP);
    for (int i = 0; i < 5; i++) {
        r2 = (i % 2 == 0 ? r_small_circle2 : r_big_circle2);
        angle2 = step2 * i;
        glVertex3f(r2 * cos(angle2)-arr[n], r2 * sin(angle2)-arr[n], -500);
    }
    glEnd();
}
于 2013-03-19T01:39:52.070 回答