X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=642fdcdc5bfce55a355ca9e68597233e8effdc66;hp=d06dd3c3adca97d186b92b82f31de7ace8a43e16;hb=736f5bfdedf4e3cd741eed4ee2974b3d133106fd;hpb=241ec710cf9e36891031b23e5bad89beb20c0944 diff --git a/scene.c b/scene.c index d06dd3c..642fdcd 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(-near, far, -near*(GLfloat) h / (GLfloat) w, - far*(GLfloat) h / (GLfloat) w, nearClip, farClip); - else - glFrustum(-near*(GLfloat) w / (GLfloat) h, - far*(GLfloat) w / (GLfloat) h, near, far, nearClip, farClip); - glMatrixMode(GL_MODELVIEW); + width = w; + height = h; } /** @@ -293,15 +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, 8.0, 30.0, /* eye is at (x,y,z) */ + 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 */ + 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; @@ -326,7 +340,9 @@ void display() { glPushMatrix(); glTranslatef(0.0, 0.5, 0.0); // **NOTE: Teapot currently does not rest on surface glColor3f(0.0, 0.0, 0.0); + glFrontFace(GL_CW); glutSolidTeapot(1); + glFrontFace(GL_CCW); glPopMatrix(); // Draw a white ball over the light source @@ -347,9 +363,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); @@ -401,18 +414,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); - 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 */ - // ); + glEnable(GL_CULL_FACE); + glEnable(GL_NORMALIZE); + glLineWidth(2.0); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);