⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shapes.c

📁 计算机图形学~想必是很多人需要的~在此共享一下
💻 C
📖 第 1 页 / 共 4 页
字号:
    "Specifies blue component of a color.", "%.2f" },
    { 163, 120, 210, 0.0f, 200.0f, 175.0f, 1.0f, 
    "Specifies x component of a vertex.", "%.1f" },
    { 164, 180, 210, 0.0f, 200.0f, 175.0f, 1.0f, 
    "Specifies y component of a vertex.", "%.1f" },
    
    { 165, 120, 240, 0.0f, 1.0f, 0.5f, 0.005f,
    "Specifies red component of a color.", "%.2f" },
    { 166, 180, 240, 0.0f, 1.0f, 0.0f, 0.005f, 
    "Specifies green component of a color.", "%.2f" },
    { 167, 240, 240, 0.0f, 1.0f, 1.0f, 0.005f, 
    "Specifies blue component of a color.", "%.2f" },
    { 168, 120, 270, 0.0f, 200.0f, 200.0f, 1.0f, 
    "Specifies x component of a vertex.", "%.1f" },
    { 169, 180, 270, 0.0f, 200.0f, 100.0f, 1.0f, 
    "Specifies y component of a vertex.", "%.1f" }
};

cell shadeQuad[4*3+4*2] = {
    { 170, 120, 60, 0.0f, 1.0f, 1.0f, 0.005f,
        "Specifies red component of a color.", "%.2f" },
    { 171, 180, 60, 0.0f, 1.0f, 1.0f, 0.005f, 
    "Specifies green component of a color.", "%.2f" },
    { 172, 240, 60, 0.0f, 1.0f, 1.0f, 0.005f, 
    "Specifies blue component of a color.", "%.2f" },
    { 173, 120, 90, 0.0f, 200.0f, 50.0f, 1.0f, 
    "Specifies x component of a vertex.", "%.1f" },
    { 174, 180, 90, 0.0f, 200.0f, 50.0f, 1.0f, 
    "Specifies y component of a vertex.", "%.1f" },
    
    { 175, 120, 120, 0.0f, 1.0f, 1.0f, 0.005f,
    "Specifies red component of a color.", "%.2f" },
    { 176, 180, 120, 0.0f, 1.0f, 1.0f, 0.005f, 
    "Specifies green component of a color.", "%.2f" },
    { 177, 240, 120, 0.0f, 1.0f, 0.0f, 0.005f, 
    "Specifies blue component of a color.", "%.2f" },
    { 178, 120, 150, 0.0f, 200.0f, 100.0f, 1.0f, 
    "Specifies x component of a vertex.", "%.1f" },
    { 179, 180, 150, 0.0f, 200.0f, 150.0f, 1.0f, 
    "Specifies y component of a vertex.", "%.1f" },
    
    { 180, 120, 180, 0.0f, 1.0f, 1.0f, 0.005f,
    "Specifies red component of a color.", "%.2f" },
    { 181, 180, 180, 0.0f, 1.0f, 0.0f, 0.005f, 
    "Specifies green component of a color.", "%.2f" },
    { 182, 240, 180, 0.0f, 1.0f, 1.0f, 0.005f, 
    "Specifies blue component of a color.", "%.2f" },
    { 183, 120, 210, 0.0f, 200.0f, 200.0f, 1.0f, 
    "Specifies x component of a vertex.", "%.1f" },
    { 184, 180, 210, 0.0f, 200.0f, 200.0f, 1.0f, 
    "Specifies y component of a vertex.", "%.1f" },
    
    { 185, 120, 240, 0.0f, 1.0f, 0.0f, 0.005f,
    "Specifies red component of a color.", "%.2f" },
    { 186, 180, 240, 0.0f, 1.0f, 1.0f, 0.005f, 
    "Specifies green component of a color.", "%.2f" },
    { 187, 240, 240, 0.0f, 1.0f, 1.0f, 0.005f, 
    "Specifies blue component of a color.", "%.2f" },
    { 188, 120, 270, 0.0f, 200.0f, 150.0f, 1.0f, 
    "Specifies x component of a vertex.", "%.1f" },
    { 189, 180, 270, 0.0f, 200.0f, 100.0f, 1.0f, 
    "Specifies y component of a vertex.", "%.1f" }
};

cell flatQuad[1*3+4*2] = {
    { 190, 120, 60, 0.0f, 1.0f, 1.0f, 0.005f,
        "Specifies red component of a color.", "%.2f" },
    { 191, 180, 60, 0.0f, 1.0f, 1.0f, 0.005f, 
    "Specifies green component of a color.", "%.2f" },
    { 192, 240, 60, 0.0f, 1.0f, 1.0f, 0.005f, 
    "Specifies blue component of a color.", "%.2f" },
    { 193, 120, 90, 0.0f, 200.0f, 50.0f, 1.0f, 
    "Specifies x component of a vertex.", "%.1f" },
    { 194, 180, 90, 0.0f, 200.0f, 50.0f, 1.0f, 
    "Specifies y component of a vertex.", "%.1f" },
    { 195, 120, 120, 0.0f, 200.0f, 100.0f, 1.0f, 
    "Specifies x component of a vertex.", "%.1f" },
    { 196, 180, 120, 0.0f, 200.0f, 150.0f, 1.0f, 
    "Specifies y component of a vertex.", "%.1f" },
    { 197, 120, 150, 0.0f, 200.0f, 200.0f, 1.0f, 
    "Specifies x component of a vertex.", "%.1f" },
    { 198, 180, 150, 0.0f, 200.0f, 200.0f, 1.0f, 
    "Specifies y component of a vertex.", "%.1f" },
    { 199, 120, 180, 0.0f, 200.0f, 150.0f, 1.0f, 
    "Specifies x component of a vertex.", "%.1f" },
    { 200, 180, 180, 0.0f, 200.0f, 100.0f, 1.0f, 
    "Specifies y component of a vertex.", "%.1f" }
};
GLboolean clear = GL_TRUE;GLenum mode = GL_LINES;
int shaded = GL_FALSE;
int bigVertices = GL_FALSE;
int outlined = GL_FALSE;void redisplay_all(void);
void screen_menu(int);GLuint window, screen, command;GLuint sub_width = 256, sub_height = 512;GLint selection = 0;
int sm;

GLuint circleList;
#define _PI 3.14159265

GLvoid *font_style = GLUT_BITMAP_TIMES_ROMAN_10;

static float linesInit[] = {1.0, 1.0, 1.0, 
50.0, 50.0, 100.0, 100.0,
1.0, 1.0, 1.0, 
150.0, 100.0, 200.0, 150.0};

static float shadeFourInit[] = 
{1.0, 1.0, 1.0, 50.0, 50.0, 
0.0, 1.0, 1.0, 100.0, 150.0,
0.0, 1.0, 0.0, 200.0, 200.0, 
1.0, 1.0, 0.0, 150.0, 100.0};

static float flatFourInit[] = 
{1.0, 1.0, 1.0, 
50.0, 50.0, 
100.0, 150.0,
200.0, 200.0, 
150.0, 100.0};

static float flatQuadInit[] = 
{1.0, 1.0, 1.0, 
50.0, 50.0, 
100.0, 150.0,
200.0, 200.0, 
150.0, 100.0};

static float shadeThreeInit[] = 
{0.5, 1.0, 1.0, 100.0, 50.0, 
1.0, 1.0, 0.5, 50.0, 150.0,
1.0, 1.0, 1.0, 200.0, 200.0};

static float flatThreeInit[] = 
{1.0, 1.0, 1.0, 
100.0, 50.0, 
50.0, 150.0,
200.0, 200.0};

static float shadeQStripInit[] = 
{1.0, 1.0, 1.0, 25.0, 25.0, 
0.0, 1.0, 1.0, 50.0, 100.0,
1.0, 1.0, 0.0, 100.0, 50.0, 
1.0, 1.0, 0.0, 100.0, 75.0,
0.0, 1.0, 0.0, 150.0, 25.0, 
1.0, 0.0, 0.0, 175.0, 125.0};

static float tFanInit[] = 
{0.0, 0.0, 1.0, 50.0, 50.0, 
0.0, 0.5, 1.0, 100.0, 150.0,
0.5, 0.5, 1.0, 175.0, 175.0, 
0.5, 0.0, 1.0, 200.0, 100.0};

static float tStripInit[] = 
{0.0, 1.0, 1.0, 50.0, 50.0, 
1.0, 1.0, 0.0, 100.0, 150.0,
1.0, 1.0, 0.0, 175.0, 25.0, 
1.0, 0.0, 0.0, 150.0, 175.0};

static float shadePointsInit[] = 
{1.0, 1.0, 1.0, 100.0, 100.0, 
1.0, 1.0, 0.0, 200.0, 175.0,
1.0, 0.0, 1.0, 50.0, 200.0, 
0.0, 1.0, 1.0, 150.0, 150.0,
1.0, 1.0, 1.0, 75.0, 50.0, 
1.0, 1.0, 0.0, 175.0, 75.0};

static float shadeQuadInit[] = 
{1.0, 1.0, 1.0, 50.0, 50.0,
1.0, 1.0, 0.0, 100.0, 150.0,
1.0, 0.0, 1.0, 200.0, 200.0, 
0.0, 1.0, 1.0, 150.0, 100.0};

voidsetfont(char* name, int size){    font_style = GLUT_BITMAP_HELVETICA_10;    if (strcmp(name, "helvetica") == 0) {        if (size == 12)             font_style = GLUT_BITMAP_HELVETICA_12;        else if (size == 18)            font_style = GLUT_BITMAP_HELVETICA_18;    } else if (strcmp(name, "times roman") == 0) {        font_style = GLUT_BITMAP_TIMES_ROMAN_10;        if (size == 24)            font_style = GLUT_BITMAP_TIMES_ROMAN_24;    } else if (strcmp(name, "8x13") == 0) {        font_style = GLUT_BITMAP_8_BY_13;    } else if (strcmp(name, "9x15") == 0) {        font_style = GLUT_BITMAP_9_BY_15;    }}void drawstr(GLuint x, GLuint y, char* format, ...){    va_list args;    char buffer[255], *s;        va_start(args, format);    vsprintf(buffer, format, args);    va_end(args);        glRasterPos2i(x, y);    for (s = buffer; *s; s++)        glutBitmapCharacter(font_style, *s);}voidcell_draw(cell* cell){    glColor3ub(0, 255, 128);    if (selection == cell->id) {        glColor3ub(255, 255, 0);        drawstr(10, MESSAGEY, cell->info);        glColor3ub(255, 0, 0);    }        drawstr(cell->x, cell->y, cell->format, cell->value);}intcell_hit(cell* cell, int x, int y){    if (x > cell->x && x < cell->x + 60 &&        y > cell->y-20 && y < cell->y+10)        return cell->id;    return 0;}voidcell_update(cell* cell, int update){    if (selection != cell->id)        return;        cell->value += update * cell->step;        if (cell->value < cell->min)        cell->value = cell->min;    else if (cell->value > cell->max)         cell->value = cell->max;}voidcell_vector(float* dst, cell* cell, int num){    while (--num >= 0)        dst[num] = cell[num].value;}

void createCircleList (void) {
    GLUquadricObj *qobj;
    float radius = 4.0f;
    int slices = 11;
    int i;
    
    circleList = glGenLists(1);
    qobj = gluNewQuadric();
    glNewList (circleList, GL_COMPILE);
    glBegin (GL_TRIANGLE_FAN);
    glVertex2f (0.0f, 0.0f);
    for (i = 0; i <= slices; i++) {
        glVertex2f (radius * cos ((2.0 * _PI) * (float) i/(float) slices),
            radius * sin ((2.0 * _PI) * (float) i/(float) slices));
    }
    glEnd();
    glEndList();
}

void drawCircle (GLfloat coords[]) {
    glPushMatrix();
    glTranslatef(coords[0], coords[1], 0.0f);
    glCallList(circleList);
    glPopMatrix();
}voiddrawmodel(void){
    GLfloat vals[50];
        if ((mode == GL_LINES) && !shaded ) {
        cell_vector (vals, lines, sizeof(linesInit)/sizeof(float));
        glBegin (GL_LINES);
        glColor3fv (&vals[0]);
        glVertex2fv (&vals[3]);
        glVertex2fv (&vals[5]);
        glColor3fv (&vals[7]);
        glVertex2fv (&vals[10]);
        glVertex2fv (&vals[12]);
        glEnd();
        if (bigVertices) {
            glColor3fv (&vals[0]);
            drawCircle (&vals[3]);
            drawCircle (&vals[5]);
            glColor3fv (&vals[7]);
            drawCircle (&vals[10]);
            drawCircle (&vals[12]);
        }
    }
    else if ((mode == GL_TRIANGLE_FAN) || (mode == GL_TRIANGLE_STRIP) ||
        (shaded && 
        ((mode == GL_LINES) || (mode == GL_LINE_LOOP) ||
        (mode == GL_LINE_STRIP) || (mode == GL_QUADS)))) {
        
        if (mode == GL_TRIANGLE_STRIP)
            cell_vector (vals, tStrip, sizeof(tStripInit)/sizeof(float));
        else if (mode == GL_TRIANGLE_FAN)
            cell_vector (vals, tFan, sizeof(tFanInit)/sizeof(float));
        else if (mode == GL_QUADS)
            cell_vector (vals, shadeQuad, sizeof(shadeQuadInit)/sizeof(float));
        else
            cell_vector (vals, shadeFour, sizeof(shadeFourInit)/sizeof(float));
        
        if (mode == GL_TRIANGLE_FAN) 
            glBegin (GL_TRIANGLE_FAN);			
        else if (mode == GL_TRIANGLE_STRIP)
            glBegin (GL_TRIANGLE_STRIP);			
        else if (mode == GL_LINES) 
            glBegin (GL_LINES);			
        else if (mode == GL_LINE_LOOP)
            glBegin (GL_LINE_LOOP);			
        else if (mode == GL_LINE_STRIP) 
            glBegin (GL_LINE_STRIP);			
        else if (mode == GL_QUADS)
            glBegin (GL_QUADS);		
        glColor3fv (&vals[0]);
        glVertex2fv (&vals[3]);
        glColor3fv (&vals[5]);
        glVertex2fv (&vals[8]);
        glColor3fv (&vals[10]);
        glVertex2fv (&vals[13]);
        glColor3fv (&vals[15]);
        glVertex2fv (&vals[18]);
        glEnd();
        if (bigVertices) {
            glColor3fv (&vals[0]);
            drawCircle (&vals[3]);
            glColor3fv (&vals[5]);
            drawCircle (&vals[8]);
            glColor3fv (&vals[10]);
            drawCircle (&vals[13]);
            glColor3fv (&vals[15]);
            drawCircle (&vals[18]);
        }
        if (outlined) {
            if (mode == GL_TRIANGLE_FAN) {
                glLineWidth (3.0);
                glBegin (GL_LINE_STRIP);
                glColor3f (1.0f, 1.0f, 1.0f);
                glVertex2fv (&vals[3]);
                glVertex2fv (&vals[8]);
                glVertex2fv (&vals[13]);
                glVertex2fv (&vals[3]);
                glVertex2fv (&vals[18]);
                glVertex2fv (&vals[13]);
                glEnd();
                glLineWidth (1.0);
                glBegin (GL_LINE_STRIP);
                glColor3f (0.0f, 0.0f, 0.0f);
                glVertex2fv (&vals[3]);
                glVertex2fv (&vals[8]);
                glVertex2fv (&vals[13]);
                glVertex2fv (&vals[3]);
                glVertex2fv (&vals[18]);
                glVertex2fv (&vals[13]);
                glEnd();
            }
            else if (mode == GL_TRIANGLE_STRIP)  {
                glLineWidth (3.0);
                glColor3f (1.0f, 1.0f, 1.0f);
                glBegin (GL_LINE_LOOP);
                glVertex2fv (&vals[3]);
                glVertex2fv (&vals[8]);
                glVertex2fv (&vals[18]);
                glVertex2fv (&vals[13]);
                glEnd();
                glBegin (GL_LINES);
                glVertex2fv (&vals[8]);
                glVertex2fv (&vals[13]);
                glEnd();
                glLineWidth (1.0);
                glColor3f (0.0f, 0.0f, 0.0f);
                glBegin (GL_LINE_LOOP);
                glVertex2fv (&vals[3]);
                glVertex2fv (&vals[8]);
                glVertex2fv (&vals[18]);
                glVertex2fv (&vals[13]);
                glEnd();
                glBegin (GL_LINES);
                glVertex2fv (&vals[8]);
                glVertex2fv (&vals[13]);
                glEnd();
            }
        }
    }
    
    else if (!shaded && 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -