X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=26d0d421350f558cbfaca65006a19e33f6efe8fb;hb=be28556c4dcf730dee7a2bdf6538bd7fef5bc313;hp=7e72ae66e4dc340802a0567e44fb20a7bd43ed04;hpb=ef6b009c8781673f3e353d47ae270a9f712bd4bf;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index 7e72ae6..26d0d42 100644 --- a/scene.c +++ b/scene.c @@ -460,22 +460,24 @@ 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 width, int height) { - /*glViewport(0, 0, (GLsizei)width, (GLsizei)height); - printf("Width: %d, height: %d\n", width, height); +void windowReshape(int w, int h) { + GLdouble near = -10.0; + GLdouble far = 10.0; + + glViewport(0, 0, (GLsizei) w, (GLsizei) h); 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 )*/ + if (w <= h) + glOrtho(near, far, near*(GLfloat)h/(GLfloat)w, + far*(GLfloat)h/(GLfloat)w, near, far); + else + glOrtho(near*(GLfloat)w/(GLfloat)h, + far*(GLfloat)w/(GLfloat)h, near, far, near, far); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); } /** @@ -496,10 +498,20 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - glTranslatef(0.0f,0.0f,-10.0f); // Move into the Screen 10.0 + glTranslatef( 0.0f, 0.0f, 0.0f); + glBegin(GL_QUADS); + glVertex3f( 0.0f, 1.0f, -1.0f); + glVertex3f( 0.0f, 1.0f, 1.0f); + glVertex3f( 0.0f, -1.0f, 1.0f); + glVertex3f( 0.0f, -1.0f, -1.0f); + glEnd(); + + glTranslatef( 0.0f, 0.0f, -5.0f); // Move into the Screen 10.0 glutSolidTeapot(1); + gluLookAt(1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f); + glutSwapBuffers(); } @@ -528,11 +540,11 @@ int main(int argc, char **argv) { glutInitWindowSize(500, 500); glutCreateWindow("Scene Editor"); - glShadeModel(GL_SMOOTH); // Enables Smooth Shading - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background - glClearDepth(1.0f); // Depth Buffer Setup - glEnable(GL_DEPTH_TEST); // Enables Depth Testing - glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do + glShadeModel(GL_SMOOTH); // Enables Smooth Shading + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background + glClearDepth(1.0f); // Depth Buffer Setup + glEnable(GL_DEPTH_TEST); // Enables Depth Testing + glDepthFunc(GL_LEQUAL); // the type glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations