ftp://ftp.krokus.ru/pub/OpenBSD/distfiles/xscreensaver-4.22.tar.gz
[xscreensaver] / hacks / glx / blinkbox.c
index c057943f5344066893eb6704aad6e98e83b211eb..bcacb37230b896c3fe3111fcf0c46dbdda3ed364 100644 (file)
@@ -9,6 +9,9 @@
  * implied warranty.
  */
 
+/* motion blur added March 2005 by John Boero <jlboero@cs.uwm.edu>
+ */
+
 #include <X11/Intrinsic.h>
 
 extern XtAppContext app;
@@ -21,16 +24,14 @@ extern XtAppContext app;
 #define MAX_COUNT 20
 #define ALPHA_AMT 0.05
 
-/* this should be between 1 and 4 */
-#define DEF_WH      "1"
+/* this should be between 1 and 8 */
+#define DEF_WH       "2"
 #define DEF_DISSOLVE "False"
-#define DEF_FADE    "True"
+#define DEF_FADE     "True"
+#define DEF_BLUR     "True"
 
-#define DEFAULTS       "*delay:          30000         \n" \
-                               "*wireframe:  False      \n" \
-                       "*boxsize:  " DEF_WH      "\n" \
-                    "*dissolve:  " DEF_DISSOLVE "\n" \
-                    "*fade:     " DEF_FADE    "\n" \
+#define DEFAULTS       "*delay:        30000            \n" \
+                       "*wireframe:    False            \n" \
 
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
@@ -61,7 +62,7 @@ typedef struct{
 struct Bounding_box {
   Tdpos top;
   Tdpos bottom;
-} bbox = {{7,7,10},{-7,-7,-10}};
+} bbox = {{14,14,20},{-14,-14,-20}};
 
 struct Ball {
   GLfloat x;
@@ -97,21 +98,25 @@ static float LightPosition[]=  { 20.0f, 100.0f, 20.0f, 1.0f };
 
 static Bool do_dissolve;
 static Bool do_fade;
+static Bool do_blur;
 static GLfloat des_amt   = 1;
 
 static XrmOptionDescRec opts[] = {
-  { "-boxsize", ".boxsize", XrmoptionSepArg, 0 },
-  { "-dissolve", ".dissolve", XrmoptionNoArg, "True" },
+  { "-boxsize",  ".boxsize",  XrmoptionSepArg, 0      },
+  { "-dissolve", ".dissolve", XrmoptionNoArg, "True"  },
   { "+dissolve", ".dissolve", XrmoptionNoArg, "False" },
-  { "-fade",    ".fade",    XrmoptionNoArg, "True" },
-  { "+fade",    ".fade",    XrmoptionNoArg, "False" }
+  { "-fade",     ".fade",     XrmoptionNoArg, "True"  },
+  { "+fade",     ".fade",     XrmoptionNoArg, "False" },
+  { "-blur",     ".blur",     XrmoptionNoArg, "True"  },
+  { "+blur",     ".blur",     XrmoptionNoArg, "False" }
 
 };
 
 static argtype vars[] = {
-  {(caddr_t *) &bscale.wh,  "boxsize",  "Boxsize",  DEF_WH,      t_Float},
-  {(caddr_t *) &do_dissolve, "dissolve",  "Dissolve",  DEF_DISSOLVE, t_Bool},
-  {(caddr_t *) &do_fade,    "fade",     "Fade",     DEF_FADE,    t_Bool},
+  {&bscale.wh,   "boxsize",   "Boxsize",  DEF_WH,       t_Float},
+  {&do_dissolve, "dissolve",  "Dissolve", DEF_DISSOLVE, t_Bool},
+  {&do_fade,     "fade",      "Fade",     DEF_FADE,     t_Bool},
+  {&do_blur,     "blur",      "Blur",     DEF_BLUR,     t_Bool},
 };
 
 ModeSpecOpt sws_opts = {countof(opts), opts, countof(vars), vars, NULL};
@@ -271,7 +276,7 @@ unit_cube(int wire)
 void
 init_ball (ModeInfo *mi)
 {
-  #define SPHERE_SLICES 32  /* how densely to render spheres */
+  #define SPHERE_SLICES 12  /* how densely to render spheres */
   #define SPHERE_STACKS 16
   int wire = MI_IS_WIREFRAME(mi);
 
@@ -281,9 +286,9 @@ init_ball (ModeInfo *mi)
     exit(1);
   }
   if( (bscale.wh < 1) ||
-      (bscale.wh > 4) ) {
+      (bscale.wh > 8) ) {
     fprintf(stderr,"Boxsize out of range. Using default\n");
-    bscale.wh = 1;
+    bscale.wh = 2;
   }
   if (do_dissolve){
     des_amt = bscale.wh / MAX_COUNT;
@@ -313,7 +318,7 @@ init_ball (ModeInfo *mi)
   glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
   glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
   glEnable(GL_LIGHT1);
-  if (do_fade){
+  if (do_fade || do_blur) {
     glEnable(GL_BLEND);
     glDisable(GL_DEPTH_TEST);
   }
@@ -346,13 +351,49 @@ draw_ball (ModeInfo *mi)
    glRotated(0.25,1,0,0);
 
 
+   glPushMatrix();
+   glScalef(0.5,0.5,0.5);
+
    glColor3f(1,1,1);
    glPushMatrix();
-   glTranslatef(ball.x += mo.x,
-                ball.y += mo.y,
-                ball.z += mo.z);
 
-   glCallList(ballList);
+   if (!do_blur || MI_IS_WIREFRAME(mi)) {
+     glTranslatef(ball.x += mo.x,
+                  ball.y += mo.y,
+                  ball.z += mo.z);
+
+     glScalef(2,2,2);
+     glCallList(ballList);
+
+   } else {
+
+#    define blur_detail 24.0
+     float ball_alpha = 1 / blur_detail;
+
+     glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+     glTranslatef(ball.x, ball.y, ball.z);
+   
+     for (i = 0; i < blur_detail; ++i) {
+       glTranslatef(mo.x / blur_detail,
+                    mo.y / blur_detail,
+                    mo.z / blur_detail);
+
+       /* comment the following line for quick but boring linear blur */
+       ball_alpha = sin((M_PI / blur_detail) * i) / blur_detail;
+     
+       glColor4f(1, 1, 1, ball_alpha);
+
+       glScalef(2, 2, 2);
+       glCallList(ballList);
+       glScalef(.5, .5, .5);
+     }
+     i = 0;
+   
+     ball.x += mo.x;
+     ball.y += mo.y;
+     ball.z += mo.z;
+   }
+   
    glPopMatrix();
 
    while(i < 6){
@@ -441,6 +482,7 @@ draw_ball (ModeInfo *mi)
   }
 
 
+   glPopMatrix();
    glFinish();
    glXSwapBuffers(dpy, window);