From 89e90cbd07402f824253fc0a4b2f1cd7e81b31e4 Mon Sep 17 00:00:00 2001 From: Ash Tyndall Date: Fri, 21 Oct 2011 10:52:35 +0800 Subject: [PATCH] --- globals.c | 6 +++--- globals.h | 6 +++--- scene.c | 36 ++++++------------------------------ 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/globals.c b/globals.c index b53163e..374d8b3 100644 --- a/globals.c +++ b/globals.c @@ -63,9 +63,6 @@ GLfloat far = 30; GLfloat nearClip = -200; GLfloat farClip = 200; -/* Zoom factor for mouse movements */ -GLfloat zoomFactor = 1.0; - /* Recursion level for floor drawing */ int drawFloorRecurse = 8; @@ -96,5 +93,8 @@ GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; 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; + /* Beginning width, height */ int width = 500, height = 500; \ No newline at end of file diff --git a/globals.h b/globals.h index 4c7854a..dc92453 100644 --- a/globals.h +++ b/globals.h @@ -53,9 +53,6 @@ extern GLfloat far; extern GLfloat nearClip; extern GLfloat farClip; -/* Zoom factor for mouse movements */ -extern GLfloat zoomFactor; - /* Recursion level for floor drawing */ extern int drawFloorRecurse; @@ -89,4 +86,7 @@ extern GLfloat specular[]; /* Beginning width, height */ extern int width, height; +/* Zoom and rotate tracking */ +GLfloat zoomFactor, rotateFactor; + #endif /* GLOBALS_H */ \ No newline at end of file diff --git a/scene.c b/scene.c index 642fdcd..c024bf1 100644 --- a/scene.c +++ b/scene.c @@ -206,16 +206,6 @@ void mouse(int button, int state, int x, int y) { moving = 0; } } - if (button == GLUT_MIDDLE_BUTTON) { - if (state == GLUT_DOWN) { - lightMoving = 1; - lightStartX = x; - lightStartY = y; - } - if (state == GLUT_UP) { - lightMoving = 0; - } - } } /** @@ -266,19 +256,12 @@ void keyboard(unsigned char key, int x, int y) { */ void motion(int x, int y) { if (moving) { - angle = angle + (x - startx); - angle2 = angle2 + (y - starty); + zoomFactor += (x - startx); + rotateFactor += (y - starty); startx = x; starty = y; glutPostRedisplay(); } - if (lightMoving) { - lightAngle += (x - lightStartX)/40.0; - lightHeight += (lightStartY - y)/20.0; - lightStartX = x; - lightStartY = y; - glutPostRedisplay(); - } } /** @@ -309,26 +292,19 @@ void display() { glLoadIdentity(); gluLookAt( - 0.0, 0.0, 5.0, /* eye is at (x,y,z) */ + 0.0, 0.0, 5.0 + 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 */ ); glRotatef(75.0, 1.0, 0.0, 0.0); - /* Reposition the light source. */ - lightPosition[0] = 12*cos(lightAngle); - lightPosition[1] = lightHeight; - lightPosition[2] = 12*sin(lightAngle); - lightPosition[3] = 0.0; - glPushMatrix(); /* Perform scene rotations based on user mouse/keyboard input. */ - glRotatef(angle, 0.0, 1.0, 0.0); - glRotatef(angle2, 1.0, 0.0, 0.0); - glTranslatef(camx, camy, camz); - glRotatef(rot, 1.0, 0.0, 0.0); + glRotatef(rotateFactor, 0.0, 0.0, 1.0); + //glTranslatef(camx, camy, camz); + //glRotatef(rot, 1.0, 0.0, 0.0); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); -- 2.20.1