From bf3cf131a6c4b18ca07a2a85156c063ff3bdcd04 Mon Sep 17 00:00:00 2001 From: Ash Tyndall Date: Thu, 20 Oct 2011 11:56:13 +0800 Subject: [PATCH] --- globals.c | 2 +- globals.h | 2 +- scene.c | 29 +++++++++++++++++++---------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/globals.c b/globals.c index 56b8d1a..03d2f6f 100644 --- a/globals.c +++ b/globals.c @@ -73,7 +73,7 @@ int drawFloorRecurse = 5; int floorSize = 200; /* Current camera x, y, z coords */ -GLfloat x = 0.0, y = 0.0, z = 0.0; +GLfloat camx = 0.0, camy = 0.0, camz = 0.0; /* Light 0 parameters */ GLfloat diffuse0[] = {1.0, 1.0, 1.0, 1.0}; diff --git a/globals.h b/globals.h index 04841f8..d856c57 100644 --- a/globals.h +++ b/globals.h @@ -63,7 +63,7 @@ extern int drawFloorRecurse; extern int floorSize; /* Current camera position */ -extern GLfloat x, y, z; +extern GLfloat camx, camy, camz; /* Light 0 parameters */ extern GLfloat diffuse0[]; diff --git a/scene.c b/scene.c index a988ca8..9c6d0c4 100644 --- a/scene.c +++ b/scene.c @@ -226,28 +226,37 @@ 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(); } @@ -282,10 +291,10 @@ void display() { gluLookAt( 0.0, 0.0, 10.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 */ + 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 -- 2.20.1