From http://www.jwz.org/xscreensaver/xscreensaver-5.18.tar.gz
[xscreensaver] / hacks / glx / boing.c
index 828c754718a66a351983b0871d313d3d5dabca58..3396217ffeabe84c5fe0b091722734d93d154c7b 100644 (file)
@@ -1,4 +1,4 @@
-/* boing, Copyright (c) 2005 Jamie Zawinski <jwz@jwz.org>
+/* boing, Copyright (c) 2005-2012 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -42,7 +42,7 @@
 #define DEF_SMOOTH      "False"
 #define DEF_SCANLINES   "True"
 #define DEF_SPEED       "1.0"
-#define DEF_SIZE        "0.5"
+#define DEF_BALL_SIZE   "0.5"
 #define DEF_ANGLE       "15"
 #define DEF_MERIDIANS   "16"
 #define DEF_PARALLELS   "8"
@@ -109,6 +109,8 @@ static XrmOptionDescRec opts[] = {
   { "-ball-color2",".ballColor2",XrmoptionSepArg, 0 },
   { "-grid-color", ".gridColor", XrmoptionSepArg, 0 },
   { "-shadow-color",".shadowColor",XrmoptionSepArg, 0 },
+  { "-background",  ".boingBackground",XrmoptionSepArg, 0 },
+  { "-bg",          ".boingBackground",XrmoptionSepArg, 0 },
 };
 
 static argtype vars[] = {
@@ -118,7 +120,7 @@ static argtype vars[] = {
   {&scanlines_p,"scanlines","Scanlines",  DEF_SCANLINES, t_Bool},
   {&speed,     "speed",     "Speed",      DEF_SPEED,     t_Float},
   {&angle,     "angle",     "Angle",      DEF_ANGLE,     t_Int},
-  {&ball_size, "ballSize",  "BallSize",   DEF_SIZE,      t_Float},
+  {&ball_size, "ballSize",  "BallSize",   DEF_BALL_SIZE, t_Float},
   {&meridians, "meridians", "meridians",  DEF_MERIDIANS, t_Int},
   {&parallels, "parallels", "parallels",  DEF_PARALLELS, t_Int},
   {&tiles,     "tiles",     "Tiles",      DEF_TILES,     t_Int},
@@ -376,7 +378,7 @@ draw_scanlines (ModeInfo *mi)
       int lh, ls;
       int y;
       glLoadIdentity();
-      gluOrtho2D (0, w, 0, h);
+      glOrtho (0, w, 0, h, -1, 1);
 
       if      (h > 500) lh = 4, ls = 4;
       else if (h > 300) lh = 2, ls = 1;
@@ -459,6 +461,13 @@ reshape_boing (ModeInfo *mi, int width, int height)
 
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
+
+  if (height > width)
+    {
+      GLfloat s = width / (GLfloat) height;
+      glScalef (s, s, s);
+    }
+
   gluPerspective (8.0, 1/h, 1.0, 10.0);
 
   glMatrixMode(GL_MODELVIEW);
@@ -493,7 +502,9 @@ boing_handle_event (ModeInfo *mi, XEvent *event)
     }
   else if (event->xany.type == ButtonPress &&
            (event->xbutton.button == Button4 ||
-            event->xbutton.button == Button5))
+            event->xbutton.button == Button5 ||
+            event->xbutton.button == Button6 ||
+            event->xbutton.button == Button7))
     {
       gltrackball_mousewheel (bp->trackball, event->xbutton.button, 10,
                               !!event->xbutton.state);
@@ -525,8 +536,6 @@ init_boing (ModeInfo *mi)
       fprintf(stderr, "%s: out of memory\n", progname);
       exit(1);
     }
-
-    bp = &bps[MI_SCREEN(mi)];
   }
 
   bp = &bps[MI_SCREEN(mi)];
@@ -627,6 +636,18 @@ draw_boing (ModeInfo *mi)
     tick_physics (mi);
 
   glPushMatrix ();
+
+  {
+    double rot = current_device_rotation();
+    glRotatef(rot, 0, 0, 1);
+    if ((rot >  45 && rot <  135) ||
+        (rot < -45 && rot > -135))
+      {
+        GLfloat s = MI_WIDTH(mi) / (GLfloat) MI_HEIGHT(mi);
+        glScalef (1/s, s, 1);
+      }
+  }
+
   gltrackball_rotate (bp->trackball);
 
   glLightfv (GL_LIGHT0, GL_POSITION, bp->lightpos);