From: Ash Tyndall Date: Fri, 21 Oct 2011 01:11:23 +0000 (+0800) Subject: (no commit message) X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=8664ff7d3cbe2e5285d067231f54772b46649653;p=atyndall%2Fcits2231.git --- diff --git a/globals.c b/globals.c index 467d27b..800f363 100644 --- a/globals.c +++ b/globals.c @@ -94,4 +94,7 @@ GLfloat glightmodel[] = {0.2,0.2,0.2,1}; /* Material types */ GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; GLfloat diffuse[] = {1.0, 0.8, 0.0, 1.0}; -GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; \ No newline at end of file +GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; + +/* Beginning width, height */ +int width = 500, height = 500; \ No newline at end of file diff --git a/globals.h b/globals.h index 6f6a626..4c7854a 100644 --- a/globals.h +++ b/globals.h @@ -86,5 +86,7 @@ extern GLfloat ambient[]; extern GLfloat diffuse[]; extern GLfloat specular[]; -#endif /* GLOBALS_H */ +/* Beginning width, height */ +extern int width, height; +#endif /* GLOBALS_H */ \ No newline at end of file diff --git a/scene.c b/scene.c index a307bc8..83e1c29 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); - printf("I am called!\n"); + width = w; + height = h; } /** @@ -285,14 +286,31 @@ 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 = (float)height / (float)width; + if ( width > height ) aspect = (float)width / (float)height; + + gluPerspective( + 90.0, + aspect, + 0.1, + 100 + ); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - //gluLookAt( - // -30.0, -30.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 */ - // ); + gluLookAt( + 0.0, 0.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 */ + ); + + glRotatef(30.0, 1.0, 0.0, 0.0); /* Reposition the light source. */ lightPosition[0] = 12*cos(lightAngle);