All pastes #710096 Raw Edit

Anonymous

public text v1 · immutable
#710096 ·published 2007-09-25 06:44 UTC
rendered paste body

/* Relevant part of main */

    glClearColor( 0, 0, 0, 0);
    glViewport( 0, 0, RES_X, RES_Y );
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glClear ( GL_COLOR_BUFFER_BIT );

    icosahedron *ball;
    float origin[3] = { 400.0, 300.0, 0};
    ball = new icosahedron(origin);
    ball->draw();

    SDL_GL_SwapBuffers();
    SDL_Delay(1000);
    delete ball;

/*  end main snippet */


/* Relevant parts of icosahedron.cpp */
static GLfloat vdata[12][13] = {
    {-X, 0.0, Z}, {X, 0.0, Z}, {-X, 0.0, -Z}, {X, 0.0, -Z},
    {0.0, Z, X}, {0.0, Z, -X}, {0.0, -Z, X}, {0.0, -Z, -X},
    {Z, X, 0.0}, {-Z, X, 0.0}, {Z, -X, 0.0}, {-Z, -X, 0.0}
};
        
static GLuint tindices[20][3] = { 
    {1, 4, 0}, {4, 9, 0}, {4, 5, 9}, {8, 5, 4}, {1, 8, 4},
    {1, 10, 8}, {10, 3, 8}, {8, 3, 5}, {3, 2, 5}, {3, 7, 2}, 
    {3, 10, 7}, {10, 6, 7}, {6, 11, 7}, {6, 0, 11}, {6, 1, 0},
    {10, 1, 6}, {11, 0, 9}, {2, 11, 9}, {5, 2, 9}, {11, 2, 7},
};

void icosahedron::draw( )
{
    glPushMatrix();
        glLoadIdentity();
        glTranslatef(x, y, z);
        glBegin(GL_TRIANGLES);
            for (int i=0; i < 20; i++)
            {
                glColor3f( 1.0 / (i + 1), 1.0 / (i + 1), 1.0 / (i + 1));
                glVertex3fv(&vdata[tindices[i][0]][0]);
                glVertex3fv(&vdata[tindices[i][1]][0]);
                glVertex3fv(&vdata[tindices[i][2]][0]);
            }
        glEnd();

    glPopMatrix();
}