X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=1654527fcb2cc554b304153043d7b0172c091b67;hp=b0268832e2149bc5f11b0e6cbcfb9f7319d2b30d;hb=bb84977df53fb16ba10eecb52b219071ff786126;hpb=71f65a8fdceed0f4ae289fe99ec013d2edd76ae3 diff --git a/scene.c b/scene.c index b026883..1654527 100644 --- a/scene.c +++ b/scene.c @@ -226,28 +226,44 @@ void mouse(int button, int state, int x, int y) { } } +/** + * 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; + 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,14 +295,16 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt( - x, y, z, /* eye is at (x,y,z) */ + 100.0, 100.0, 100.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); + glRotatef(rot, 1.0, 0.0, 0.0); /* Reposition the light source. */ lightPosition[0] = 12*cos(lightAngle); @@ -310,7 +328,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(100); glPopMatrix(); // Draw a white ball over the light source