summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2005-01-09 16:48:52 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2005-01-09 16:48:52 +0000
commit1b058a06c2e17e44930ed99a32f46f8e5c484fba (patch)
treeac459525ccd80f576e574cf893c435033825db04 /progs
parentc1065ee977f70042e54a930a6cd3af819d4a9806 (diff)
rotate at a reasonable rate
Diffstat (limited to 'progs')
-rw-r--r--progs/xdemos/shape.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/progs/xdemos/shape.c b/progs/xdemos/shape.c
index 9cae9eb289..dbbc0b4ff7 100644
--- a/progs/xdemos/shape.c
+++ b/progs/xdemos/shape.c
@@ -17,6 +17,9 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/time.h>
+#include <time.h>
+#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
@@ -37,6 +40,21 @@ static int MinSides = 3;
static int MaxSides = 20;
+/* return current time (in seconds) */
+static double
+current_time(void)
+{
+ struct timeval tv;
+#ifdef __VMS
+ (void) gettimeofday(&tv, NULL );
+#else
+ struct timezone tz;
+ (void) gettimeofday(&tv, &tz);
+#endif
+ return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
+}
+
+
/*
* Draw the OpenGL stuff and do a SwapBuffers.
*/
@@ -140,17 +158,6 @@ static void display(Display *dpy, Window win)
/*
- * Called when no events are pending.
- */
-static void idle(void)
-{
- Xangle += 2.0;
- Yangle += 3.3;
- Redraw = 1;
-}
-
-
-/*
* This is called when we have to recompute the window shape bitmask.
* We just generate an n-sided regular polygon here but any other shape
* would be possible.
@@ -262,11 +269,15 @@ static void event_loop(Display *dpy, Window win)
}
}
else {
- idle();
- if (Redraw) {
- display(dpy, win);
- Redraw = 0;
- }
+ static double t0 = -1.0;
+ double dt, t = current_time();
+ if (t0 < 0.0)
+ t0 = t;
+ dt = t - t0;
+ Xangle += 90.0 * dt; /* 90 degrees per second */
+ Yangle += 70.0 * dt;
+ t0 = t;
+ display(dpy, win);
}
}
}