X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=a8664791502e16f146b5417c40e2af6982cc8a65;hp=8ce005bade04a86858131ec1ddd995dd027dc1bb;hb=5157d8d5fc2604ea53efb5d02c8cd3f5d9a5669f;hpb=9ef3cb688ee424d11b9b9549ec3cb3dac29334c4 diff --git a/scene.c b/scene.c index 8ce005b..a866479 100644 --- a/scene.c +++ b/scene.c @@ -182,19 +182,19 @@ void makeMenu() { * @param w New width * @param h New height */ -/*void windowReshape(int w, int h) { +void windowReshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) - glOrtho(near, far, near*(GLfloat)h/(GLfloat)w, + glFrustum(near, far, near*(GLfloat)h/(GLfloat)w, far*(GLfloat)h/(GLfloat)w, -100, 100); else - glOrtho(near*(GLfloat)w/(GLfloat)h, + glFrustum(near*(GLfloat)w/(GLfloat)h, far*(GLfloat)w/(GLfloat)h, near, far, nearClip, farClip); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); -}*/ +} /** * Called when mouse event occurs @@ -226,28 +226,45 @@ void mouse(int button, int state, int x, int y) { } } -void keyboard(unsigned char key, int x1, int y1) { +/** + * Keybord event handler + * w/s increase/decrease the z + * a/d increase/decrease the x + * q/e increase/decrease the y + * z/x increase/decrease the angle + * @param key Key pressed + * @param x x co-ordinate of mouse + * @param y y co-ordinate of mouse + */ +void keyboard(unsigned char key, int x, int y) { switch(key) { case 'w': - z = z - 1; + camz = camz - 1; break; case 'a': - x = x - 1; + camx = camx - 1; break; case 's': - z = z + 1; + camz = camz + 1; break; case 'd': - x = x + 1; + camx = camx + 1; break; case 'q': - y = y + 1; + camy = camy + 1; break; case 'e': - y = y - 1; + camy = camy - 1; + break; + case 'z': + rot = rot + 1; + break; + case 'x': + rot = rot - 1; break; } - printf("Camera is now at (%f, %f, %f)\n", x, y, z); + printf("Camera is now at (%f, %f, %f), angle %f\n", camx, camy, camz, rot); + glutPostRedisplay(); } /** @@ -279,16 +296,16 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt( - 0.0, 0.0, 10.0, /* eye is at (x,y,z) */ + 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 */ ); - glTranslatef(x, y, z); + glTranslatef(camx, camy, camz); // **NOTE: Currently this rotation function is all that moves the camera off // the flat surface. Need to integrate function into gluLookAt - glRotatef(30.0, 1.0, 0.0, 0.0); + glRotatef(rot, 1.0, 0.0, 0.0); /* Reposition the light source. */ lightPosition[0] = 12*cos(lightAngle); @@ -300,7 +317,7 @@ void display() { /* Perform scene rotations based on user mouse input. */ glRotatef(angle, 0.0, 1.0, 0.0); - //glRotatef(angle2, 1.0, 0.0, 0.0); **NOTE: Only one degree of freedom + glRotatef(angle2, 1.0, 0.0, 0.0); //**NOTE: Only one degree of freedom glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); @@ -312,7 +329,7 @@ void display() { glPushMatrix(); glTranslatef(0.0, 1.0, 0.0); // **NOTE: Teapot does not rest on surface glColor3f(0.5, 0.5, 0.5); - glutSolidTeapot(1); + glutSolidTeapot(25); glPopMatrix(); // Draw a white ball over the light source @@ -336,12 +353,12 @@ void init() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective( - 60.0, /* field of view in degree */ - 1.0, /* aspect ratio */ - nearClip, /* Z near */ - farClip /* Z far */ - ); + //gluPerspective( + // 60.0, /* field of view in degree */ + // 1.0, /* aspect ratio */ + // nearClip, /* Z near */ + // farClip /* Z far */ + // ); glMatrixMode(GL_MODELVIEW); glLoadIdentity();