X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=3d7dcd3d490aed938e1c9948038e4e8fa58bec59;hp=485e8a95c3dedc2bde70027f68f59dd797c355a3;hb=4db627cb2b67a5fd49b65b2b8cde754deeddf3e3;hpb=d4d78a8d7485bc1b7c2736f890857c9cd8360969 diff --git a/scene.c b/scene.c index 485e8a9..3d7dcd3 100644 --- a/scene.c +++ b/scene.c @@ -226,28 +226,38 @@ 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 + * @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; } - printf("Camera is now at (%f, %f, %f)\n", x, y, z); + printf("Camera is now at (%f, %f, %f)\n", camx, camy, camz); + glutPostRedisplay(); } /** @@ -279,11 +289,13 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt( - x, y, z, /* 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(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);