diff options
author | Brian Paul <brian.paul@tungstengraphics.com> | 2005-01-09 17:37:50 +0000 |
---|---|---|
committer | Brian Paul <brian.paul@tungstengraphics.com> | 2005-01-09 17:37:50 +0000 |
commit | 92eddb0fd404624ca198f19e4088927701eec7f5 (patch) | |
tree | dd93d51d271e6bd43d09af9e8b0f3a98a640a8d2 /progs | |
parent | 516f9bc6e306fe7820649ead125d557b46ca8419 (diff) |
better animate rate (Marcelo Magallon)
Diffstat (limited to 'progs')
-rw-r--r-- | progs/demos/bounce.c | 23 | ||||
-rw-r--r-- | progs/demos/geartrain.c | 10 | ||||
-rw-r--r-- | progs/demos/geartrain.dat | 2 | ||||
-rw-r--r-- | progs/demos/gloss.c | 18 | ||||
-rw-r--r-- | progs/demos/ipers.c | 14 | ||||
-rw-r--r-- | progs/demos/morph3d.c | 9 | ||||
-rw-r--r-- | progs/demos/pointblast.c | 16 | ||||
-rw-r--r-- | progs/demos/reflect.c | 14 | ||||
-rw-r--r-- | progs/demos/renormal.c | 10 | ||||
-rw-r--r-- | progs/demos/shadowtex.c | 10 | ||||
-rw-r--r-- | progs/demos/spectex.c | 22 | ||||
-rw-r--r-- | progs/demos/spriteblast.c | 12 | ||||
-rw-r--r-- | progs/demos/terrain.c | 18 | ||||
-rw-r--r-- | progs/demos/texcyl.c | 16 | ||||
-rw-r--r-- | progs/demos/texobj.c | 8 | ||||
-rw-r--r-- | progs/demos/tunnel.c | 25 | ||||
-rw-r--r-- | 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 c0f739ea47..2f3fa9fd97 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) diff --git a/progs/demos/geartrain.c b/progs/demos/geartrain.c index ec31e743ab..3feb2a0524 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 6b46745a2b..374de48bd5 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 e7d687508c..4e7adc8d48 100644 --- a/progs/demos/gloss.c +++ b/progs/demos/gloss.c @@ -21,9 +21,10 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <string.h> #include <GL/glut.h> -#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 d43c662234..6e153c04e1 100644 --- a/progs/demos/ipers.c +++ b/progs/demos/ipers.c @@ -9,7 +9,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#include <time.h> +#include <string.h> #if defined (WIN32)|| defined(_WIN32) #include <windows.h> @@ -18,7 +18,7 @@ #include <GL/glut.h> -#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 2ce04a3099..047d571c70 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 14e9cf359f..715813f176 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<numPoints; i++) { distance = pointVelocity[i][0] * theTime; @@ -139,9 +145,9 @@ updatePointList(void) pointTime[i] = 0.0; /* Reset the particles sense of up time. */ } motion = 1; - pointTime[i] += TIME_DELTA; + pointTime[i] += dt; } - theTime += TIME_DELTA; + theTime += dt; if (!motion && !spin) { if (repeat) { makePointList(); @@ -264,7 +270,7 @@ menu(int option) case 0: makePointList(); break; -#if GL_ARB_point_parameters +#ifdef GL_ARB_point_parameters case 1: glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, constant); break; @@ -281,7 +287,7 @@ menu(int option) case 5: blend = 0; break; -#if GL_ARB_point_parameters +#ifdef GL_ARB_point_parameters case 6: glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1.0); break; diff --git a/progs/demos/reflect.c b/progs/demos/reflect.c index 91b2ad9e73..d259d7b718 100644 --- a/progs/demos/reflect.c +++ b/progs/demos/reflect.c @@ -31,8 +31,8 @@ #include <stdio.h> #include <stdlib.h> #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 4fc19578cd..9e5da95484 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 18aad47ed5..e918751a7a 100644 --- a/progs/demos/shadowtex.c +++ b/progs/demos/shadowtex.c @@ -33,7 +33,7 @@ #include <stdlib.h> #include <math.h> #include <GL/glut.h> -#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 9364245995..cfa7f74a21 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 63dc7d12bb..d6e9a4de2f 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<numPoints; i++) { distance = pointVelocity[i][0] * theTime; @@ -164,9 +170,9 @@ updatePointList(void) pointTime[i] = 0.0; /* Reset the particles sense of up time. */ } motion = 1; - pointTime[i] += TIME_DELTA; + pointTime[i] += dt; } - theTime += TIME_DELTA; + theTime += dt; if (!motion && !spin) { if (repeat) { makePointList(); diff --git a/progs/demos/terrain.c b/progs/demos/terrain.c index 9063c939d5..990c7b8b57 100644 --- a/progs/demos/terrain.c +++ b/progs/demos/terrain.c @@ -69,7 +69,7 @@ static int scrheight = HEIGHT; static float obs[3] = { OBSSTARTX, heightMnt * 1.3, OBSSTARTY }; static float dir[3], v1[2], v2[2]; -static float v = 15.0; +static float v = 900.0; static float alpha = 75.0; static float beta = 90.0; @@ -77,6 +77,12 @@ static void calcposobs(void) { float alpha1, alpha2; + 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[2] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); @@ -97,9 +103,9 @@ calcposobs(void) v2[0] = sin(alpha2 * M_PI / 180.0); v2[1] = cos(alpha2 * M_PI / 180.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; if (obs[1] < 0.0) obs[1] = 0.0; @@ -432,10 +438,10 @@ key(unsigned char k, int x, int y) exit(0); break; case 'a': - v += 0.5; + v += 50.; break; case 'z': - v -= 0.5; + v -= 50.; break; case 'p': if (poutline) { diff --git a/progs/demos/texcyl.c b/progs/demos/texcyl.c index 52f7da0af2..c04d5004e3 100644 --- a/progs/demos/texcyl.c +++ b/progs/demos/texcyl.c @@ -12,9 +12,10 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <string.h> #include <GL/glut.h> -#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 f30ede464c..40bce6e569 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 f0faa61a0b..a47b916d60 100644 --- a/progs/demos/tunnel.c +++ b/progs/demos/tunnel.c @@ -9,14 +9,14 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#include <time.h> +#include <string.h> #ifdef WIN32 #include <windows.h> #endif #include <GL/glut.h> -#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 436f01b3e4..14248c095c 100644 --- a/progs/demos/tunnel2.c +++ b/progs/demos/tunnel2.c @@ -12,14 +12,14 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#include <time.h> +#include <string.h> #ifdef WIN32 #include <windows.h> #endif #include <GL/glut.h> -#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 |