From: Ash Tyndall Date: Fri, 21 Oct 2011 03:09:14 +0000 (+0800) Subject: (no commit message) X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=5eb90acec725198d090e065c1bdc7d41dd4ce02b;p=atyndall%2Fcits2231.git --- diff --git a/globals.c b/globals.c index 374d8b3..a567458 100644 --- a/globals.c +++ b/globals.c @@ -70,7 +70,8 @@ int drawFloorRecurse = 8; int floorSize = 200; /* Current camera x, y, z coords */ -GLfloat camx = 0.0, camy = 0.0, camz = 0.0, rot = 0.0; +GLfloat camx = 0.0, camy = 0.0, camz = 0.0, keyrot = 0.0; +GLfloat factor = 1.0; /* Length of axis lines */ GLfloat lineLength = 5; @@ -82,7 +83,6 @@ GLfloat specular0[]={1.0, 0.0, 0.0, 1.0}; GLfloat emission0[] = {0.0, 0.3, 0.3, 1.0}; GLfloat direction0[] = {0.0, 0.0, 0.0}; -GLfloat light0_pos[] ={1.0, 1.0, 0,0, 0.5}; GLfloat shine = 100.0; @@ -94,7 +94,8 @@ GLfloat diffuse[] = {1.0, 0.8, 0.0, 1.0}; GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; /* Zoom and rotate tracking */ -GLfloat zoomFactor = 0.0, rotateFactor = 0.0; +GLfloat zoom = 0.0, rotate = 0.0; +GLfloat zoomFactor = 0.5, rotateFactor = 0.5; /* Beginning width, height */ int width = 500, height = 500; \ No newline at end of file diff --git a/globals.h b/globals.h index dc92453..b6e0454 100644 --- a/globals.h +++ b/globals.h @@ -60,7 +60,8 @@ extern int drawFloorRecurse; extern int floorSize; /* Current camera position */ -extern GLfloat camx, camy, camz, rot; +extern GLfloat camx, camy, camz, keyrot; +extern GLfloat factor; /* Length of axis lines */ extern GLfloat lineLength; @@ -87,6 +88,7 @@ extern GLfloat specular[]; extern int width, height; /* Zoom and rotate tracking */ -GLfloat zoomFactor, rotateFactor; +extern GLfloat zoom, rotate; +extern GLfloat zoomFactor, rotateFactor; #endif /* GLOBALS_H */ \ No newline at end of file diff --git a/scene.c b/scene.c index db6b635..a02ae84 100644 --- a/scene.c +++ b/scene.c @@ -221,31 +221,50 @@ void mouse(int button, int state, int x, int y) { void keyboard(unsigned char key, int x, int y) { switch(key) { case 'w': - camz = camz - 1; + case 'W': + camz -= factor; break; case 'a': - camx = camx - 1; + case 'A': + camx -= factor; break; case 's': - camz = camz + 1; + case 'S': + camz -= factor; break; case 'd': - camx = camx + 1; + case 'D': + camx += factor; break; case 'q': - camy = camy + 1; + case 'Q': + camy += factor; break; case 'e': - camy = camy - 1; + case 'E': + camy -= factor; break; case 'z': - rot = rot + 1; + case 'Z': + keyrot += factor; break; case 'x': - rot = rot - 1; + case 'X': + keyrot += factor; break; + case '=': + case '+': + factor += 0.1; + printf("Factor of change is now %f\n", factor); + break; + case '-': + case '_': + factor -= 0.1; + printf("Factor of change is now %f\n", factor); + break; + } - printf("Camera is now at (%f, %f, %f), angle %f\n", camx, camy, camz, rot); + printf("Camera is now at (%f, %f, %f), angle %f\n", camx, camy, camz, keyrot); glutPostRedisplay(); } @@ -256,8 +275,8 @@ void keyboard(unsigned char key, int x, int y) { */ void motion(int x, int y) { if (moving) { - zoomFactor += (y - starty); - rotateFactor += (x - startx); + zoom += (y - starty); + rotate += (x - startx); startx = x; starty = y; glutPostRedisplay(); @@ -298,15 +317,8 @@ void display() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - GLfloat zcoord = 5.0 + (zoomFactor*0.2); - if ( zcoord < 0.0 ) { - printf("zf: %f", zoomFactor); - zcoord = 0.0; - zoomFactor = 0.0; - } - gluLookAt( - 0.0, 0.0, zcoord, /* eye is at (x,y,z) */ + 0.0, 0.0, 5.0 + (zoom*zoomFactor), /* 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 */ ); @@ -319,16 +331,12 @@ void display() { lightPosition[2] = 12*sin(lightAngle); lightPosition[3] = 0.0; - - //glRotatef(angle, 0.0, 1.0, 0.0); - // glRotatef(angle2, 1.0, 0.0, 0.0); - glPushMatrix(); /* Perform scene rotations based on user mouse/keyboard input. */ - glRotatef(rotateFactor*0.5, 0.0, 1.0, 0.0); - //glTranslatef(camx, camy, camz); - //glRotatef(rot, 1.0, 0.0, 0.0); + glRotatef(rotate*rotateFactor, 0.0, 1.0, 0.0); + glTranslatef(camx, camy, camz); + glRotatef(keyrot, 1.0, 0.0, 0.0); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); @@ -363,7 +371,6 @@ void display() { * init function; sets initial OpenGL state */ void init() { - glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); glLightfv(GL_LIGHT0, GL_SPECULAR, specular0);