X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=9eb68f0b492a691de10b236d394e2fadc532d8a3;hb=4d4ca4a795d149268a8b46b8848ba52e33b5347c;hp=8b52285d89ac58a262add566cf61db38722edf26;hpb=bbcc709acd8f62bd313215c7e71710f3ebcf01c0;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index 8b52285..9eb68f0 100644 --- a/scene.c +++ b/scene.c @@ -529,7 +529,7 @@ drawFloor(void) static GLfloat lightColor[] = {1.0, 1.0, 1.0, 1.0}; /* green-tinted */ static GLfloat lightPosition[4]; -static float lightAngle = 0.0, lightHeight = 20; +static float lightAngle = 10.0, lightHeight = 20; /** @@ -561,7 +561,7 @@ void display() { /* Draw a yellow ball at the light source. */ glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]); - glutSolidSphere(1.0, 5, 5); + glutSolidSphere(90.0, 5, 5); glEnable(GL_LIGHTING); glPopMatrix(); @@ -571,6 +571,37 @@ void display() { glutSwapBuffers(); } +/** + * init function; sets initial OpenGL state + */ +void init() { + glEnable(GL_CULL_FACE); + glEnable(GL_DEPTH_TEST); + glEnable(GL_TEXTURE_2D); + glLineWidth(3.0); + + glMatrixMode(GL_PROJECTION); + gluPerspective( + 60.0, /* field of view in degree */ + 1.0, /* aspect ratio */ + 0.0, /* Z near */ + 900.0 /* Z far */ + ); + + glMatrixMode(GL_MODELVIEW); + gluLookAt( + 0.0, 8.0, 60.0, /* eye is at (0,8,60) */ + 0.0, 8.0, 0.0, /* center is at (0,8,0) */ + 0.0, 1.0, 0.0 /* up is in postivie Y direction */ + ); + + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); + glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor); + glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1); + glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHTING); +} /** * Main function @@ -579,63 +610,39 @@ void display() { * @return Program exit code */ int main(int argc, char **argv) { + if(argc>1) + strcpy(dataDir, argv[1]); + else if(opendir(dirDefault1)) + strcpy(dataDir, dirDefault1); + else if(opendir(dirDefault2)) + strcpy(dataDir, dirDefault2); + else fileErr(dirDefault1); - if(argc>1) - strcpy(dataDir, argv[1]); - else if(opendir(dirDefault1)) - strcpy(dataDir, dirDefault1); - else if(opendir(dirDefault2)) - strcpy(dataDir, dirDefault2); - else fileErr(dirDefault1); + for(int i=0; i