void createRing(GLfloat centerx, GLfloat centery, GLfloat centerz, GLfloat radius, GLfloat h, GLfloat thick)
{
    /* function createRing()
    링의 중심 x,y,z좌표, 반지름, 높이, 두께를 받아 링을 생성하는 함수
    centerx : 링의 중심 x좌표
    centery : 링의 중심 y좌표
    centerz : 링의 중심 z좌표
    radius : 링의 반지름
    h  : 링의 높이
    thick : 링의 두께
    */
    GLfloat x, y, angle;

    glColor3ub(148, 0, 211);
    glBegin(GL_QUAD_STRIP);           //링의 윗면
    for(angle = (2.0f*GL_PI); angle > 0.0f; angle -= (GL_PI/8.0f))
    {
        x = centerx + radius*sin(angle);
        y = centery + radius*cos(angle);
        glNormal3f(0.0f, 0.0f, -1.0f);
        glVertex3f(x, y, centerz);
        x = centerx + (radius-thick)*sin(angle);
        y = centery + (radius-thick)*cos(angle);
        glVertex3f(x, y, centerz);
    }
    glEnd();

    int color = 0;
    glBegin(GL_QUAD_STRIP);            //링의 바깥쪽 옆면
    for(angle = 0.0f; angle < (2.0f*GL_PI); angle += (GL_PI/8.0f))
    {
        x = centerx + radius*sin(angle);
        y = centery + radius*cos(angle);
        glNormal3f(sin(angle), cos(angle), 0.0f);
        glVertex3f(x, y, centerz);
        glVertex3f(x, y, centerz + h);
        color++;
    }
    glEnd();

    glColor3ub(148, 0, 211);
    glBegin(GL_QUAD_STRIP);            //링의 안쪽 옆면
    for(angle = (2.0f*GL_PI); angle > 0.0f; angle -= (GL_PI/8.0f))
    {
        x = centerx + (radius-thick)*sin(angle);
        y = centery + (radius-thick)*cos(angle);
        glNormal3f(-sin(angle), -cos(angle), 0.0f);
        glVertex3f(x, y, centerz);
        glVertex3f(x, y, centerz + h);
    }
    glEnd();

    glBegin(GL_QUAD_STRIP);           //원기둥의 밑면
    for(angle = 0.0f; angle < (2.0f*GL_PI); angle += (GL_PI/8.0f))
    {
        x = centerx + radius*sin(angle);
        y = centery + radius*cos(angle);
        glNormal3f(0.0f, 0.0f, 1.0f);
        glVertex3f(x, y, centerz+h);
        x = centerx + (radius-thick)*sin(angle);
        y = centery + (radius-thick)*cos(angle);
        glVertex3f(x, y, centerz+h);
    }
    glEnd();
}

+ Recent posts