OpenGL绘制填充五角星

来源:互联网 发布:贪心算法 回溯算法 编辑:程序博客网 时间:2024/04/28 15:19

GLfloat out_length = sqrt(1.0 / (2 - 2 * cos(72 * PI / 180))),

bx = out_length * cos(18 * PI / 180),

by = out_length * sin(18 * PI / 180),

cx = out_length * sin(36 * PI / 180),

cy = -out_length * cos(36 * PI / 180);

GLfloat fx = cx * (by - out_length) / (cy - out_length), fy = by,

in_length = sqrt(fx * fx + fy * fy),

gx = in_length * cos(18 * PI / 180),

gy = -in_length * sin(18 * PI / 180);

 

GLfloat point_a[2] = {0, out_length},

point_b[2] = {bx, by},

point_c[2] = {cx, cy},

point_d[2] = {-cx, cy},

point_e[2] = {-bx, by},

point_f[2] = {fx, fy},

point_g[2] = {gx, gy},

point_h[2] = {0, -in_length},

point_i[2] = {-gx, gy},

point_j[2] = {-fx, fy};

glBegin(GL_TRIANGLE_FAN);

glVertex2f(0.0f, 0.0f);

glVertex2f(point_a[0], point_a[1]);

glVertex2f(point_f[0], point_f[1]);

glVertex2f(point_b[0], point_b[1]);

glVertex2f(point_g[0], point_g[1]);

glVertex2f(point_c[0], point_c[1]);

glVertex2f(point_h[0], point_h[1]);

glVertex2f(point_d[0], point_d[1]);

glVertex2f(point_i[0], point_i[1]);

glVertex2f(point_e[0], point_e[1]);

glVertex2f(point_j[0], point_j[1]);

glVertex2f(point_a[0], point_a[1]);

glEnd();

原创粉丝点击