compute reasonable animate rate (Marcelo Magallon)
This commit is contained in:
@@ -108,7 +108,6 @@ void FillTorus(float rc, int numc, float rt, int numt)
|
|||||||
|
|
||||||
float Clamp(int iters_left, float t)
|
float Clamp(int iters_left, float t)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (iters_left < 3) {
|
if (iters_left < 3) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
@@ -119,6 +118,17 @@ void DrawScene(void)
|
|||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
GLboolean goIdle;
|
GLboolean goIdle;
|
||||||
|
static double t0 = -1.;
|
||||||
|
double t, dt;
|
||||||
|
t = glutGet(GLUT_ELAPSED_TIME) / 1000.;
|
||||||
|
if (t0 < 0.)
|
||||||
|
t0 = t;
|
||||||
|
dt = t - t0;
|
||||||
|
|
||||||
|
if (dt < 1./30.)
|
||||||
|
return;
|
||||||
|
|
||||||
|
t0 = t;
|
||||||
|
|
||||||
goIdle = GL_TRUE;
|
goIdle = GL_TRUE;
|
||||||
for (i = 0; i < RINGS; i++) {
|
for (i = 0; i < RINGS; i++) {
|
||||||
@@ -167,6 +177,10 @@ float MyRand(void)
|
|||||||
return 10.0 * ( (float) rand() / (float) RAND_MAX - 0.5 );
|
return 10.0 * ( (float) rand() / (float) RAND_MAX - 0.5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(GLUTCALLBACK)
|
||||||
|
#define GLUTCALLBACK
|
||||||
|
#endif
|
||||||
|
|
||||||
void GLUTCALLBACK glut_post_redisplay_p(void)
|
void GLUTCALLBACK glut_post_redisplay_p(void)
|
||||||
{
|
{
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
#include "../util/readtex.c"
|
#include "readtex.h"
|
||||||
|
|
||||||
|
|
||||||
#ifndef PI
|
#ifndef PI
|
||||||
@@ -820,8 +820,16 @@ void Reshape(int width, int height)
|
|||||||
|
|
||||||
void Idle(void)
|
void Idle(void)
|
||||||
{
|
{
|
||||||
xRotation += .75;
|
static double t0 = -1.;
|
||||||
yRotation += .375;
|
double t, dt;
|
||||||
|
t = glutGet(GLUT_ELAPSED_TIME) / 1000.;
|
||||||
|
if (t0 < 0.)
|
||||||
|
t0 = t;
|
||||||
|
dt = t - t0;
|
||||||
|
t0 = t;
|
||||||
|
|
||||||
|
xRotation += .75*60.*dt;
|
||||||
|
yRotation += .375*60.*dt;
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,7 +45,7 @@ enum {
|
|||||||
|
|
||||||
#define MAXSTARS 400
|
#define MAXSTARS 400
|
||||||
#define MAXPOS 10000
|
#define MAXPOS 10000
|
||||||
#define MAXWARP 10
|
#define MAXWARP 500
|
||||||
#define MAXANGLES 6000
|
#define MAXANGLES 6000
|
||||||
|
|
||||||
|
|
||||||
@@ -115,6 +115,13 @@ void MoveStars(void)
|
|||||||
{
|
{
|
||||||
float offset;
|
float offset;
|
||||||
GLint n;
|
GLint n;
|
||||||
|
static double t0 = -1.;
|
||||||
|
double t, dt;
|
||||||
|
t = glutGet(GLUT_ELAPSED_TIME) / 1000.;
|
||||||
|
if (t0 < 0.)
|
||||||
|
t0 = t;
|
||||||
|
dt = 85.*(t - t0);
|
||||||
|
t0 = t;
|
||||||
|
|
||||||
offset = speed * 60.0;
|
offset = speed * 60.0;
|
||||||
|
|
||||||
@@ -122,10 +129,10 @@ void MoveStars(void)
|
|||||||
stars[n].x[1] = stars[n].x[0];
|
stars[n].x[1] = stars[n].x[0];
|
||||||
stars[n].y[1] = stars[n].y[0];
|
stars[n].y[1] = stars[n].y[0];
|
||||||
stars[n].z[1] = stars[n].z[0];
|
stars[n].z[1] = stars[n].z[0];
|
||||||
stars[n].x[0] += stars[n].offsetX;
|
stars[n].x[0] += stars[n].offsetX*dt;
|
||||||
stars[n].y[0] += stars[n].offsetY;
|
stars[n].y[0] += stars[n].offsetY*dt;
|
||||||
stars[n].z[0] -= offset;
|
stars[n].z[0] -= offset*dt;
|
||||||
stars[n].rotation += stars[n].offsetR;
|
stars[n].rotation += stars[n].offsetR*dt;
|
||||||
if (stars[n].rotation > MAXANGLES) {
|
if (stars[n].rotation > MAXANGLES) {
|
||||||
stars[n].rotation = 0.0;
|
stars[n].rotation = 0.0;
|
||||||
}
|
}
|
||||||
@@ -296,6 +303,10 @@ static GLenum Args(int argc, char **argv)
|
|||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(GLUTCALLBACK)
|
||||||
|
#define GLUTCALLBACK
|
||||||
|
#endif
|
||||||
|
|
||||||
void GLUTCALLBACK glut_post_redisplay_p(void)
|
void GLUTCALLBACK glut_post_redisplay_p(void)
|
||||||
{
|
{
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
|
@@ -265,6 +265,17 @@ void Mouse(int button, int state, int mouseX, int mouseY)
|
|||||||
|
|
||||||
void Animate(void)
|
void Animate(void)
|
||||||
{
|
{
|
||||||
|
static double t0 = -1.;
|
||||||
|
double t, dt;
|
||||||
|
t = glutGet(GLUT_ELAPSED_TIME) / 1000.;
|
||||||
|
if (t0 < 0.)
|
||||||
|
t0 = t;
|
||||||
|
dt = t - t0;
|
||||||
|
|
||||||
|
if (dt < 1./60.)
|
||||||
|
return;
|
||||||
|
|
||||||
|
t0 = t;
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case OP_STRETCH:
|
case OP_STRETCH:
|
||||||
@@ -307,6 +318,10 @@ static GLenum Args(int argc, char **argv)
|
|||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(GLUTCALLBACK)
|
||||||
|
#define GLUTCALLBACK
|
||||||
|
#endif
|
||||||
|
|
||||||
void GLUTCALLBACK glut_post_redisplay_p(void)
|
void GLUTCALLBACK glut_post_redisplay_p(void)
|
||||||
{
|
{
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
|
@@ -87,8 +87,25 @@ GLubyte contourTexture2[] = {
|
|||||||
255, 127, 127, 127,
|
255, 127, 127, 127,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if !defined(GLUTCALLBACK)
|
||||||
|
#define GLUTCALLBACK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void GLUTCALLBACK glut_post_redisplay_p(void)
|
void GLUTCALLBACK glut_post_redisplay_p(void)
|
||||||
{
|
{
|
||||||
|
static double t0 = -1.;
|
||||||
|
double t, dt;
|
||||||
|
t = glutGet(GLUT_ELAPSED_TIME) / 1000.;
|
||||||
|
if (t0 < 0.)
|
||||||
|
t0 = t;
|
||||||
|
dt = t - t0;
|
||||||
|
|
||||||
|
if (dt < 1./30.)
|
||||||
|
return;
|
||||||
|
|
||||||
|
t0 = t;
|
||||||
|
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user