glx: indent -br -i3 -npcs --no-tabs single2.c
[mesa.git] / progs / demos / morph3d.c
index af052926d7d58e8b09c915ade5b3694f3b99adef..6aca8270ff515a250505fc44759dbc2b0a674797 100644 (file)
@@ -1,21 +1,3 @@
-/* $Id: morph3d.c,v 1.2 1999/09/17 12:27:01 brianp Exp $ */
-
-/*
- * $Log: morph3d.c,v $
- * Revision 1.2  1999/09/17 12:27:01  brianp
- * silenced some warnings
- *
- * Revision 1.1.1.1  1999/08/19 00:55:40  jtg
- * Imported sources
- *
- * Revision 3.1  1998/06/29 02:37:30  brianp
- * minor changes for Windows (Ted Jump)
- *
- * Revision 3.0  1998/02/14 18:42:29  brianp
- * initial rev
- *
- */
-
 
 /*-
  * morph3d.c - Shows 3D morphing objects
@@ -194,6 +176,7 @@ So the angle is:
 
 static int       mono=0;
 static int       smooth=1;
+static int       anim=1;
 static GLint     WindH, WindW;
 static GLfloat   step=0;
 static GLfloat   seno;
@@ -498,7 +481,7 @@ static void draw_dodeca( void )
 {
   GLuint list;
 
-  #define TAU ((SQRT5+1)/2)
+#define TAU ((SQRT5+1)/2)
 
   list = glGenLists( 1 );
   glNewList( list, GL_COMPILE );
@@ -699,11 +682,19 @@ static void draw ( void ) {
 
   glutSwapBuffers();
 
-  step+=0.05;
 }
 
 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;
+
+  step += dt;
+
    glutPostRedisplay();
 }
 
@@ -729,11 +720,19 @@ static void key( unsigned char k, int x, int y )
     case '4': object=4; break;
     case '5': object=5; break;
     case ' ': mono^=1; break;
-    case 13: smooth^=1; break;
+    case 's': smooth^=1; break;
+    case 'a':
+       anim^=1;
+       if (anim)
+          glutIdleFunc( idle_ );
+       else
+          glutIdleFunc(NULL);
+       break;
     case 27:
        exit(0);
   }
   pinit();
+  glutPostRedisplay();
 }
 
 static void pinit(void)
@@ -827,7 +826,7 @@ static void pinit(void)
 
 }
 
-void INIT(void)
+int main(int argc, char **argv)
 {
   printf("Morph 3D - Shows morphing platonic polyhedra\n");
   printf("Author: Marcelo Fernandes Vianna (vianna@cat.cbpf.br)\n\n");
@@ -842,6 +841,7 @@ void INIT(void)
 
   object=1;
 
+  glutInit(&argc, argv);
   glutInitWindowPosition(0,0);
   glutInitWindowSize(640,480);
 
@@ -889,9 +889,3 @@ void INIT(void)
   glutMainLoop();
   
 }
-
-int main(int argc, char **argv)
-{
-  INIT();
-  return(0);
-}