You are on page 1of 14

 

 
TCS 2111 
Computer Graphics 

 
Animated Carrousel

Mohamad Reza Shakouri 

 

1051800013 

Mohamad Hadi Behnia   

 

1051109276 

Farzaneh Masoumian 

 

1051108358 

 

 
Trimester 2/ Session 2007/2008 

 
Faculty of Information Technology and Science 
Multimedia University 
December 2007 

................................ 5  2..............................................................................................................................................................................................Table of Contents  Introduction ......................................................................................................................................................................................................................... 8  Source code ................................................................................. 5  3................................................................................................................................ 5  1.. 4  Models used in this program .................................... Tree ................................................ 7  Mapping ............................................................................................ 6  Interactive functions ............... Carousel ........................................... 3  Screenshots ......................................................................................................................................................................................................................................................................................... Man ...................................................... 9    2 | P a g e     ...............................................................................

This in turn caused SGI market share to weaken as more 3D graphics hardware suppliers entered the market. By the early 1990s. keyboard and mouse API. IrisGL. overshadowing the open standards-based PHIGS. The OpenGL standardized access to hardware. OpenGL evolved from (and is very similar in style to) SGI's earlier 3D interface. in part because it was developed before the X Window System and Sun's News systems were developed. and pushed the development responsibility of hardware interface programs. by changing to the OpenGL API they planned to keep their customers locked onto SGI (and IBM) hardware for a few years while market support for OpenGL matured. In an effort to influence the market. In 1992. sometimes called device drivers. Also. to hardware manufacturers and delegated windowing functions to the underlying operating system. PHIGS was considered difficult to use and outdated in terms of functionality. This was because IRIS GL was considered easier to use. SGI would continue to try to maintain their customers tied to SGI hardware by developing the advanced and proprietary Iris Inventor and Iris Performer programming APIs. By contrast. SGI led the creation of the OpenGL architectural review board (OpenGL ARB). SGI considered that the IrisGL API itself wasn't suitable for opening due to licensing and patent issues. Silicon Graphics (SGI) was a leader in 3D graphics for workstations. This was expensive and resulted in much duplication of effort. Software developers wrote custom interfaces and drivers for each piece of hardware. supported by extensions made to the PHIGS standard. the group of companies that would maintain and expand the OpenGL specification for years to come. the IrisGL had API functions that were not relevant to 3D graphics. SGI's competitors (including Sun Microsystems. Their IRIS GL API was considered the state of the art and became the de facto industry standard. SGI had a large number of software customers. If 3 | P a g e     .Introduction In the 1980s. it included a windowing. One of the restrictions of IrisGL was that it only provided access to features supported by the underlying hardware. getting them all to speak the same language in this way had a remarkable impact by giving software developers a higher level platform for 3D-software development. Hewlett-Packard and IBM) were also able to bring to market 3D hardware. As a result. and because it supported immediate mode rendering. SGI decided to turn the IrisGL API into an open standard. With so many different kinds of graphic hardware. Meanwhile. developing software that could function with a wide range of graphics hardware was a real challenge. For example. SGI released the OpenGL standard. In addition.

the graphics hardware did not support a feature. On 17 December 1997. strategic reasons at Microsoft. It initially showed some promise of bringing order to the world of interactive 3D computer graphics APIs. In 1994 SGI played with the idea of releasing something called "OpenGL++" which included elements such as a scene-graph API (presumably based around their Performer technology). but on account of financial constraints at SGI. then the application could not use it. which was a joint effort with the goal of unifying the OpenGL and Direct3D interfaces (and adding a scene-graph API too). Microsoft released Direct3D in 1995. The specification was circulated among a few interested parties – but never turned into a product. allowing applications to use advanced graphics on relatively low-powered systems. which would become the main competitor of OpenGL. it was abandoned in 1999. and general lack of industry support. OpenGL overcame this problem by providing support in software for features unsupported by hardware. In 1998 Hewlett-Packard joined the project. Microsoft and SGI initiated the Fahrenheit project. Screenshots 4 | P a g e     .

2. Tree This model includes triangles and cylinder the trick is we draw 12 triangles and rotate them by 30 degree each time.Models used in this program 1. one cylinder and one cube 5 | P a g e     . Carousel One cone. Also we use mapping for triangles.

We scale one of them by Y-axis and four of them by X-axis 6 | P a g e     .The sketch is like this: We used texture mapping and material for making the carousel natural. We draw 6 spheres 2. Man The man model is made by 6 spheres the step to make man model is listed below: 1. 3.

mykeyborad() is habdeling the speed of spinning and bouncing . After the scaling part we combined these six spheres like this and used glRotatef() to rotate the legs and hands a bit . Interactive functions   We use two functions with name of mykeyboard() and myspecailkey(). Horse We use same steps for horse but the body is scales on X-axis and the legs is scaled on Y-axis and the we use cylinder for the pole up the head of horse. 4. W: speed up S: decrease speed Q: increase bounce 7 | P a g e     .3.

A: decrease bounce In myspecialkey() . It stars from the first pixel of picture and texture it until to the end. Texture maps we used in this project are GRASS SKY FLOOR 8 | P a g e     . the picture should be bit map file. Then we bind the texture map to polygons. we handle camera location Arrow up: goes deep Arrow down: goes far Arrow left: goes to let by X-axis Arrow right: goes to right by X-axis Page up: goes high Page down: goes low Home: make everything to first situation Mapping   For the mapping we used one header file which upload on picture to texture map.

float c_z=10. image = loadBMP("floor. delete image.h> #include <iostream> #include <string> #include <map> #include "imageloader. because pixels are stored //as unsigned numbers image->pixels). glTexCoord2f(1.0f.0f.1. mat[0] = 0.0f. mat[1] = 0.0f). delete image. //Enable light #1 glEnable(GL_NORMALIZE). GL_TEXTURE_MIN_FILTER. glVertex3f(2.75164. delete image. //The border of the image GL_RGB. 0. GLfloat fogColor[4] = {0. _textureId1).22648.3.0f).0). // glEnable (GL_DEPTH_TEST).555802. glEnd(). mat[2] = 0. //The id of the texture GLuint _textureId1. } 9 | P a g e     .04. 0.0f). GL_TEXTURE_MAG_FILTER. this material is gold we found from internet mat[0] = 0. 2.Source code #include <GL/glut.0f.0f). //Returns the id of the texture } GLuint _textureId. //Tell OpenGL which texture to edit //Map the image to the texture glTexImage2D(GL_TEXTURE_2D.0. i=i+20. //The actual pixel data return textureId.0. because pixels are stored in RGB format GL_UNSIGNED_BYTE. glEnable(GL_LIGHTING). float z1=0. GLuint _textureId2. glColor3f(0.0f. //enable the depth testing void init(void) { glClearColor (0.6.0.0f). glRotatef(i.0f. 0. GL_TEXTURE_MIN_FILTER. //GL_RGB. //GL_UNSIGNED_BYTE. GLuint loadTexture(Image* image) { GLuint textureId.6). float b=0. glTexCoord2f(1. mat[1] = 0. _textureId2 = loadTexture(image). GL_DIFFUSE. //0 for now GL_RGB. 0. glMaterialfv(GL_FRONT. float z=0.60648.0f). GL_NEAREST). glTranslatef(0.0f. 0. glBindTexture(GL_TEXTURE_2D. glBegin(GL_TRIANGLES). //Enable lighting glEnable(GL_LIGHT0). glTexParameteri(GL_TEXTURE_2D. //Make room for our texture glBindTexture(GL_TEXTURE_2D. glScalef(0. 0. 0.0). textureId). glMaterialfv(GL_FRONT. //Format OpenGL uses for image image->width. mat). GL_SPECULAR.0.h> #include <math. glGenTextures(1. 1. _textureId1 = loadTexture(image).0f. _textureId = loadTexture(image). 0. -2.0f.6.24725. 1. float s=4. i <= 360.bmp"). glEnable(GL_TEXTURE_2D). GL_LINEAR). 0. glTexParameteri(GL_TEXTURE_2D. } //global variables for spinning and bouncing float y=0. // function to draw tree model void tree() { static GLUquadric* quadric = gluNewQuadric(). image = loadBMP("grass.1995. 0. for (int i=0 . mat). mat). mat[1] = 0. GL_AMBIENT. glTexParameteri(GL_TEXTURE_2D.0f. 0. //Automatically normalize normals glShadeModel(GL_SMOOTH). -2.6). mat[2] = 0.366065. GL_LINEAR). GL_NEAREST). //Bottom glTexParameteri(GL_TEXTURE_2D. //Enable smooth shading Image* image = loadBMP("stars1. mat[3] = 1.0745.bmp"). image->height. GL_TEXTURE_MAG_FILTER.0}.0.4 * 128. glVertex3f(-2. GLfloat density = 0.0f. GL_SHININESS. glPopMatrix(). glMaterialf(GL_FRONT.0f). 0.bmp").628281. float c_x=5. mat[0] = 0. 0. 0. glEnable(GL_COLOR_MATERIAL).0.0.0. float mat[3]. &textureId). float c_y=1.) { glPushMatrix().07. float temp1 = 0. glMaterialfv(GL_FRONT.0f).h> #include <stdlib. //Width and height 0.h" using namespace std. glTexCoord2f(0.5. glShadeModel (GL_FLAT).3. glNormal3f(0.0.// putting material . //Enable light #0 glEnable(GL_LIGHT1).1.0). 0. float x=9. glVertex3f(0. mat[2] = 0. //Always GL_TEXTURE_2D 0.0.0.

0.0.0f.32).0f.0.5.1. glScalef(2. glTranslatef(3.0. glBegin(GL_QUADS).0f). 8.0. glScalef(1.0f). GL_TEXTURE_MIN_FILTER.0f). glPushMatrix().0.0.0. glPushMatrix(). GL_NEAREST). glScalef (1. 10 | P a g e     .06f. glPopMatrix().0.2. 8. 8. 8.glDisable(GL_TEXTURE_2D). 0. glScalef(1. glNormal3f(0.7. 0. glutSolidSphere ( 0. glPopMatrix(). glutSolidSphere ( 1.0. glTranslatef(-3. glTranslatef(0. glPopMatrix().0. glBegin(GL_QUADS).5.0f.0f). glTexCoord2f(1.0f).0. 0.0).0. } //drawing man void man() { float mat[3].5.0.5).05.1.5. glPushMatrix().3f.0.0.2. glRotatef(30.0f).0f).8.0f.32). glPopMatrix().0).32.0. glutSolidSphere ( 0. glTexParameteri(GL_TEXTURE_2D.1. glColor3f(0. 1.-19. glPushMatrix(). glutSolidSphere ( 0.0.6. glVertex3f(-8. 1. glRotatef(-30.1.0.0.076). glVertex3f(-8.5. -5.0. glScalef(1. glTexCoord2f(0. GL_LINEAR).1. glRotatef(-30.0.-1.0).7.0.0. glTexCoord2f(1.1.1.0f. glVertex3f(-8. 1. glutSolidSphere ( 1.3. glVertex3f(8.5.0f. glNormal3f(0. glTexParameteri(GL_TEXTURE_2D.7).6).0.0f.0. glPopMatrix().1. glScalef(1.1. 0. glRotatef(86.0). glTexParameteri(GL_TEXTURE_2D. 5.6).0f.0.0f.5). 1.0). glRotatef(90.0. GL_TEXTURE_MIN_FILTER.0f). } // ufo is going on sly void ufo() { glPushMatrix(). glPopMatrix().32.0). glColor3f(1.0).0f). glPushMatrix().0.0).0. 8.5.0f.0). glutSolidCube(2). glDisable(GL_TEXTURE_2D). 1.0). glTexCoord2f(1.0.5). glRotatef(30.0).0.3).32.0f.0. 5. -5.3.0f.0f).0f. glPushMatrix(). 0.32.32).5.0.0.5. GL_LINEAR). -5.0).1. glTranslatef(0.06f.0.0f).6.0.0. 8.0f. glPopMatrix(). glPushMatrix().-1.0f. glRotatef(90.0f.0.7.0.0.0. glPushMatrix().0. glVertex3f(8. glPopMatrix(). glScalef(0. 0.0). } // for the sky at background void shper() { glEnable(GL_TEXTURE_2D).0. glVertex3f(8. glutSolidSphere ( 0.228.6).0.0.32). 1.0f). glTexCoord2f(0. 0. 5.0).0.0f.0f.8. glTranslatef(-0.0. glVertex3f(8.0f). glutSolidSphere ( 0.0).0f.5.0.5. glutSolidSphere ( 1.5.0.0. glTranslatef(-0. glVertex3f(-8. glTexCoord2f(0.6.6). _textureId).32.0. glPopMatrix().0. 0. 8.32. GL_TEXTURE_MAG_FILTER. glPopMatrix().0.0.3.0f). glScalef(1. glColor3f(0.0. GL_TEXTURE_MAG_FILTER.0f).1.32). glTexParameteri(GL_TEXTURE_2D.0. glPushMatrix(). 0. glPopMatrix().0f. glColor3f(0. glTranslatef(0.0.6. 0.5. GL_NEAREST).32). 8.0f). gluCylinder(quadric. glPushMatrix(). glEnd().0.0. glBindTexture(GL_TEXTURE_2D.3.0.6. glTexCoord2f(0.0f).0.5).32.0f.32.0.1. glTranslatef(-0.0.0.0.0.8. 5. 1.5.1.32).0f.0f.32. 0.0f. glPushMatrix(). glScalef(1.0f). glTexCoord2f(1.7.0. glEnd().6).0f.384 . glRotatef(90.0. -5.5.32).0f.1.0f).0). glPopMatrix().1).

0.0.0.0. GL_TEXTURE_MIN_FILTER. glPopMatrix().0f).076).0f).5). glPopMatrix(). 4. -3.0. glTexParameteri(GL_TEXTURE_2D. -3.0. glScalef (1. glPushMatrix(). 1.1. glColor3f(1. -3. 0. glColor3f(0. GL_TEXTURE_MAG_FILTER. 0. 4.1. 0.7. glColor3f(0.0f. glTexParameteri(GL_TEXTURE_2D.32. glPopMatrix().1. glBindTexture(GL_TEXTURE_2D.0.05f.6.0f. GL_LINEAR). glColor3f(0.0f. glTexParameteri(GL_TEXTURE_2D. glTexCoord2f(1.1.0.0).0f.32.2.0).0. glutSolidSphere ( 0. 0. glVertex3f(10. GL_NEAREST). 0.32.-0. glColor3f(0. glPopMatrix().0f). glTexCoord2f(0. float mat[3]. -10.0. glPopMatrix(). glEnable(GL_TEXTURE_2D). glColor3f(0. 10.8.4. glRotatef(90. 0. GL_TEXTURE_MIN_FILTER.2.0.0.0f).6.-0. glDisable(GL_TEXTURE_2D). glPushMatrix(). glEnd().0).0.0.0. GL_LINEAR). glBindTexture(GL_TEXTURE_2D.0f).0. glPushMatrix(). glTexCoord2f(0. glutSolidSphere ( 0.5.0).3.-0.0f. glPushMatrix(). 0. glVertex3f(-10. 0.0).32).0. glPopMatrix(). GL_TEXTURE_MIN_FILTER. 1. } // coursel void roof(void) { static GLUquadric* quadric = gluNewQuadric().6. glutSolidSphere ( 0. glutSolidSphere ( 0.7). float mat[3].0). glTexParameteri(GL_TEXTURE_2D. /////////////////////////////////////////////////////////////////////////////////////////////////////// glEnable(GL_TEXTURE_2D). glTranslatef(0.0). glutSolidSphere ( 0. GL_TEXTURE_MAG_FILTER. 0. glBegin(GL_QUADS). glPopMatrix(). glTexCoord2f(0. GL_NEAREST). 1. glTexCoord2f(1. 0. glVertex3f(10. glPushMatrix().35.5.05f.5).4.0f. GL_LINEAR). glTexCoord2f(1. 0. } // horse void horse(void) { static GLUquadric* quadric = gluNewQuadric().6.6).0.0.32).0.4. 0. glPopMatrix().7.3.0f). 0.0).0f). glPushMatrix().3).0.-0.0.4.0. 1. GL_NEAREST).0. glPopMatrix().1). glTranslatef(2.0).1.0.0. 1.5.5).32.0f). glTexParameteri(GL_TEXTURE_2D. GL_TEXTURE_MAG_FILTER. _textureId1).228.4.0f. glTexParameteri(GL_TEXTURE_2D.0. glPushMatrix().0.0).0).glPopMatrix().32.0f). 0.0.0). ////////////////////////////////////////////////////////////////////////////////////////////////////////// glTexParameteri(GL_TEXTURE_2D. 1.0.0f.32).0f. glScalef (1. 0. -3. glEnd().0).0. glNormal3f(1.0).0. -3. -3. glVertex3f(-4. GL_LINEAR). 0.0).32. 1.0. glVertex3f(-10. glVertex3f(4.7). glTranslatef(2.32.0).0.32). -4. gluCylinder(quadric. glScalef (0.-0. glTexParameteri(GL_TEXTURE_2D. glutSolidSphere ( 0. glTranslatef(-2. GL_TEXTURE_MAG_FILTER.384 . glNormal3f(1. glTranslatef(-0.0).5. 0. 1. GL_NEAREST).5.0f).0.5). -4. glTexCoord2f(0. glPushMatrix().5. glPushMatrix().4. glVertex3f(4.1.5. -3.0.0).0. glPushMatrix(). 0. glPopMatrix(). glTranslatef(0.1.0). glPushMatrix().0f. GL_TEXTURE_MIN_FILTER.0.2.0. glutSolidCube(1).32). -10. _textureId2). 10. glPushMatrix().3.0. glPopMatrix().0. 0.5. glColor3f(0.1. // GRASS glColor3f(1.0).0).0.0f.5. glPopMatrix().0. glTranslatef(-0. 11 | P a g e     . 0.3.0.32). glColor3f(0.0).7). -3.1. glutSolidSphere ( 0. glRotatef(90. glTexCoord2f(1. //floor glVertex3f(-4.32).5.5. 0.0.-0. glTranslatef(0.0. glTranslatef(-2. glScalef (0.32.7. glBegin(GL_QUADS).

glTranslatef(7.508273. glPushMatrix().0.0).0.0.2f.0. mat[1] = 0.0.5. glTranslatef(0.0).1). 0.0. ///////////////////////////////////////////////////////////////////////////////////////////////////////////// glColor3f(0.-1.0. 1.5f.0. gluCylinder(quadric.0).0. glMaterialf(GL_FRONT.0. horse().0).0. glPushMatrix().3).0. glPushMatrix(). glPushMatrix(). glutSolidCube(3). mat[1] = 0. tree().0).0.5. glRotatef(180. glPushMatrix().0). tree(). glPopMatrix().0.0. // The Sun glPopMatrix().0.0. mat).2. glPopMatrix(). 0.0).1.5). glMaterialfv(GL_FRONT.0. glPushMatrix(). glPushMatrix(). glPopMatrix(). glPopMatrix(). //roof glPushMatrix().0).0. tree(). roof(). mat[3] = 1. glPushMatrix().0.0.0).0.5). glPushMatrix().5).19225.0.0.-1.0.04296875.0.3.2f.0.0).y.0).0). glColor3f(0.384 .-1. glTranslatef(-2. glPushMatrix(). glPopMatrix().0).0). glTranslatef(-1. glRotatef(z1.5. glPopMatrix(). mat).0. glPushMatrix().3.0.-2.0). glPushMatrix(). mat[2] = 0.2.0.0.-3. glTranslatef(x.y. glTranslatef(0. 0. glPopMatrix().0).50754. glTranslatef (0. glTranslatef(0.0.0. glPopMatrix().4).0.5f.0.1. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// glPushMatrix().5.0.508273. glMaterialfv(GL_FRONT. tree().3.8).0).5.0.0. mat[1] = 0. mat).0. man ().-3.1).0.0.0.0. mat[0] = 0.5. glTranslatef(-2.0. glTranslatef(-1. 0. ufo().32.0.0).0.-4.0.0.5. glPopMatrix().-3.32. tree().0).1. glTranslatef(0.0. glPushMatrix().0.0.0. glutSolidCone (4.z). tree().0.0.50754.0. glMaterialfv(GL_FRONT. glTranslatef(0.0f.5.19225.05859375).19225.0. glScalef (0.-1. tree(). glRotatef(45. mat[2] = 0. glPopMatrix().1.glDisable(GL_TEXTURE_2D). GL_SPECULAR. GL_SHININESS.0). mat[2] = 0.0. glTranslatef(5.0. glRotatef(90.0* 128. glTranslatef(0. glScalef(0.0.1.-2.5 . ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// mat[0] = 0.076).4.1.-1.0). GL_AMBIENT.0.0.0. glPopMatrix(). ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } // putting whole things toghether void myobjects(void) { static GLUquadric* quadric = gluNewQuadric().-1. glPushMatrix().0. glTranslatef(-3.1.50754. glPopMatrix(). glScalef(2.0. 0.0).508273. glRotatef(90.0. glTranslatef(-2.0. glPopMatrix().3. glPopMatrix(). glPushMatrix().6171875 .0.0).0.-5.0. 12 | P a g e     .1. //base glPopMatrix().0.0. glTranslatef(6.3. glColor3f(0. glPopMatrix().228.0.0.0.5. //bar mat[0] = 0. tree(). glPopMatrix().0). glPushMatrix().0.0. glRotatef(180. GL_DIFFUSE.4. shper().0). tree().1. glRotatef(z1. glScalef (0. glColor3f(0.0.0. glTranslatef (0.

4. glPushMatrix().0). 20. man ().0. glScalef (0.0.0.-2.0.-1. cout <<x<<endl.5).0). glTranslatef(0. (GLsizei) w.3).0).0. myobjects().0).1. glLoadIdentity (). 0.0.0. // set the fog to look the nicest.3. 0. 1.0.y.0. //enable the fog glFogi (GL_FOG_MODE.0).0).0.3.0. fogColor).0. //set the density to the value above glHint (GL_FOG_HINT.0.3). GLfloat lightPos1[] = {0.4).3.0). if( temp1 == 0 ) y=y+b.0.0. 0.1.0.0. glRotatef(90.3).0. 1.3.y.1.0.3. glLightModelfv(GL_LIGHT_MODEL_AMBIENT.0. glPopMatrix().4.4).0.y.0.3 ) { y =y-b.0). c_z.5f.0. // Add ambient light GLfloat ambientColor[] = {0. glTranslatef(2.0. glTranslatef (0.1. glRotatef(-90.y. ambientColor).3. 1. horse().3.4.0.1.y. glPushMatrix(). glLightfv(GL_LIGHT1.3.0.0.0.0). glTranslatef(0.4f}.4).5. glutSwapBuffers().0.5).0. 13 | P a g e     . glTranslatef (0.0. 1.5. glRotatef(z1.0.0.0.4. glPopMatrix().0. glScalef (0.0.0. glutTimerFunc(1.3.5). glTranslatef(0. horse(). glutPostRedisplay().y. glTranslatef(0.0).0. GL_DIFFUSE. 0. 0.0).0.0. glEnable(GL_DEPTH_TEST) .0.0. //Add directed light GLfloat lightColor1[] = {1.0). horse(). man ().5.0. glPushMatrix().0.3. glRotatef(z1. if ( y <= 0) { temp1 = 0.3) temp1 = 0.0). glTranslatef(0.0. } void reshape (int w.0). 0. glTranslatef(0.0f.0f.0.5). x-=0.0. glTranslatef (0. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT). glRotatef(z1.3.0.0.-1. if (temp1 >= 0. if(x <= -8) x = 8.0.0. gluLookAt (c_x. glTranslatef (0. 1. if ( y > 0.0. //set the fog color to our color chosen above glFogf (GL_FOG_DENSITY. glTranslatef(0. glLoadIdentity(). glTranslatef(0. glRotatef(-90.0. c_y. glPopMatrix(). glutPostRedisplay(). glPopMatrix(). glPushMatrix(). glRotatef(z1.0.0.0. } z1-=s.0). glScalef (0. glTranslatef(0.0.0. lightColor1).0. 0.-1.3. gluPerspective(80.1.076.update. 0. glScalef (0.-2. glTranslatef(0.0.0. glEnable (GL_FOG).1. glPopMatrix(). glTranslatef (0.0.0.0.0).0). } cout <<y<<endl.1. glTranslatef(0.0f}.0.0).0. GL_NICEST). 0.1. may slow down on older cards glColor3f(1.0).0. density).0).0.0. glPushMatrix().0.-1. } // animation function which udate the scene 1 in milisecond void update ( int value) { float temp =x.1. 0.5. man ().1.2.228. lightPos1). GL_EXP2).0).0. glRotatef(z1.0.0. int h) { glViewport (0.0f. glFlush().0). //set the fog mode to GL_EXP2 glFogfv (GL_FOG_COLOR.0.0f}.0.3.0.0.0.0).glPushMatrix().0.0.1. (GLfloat) w/(GLfloat) h. glTranslatef (0. (GLsizei) h). 0.1. glDepthFunc(GL_LESS).0). 0. glScalef (0.0).0.0). glPopMatrix(). glPushMatrix().1. } void display(void) { glClearColor(0.0.0. glMatrixMode(GL_MODELVIEW). glTranslatef(2.0).-1.0.0).1. -0.0. glMatrixMode (GL_PROJECTION). glLightfv(GL_LIGHT1. glScalef (0.0f.5.4.0f. GL_POSITION.0. 0.2.0.4.0).0.0. glRotatef(90. 0. 1.-1. glPopMatrix(). glRotatef(z1.384 .0).0.

argv). break. return 0. break. case 's' : s -= speed. } glutPostRedisplay(). break. case GLUT_KEY_HOME :c_x=5. char** argv) { glutInit(&argc. case GLUT_KEY_PAGE_DOWN : c_y-=angleInc.3.c_z=10. break. glutInitWindowSize (500. } int main(int argc. int y) { static const GLfloat angleInc = 0. break. case 'a' : b -= bounce. case GLUT_KEY_UP : c_z -= angleInc. case GLUT_KEY_LEFT : c_x-= angleInc.update. break.} void myKeyboard(unsigned char key.s=0 . glutCreateWindow ("marry go round"). break. init (). } 14 | P a g e     . case 'q' : b += bounce. int x. float bounce = 0. 100). case GLUT_KEY_PAGE_UP : c_y+=angleInc. 500). break. float speed=1. break.07.s=4. case GLUT_KEY_RIGHT : c_x += angleInc.0). glutKeyboardFunc(myKeyboard). switch (key) { case 'w' : s += speed. glutReshapeFunc(reshape).1. int y) { static const GLdouble posInc = 0. switch (key) { case GLUT_KEY_DOWN : c_z += angleInc.03. glutDisplayFunc(display). case 'p' : b = 0. glutInitWindowPosition (100. break.b=0. break. } glutPostRedisplay().c_y=1. glutTimerFunc(1. glutMainLoop(). break. glutSpecialFunc(mySpecialKey). } void mySpecialKey(int key. glutInitDisplayMode(GLUT_DEPTH|GLUT_RGBA|GLUT_DOUBLE). int x.