X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=3d7dcd3d490aed938e1c9948038e4e8fa58bec59;hp=ecabe1f16b5ffc278f564915507a5987fc1b7a66;hb=4db627cb2b67a5fd49b65b2b8cde754deeddf3e3;hpb=e1106adcec8622ffa66be50379561f4c9cd06ea6 diff --git a/scene.c b/scene.c index ecabe1f..3d7dcd3 100644 --- a/scene.c +++ b/scene.c @@ -226,6 +226,40 @@ 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': + camz = camz - 1; + break; + case 'a': + camx = camx - 1; + break; + case 's': + camz = camz + 1; + break; + case 'd': + camx = camx + 1; + break; + case 'q': + camy = camy + 1; + break; + case 'e': + camy = camy - 1; + break; + } + printf("Camera is now at (%f, %f, %f)\n", camx, camy, camz); + glutPostRedisplay(); +} + /** * Called when motion event occurs * @param x Mouse x position @@ -255,15 +289,16 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt( - 0.0, 0.0, 10.0, /* 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(20, 1.0, 0.0, 0.0); + glRotatef(30.0, 1.0, 0.0, 0.0); /* Reposition the light source. */ lightPosition[0] = 12*cos(lightAngle); @@ -376,6 +411,7 @@ int main(int argc, char **argv) { //glutReshapeFunc(windowReshape); glutDisplayFunc(display); glutMouseFunc(mouse); + glutKeyboardFunc(keyboard); glutMotionFunc(motion); makeMenu();