X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=892a087b7ad8e49a6baf1cb4ca9870698508cfe0;hp=de52ab893e4877ecc94830012c10a9543b9658a8;hb=0e6f9e61d354ba9e4f4fa9c9efa6fb84374c519f;hpb=71a79323a397f78dba55423678096176a98106cb diff --git a/scene.c b/scene.c index de52ab8..892a087 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(30.0, 1.0, 0.0, 0.0); + glRotatef(50.0, 1.0, 0.0, 0.0); /* Reposition the light source. */ lightPosition[0] = 12*cos(lightAngle); @@ -314,8 +349,8 @@ void init() { gluPerspective( 60.0, /* field of view in degree */ 1.0, /* aspect ratio */ - near, /* Z near */ - far /* Z far */ + nearClip, /* Z near */ + farClip /* Z far */ ); glMatrixMode(GL_MODELVIEW); @@ -376,6 +411,7 @@ int main(int argc, char **argv) { //glutReshapeFunc(windowReshape); glutDisplayFunc(display); glutMouseFunc(mouse); + glutKeyboardFunc(keyboard); glutMotionFunc(motion); makeMenu();