X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=d06dd3c3adca97d186b92b82f31de7ace8a43e16;hp=0c5329b2d01d38f5f52c0f66e6eeb991bc5002fb;hb=241ec710cf9e36891031b23e5bad89beb20c0944;hpb=84eea711e741871dfb6cc595a0989e1369998d7f diff --git a/scene.c b/scene.c index 0c5329b..d06dd3c 100644 --- a/scene.c +++ b/scene.c @@ -184,7 +184,15 @@ 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 + 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); } /** @@ -285,8 +293,15 @@ void motion(int x, int y) { */ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + gluLookAt( + 0.0, 8.0, 30.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 */ + ); + /* Reposition the light source. */ lightPosition[0] = 12*cos(lightAngle); lightPosition[1] = lightHeight; @@ -391,20 +406,13 @@ int main(int argc, char **argv) { 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 */ - ); + //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 */ + // ); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);