From 92eddb0fd404624ca198f19e4088927701eec7f5 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sun, 9 Jan 2005 17:37:50 +0000 Subject: [PATCH] better animate rate (Marcelo Magallon) --- progs/demos/bounce.c | 23 ++++++++++++++++------- progs/demos/geartrain.c | 10 +++++++--- progs/demos/geartrain.dat | 2 +- progs/demos/gloss.c | 18 ++++++++++++------ progs/demos/ipers.c | 14 ++++++++++---- progs/demos/morph3d.c | 9 ++++++++- progs/demos/pointblast.c | 16 +++++++++++----- progs/demos/reflect.c | 14 ++++++++++---- progs/demos/renormal.c | 10 ++++++++-- progs/demos/shadowtex.c | 10 ++++++++-- progs/demos/spectex.c | 22 +++++++++++++--------- progs/demos/spriteblast.c | 12 +++++++++--- progs/demos/terrain.c | 18 ++++++++++++------ progs/demos/texcyl.c | 16 ++++++++++++---- progs/demos/texobj.c | 8 +++++++- progs/demos/tunnel.c | 25 ++++++++++++++++--------- progs/demos/tunnel2.c | 27 +++++++++++++++++---------- 17 files changed, 177 insertions(+), 77 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 #include #include +#include +#include #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) diff --git a/progs/demos/geartrain.c b/progs/demos/geartrain.c index ec31e743abc..3feb2a0524b 100644 --- a/progs/demos/geartrain.c +++ b/progs/demos/geartrain.c @@ -912,14 +912,18 @@ draw (void) } - - static void idle (void) { int i; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; for (i = 0; i < number_of_gears; i++) - g[i].angle += g[i].angular_velocity; + g[i].angle += g[i].angular_velocity * dt; glutPostRedisplay(); } diff --git a/progs/demos/geartrain.dat b/progs/demos/geartrain.dat index 6b46745a2b5..374de48bd5e 100644 --- a/progs/demos/geartrain.dat +++ b/progs/demos/geartrain.dat @@ -7,7 +7,7 @@ APOSITION = -7.000 0.000 0.000 ACOLOR = 0.800 0.500 0.200 ALENGTH = 6.000 AMOTORED = 1 -AANGULARVELOCITY = 2.000 +AANGULARVELOCITY = 90.000 ADIRECTION = 1 ANAME = AXLE2 diff --git a/progs/demos/gloss.c b/progs/demos/gloss.c index e7d687508c2..4e7adc8d48f 100644 --- a/progs/demos/gloss.c +++ b/progs/demos/gloss.c @@ -21,9 +21,10 @@ #include #include #include +#include #include -#include "readtex.c" /* I know, this is a hack. */ +#include "readtex.h" #define SPECULAR_TEXTURE_FILE "../images/reflect.rgb" #define BASE_TEXTURE_FILE "../images/tile.rgb" @@ -43,7 +44,7 @@ static GLuint Object = 0; static GLboolean Animate = GL_TRUE; static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0; -static GLfloat DXrot = 1.0, DYrot = 2.5; +static GLfloat DXrot = 20.0, DYrot = 50.; static GLfloat Black[4] = { 0, 0, 0, 0 }; static GLfloat White[4] = { 1, 1, 1, 1 }; @@ -58,13 +59,18 @@ static GLint T0 = 0; static GLint Frames = 0; - - static void Idle( void ) { + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + if (Animate) { - Xrot += DXrot; - Yrot += DYrot; + Xrot += DXrot*dt; + Yrot += DYrot*dt; glutPostRedisplay(); } } diff --git a/progs/demos/ipers.c b/progs/demos/ipers.c index d43c662234e..6e153c04e15 100644 --- a/progs/demos/ipers.c +++ b/progs/demos/ipers.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #if defined (WIN32)|| defined(_WIN32) #include @@ -18,7 +18,7 @@ #include -#include "readtex.c" +#include "readtex.h" #ifdef XMESA #include "GL/xmesa.h" @@ -543,6 +543,12 @@ draw(void) static GLfloat alpha = 0.0f; static GLfloat beta = 0.0f; static float fr = 0.0; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; dojoy(); @@ -586,8 +592,8 @@ draw(void) drawipers(0, FROM_NONE); glPopMatrix(); - alpha += 0.5f; - beta += 0.3f; + alpha += 4.f * dt; + beta += 2.4f * dt; glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); diff --git a/progs/demos/morph3d.c b/progs/demos/morph3d.c index 2ce04a30992..047d571c705 100644 --- a/progs/demos/morph3d.c +++ b/progs/demos/morph3d.c @@ -660,6 +660,13 @@ static void draw_ico( void ) } static void draw ( void ) { + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glPushMatrix(); @@ -681,7 +688,7 @@ static void draw ( void ) { glutSwapBuffers(); - step+=0.05; + step += dt; } static void idle_( void ) diff --git a/progs/demos/pointblast.c b/progs/demos/pointblast.c index 14e9cf359fb..715813f1763 100644 --- a/progs/demos/pointblast.c +++ b/progs/demos/pointblast.c @@ -79,7 +79,6 @@ static float float_rand(void) { return rand() / (float) RAND_MAX; } #define MEAN_VELOCITY 3.0 #define GRAVITY 2.0 -#define TIME_DELTA 0.025 /* The speed of time. */ /* Modeling units of ground extent in each X and Z direction. */ #define EDGE 12 @@ -114,6 +113,13 @@ updatePointList(void) float distance; int i; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + motion = 0; for (i=0; i #include #include "GL/glut.h" -#include "../util/showbuffer.c" -#include "../util/readtex.c" +#include "showbuffer.h" +#include "readtex.h" #define DEG2RAD (3.14159/180.0) @@ -318,8 +318,14 @@ static void draw_scene( void ) static void idle( void ) { - spin += 2.0; - yrot += 3.0; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + spin += 60.0 * dt; + yrot += 90.0 * dt; glutPostRedisplay(); } diff --git a/progs/demos/renormal.c b/progs/demos/renormal.c index 4fc19578cde..9e5da95484c 100644 --- a/progs/demos/renormal.c +++ b/progs/demos/renormal.c @@ -13,9 +13,15 @@ static GLfloat Phi = 0.0; -static void Idle(void) +static void Idle( void ) { - Phi += 0.1; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + Phi += 3.0 * dt; glutPostRedisplay(); } diff --git a/progs/demos/shadowtex.c b/progs/demos/shadowtex.c index 18aad47ed53..e918751a7ad 100644 --- a/progs/demos/shadowtex.c +++ b/progs/demos/shadowtex.c @@ -33,7 +33,7 @@ #include #include #include -#include "../util/showbuffer.c" +#include "showbuffer.h" #if 0 /* change to 1 if you want to use the old SGIX extensions */ #undef GL_ARB_depth_texture @@ -386,7 +386,13 @@ Reshape(int width, int height) static void Idle(void) { - Yrot += 5.0; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + Yrot += 75.0 * dt; /*LightLongitude -= 5.0;*/ glutPostRedisplay(); } diff --git a/progs/demos/spectex.c b/progs/demos/spectex.c index 9364245995d..cfa7f74a21a 100644 --- a/progs/demos/spectex.c +++ b/progs/demos/spectex.c @@ -25,8 +25,8 @@ static GLUquadricObj *Quadric; static GLuint Sphere; static GLfloat LightPos[4] = {10.0, 10.0, 10.0, 1.0}; -static GLfloat Delta = 1.0; -static GLint Mode = 0; +static GLfloat Delta = 20.0; +static GLint Mode = 4; /*static GLfloat Blue[4] = {0.0, 0.0, 1.0, 1.0};*/ /*static GLfloat Gray[4] = {0.5, 0.5, 0.5, 1.0};*/ @@ -34,14 +34,18 @@ static GLfloat Black[4] = {0.0, 0.0, 0.0, 1.0}; static GLfloat White[4] = {1.0, 1.0, 1.0, 1.0}; - -static void Idle( void ) +static void +Idle(void) { - LightPos[0] += Delta; - if (LightPos[0]>15.0) - Delta = -1.0; - else if (LightPos[0]<-15.0) - Delta = 1.0; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + LightPos[0] += Delta * dt; + if (LightPos[0]>15.0 || LightPos[0]<-15.0) + Delta = -Delta; glutPostRedisplay(); } diff --git a/progs/demos/spriteblast.c b/progs/demos/spriteblast.c index 63dc7d12bb8..d6e9a4de2fd 100644 --- a/progs/demos/spriteblast.c +++ b/progs/demos/spriteblast.c @@ -104,7 +104,6 @@ static float float_rand(void) { return rand() / (float) RAND_MAX; } #define MEAN_VELOCITY 3.0 #define GRAVITY 2.0 -#define TIME_DELTA 0.025 /* The speed of time. */ /* Modeling units of ground extent in each X and Z direction. */ #define EDGE 12 @@ -139,6 +138,13 @@ updatePointList(void) float distance; int i; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + motion = 0; for (i=0; i #include #include +#include #include -#include "readtex.c" /* I know, this is a hack. */ +#include "readtex.h" #define TEXTURE_FILE "../images/reflect.rgb" @@ -30,7 +31,7 @@ static GLuint CylinderObj = 0; static GLboolean Animate = GL_TRUE; static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0; -static GLfloat DXrot = 1.0, DYrot = 2.5; +static GLfloat DXrot = 50.0, DYrot = 125.0; /* performance info */ static GLint T0 = 0; @@ -39,9 +40,16 @@ static GLint Frames = 0; static void Idle( void ) { + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + if (Animate) { - Xrot += DXrot; - Yrot += DYrot; + Xrot += DXrot * dt; + Yrot += DYrot * dt; glutPostRedisplay(); } } diff --git a/progs/demos/texobj.c b/progs/demos/texobj.c index f30ede464c0..40bce6e5695 100644 --- a/progs/demos/texobj.c +++ b/progs/demos/texobj.c @@ -85,7 +85,13 @@ static void draw( void ) static void idle( void ) { - Angle += 2.0; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + Angle += 120.0*dt; glutPostRedisplay(); } diff --git a/progs/demos/tunnel.c b/progs/demos/tunnel.c index f0faa61a0bf..a47b916d60d 100644 --- a/progs/demos/tunnel.c +++ b/progs/demos/tunnel.c @@ -9,14 +9,14 @@ #include #include #include -#include +#include #ifdef WIN32 #include #endif #include -#include "readtex.c" +#include "readtex.h" #include "tunneldat.h" #ifdef XMESA @@ -55,7 +55,7 @@ static int win = 0; static float obs[3] = { 1000.0, 0.0, 2.0 }; static float dir[3]; -static float v = 0.5; +static float v = 30.; static float alpha = 90.0; static float beta = 90.0; @@ -84,7 +84,7 @@ inittextures(void) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - GL_LINEAR_MIPMAP_LINEAR); + GL_LINEAR_MIPMAP_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glGenTextures(1, &t2id); @@ -160,6 +160,13 @@ drawobjs(const int *l, const float *f) static void calcposobs(void) { + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + dir[0] = sin(alpha * M_PI / 180.0); dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); dir[2] = cos(beta * M_PI / 180.0); @@ -171,9 +178,9 @@ calcposobs(void) if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) dir[2] = 0; - obs[0] += v * dir[0]; - obs[1] += v * dir[1]; - obs[2] += v * dir[2]; + obs[0] += v * dir[0] * dt; + obs[1] += v * dir[1] * dt; + obs[2] += v * dir[2] * dt; } static void @@ -204,10 +211,10 @@ key(unsigned char k, int x, int y) break; case 'a': - v += 0.01; + v += 5.; break; case 'z': - v -= 0.01; + v -= 5.; break; #ifdef XMESA diff --git a/progs/demos/tunnel2.c b/progs/demos/tunnel2.c index 436f01b3e49..14248c095c0 100644 --- a/progs/demos/tunnel2.c +++ b/progs/demos/tunnel2.c @@ -12,14 +12,14 @@ #include #include #include -#include +#include #ifdef WIN32 #include #endif #include -#include "readtex.c" +#include "readtex.h" #include "tunneldat.h" #ifdef FX @@ -51,11 +51,11 @@ static GLint Frames = 0; static float obs[3] = { 1000.0, 0.0, 2.0 }; static float dir[3]; -static float v = 0.5; +static float v = 30.; static float alpha = 90.0; static float beta = 90.0; -static int fog = 0; +static int fog = 1; static int bfcull = 1; static int usetex = 1; static int cstrip = 0; @@ -97,7 +97,7 @@ inittextures(void) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - GL_LINEAR_MIPMAP_NEAREST); + GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); @@ -158,6 +158,13 @@ drawobjs(const int *l, const float *f) static void calcposobs(void) { + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + dir[0] = sin(alpha * M_PI / 180.0); dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); dir[2] = cos(beta * M_PI / 180.0); @@ -169,9 +176,9 @@ calcposobs(void) if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) dir[2] = 0; - obs[0] += v * dir[0]; - obs[1] += v * dir[1]; - obs[2] += v * dir[2]; + obs[0] += v * dir[0] * dt; + obs[1] += v * dir[1] * dt; + obs[2] += v * dir[2] * dt; } static void @@ -202,10 +209,10 @@ key(unsigned char k, int x, int y) break; case 'a': - v += 0.01; + v += 5.; break; case 'z': - v -= 0.01; + v -= 5.; break; #ifdef XMESA -- 2.30.2