http://packetstormsecurity.org/UNIX/admin/xscreensaver-3.29.tar.gz
[xscreensaver] / hacks / glx / rubik.c
index d52dda15ffde1736295ab6206adeb796c4ae4b52..b6603daa19409f0fb64502f0f4290783e35097fb 100644 (file)
@@ -22,7 +22,7 @@ static const char sccsid[] = "@(#)rubik.c     4.07 97/11/24 xlockmore";
  * event will the author be liable for any lost revenue or profits or
  * other special, indirect and consequential damages.
  *
- * This mode shows a auto-solving rubik's cube "puzzle". If somebody
+ * This mode shows an auto-solving rubik's cube "puzzle". If somebody
  * intends to make a game or something based on this code, please let me
  * know first, my e-mail address is provided in this comment. Marcelo.
  *
@@ -32,14 +32,15 @@ static const char sccsid[] = "@(#)rubik.c   4.07 97/11/24 xlockmore";
  * Since I'm not a native English speaker, my apologies for any grammatical
  * mistake.
  *
- * My e-mail addresses are
- * vianna@cat.cbpf.br 
- *         and
+ * My e-mail address is
  * m-vianna@usa.net
  *
  * Marcelo F. Vianna (Jul-31-1997)
  *
  * Revision History:
+ * 26-Sep-98: Added some more movement (the cube do not stays in the screen
+ *            center anymore. Also fixed the scale problem imediatelly after
+ *            shuffling when the puzzle is solved.
  * 08-Aug-97: Now has some internals from xrubik by David Bagley
  *            This should make it easier to add features.
  * 02-Aug-97: Now behaves more like puzzle.c: first show the cube being
@@ -125,14 +126,17 @@ static const char sccsid[] = "@(#)rubik.c 4.07 97/11/24 xlockmore";
 # define PROGCLASS     "Rubik"
 # define HACK_INIT     init_rubik
 # define HACK_DRAW     draw_rubik
+# define HACK_RESHAPE reshape_rubik
 # define rubik_opts    xlockmore_opts
 # define DEFAULTS      "*delay: 40000 \n"              \
                                        "*count: -30 \n"                \
+                                       "*showFPS: False \n"    \
                                        "*cycles: 5 \n"                 \
                                        "*size:  -6 \n"
 # include "xlockmore.h"                                /* from the xscreensaver distribution */
 #else /* !STANDALONE */
 # include "xlock.h"                                    /* from the xlockmore distribution */
+# include "vis.h"
 #endif /* !STANDALONE */
 
 #ifdef USE_GL
@@ -158,13 +162,13 @@ static OptionStruct desc[] =
 };
 
 ModeSpecOpt rubik_opts =
-{2, opts, 1, vars, desc};
+{sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
 
 #ifdef USE_MODULES
 ModStruct   rubik_description =
 {"rubik", "init_rubik", "draw_rubik", "release_rubik",
  "draw_rubik", "change_rubik", NULL, &rubik_opts,
- 1000, -30, 5, -6, 1.0, "",
+ 10000, -30, 5, -6, 4, 1.0, "",
  "Shows an auto-solving Rubik's Cube", 0, NULL};
 
 #endif
@@ -490,7 +494,7 @@ draw_cubit(ModeInfo * mi,
           int back, int front, int left, int right, int bottom, int top)
 {
        rubikstruct *rp = &rubik[MI_SCREEN(mi)];
-       int         mono = MI_WIN_IS_MONO(mi);
+       int         mono = MI_IS_MONO(mi);
 
        if (!rp->AreObjectsDefined[ObjCubit]) {
                glNewList(objects + ObjCubit, GL_COMPILE_AND_EXECUTE);
@@ -1558,7 +1562,7 @@ shuffle(ModeInfo * mi)
                        (void) fprintf(stderr,
                                       "Could not allocate memory for rubik row position info\n");
        }
-       rp->storedmoves = MI_BATCHCOUNT(mi);
+       rp->storedmoves = MI_COUNT(mi);
        if (rp->storedmoves < 0) {
                if (rp->moves != NULL)
                        (void) free((void *) rp->moves);
@@ -1608,6 +1612,7 @@ shuffle(ModeInfo * mi)
                        evalmovement(mi, move);
                rp->moves[i] = move;
        }
+
        rp->movement.face = NO_FACE;
        rp->rotatestep = 0;
        rp->action = hideshuffling ? ACTION_SOLVE : ACTION_SHUFFLE;
@@ -1615,8 +1620,8 @@ shuffle(ModeInfo * mi)
        rp->done = 0;
 }
 
-static void
-reshape(ModeInfo * mi, int width, int height)
+void
+reshape_rubik(ModeInfo * mi, int width, int height)
 {
        rubikstruct *rp = &rubik[MI_SCREEN(mi)];
 
@@ -1674,7 +1679,7 @@ init_rubik(ModeInfo * mi)
 
        if ((rp->glx_context = init_GL(mi)) != NULL) {
 
-               reshape(mi, MI_WIN_WIDTH(mi), MI_WIN_HEIGHT(mi));
+               reshape_rubik(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
                objects = glGenLists(1);
                pinit(mi);
        } else {
@@ -1689,6 +1694,8 @@ draw_rubik(ModeInfo * mi)
        Display    *display = MI_DISPLAY(mi);
        Window      window = MI_WINDOW(mi);
 
+       MI_IS_DRAWN(mi) = True;
+
        if (!rp->glx_context)
                return;
 
@@ -1701,7 +1708,19 @@ draw_rubik(ModeInfo * mi)
 
        glTranslatef(0.0, 0.0, -10.0);
 
-       if (!MI_WIN_IS_ICONIC(mi)) {
+    {
+      static int frame = 0;
+      GLfloat x, y, z;
+#     define SINOID(SCALE,SIZE) \
+        ((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2)
+      x = SINOID(0.0071, 2.0);
+      y = SINOID(0.0053, 2.0);
+      z = SINOID(0.0037, 4.0);
+      frame++;
+      glTranslatef(x, y, z);
+    }
+
+       if (!MI_IS_ICONIC(mi)) {
                glScalef(Scale4Window * rp->WindH / rp->WindW, Scale4Window, Scale4Window);
        } else {
                glScalef(Scale4Iconic * rp->WindH / rp->WindW, Scale4Iconic, Scale4Iconic);
@@ -1711,6 +1730,10 @@ draw_rubik(ModeInfo * mi)
        glRotatef(rp->step * 95, 0, 1, 0);
        glRotatef(rp->step * 90, 0, 0, 1);
 
+       draw_cube(mi);
+    if (mi->fps_p) do_fps (mi);
+       glXSwapBuffers(display, window);
+
        if (rp->action == ACTION_SHUFFLE) {
                if (rp->done) {
                        if (++rp->rotatestep > DELAY_AFTER_SHUFFLING) {
@@ -1763,14 +1786,10 @@ draw_rubik(ModeInfo * mi)
                }
        }
 
-       draw_cube(mi);
-
        glPopMatrix();
 
        glFlush();
 
-       glXSwapBuffers(display, window);
-
        rp->step += 0.05;
 }