diff options
author | Brian Paul <brian.paul@tungstengraphics.com> | 2005-01-09 16:52:53 +0000 |
---|---|---|
committer | Brian Paul <brian.paul@tungstengraphics.com> | 2005-01-09 16:52:53 +0000 |
commit | 429efa9f00b63f08ba4bc76e5b8ba80aceee24ec (patch) | |
tree | 811037224a7a5efc9cbdc1282e1eff5e38341bdc /progs/redbook | |
parent | 1b058a06c2e17e44930ed99a32f46f8e5c484fba (diff) |
animation rate patch (Marcello Magallon)
Diffstat (limited to 'progs/redbook')
-rw-r--r-- | progs/redbook/alpha3D.c | 18 | ||||
-rw-r--r-- | progs/redbook/double.c | 15 |
2 files changed, 28 insertions, 5 deletions
diff --git a/progs/redbook/alpha3D.c b/progs/redbook/alpha3D.c index 413836edd5..6169bd162b 100644 --- a/progs/redbook/alpha3D.c +++ b/progs/redbook/alpha3D.c @@ -49,7 +49,7 @@ #define MAXZ 8.0 #define MINZ -8.0 -#define ZINC 0.4 +#define ZINC 4. static float solidZ = MAXZ; static float transparentZ = MINZ; @@ -130,11 +130,21 @@ void reshape(int w, int h) void animate(void) { + static double t0 = -1.; if (solidZ <= MINZ || transparentZ >= MAXZ) + { glutIdleFunc(NULL); + t0 = -1.; + } else { - solidZ -= ZINC; - transparentZ += ZINC; + double t, dt; + t = glutGet(GLUT_ELAPSED_TIME) / 1000.; + if (t0 < 0.) + t0 = t; + dt = t - t0; + t0 = t; + solidZ -= ZINC*dt; + transparentZ += ZINC*dt; glutPostRedisplay(); } } @@ -163,7 +173,7 @@ void keyboard(unsigned char key, int x, int y) int main(int argc, char** argv) { glutInit(&argc, argv); - glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutCreateWindow(argv[0]); init(); diff --git a/progs/redbook/double.c b/progs/redbook/double.c index a41229d12f..3153c70cc1 100644 --- a/progs/redbook/double.c +++ b/progs/redbook/double.c @@ -45,6 +45,7 @@ #include <stdlib.h> static GLfloat spin = 0.0; +static GLdouble t0 = 0.; void display(void) { @@ -58,9 +59,18 @@ void display(void) glutSwapBuffers(); } +GLdouble gettime(void) +{ + return (GLdouble)(glutGet(GLUT_ELAPSED_TIME)) / 1000.; +} + void spinDisplay(void) { - spin = spin + 2.0; + GLdouble t, dt; + t = gettime(); + dt = t - t0; + t0 = t; + spin = spin + 120.0*dt; if (spin > 360.0) spin = spin - 360.0; glutPostRedisplay(); @@ -88,7 +98,10 @@ void mouse(int button, int state, int x, int y) switch (button) { case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) + { + t0 = gettime(); glutIdleFunc(spinDisplay); + } break; case GLUT_MIDDLE_BUTTON: if (state == GLUT_DOWN) |