From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / glx / antmaze.c
index 426be4311ea811fffd4294dbcfeab5eab0fffa96..229257b9576fc7680ab606e862ce8eabf6d8fa01 100644 (file)
  * tennessy@cs.ubc.ca
  */
 
-#if !defined( lint ) && !defined( SABER )
+#if 0
 static const char sccsid[] = "@(#)antmaze.c    5.01 2001/03/01 xlockmore";
 #endif
 
 #ifdef STANDALONE
 # define MODE_antmaze
 # define DEFAULTS      "*delay:                20000   \n"     \
-                       "*showFPS:      False   \n"
+                       "*showFPS:      False   \n" \
+                       "*fpsSolid:     True    \n"
 
 # define refresh_antmaze 0
+# define release_antmaze 0
 # include "xlockmore.h"                /* from the xscreensaver distribution */
 #else /* !STANDALONE */
 # include "xlock.h"            /* from the xlockmore distribution */
-
 #endif /* !STANDALONE */
 
+#ifdef HAVE_JWXYZ
+# include "jwxyz.h"
+#else
+# include <X11/Xlib.h>
+# include <GL/gl.h>
+# include <GL/glu.h>
+#endif
+
+#ifdef HAVE_JWZGLES
+# include "jwzgles.h"
+#endif /* HAVE_JWZGLES */
+
 #ifdef MODE_antmaze
 
 
+#include "sphere.h"
+#include "tube.h"
 #include "rotator.h"
 #include "gltrackball.h"
 
@@ -67,7 +82,7 @@ ENTRYPOINT ModeSpecOpt antmaze_opts =
 
 #ifdef USE_MODULES
 ModStruct   antmaze_description =
-{"antmaze", "init_antmaze", "draw_antmaze", "release_antmaze",
+{"antmaze", "init_antmaze", "draw_antmaze", NULL,
  "draw_antmaze", "change_antmaze", NULL, &antmaze_opts,
  1000, 1, 1, 1, 4, 1.0, "",
  "draws some ants", 0, NULL};
@@ -174,6 +189,7 @@ static const GLfloat position1[] = {-1.0, -5.0, 1.0, 1.0};
 /* filled sphere */
 static Bool mySphere(float radius) 
 {
+#if 0
   GLUquadricObj *quadObj;
 
   if((quadObj = gluNewQuadric()) == 0)
@@ -181,7 +197,13 @@ static Bool mySphere(float radius)
   gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
   gluSphere(quadObj, radius, 16, 16);
   gluDeleteQuadric(quadObj);
-
+#else
+    glPushMatrix();
+    glScalef (radius, radius, radius);
+    glRotatef (90, 1, 0, 0);
+    unit_sphere (16, 16, False);
+    glPopMatrix();
+#endif
   return True;
 }
 
@@ -204,6 +226,7 @@ static Bool mySphere2(float radius)
 /* textured sphere */
 static Bool mySphereTex(float radius) 
 {
+#if 0
   GLUquadricObj *quadObj;
   
   if((quadObj = gluNewQuadric()) == 0)
@@ -213,6 +236,13 @@ static Bool mySphereTex(float radius)
   gluQuadricNormals(quadObj, GLU_SMOOTH);
   gluSphere(quadObj, radius, 32, 16);
   gluDeleteQuadric(quadObj);
+#else
+    glPushMatrix();
+    glScalef (radius, radius, radius);
+    glRotatef (90, 1, 0, 0);
+    unit_sphere (32, 16, False);
+    glPopMatrix();
+#endif
 
   return True;
 }
@@ -220,6 +250,7 @@ static Bool mySphereTex(float radius)
 /* filled cone */
 static Bool myCone(float radius) 
 {
+#if 0
   GLUquadricObj *quadObj;
   
   if ((quadObj = gluNewQuadric()) == 0)
@@ -227,6 +258,12 @@ static Bool myCone(float radius)
   gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
   gluCylinder(quadObj, radius, 0, radius * 2, 8, 1);
   gluDeleteQuadric(quadObj);
+#else
+    cone (0, 0, 0,
+          0, 0, radius * 2,
+          radius, 0,
+          8, True, True, False);
+#endif
   return True;
 }
 
@@ -1251,15 +1288,6 @@ static void pinit(antmazestruct *mp)
 /*   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); */
 }
 
-ENTRYPOINT void release_antmaze(ModeInfo * mi) 
-{
-  if(antmaze) {
-       free((void *) antmaze);
-       antmaze = (antmazestruct *) NULL;
-  }
-  FreeAllGL(mi);
-}
-
 #define MAX_MAGNIFICATION 10
 #define max(a, b) a < b ? b : a
 #define min(a, b) a < b ? a : b
@@ -1268,55 +1296,30 @@ ENTRYPOINT Bool antmaze_handle_event (ModeInfo *mi, XEvent *event)
 {
   antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
 
-  switch(event->xany.type) {
-  case ButtonPress:
-
-    switch(event->xbutton.button) {
+  if (gltrackball_event_handler (event, mp->trackball,
+                                 MI_WIDTH (mi), MI_HEIGHT (mi),
+                                 &mp->button_down_p))
+    return True;
 
-    case Button1:
-      mp->button_down_p = True;
-      gltrackball_start(mp->trackball, 
-                       event->xbutton.x, event->xbutton.y,
-                       MI_WIDTH (mi), MI_HEIGHT (mi));
-      break;
+  if (event->xany.type == ButtonPress)
+    {
+      switch(event->xbutton.button) {
 
-    case Button3:
-      mp->focus = (mp->focus + 1) % ANTCOUNT;
-      break;
+      case Button3:
+        mp->focus = (mp->focus + 1) % ANTCOUNT;
+        return True;
       
-    case Button4:
-      mp->mag = max(mp->mag-1, 1);
-      break;
+      case Button4:
+        mp->mag = max(mp->mag-1, 1);
+        return True;
 
-    case Button5:
-      mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
-      break;
-    }
-
-    break;
-    
-  case ButtonRelease:
-
-    switch(event->xbutton.button) {
-    case Button1:
-      mp->button_down_p = False;
-      break;
+      case Button5:
+        mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
+        return True;
+      }
     }
 
-    break;
-
-  case MotionNotify:
-    if(mp->button_down_p)
-      gltrackball_track(mp->trackball,
-                       event->xmotion.x, event->xmotion.y,
-                       MI_WIDTH (mi), MI_HEIGHT (mi));
-    break;
-    
-  default:
-    return False;
-  }
-
-  return True;
+  return False;
 }
 
 ENTRYPOINT void init_antmaze(ModeInfo * mi) 
@@ -1326,11 +1329,7 @@ ENTRYPOINT void init_antmaze(ModeInfo * mi)
 
   antmazestruct *mp;
   
-  if (antmaze == NULL) {
-       if ((antmaze = (antmazestruct *) calloc(MI_NUM_SCREENS(mi),
-                                               sizeof (antmazestruct))) == NULL)
-         return;
-  }
+  MI_INIT(mi, antmaze, NULL);
   mp = &antmaze[MI_SCREEN(mi)];
   mp->step = NRAND(90);
   mp->ant_position = NRAND(90);
@@ -1397,7 +1396,7 @@ ENTRYPOINT void init_antmaze(ModeInfo * mi)
   mp->mag = 4.0;
 
   mp->rot = make_rotator (rot_speed, rot_speed, rot_speed, 1, 0, True);
-  mp->trackball = gltrackball_init ();
+  mp->trackball = gltrackball_init (False);
   
   if ((mp->glx_context = init_GL(mi)) != NULL) {
     reshape_antmaze(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
@@ -1408,6 +1407,22 @@ ENTRYPOINT void init_antmaze(ModeInfo * mi)
     MI_CLEARWINDOW(mi);
 }
 
+static void
+device_rotate(ModeInfo *mi)
+{
+#if 0
+  GLfloat rot = current_device_rotation();
+  glRotatef(rot, 0, 0, 1);
+  if ((rot >  45 && rot <  135) ||
+      (rot < -45 && rot > -135))
+    {
+      GLfloat s = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
+      glScalef (1/s, s, 1);
+    }
+#endif
+}
+
+
 ENTRYPOINT void draw_antmaze(ModeInfo * mi) 
 {
   double h = (GLfloat) MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
@@ -1443,6 +1458,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
 
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
+  device_rotate(mi);
 
   glPushMatrix();
 
@@ -1464,7 +1480,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
 
   /* sync */
   if(!draw_antmaze_strip(mi)) {
-    release_antmaze(mi);
+    MI_ABORT(mi);
     return;
   }
 
@@ -1478,6 +1494,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
   glViewport((17*MI_WIDTH(mi))/32, MI_HEIGHT(mi)/2, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
+  device_rotate(mi);
   gluPerspective(45, 1/h, 1, 25.0);
   glMatrixMode(GL_MODELVIEW);
     
@@ -1489,7 +1506,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
 
   /* sync */
   if(!draw_antmaze_strip(mi)) {
-    release_antmaze(mi);
+    MI_ABORT(mi);
     return;
   }
 
@@ -1500,6 +1517,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
   glViewport((5*MI_WIDTH(mi))/8, MI_HEIGHT(mi)/8, (11*MI_WIDTH(mi))/32, 3*MI_HEIGHT(mi)/8);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
+  device_rotate(mi);
   gluPerspective(45, 1/h, 1, 25.0);
   glMatrixMode(GL_MODELVIEW);
     
@@ -1564,7 +1582,10 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
 /*   glPopMatrix(); */
 /*   glPopMatrix(); */
   
-  if (MI_IS_FPS(mi)) do_fps (mi);
+  if (MI_IS_FPS(mi)) {
+    glViewport(0, 0, MI_WIDTH(mi), MI_HEIGHT(mi));
+    do_fps (mi);
+  }
   glFlush();
   
   glXSwapBuffers(display, window);