From: Ash Tyndall Date: Sun, 9 Oct 2011 11:17:09 +0000 (+0800) Subject: (no commit message) X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=def47f5467d5b96672c25d79034c88471d580724;p=atyndall%2Fcits2231.git --- diff --git a/scene.c b/scene.c index c93b652..30d982a 100644 --- a/scene.c +++ b/scene.c @@ -460,34 +460,25 @@ void makeMenu() { /** * Called when window is resized - * @param width New width - * @param height New height + * @param w New width + * @param h New height */ void windowReshape(int w, int h) { - /*glViewport(0, 0, (GLsizei)width, (GLsizei)height); - printf("Width: %d, height: %d\n", width, height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective( 60 * ((GLfloat)height/(GLfloat)width), (GLfloat)width/(GLfloat)height, 0.1, 1000.0); - glMatrixMode(GL_MODELVIEW); - - GLdouble near = 0.1; - GLdouble far = 1000.0; - GLdouble a = (GLfloat)height/(GLfloat)width; - GLdouble fov = 60; - glFrustum( -a*near*tan(fov/2), a*near*tan(fov/2), -a*near*tan(fov/2), a*near*tan(fov/2), near, far )*/ - glViewport(0, 0, (GLsizei) w, (GLsizei) h); // what's GLsizei? Why is it called inside glViewPort? - glMatrixMode(GL_PROJECTION); // is it necessary to reset the projection matrix? + GLdouble near = -10.0; + GLdouble far = 10.0; + + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); glLoadIdentity(); - if (w <= h) // is this calculation universal, could I use it on another program? - glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w, - 5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0); + if (w <= h) + glOrtho(near, far, near*(GLfloat)h/(GLfloat)w, + far*(GLfloat)h/(GLfloat)w, near, far); else - glOrtho(-5.0*(GLfloat)w/(GLfloat)h, - 5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0); - glMatrixMode(GL_MODELVIEW); // why do I set to GL_MODELVIEW at the end? - glLoadIdentity(); // why does it get a reset? + glOrtho(near*(GLfloat)w/(GLfloat)h, + far*(GLfloat)w/(GLfloat)h, near, far, near, far); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); } /** @@ -508,7 +499,7 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - glTranslatef(0.0f,0.0f,-4.0f); // Move into the Screen 10.0 + glTranslatef(0.0f,0.0f,-5.0f); // Move into the Screen 10.0 glutSolidTeapot(1);