summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian <[email protected]>2008-01-28 12:35:20 -0700
committerBrian <[email protected]>2008-01-28 12:36:01 -0700
commite7007c6fb02ed885ef6edf8bb364ea3c81ae6e1d (patch)
tree7a941c18ffa9f6a35250aa7bdca2cc16c7200da5
parent3bfef648000e544a3505feea5bda7aa9f184f304 (diff)
Added d/D keys to change viewing distance, 'a' to toggle animation
-rw-r--r--progs/demos/gears.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/progs/demos/gears.c b/progs/demos/gears.c
index ab9bc007421..7abbd3670bd 100644
--- a/progs/demos/gears.c
+++ b/progs/demos/gears.c
@@ -27,6 +27,9 @@ static GLint T0 = 0;
static GLint Frames = 0;
static GLint autoexit = 0;
static GLint win = 0;
+static GLboolean Visible = GL_TRUE;
+static GLboolean Animate = GL_TRUE;
+static GLfloat viewDist = 40.0;
/**
@@ -179,6 +182,9 @@ draw(void)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
+
+ glTranslatef(0.0, 0.0, -viewDist);
+
glRotatef(view_rotx, 1.0, 0.0, 0.0);
glRotatef(view_roty, 0.0, 1.0, 0.0);
glRotatef(view_rotz, 0.0, 0.0, 1.0);
@@ -240,6 +246,15 @@ idle(void)
glutPostRedisplay();
}
+static void
+update_idle_func(void)
+{
+ if (Visible && Animate)
+ glutIdleFunc(idle);
+ else
+ glutIdleFunc(NULL);
+}
+
/* change view angle, exit upon ESC */
/* ARGSUSED1 */
static void
@@ -252,6 +267,16 @@ key(unsigned char k, int x, int y)
case 'Z':
view_rotz -= 5.0;
break;
+ case 'd':
+ viewDist += 1.0;
+ break;
+ case 'D':
+ viewDist -= 1.0;
+ break;
+ case 'a':
+ Animate = !Animate;
+ update_idle_func();
+ break;
case 27: /* Escape */
cleanup();
exit(0);
@@ -297,8 +322,6 @@ reshape(int width, int height)
glLoadIdentity();
glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -40.0);
}
static void
@@ -351,13 +374,12 @@ init(int argc, char *argv[])
}
}
+
static void
visible(int vis)
{
- if (vis == GLUT_VISIBLE)
- glutIdleFunc(idle);
- else
- glutIdleFunc(NULL);
+ Visible = vis;
+ update_idle_func();
}
int main(int argc, char *argv[])
@@ -375,6 +397,7 @@ int main(int argc, char *argv[])
glutKeyboardFunc(key);
glutSpecialFunc(special);
glutVisibilityFunc(visible);
+ update_idle_func();
glutMainLoop();
return 0; /* ANSI C requires main to return int. */