X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=9fc30e76005acac8a89da7b455c5c55479a8c3f1;hp=e1b053fdd0a3f3a416a8dd836d97e0f7565c603a;hb=2d70944922c54d4814b5fcd779a884ba259c4742;hpb=b03479cc770df967f68e22319ee748dd26c448d4 diff --git a/scene.c b/scene.c index e1b053f..9fc30e7 100644 --- a/scene.c +++ b/scene.c @@ -135,6 +135,13 @@ int drawFloorRecurse = 5; /* Size of floor, from -n to n */ int floorSize = 100; +/* Light 0 parameters */ +GLfloat diffuse0[] = {1.0, 1.0, 1.0, 1.0}; +GLfloat ambient0[] = {1.0, 1.0, 1.0, 1.0}; +GLfloat specular0[] = {1.0, 1.0, 1.0, 1.0}; +GLfloat light0_pos[] ={ 1.0, 2.0, 3,0, 1.0}; + + /** * Prints out error message when file cannot be read * @param fileName Name of file that could not be read @@ -600,6 +607,24 @@ void drawFloor() { drawSquare(0, -floorSize, -floorSize, floorSize, floorSize); } +/** + * Draw x, z axis on floor + */ +void drawLine() { + glDisable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4ub( 0.0, 0.0, 0.0, 0.5 ); + + glBegin(GL_LINES); + glVertex3i( 10.0, 0.1, 10.0); + glVertex3i( -10.0, 0.1, -10.0); + glEnd(); + + glDisable(GL_BLEND); + glEnable(GL_TEXTURE_2D); +} + /** * Display function */ @@ -632,20 +657,20 @@ void display() { drawFloor(); - glPushMatrix(); + drawLine(); - glTranslatef(0.0, 1.0, 0.0); - glutWireTeapot(1); // Draw teapot for test + // Draw teapot for a test object + glPushMatrix(); + glTranslatef(0.0, 1.0, 0.0); // **NOTE: Teapot does not rest on surface + glutWireTeapot(1); glPopMatrix(); + // Draw a white ball over the light source glPushMatrix(); glDisable(GL_LIGHTING); glColor3f(1.0, 1.0, 1.0); - - /* Draw a yellow ball at the light source. */ glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]); glutSolidSphere(1.0, 50, 50); - glEnable(GL_LIGHTING); glPopMatrix(); @@ -662,23 +687,17 @@ void init() { glLoadIdentity(); gluPerspective( - 60.0, /* field of view in degree */ - 1.0, /* aspect ratio */ - near, /* Z near */ + 60.0, /* field of view in degree */ + 1.0, /* aspect ratio */ + near, /* Z near */ far /* Z far */ ); - -GLfloat diffuse0[] = {1.0, 1.0, 1.0, 1.0}; -GLfloat ambient0[] = {1.0, 1.0, 1.0, 1.0}; -GLfloat specular0[] = {1.0, 1.0, 1.0, 1.0}; -GLfloat light0_pos[] ={ 1.0, 2.0, 3,0, 1.0}; - -glEnable(GL_LIGHT0); -glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); -glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); -glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); -glLightfv(GL_LIGHT0, GL_SPECULAR, specular0); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); + glLightfv(GL_LIGHT0, GL_SPECULAR, specular0); glEnable(GL_LIGHTING); glMatrixMode(GL_MODELVIEW); @@ -725,7 +744,6 @@ int main(int argc, char **argv) { glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); - //glutIdleFunc(idle); makeMenu();