📜  opengl draw cresent moon c++ 代码示例

📅  最后修改于: 2022-03-11 14:44:48.960000             🧑  作者: Mango

代码示例1
//first circle moon
    int moonr = 50;
    int mooncenterx = 700;
    int mooncentery = 500;
    int moonsteps = 100;
    float circleangle = PI * 2.0f;
    glColor3f(1.0, 1.0, 1.0);
    glBegin(GL_TRIANGLE_FAN);

    for (int a = 0; a <= moonsteps; a++) {
        float angle = circleangle * float(a) / float(moonsteps);//get the current angl
        float moonx = moonr * cosf(angle);//calculate the x component
        float moony = moonr * sinf(angle);//calculate the y component
        glVertex2f(moonx + mooncenterx, moony + mooncentery);//output vertex
    }
    glEnd();

    //second circle moon
    int moon2r = 50;
    int mooncenter2x = 725;
    int mooncenter2y = 525;
    int moonsteps2 = 100;
    float circleangle2 = PI * 2.0f;
    glColor3f(0.5, 0.9, 0.4);
    glBegin(GL_TRIANGLE_FAN);

    for (int b = 0; b <= moonsteps; b++) {
        float angle2 = circleangle * float(b) / float(moonsteps2);//get the current angle
        float moon2x = moonr * cosf(angle2);//calculate the x component
        float moon2y = moonr * sinf(angle2);//calculate the y component
        glVertex2f(moon2x + mooncenter2x, moon2y + mooncenter2y);//output vertex
    }
    glEnd();