+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\r
+ \r
+ // Redraw projection matrix\r
+ glMatrixMode(GL_PROJECTION);\r
+ glLoadIdentity();\r
+\r
+ float aspect;\r
+ if ( width <= height ) {\r
+ aspect = (float)height / (float)width;\r
+ } else {\r
+ aspect = (float)width / (float)height;\r
+ }\r
+\r
+ gluPerspective(\r
+ 75.0,\r
+ aspect,\r
+ 0.1,\r
+ 300\r
+ );\r
+\r
+ glMatrixMode(GL_MODELVIEW);\r
+ glLoadIdentity();\r
+\r
+ gluLookAt(\r
+ 0.0, 0.0, 15.0 + (zoom*zoomFactor), /* eye is at (x,y,z) */\r
+ 0.0, 0.0, 0.0, /* center is at (x,y,z) */\r
+ 0.0, 10.0, 0.0 /* up is in postivie Y direction */\r
+ );\r
+\r
+ glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0);\r
+\r
+ /* Reposition the light source 0. */\r
+ lightPosition0[0] = 12*cos(lightAngle0);\r
+ lightPosition0[1] = lightHeight0;\r
+ lightPosition0[2] = 12*sin(lightAngle0);\r
+ lightPosition0[3] = 0.0;\r
+\r
+ direction0[0] = lightPosition0[0];\r
+ direction0[2] = lightPosition0[2];\r
+\r
+ /* Reposition the light source 1. */\r
+ lightPosition1[0] = 12*cos(lightAngle1);\r
+ lightPosition1[1] = lightHeight1;\r
+ lightPosition1[2] = 12*sin(lightAngle1);\r
+ lightPosition1[3] = 0.0;\r
+\r
+ direction1[0] = lightPosition1[0];\r
+ direction1[2] = lightPosition1[2];\r
+\r
+ glPushMatrix();\r
+\r
+ /* Perform scene rotations based on user mouse/keyboard input. */\r
+ glRotatef(rotate*rotateFactor, 0.0, 1.0, 0.0);\r
+ glTranslatef(camx, camy, camz);\r
+ glRotatef(keyrot, 1.0, 0.0, 0.0);\r
+\r
+ glLightfv(GL_LIGHT0, GL_POSITION, lightPosition0);\r
+ glLightfv(GL_LIGHT1, GL_POSITION, lightPosition1);\r
+\r
+ drawFloor();\r
+ \r
+ // Draw sceneObjs array\r
+ for ( int i = 0; i < nObjects; i++ ) {\r
+ glPushMatrix();\r
+ SceneObject so = sceneObjs[i];\r
+\r
+ // Apply rotation vector\r
+ GLfloat* rv = &so.rotation.vector;\r
+ printf("%f, %f, %f\n", rv[0], rv[1], rv[2]);\r
+ glRotatef(so.rotation.amount, rv[0], rv[1], rv[2]);\r
+\r
+ // Apply scaling vector\r
+ GLfloat* sv = &so.scale;\r
+ glScalef(sv[0], sv[1], sv[2]);\r
+\r
+ // Apply translation vector\r
+ glTranslatef(so.x, so.y, so.z);\r
+\r
+ // Apply texture\r
+ if ( so.texture > 0 ) {\r
+ getTexture(so.texture);\r
+ glBindTexture(GL_TEXTURE_2D, so.texture);\r
+ } else {\r
+ glBindTexture(GL_TEXTURE_2D, 0);\r
+ }\r
+\r
+ // Draw actual object\r
+ if ( so.mesh > 0 ) {\r
+ // drawMesh();\r
+ } else if ( so.mesh == -1 ) { // a mesh of -1 draws the teapot\r
+ // The teapot does not obey the right-hand rule\r
+ glFrontFace(GL_CW);\r
+ glutSolidTeapot(1);\r
+ glFrontFace(GL_CCW);\r
+ }\r
+\r
+ glBindTexture(GL_TEXTURE_2D, 0);\r
+ glPopMatrix();\r
+ }\r
+ \r
+\r
+ // Draw a white ball over the light source\r
+ glPushMatrix();\r
+ glDisable(GL_LIGHTING);\r
+ glColor3f(1.0, 1.0, 1.0);\r
+ glTranslatef(lightPosition0[0], lightPosition0[1], lightPosition0[2]);\r
+ glutSolidSphere(0.5, 50, 50);\r
+ glEnable(GL_LIGHTING);\r
+ glPopMatrix();\r
+\r
+ // Draw a white ball over the light source\r
+ glPushMatrix();\r
+ glDisable(GL_LIGHTING);\r
+ glColor3f(1.0, 1.0, 1.0);\r
+ glTranslatef(lightPosition1[0], lightPosition1[1], lightPosition1[2]);\r
+ glutSolidSphere(0.5, 50, 50);\r
+ glEnable(GL_LIGHTING);\r
+ glPopMatrix();\r
+\r
+ drawAxisLines();\r
+\r
+ glPopMatrix();\r
+\r
+ glutSwapBuffers();\r
+}\r
+\r
+/**\r
+ * init function; sets initial OpenGL state\r
+ */\r
+void init() {\r
+ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);\r
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);\r
+ glLightfv(GL_LIGHT0, GL_SPECULAR, specular0);\r
+ glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, direction0);\r
+\r
+ glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);\r
+ glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);\r
+ glLightfv(GL_LIGHT1, GL_SPECULAR, specular1);\r
+ glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, direction1);\r
+\r
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glightmodel);\r
+ glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);\r
+\r
+ glEnable(GL_LIGHT0);\r
+ glEnable(GL_LIGHT1);\r
+ glEnable(GL_LIGHTING);\r