X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=76b2880471a9b8acc4e0397c8eef2c072c6c7e58;hp=8ea0985a2b0eaed91161e62819b6fbbf4ec8b007;hb=c1ea046313919520b40b6142cd72c9e053e30f01;hpb=765d3843d11aef036fc03ee614d3ec737929dc70 diff --git a/scene.c b/scene.c index 8ea0985..76b2880 100644 --- a/scene.c +++ b/scene.c @@ -184,15 +184,8 @@ void makeMenu() { */ void windowReshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - if (w <= h) - glFrustum(-nearClip, farClip, -nearClip*(GLfloat) h / (GLfloat) w, - farClip*(GLfloat) h / (GLfloat) w, nearClip, farClip); - else - glFrustum(-nearClip*(GLfloat) w / (GLfloat) h, - farClip*(GLfloat) w / (GLfloat) h, nearClip, farClip, nearClip, farClip); - glMatrixMode(GL_MODELVIEW); + width = w; + height = h; } /** @@ -293,8 +286,36 @@ void motion(int x, int y) { */ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // Redraw projection matrix + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + float aspect; + if ( width <= height ) { + aspect = (float)height / (float)width; + } else { + aspect = (float)width / (float)height; + } + + gluPerspective( + 75.0, + aspect, + 0.1, + 200 + ); + + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + gluLookAt( + 0.0, 0.0, 5.0, /* eye is at (x,y,z) */ + 0.0, 0.0, 0.0, /* center is at (x,y,z) */ + 0.0, 1.0, 0.0 /* up is in postivie Y direction */ + ); + + glRotatef(75.0, 1.0, 0.0, 0.0); + /* Reposition the light source. */ lightPosition[0] = 12*cos(lightAngle); lightPosition[1] = lightHeight; @@ -340,9 +361,6 @@ void display() { * init function; sets initial OpenGL state */ void init() { - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); @@ -353,11 +371,11 @@ void init() { glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glightmodel); - glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); - glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse); - glMaterialfv(GL_FRONT, GL_SPECULAR, specular); - glMaterialfv(GL_FRONT, GL_EMISSION, emission0); - glMaterialf(GL_FRONT, GL_SHININESS, shine); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission0); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shine); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); @@ -395,25 +413,12 @@ int main(int argc, char **argv) { glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // the type glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glFrontFace(GL_CW); glEnable(GL_TEXTURE_2D); + glEnable(GL_NORMALIZE); glLineWidth(1.0); - // **NOTE: Currently the perspective and look-at code is static, for testing purposes - //glMatrixMode(GL_PROJECTION); - //gluPerspective( - // 40.0, /* field of view in degree */ - // 1.0, /* aspect ratio */ - // 1.0, /* Z near */ // **NOTE: Seems to be issue with near < 0 causing invisible everything - // 100.0 /* Z far */ - // ); - - glMatrixMode(GL_MODELVIEW); - gluLookAt( - 0.0, 35.0, -20.0, /* eye is at (x,y,z) */ - 0.0, 10.0, 0.0, /* center is at (x,y,z) */ - 0.0, 1.0, 0.0 /* up is in postivie Y direction */ - ); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glutReshapeFunc(windowReshape);