(no commit message)
[atyndall/cits2231.git] / scene.c
diff --git a/scene.c b/scene.c
index e1b053f..927c1f4 100644 (file)
--- a/scene.c
+++ b/scene.c
@@ -123,8 +123,8 @@ GLfloat angle = -150;   /* in degrees */
 GLfloat angle2 = 30;   /* in degrees */\r
 \r
 /* Near and far parameters */\r
-GLfloat near = -10;\r
-GLfloat far = 10;\r
+GLfloat near = -100;\r
+GLfloat far = 100;\r
 \r
 /* Zoom factor for mouse movements */\r
 GLfloat zoomFactor = 1.0;\r
@@ -135,6 +135,15 @@ int drawFloorRecurse = 5;
 /* Size of floor, from -n to n */\r
 int floorSize = 100;\r
 \r
+/* Light 0 parameters */\r
+GLfloat diffuse0[] = {1.0, 1.0, 1.0, 1.0};\r
+GLfloat ambient0[] = {0.0, 0.0, 0.0, 1.0};\r
+GLfloat specular0[] = {1.0, 1.0, 1.0, 1.0};\r
+GLfloat emission0[] = {0.0, 0.0, 0.0, 0.0};\r
+GLfloat light0_pos[] ={1.0, 1.0, 0,0, 1.0};\r
+GLfloat glightmodel[] = {0.2,0.2,0.2,1};\r
+\r
+\r
 /**\r
  * Prints out error message when file cannot be read\r
  * @param fileName Name of file that could not be read\r
@@ -600,6 +609,25 @@ void drawFloor() {
   drawSquare(0, -floorSize, -floorSize, floorSize, floorSize);\r
 }\r
 \r
+/**\r
+ * Draw x, z axis on floor\r
+ */\r
+void drawLine() {\r
+    // **NOTE: fix function\r
+    glDisable(GL_TEXTURE_2D);\r
+    glEnable(GL_BLEND);\r
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r
+    glColor4ub( 0.0, 0.0, 0.0, 0.5 );\r
+\r
+    glBegin(GL_LINES);\r
+    glVertex3i( 10.0, 0.1, 10.0);\r
+    glVertex3i( -10.0, 0.1, -10.0);\r
+    glEnd();\r
+\r
+    glDisable(GL_BLEND);\r
+    glEnable(GL_TEXTURE_2D);\r
+}\r
+\r
 /**\r
  * Display function\r
  */\r
@@ -612,6 +640,7 @@ void display() {
     0.0, 1.0,  0.0   /* up is in postivie Y direction */\r
     );\r
 \r
+\r
   // **NOTE: Currently this rotation function is all that moves the camera off\r
   //         the flat surface. Need to integrate function into gluLookAt\r
   glRotatef(30.0, 1.0, 0.0, 0.0);\r
@@ -632,20 +661,21 @@ void display() {
 \r
     drawFloor();\r
 \r
-    glPushMatrix();\r
+    drawLine();\r
     \r
-      glTranslatef(0.0, 1.0, 0.0);\r
-      glutWireTeapot(1); // Draw teapot for test\r
+    // Draw teapot for a test object\r
+    glPushMatrix();\r
+      glTranslatef(0.0, 0.5, 0.0); // **NOTE: Teapot does not rest on surface\r
+      glColor3f(0.5, 0.5, 0.5);\r
+      glutSolidTeapot(1);\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
-\r
-      /* Draw a yellow ball at the light source. */\r
       glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);\r
       glutSolidSphere(1.0, 50, 50);\r
-\r
       glEnable(GL_LIGHTING);\r
     glPopMatrix();\r
 \r
@@ -662,24 +692,26 @@ void init() {
   glLoadIdentity();\r
 \r
   gluPerspective(\r
-       60.0,  /* field of view in degree */\r
-        1.0,  /* aspect ratio */\r
-     near,  /* Z near */\r
+    60.0,  /* field of view in degree */\r
+     1.0,  /* aspect ratio */\r
+    near,  /* Z near */\r
      far   /* Z far */\r
     );    \r
 \r
-\r
-GLfloat diffuse0[] = {1.0, 1.0, 1.0, 1.0};\r
-GLfloat ambient0[] = {1.0, 1.0, 1.0, 1.0};\r
-GLfloat specular0[] = {1.0, 1.0, 1.0, 1.0};\r
-GLfloat light0_pos[] ={ 1.0, 2.0, 3,0, 1.0};\r
-\r
-glEnable(GL_LIGHT0);\r
-glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);\r
-glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);\r
-glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);\r
-glLightfv(GL_LIGHT0, GL_SPECULAR, specular0);\r
+  \r
+  glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);\r
+  glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);\r
+  glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);\r
+  glLightfv(GL_LIGHT0, GL_SPECULAR, specular0);\r
+  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glightmodel);\r
+  glEnable(GL_LIGHT0);\r
   glEnable(GL_LIGHTING);\r
+  glEnable(GL_COLOR_MATERIAL);\r
+  glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );\r
+  glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specular0);\r
+  glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, emission0);\r
+\r
+  \r
 \r
   glMatrixMode(GL_MODELVIEW);\r
   glLoadIdentity();\r
@@ -725,7 +757,6 @@ int main(int argc, char **argv) {
   glutDisplayFunc(display);\r
   glutMouseFunc(mouse);\r
   glutMotionFunc(motion);\r
-  //glutIdleFunc(idle);\r
 \r
   makeMenu();\r
 \r

UCC git Repository :: git.ucc.asn.au