X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=b0268832e2149bc5f11b0e6cbcfb9f7319d2b30d;hp=e8d7bb8777b809d75f424e7d4f99be53ada81b15;hb=71f65a8fdceed0f4ae289fe99ec013d2edd76ae3;hpb=4b694f000a2b15bb70939493eaeae2847f099f4b diff --git a/scene.c b/scene.c index e8d7bb8..b026883 100644 --- a/scene.c +++ b/scene.c @@ -226,6 +226,30 @@ void mouse(int button, int state, int x, int y) { } } +void keyboard(unsigned char key, int x, int y) { + switch(key) { + case 'w': + z = z - 1; + break; + case 'a': + x = x - 1; + break; + case 's': + z = z + 1; + break; + case 'd': + x = x + 1; + break; + case 'q': + y = y + 1; + break; + case 'e': + y = y - 1; + break; + } + printf("Camera is now at (%f, %f, %f)\n", x, y, z); +} + /** * Called when motion event occurs * @param x Mouse x position @@ -255,12 +279,11 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt( - 0.0, 10.0, 10.0, /* eye is at (x,y,z) */ + x, y, z, /* 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 */ ); - // **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); @@ -376,6 +399,7 @@ int main(int argc, char **argv) { //glutReshapeFunc(windowReshape); glutDisplayFunc(display); glutMouseFunc(mouse); + glutKeyboardFunc(keyboard); glutMotionFunc(motion); makeMenu();