summaryrefslogtreecommitdiffstats
path: root/progs/redbook/double.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2005-01-09 16:52:53 +0000
committerBrian Paul <[email protected]>2005-01-09 16:52:53 +0000
commit429efa9f00b63f08ba4bc76e5b8ba80aceee24ec (patch)
tree811037224a7a5efc9cbdc1282e1eff5e38341bdc /progs/redbook/double.c
parent1b058a06c2e17e44930ed99a32f46f8e5c484fba (diff)
animation rate patch (Marcello Magallon)
Diffstat (limited to 'progs/redbook/double.c')
-rw-r--r--progs/redbook/double.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/progs/redbook/double.c b/progs/redbook/double.c
index a41229d12fc..3153c70cc1d 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)