From: Ash Tyndall Date: Thu, 20 Oct 2011 03:47:00 +0000 (+0800) Subject: (no commit message) X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=d95870a5f740a7ed8c1adbd63b6ffd26fb5a3940;p=atyndall%2Fcits2231.git --- diff --git a/globals.c b/globals.c index b441f8c..56b8d1a 100644 --- a/globals.c +++ b/globals.c @@ -72,6 +72,9 @@ int drawFloorRecurse = 5; /* Size of floor, from -n to n */ int floorSize = 200; +/* Current camera x, y, z coords */ +GLfloat x = 0.0, y = 0.0, z = 0.0; + /* Light 0 parameters */ GLfloat diffuse0[] = {1.0, 1.0, 1.0, 1.0}; GLfloat ambient0[] = {0.0, 0.0, 0.0, 1.0}; diff --git a/globals.h b/globals.h index ac0184c..04841f8 100644 --- a/globals.h +++ b/globals.h @@ -62,6 +62,9 @@ extern int drawFloorRecurse; /* Size of floor, from -n to n */ extern int floorSize; +/* Current camera position */ +extern GLfloat x, y, z; + /* Light 0 parameters */ extern GLfloat diffuse0[]; extern GLfloat ambient0[]; diff --git a/scene.c b/scene.c index e8d7bb8..f748458 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)", 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(); diff --git a/scene.h b/scene.h index 57fb933..33955b4 100644 --- a/scene.h +++ b/scene.h @@ -17,6 +17,7 @@ void makeMenu(); void windowReshape(int w, int h); void mouse(int button, int state, int x, int y); +void keyboard(unsigned char key, int x, int y); void motion(int x, int y); void display();