#define MAXZ 8.0
#define MINZ -8.0
-#define ZINC 0.4
+#define ZINC 4.
static float solidZ = MAXZ;
static float transparentZ = MINZ;
void animate(void)
{
+ static double t0 = -1.;
if (solidZ <= MINZ || transparentZ >= MAXZ)
+ {
glutIdleFunc(NULL);
+ t0 = -1.;
+ }
else {
- solidZ -= ZINC;
- transparentZ += ZINC;
+ double t, dt;
+ t = glutGet(GLUT_ELAPSED_TIME) / 1000.;
+ if (t0 < 0.)
+ t0 = t;
+ dt = t - t0;
+ t0 = t;
+ solidZ -= ZINC*dt;
+ transparentZ += ZINC*dt;
glutPostRedisplay();
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
- glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
+ glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow(argv[0]);
init();
#include <stdlib.h>
static GLfloat spin = 0.0;
+static GLdouble t0 = 0.;
void display(void)
{
glutSwapBuffers();
}
+GLdouble gettime(void)
+{
+ return (GLdouble)(glutGet(GLUT_ELAPSED_TIME)) / 1000.;
+}
+
void spinDisplay(void)
{
- spin = spin + 2.0;
+ GLdouble t, dt;
+ t = gettime();
+ dt = t - t0;
+ t0 = t;
+ spin = spin + 120.0*dt;
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay();
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
+ {
+ t0 = gettime();
glutIdleFunc(spinDisplay);
+ }
break;
case GLUT_MIDDLE_BUTTON:
if (state == GLUT_DOWN)