/* code by Iolaire McKinnon #include #include #ifndef M_PI #define M_PI 3.14159265358979323846 #endif static int j = 0, size = 40, lambda = 10, i, a, doPoints = 0, direction = 1; static float c, xaxis, xoffset, zaxis, shiny; void initlights(void) { GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; GLfloat position[] = {1.0, 3.0, 4.0, 1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_POSITION, position); } void myinit(void) { GLfloat fogColor[4] = {0.2, 0.1, 0.8, 1.0}; glEnable(GL_FOG); glFogi (GL_FOG_MODE, GL_LINEAR); glHint (GL_FOG_HINT, GL_NICEST); /* per pixel */ glFogf (GL_FOG_START, 2.0); glFogf (GL_FOG_END, 10.0); glFogfv (GL_FOG_COLOR, fogColor); glClearColor(0.0, 0.0, 0.0, 1.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); initlights(); } void display(void) { if (lambda < 1) { lambda = 1; } if (lambda > 40) { lambda = 40; } if (shiny < 0) { shiny = 0; } GLfloat mat_diffuse[] = {0.6, 0.6, 0.6, 1.0}; GLfloat mat_specular[] = {1.0, 1.0, 1.0, 0.2}; GLfloat mat_shininess[] = {shiny}; glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0, 1.0, 0.0); glPointSize(4.0); if(doPoints) { glBegin(GL_POINTS); } else { glBegin(GL_TRIANGLES); } c = sin(j*M_PI/180.0); for (a = 1; a < size; a++) { for (i = 1; i < size; i++) { // Triangle 1 c = sin((j + (lambda * i)) * (M_PI / 180.0)); xoffset = cos((j + (lambda * i)) * (M_PI / 180.0)); xaxis = (float) i + xoffset; zaxis = (float) a; glVertex3f(xaxis, c, zaxis); //start c = sin((j + (lambda * (i+1))) * (M_PI / 180.0)); xoffset = cos((j + (lambda * (i+1))) * (M_PI / 180.0)); xaxis = (float) (i+1) + xoffset; zaxis = (float) a; glVertex3f(xaxis, c, zaxis); // 1 up x c = sin((j + (lambda * i)) * (M_PI / 180.0)); xoffset = cos((j + (lambda * i)) * (M_PI / 180.0)); xaxis = (float) i + xoffset; zaxis = (float) a+1; glVertex3f(xaxis, c, zaxis); // 1 up z // Triangle2 c = sin((j + (lambda * i)) * (M_PI / 180.0)); xoffset = cos((j + (lambda * i)) * (M_PI / 180.0)); xaxis = (float) i + xoffset; zaxis = (float) a+1; glVertex3f(xaxis, c, zaxis); // 1 up z c = sin((j + (lambda * (i+1))) * (M_PI / 180.0)); xoffset = cos((j + (lambda * (i+1))) * (M_PI / 180.0)); xaxis = (float) (i+1) + xoffset; zaxis = (float) a; glVertex3f(xaxis, c, zaxis); // 1 up x c = sin((j + (lambda * (i+1))) * (M_PI / 180.0)); xoffset = cos((j + (lambda * (i+1))) * (M_PI / 180.0)); xaxis = (float) (i+1) + xoffset; zaxis = (float) a+1; glVertex3f(xaxis, c, zaxis); // 1 up x and z /* 35------6 |\\ | | \\ T2 | | \\ | | \\ | Layout | T1 \\ | | \\| 1------24 */ } } glEnd(); j++; glutSwapBuffers(); } void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective(80.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef (-20.0, -3.0, -30.0); } /* ARGSUSED1 */ void keyboard (unsigned char key, int x, int y) { switch (key) { case 'z': lambda = lambda + 1; glutPostRedisplay(); break; case 'x': lambda = lambda - 1; glutPostRedisplay(); break; case ',': shiny = shiny + 1; glutPostRedisplay(); break; case '.': shiny = shiny - 1; glutPostRedisplay(); break; case 'p': doPoints = !doPoints; glutPostRedisplay(); break; case 27: exit(0); break; default: break; } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (500, 500); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); myinit (); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutIdleFunc(display); glutMainLoop(); return 0; }