diff options
author | Brian Paul <[email protected]> | 2005-01-09 17:37:50 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2005-01-09 17:37:50 +0000 |
commit | 92eddb0fd404624ca198f19e4088927701eec7f5 (patch) | |
tree | dd93d51d271e6bd43d09af9e8b0f3a98a640a8d2 /progs/demos/bounce.c | |
parent | 516f9bc6e306fe7820649ead125d557b46ca8419 (diff) |
better animate rate (Marcelo Magallon)
Diffstat (limited to 'progs/demos/bounce.c')
-rw-r--r-- | progs/demos/bounce.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/progs/demos/bounce.c b/progs/demos/bounce.c index c0f739ea47c..2f3fa9fd97e 100644 --- a/progs/demos/bounce.c +++ b/progs/demos/bounce.c @@ -14,6 +14,8 @@ #include <stdlib.h> #include <string.h> #include <GL/glut.h> +#include <sys/time.h> +#include <time.h> #define COS(X) cos( (X) * 3.14159/180.0 ) #define SIN(X) sin( (X) * 3.14159/180.0 ) @@ -25,12 +27,12 @@ GLboolean IndexMode = GL_FALSE; GLuint Ball; GLenum Mode; -GLfloat Zrot = 0.0, Zstep = 6.0; +GLfloat Zrot = 0.0, Zstep = 180.0; GLfloat Xpos = 0.0, Ypos = 1.0; -GLfloat Xvel = 0.2, Yvel = 0.0; +GLfloat Xvel = 2.0, Yvel = 0.0; GLfloat Xmin = -4.0, Xmax = 4.0; GLfloat Ymin = -3.8, Ymax = 4.0; -GLfloat G = -0.1; +GLfloat G = -9.8; static GLuint make_ball(void) @@ -149,10 +151,17 @@ static void idle(void) { static float vel0 = -100.0; + static double t0 = -1.; + double t, dt; + t = glutGet(GLUT_ELAPSED_TIME) / 1000.; + if (t0 < 0.) + t0 = t; + dt = t - t0; + t0 = t; - Zrot += Zstep; + Zrot += Zstep*dt; - Xpos += Xvel; + Xpos += Xvel*dt; if (Xpos >= Xmax) { Xpos = Xmax; Xvel = -Xvel; @@ -163,8 +172,8 @@ idle(void) Xvel = -Xvel; Zstep = -Zstep; } - Ypos += Yvel; - Yvel += G; + Ypos += Yvel*dt; + Yvel += G*dt; if (Ypos < Ymin) { Ypos = Ymin; if (vel0 == -100.0) |