/*
   Basic function to draw a unit cube centered at the origin with
   faces perpendicular to the standard x, y, and z axes, in a color
   specified through the parameters to the function.  This cube is
   extremely simple but is enough to allow us to build examples on
   it.
   
   Steve Cunningham, 2000
*/

void cube(float r, float g, float b)
{
// define point and color data types
	color cubecolor;
    point3 vertices[8]={{-1.0, -1.0, -1.0},
                        {-1.0, -1.0,  1.0},
                        {-1.0,  1.0, -1.0},
                        {-1.0,  1.0,  1.0},
                        { 1.0, -1.0, -1.0},
                        { 1.0, -1.0,  1.0},
                        { 1.0,  1.0, -1.0},
                        { 1.0,  1.0,  1.0} };

    point3 normals[6]={{ 0.0, 0.0, 1.0},
                       {-1.0, 0.0, 0.0},
                       { 0.0, 0.0,-1.0},
                       { 1.0, 0.0, 0.0},
                       { 0.0,-1.0, 0.0},
                       { 0.0, 1.0, 0.0} };

	GLfloat mat_shininess[]={ 50.0 };
	GLfloat mat_specular[] = { 0.8, 0.8, 0.8, 1.0 };
    cubecolor[0] = r; cubecolor[1] = g; cubecolor[2] = b; cubecolor[3] = 1.0;
	
    glMaterialfv(GL_FRONT, GL_AMBIENT, cubecolor );
    glMaterialfv(GL_FRONT, GL_DIFFUSE, cubecolor );
        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular );
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess );
    glBegin(GL_QUADS);
      glNormal3fv(normals[0]);   // first quad: positive Z face
      glVertex3fv(vertices[1]);
      glNormal3fv(normals[0]);
      glVertex3fv(vertices[5]);
      glNormal3fv(normals[0]);
      glVertex3fv(vertices[7]);
      glNormal3fv(normals[0]);
      glVertex3fv(vertices[3]);
      glNormal3fv(normals[5]);   // second quad: positive Y face
      glVertex3fv(vertices[7]);
      glNormal3fv(normals[5]);
      glVertex3fv(vertices[6]);
      glNormal3fv(normals[5]);
      glVertex3fv(vertices[2]);
      glNormal3fv(normals[5]);
      glVertex3fv(vertices[3]);
      glNormal3fv(normals[2]);   // third quad: negative Z face
      glVertex3fv(vertices[2]);
      glNormal3fv(normals[2]);
      glVertex3fv(vertices[6]);
      glNormal3fv(normals[2]);
      glVertex3fv(vertices[4]);
      glNormal3fv(normals[2]);
      glVertex3fv(vertices[0]);
      glNormal3fv(normals[3]);  // fourth quad: positive X face
      glVertex3fv(vertices[5]);
      glNormal3fv(normals[3]);
      glVertex3fv(vertices[4]);
      glNormal3fv(normals[3]);
      glVertex3fv(vertices[6]);
      glNormal3fv(normals[3]);
      glVertex3fv(vertices[7]);
      glNormal3fv(normals[4]);  // fifth quad: negative Y face
      glVertex3fv(vertices[4]);
      glNormal3fv(normals[4]);
      glVertex3fv(vertices[5]);
      glNormal3fv(normals[4]);
      glVertex3fv(vertices[1]);
      glNormal3fv(normals[4]);
      glVertex3fv(vertices[0]);
      glNormal3fv(normals[1]);  // sixth quad: negative X face
      glVertex3fv(vertices[0]);
      glNormal3fv(normals[1]);
      glVertex3fv(vertices[1]);
      glNormal3fv(normals[1]);
      glVertex3fv(vertices[3]);
      glNormal3fv(normals[1]);
      glVertex3fv(vertices[2]);
    glEnd();
 }