X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=cb6fd4e7eca2bea194fe8f1604f867fb4570a9ba;hp=0c5329b2d01d38f5f52c0f66e6eeb991bc5002fb;hb=9644796a64e902273a02a75c68e22da05b3a87ec;hpb=84eea711e741871dfb6cc595a0989e1369998d7f diff --git a/scene.c b/scene.c index 0c5329b..cb6fd4e 100644 --- a/scene.c +++ b/scene.c @@ -184,7 +184,8 @@ void makeMenu() { */ void windowReshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); - // **NOTE: windowReshape needs to be re-written using glFrustrum and perspective projection calculations + width = w; + height = h; } /** @@ -285,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; @@ -332,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); @@ -345,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); @@ -386,26 +412,10 @@ int main(int argc, char **argv) { glDepthRange(0,1); glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // the type - glEnable(GL_CULL_FACE); 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);