~ubuntu-branches/ubuntu/dapper/xscreensaver/dapper

« back to all changes in this revision

Viewing changes to hacks/glx/rubik.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2005-10-11 21:00:42 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20051011210042-u7q6zslgevdxspr3
Tags: 4.21-4ubuntu17
updated pt_BR again, fixed to UTF-8 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C; tab-width: 4 -*- */
2
 
/* rubik --- Shows a auto-solving Rubik's cube */
3
 
 
4
 
#if !defined( lint ) && !defined( SABER )
5
 
static const char sccsid[] = "@(#)rubik.c       4.07 97/11/24 xlockmore";
6
 
 
 
2
/* rubik --- Shows an auto-solving Rubik's cube */
 
3
 
 
4
#if 0
 
5
static const char sccsid[] = "@(#)rubik.c       5.01 2001/03/01 xlockmore";
7
6
#endif
8
7
 
9
 
#undef DEBUG_LISTS
10
 
#undef LMN
11
 
 
12
8
/*-
13
9
 * Permission to use, copy, modify, and distribute this software and its
14
10
 * documentation for any purpose and without fee is hereby granted,
30
26
 * to use OpenGL at home.
31
27
 *
32
28
 * Since I'm not a native English speaker, my apologies for any grammatical
33
 
 * mistake.
 
29
 * mistakes.
34
30
 *
35
31
 * My e-mail address is
36
 
 * m-vianna@usa.net
 
32
 * mfvianna@centroin.com.br
37
33
 *
38
34
 * Marcelo F. Vianna (Jul-31-1997)
39
35
 *
40
36
 * Revision History:
41
 
 * 26-Sep-98: Added some more movement (the cube do not stays in the screen
42
 
 *            center anymore. Also fixed the scale problem imediatelly after
43
 
 *            shuffling when the puzzle is solved.
44
 
 * 08-Aug-97: Now has some internals from xrubik by David Bagley
45
 
 *            This should make it easier to add features.
46
 
 * 02-Aug-97: Now behaves more like puzzle.c: first show the cube being
47
 
 *            shuffled and then being solved. A mode specific option was added:
48
 
 *            "+/-hideshuffling" to provide the original behavior (in which
49
 
 *            only the solution is shown).
50
 
 *            The color labels corners are now rounded.
51
 
 *            Optimized the cubit() routine using glLists.
52
 
 * 01-Aug-97: Shuffling now avoids movements that undoes the previous movement
53
 
 *            and three consecutive identical moves (which is pretty stupid).
54
 
 *            improved the "cycles" option in replacement of David's hack,
55
 
 *            now rp->anglestep is a GLfloat, so this option selects the
56
 
 *            "exact" number of frames that a rotation (movement) takes to
57
 
 *            complete.
58
 
 * 30-Jul-97: Initial release, there is no algorithm to solve the puzzle,
59
 
 *            instead, it randomly shuffle the cube and then make the
60
 
 *            movements in the reverse order.
61
 
 *            The mode was written in 1 day (I got sick and had the day off).
62
 
 *            There was not much to do since I could not leave home... :)
63
 
 *
 
37
 * 05-Apr-2002: Removed all gllist uses (fix some bug with nvidia driver)
 
38
 * 01-Mar-2001: Added FPS stuff - Eric Lassauge <lassauge@mail.dotcom.fr>
 
39
 * 01-Nov-2000: Allocation checks
 
40
 * 27-Apr-1999: LxMxN stuff added.
 
41
 * 26-Sep-1998: Added some more movement (the cube does not stay in the screen
 
42
 *              center anymore. Also fixed the scale problem immediately after
 
43
 *              shuffling when the puzzle is solved.
 
44
 * 08-Aug-1997: Now has some internals from xrubik by David Bagley
 
45
 *              This should make it easier to add features.
 
46
 * 02-Aug-1997: Now behaves more like puzzle.c: first show the cube being
 
47
 *              shuffled and then being solved. A mode specific option was
 
48
 *              added:
 
49
 *              "+/-hideshuffling" to provide the original behavior (in which
 
50
 *              only the solution is shown).
 
51
 *              The color labels corners are now rounded.
 
52
 *              Optimized the cubit() routine using glLists.
 
53
 * 01-Aug-1997: Shuffling now avoids movements that undoes the previous
 
54
 *              movement and three consecutive identical moves (which is
 
55
 *              pretty stupid).
 
56
 *              improved the "cycles" option in replacement of David's hack,
 
57
 *              now rp->anglestep is a GLfloat, so this option selects the
 
58
 *              "exact" number of frames that a rotation (movement) takes to
 
59
 *              complete.
 
60
 * 30-Jul-1997: Initial release, there is no algorithm to solve the puzzle,
 
61
 *              instead, it randomly shuffle the cube and then make the
 
62
 *              movements in the reverse order.
 
63
 *              The mode was written in 1 day (I got sick and had the day off).
 
64
 *              There was not much to do since I could not leave home... :)
64
65
 */
65
66
 
66
67
/*-
67
68
 * Color labels mapping:
68
69
 * =====================
69
70
 *
70
 
 *                       +------------+
71
 
 *                       |0-->        |
72
 
 *                       ||           |
73
 
 *                       |v           |
74
 
 *                       |   TOP(0)   |
75
 
 *                       |            |
76
 
 *                       |            |
77
 
 *                       |           8|
78
 
 *           +-----------+------------+-----------+
79
 
 *           |0-->       |0-->        |0-->       |
80
 
 *           ||          ||           ||          |
81
 
 *           |v          |v           |v          |
82
 
 *           |  LEFT(1)  |  FRONT(2)  |  RIGHT(3) |
83
 
 *           |           |            |           |
84
 
 *           |           |            |           |
85
 
 *           |          8|           8|          8|
86
 
 *           +-----------+------------+-----------+
87
 
 *                       |0-->        |
88
 
 *                       ||           |
89
 
 *                       |v           |
90
 
 *                       |  BOTTOM(4) |  rp->faces[N][X+AVSIZE*Y]=
91
 
 *                       |            |         rp->cubeLoc[N][X+AVSIZE*Y]=
92
 
 *                       |            | 
93
 
 *                       |           8|         +---+---+---+
94
 
 *                       +------------+         |   |   |   |
95
 
 *                       |0-->        |         | 0 | 1 | 2 |
96
 
 *                       ||           |         |---+---+---+
97
 
 *                       |v           |         |  xxxxx(N) |
98
 
 *                       |   BACK(5)  |         | 3 | 4 | 5 |
99
 
 *                       |            |         +---+---+---+
100
 
 *                       |            |         |   |   |  |
101
 
 *                       |           8|         | 6 | 7 | 8 |
102
 
 *                       +------------+         +---+---+---+
 
71
 *             +-----------+
 
72
 *             |0-->       |
 
73
 *             ||          |
 
74
 *             |v  TOP(0)  |
 
75
 *             |           |
 
76
 *             |          8|
 
77
 * +-----------+-----------+-----------+
 
78
 * |0-->       |0-->       |0-->       |
 
79
 * ||          ||          ||          |
 
80
 * |v  LEFT(1) |v FRONT(2) |v RIGHT(3) |
 
81
 * |           |           |           |
 
82
 * |          8|          8|          8|
 
83
 * +-----------+-----------+-----------+
 
84
 *             |0-->       |
 
85
 *             ||          |
 
86
 *             |v BOTTOM(4)|
 
87
 *             |           |
 
88
 *             |          8|
 
89
 *             +-----------+             +---+---+---+
 
90
 *             |0-->       |             | 0 | 1 | 2 |
 
91
 *             ||          |             |--xxxxx(N)-+
 
92
 *             |v  BACK(5) |             | 3 | 4 | 5 |
 
93
 *             |           |             +---+---+---+
 
94
 *             |          8|             | 6 | 7 | 8 |
 
95
 *             +-----------+             +---+---+---+
103
96
 *
104
97
 *  Map to 3d
105
98
 *  FRONT  => X, Y
110
103
 *  BOTTOM => X, Z
111
104
 */
112
105
 
113
 
/*-
114
 
 * PURIFY 3.0a on SunOS4 reports an unitialized memory read on each of
115
 
 * the glCallList() functions below when using MesaGL 2.1.  This has
116
 
 * been fixed in MesaGL 2.2 and later releases.
117
 
 */
118
 
 
119
 
/*-
120
 
 * due to a Bug/feature in VMS X11/Intrinsic.h has to be placed before xlock.
121
 
 * otherwise caddr_t is not defined correctly
122
 
 */
123
 
#include <X11/Intrinsic.h>
124
 
 
125
106
#ifdef STANDALONE
 
107
# define MODE_rubik
126
108
# define PROGCLASS      "Rubik"
127
109
# define HACK_INIT      init_rubik
128
110
# define HACK_DRAW      draw_rubik
129
 
# define HACK_RESHAPE reshape_rubik
 
111
# define HACK_RESHAPE reshape
130
112
# define rubik_opts     xlockmore_opts
131
113
# define DEFAULTS       "*delay: 40000 \n"              \
132
114
                                        "*count: -30 \n"                \
139
121
# include "vis.h"
140
122
#endif /* !STANDALONE */
141
123
 
142
 
#ifdef USE_GL
 
124
#ifdef MODE_rubik
143
125
 
 
126
#define DEF_SIZEX     "0"
 
127
#define DEF_SIZEY     "0"
 
128
#define DEF_SIZEZ     "0"
144
129
#define DEF_HIDESHUFFLING     "False"
145
130
 
 
131
static int sizex;
 
132
static int sizey;
 
133
static int sizez;
146
134
static Bool hideshuffling;
147
135
 
148
136
static XrmOptionDescRec opts[] =
149
137
{
150
 
  {"-hideshuffling", ".rubik.hideshuffling", XrmoptionNoArg, (caddr_t) "on"},
151
 
  {"+hideshuffling", ".rubik.hideshuffling", XrmoptionNoArg, (caddr_t) "off"}
 
138
        {"-sizex", ".rubik.sizex", XrmoptionSepArg, 0},
 
139
        {"-sizey", ".rubik.sizey", XrmoptionSepArg, 0},
 
140
        {"-sizez", ".rubik.sizez", XrmoptionSepArg, 0},
 
141
        {"-hideshuffling", ".rubik.hideshuffling", XrmoptionNoArg, "on"},
 
142
        {"+hideshuffling", ".rubik.hideshuffling", XrmoptionNoArg, "off"}
152
143
};
153
144
 
154
145
static argtype vars[] =
155
146
{
156
 
        {(caddr_t *) & hideshuffling, "hideshuffling", "Hideshuffling", DEF_HIDESHUFFLING, t_Bool}
 
147
        {&sizex, "sizex", "SizeX", DEF_SIZEX, t_Int},
 
148
        {&sizey, "sizey", "SizeY", DEF_SIZEY, t_Int},
 
149
        {&sizez, "sizez", "SizeZ", DEF_SIZEZ, t_Int},
 
150
        {&hideshuffling, "hideshuffling", "Hideshuffling", DEF_HIDESHUFFLING, t_Bool}
157
151
};
158
152
 
159
153
static OptionStruct desc[] =
160
154
{
 
155
        {"-sizex num", "number of cubies along x axis (overrides size)"},
 
156
        {"-sizey num", "number of cubies along y axis (overrides size)"},
 
157
        {"-sizez num", "number of cubies along z axis (overrides size)"},
161
158
        {"-/+hideshuffling", "turn on/off hidden shuffle phase"}
162
159
};
163
160
 
167
164
#ifdef USE_MODULES
168
165
ModStruct   rubik_description =
169
166
{"rubik", "init_rubik", "draw_rubik", "release_rubik",
170
 
 "draw_rubik", "change_rubik", NULL, &rubik_opts,
171
 
 10000, -30, 5, -6, 4, 1.0, "",
 
167
 "draw_rubik", "change_rubik", (char *) NULL, &rubik_opts,
 
168
 10000, -30, 5, -6, 64, 1.0, "",
172
169
 "Shows an auto-solving Rubik's Cube", 0, NULL};
173
170
 
174
171
#endif
190
187
/*************************************************************************/
191
188
 
192
189
#define MINSIZE 2
193
 
#ifdef LMN                      /* LxMxN not completed yet... */
194
190
#define MAXSIZEX (rp->sizex)
195
191
#define MAXSIZEY (rp->sizey)
196
192
#define MAXSIZEZ (rp->sizez)
197
 
#define AVSIZE (rp->avsize)
198
 
#define MAXSIZE (rp->maxsize)
199
 
#define AVSIZESQ (rp->avsizeSq)
200
 
#define MAXSIZESQ (rp->maxsizeSq)
201
 
#else
202
 
#define MAXSIZEX (rp->size)
203
 
#define MAXSIZEY (rp->size)
204
 
#define MAXSIZEZ (rp->size)
205
 
#define AVSIZE (rp->size)
206
 
#define MAXSIZE (rp->size)
207
 
#define AVSIZESQ (rp->sizeSq)
208
 
#define MAXSIZESQ (rp->sizeSq)
209
 
#endif
 
193
#define AVSIZE ((rp->sizex+rp->sizey+rp->sizez)/3.0)     /* Use of this should be minimized */
 
194
#define MAXMAXSIZE (MAX(MAXSIZEX,MAX(MAXSIZEY,MAXSIZEZ)))
210
195
#define MAXSIZEXY (MAXSIZEX*MAXSIZEY)
211
 
#define MAXSIZEZY (MAXSIZEZ*MAXSIZEY)
212
 
#define MAXSIZEXZ (MAXSIZEX*MAXSIZEZ)
 
196
#define MAXSIZEYZ (MAXSIZEY*MAXSIZEZ)
 
197
#define MAXSIZEZX (MAXSIZEZ*MAXSIZEX)
213
198
#define LASTX (MAXSIZEX-1)
214
199
#define LASTY (MAXSIZEY-1)
215
200
#define LASTZ (MAXSIZEZ-1)
230
215
#define BOTTOM 2
231
216
#define LEFT 3
232
217
#define CW (MAXORIENT+1)
 
218
#define HALF (MAXORIENT+2)
233
219
#define CCW (2*MAXORIENT-1)
234
220
 
235
221
#define TOP_FACE 0
240
226
#define BACK_FACE 5
241
227
#define NO_FACE (MAXFACES)
242
228
#define NO_ROTATION (2*MAXORIENT)
243
 
#define NO_DEPTH MAXSIZE
 
229
#define NO_DEPTH MAXMAXSIZE
244
230
 
245
231
#define REVX(a) (MAXSIZEX - a - 1)
246
232
#define REVY(a) (MAXSIZEY - a - 1)
247
233
#define REVZ(a) (MAXSIZEZ - a - 1)
248
234
 
 
235
#define CUBELEN 0.50
 
236
#define CUBEROUND (CUBELEN-0.05)
 
237
#define STICKERLONG (CUBEROUND-0.05)
 
238
#define STICKERSHORT (STICKERLONG-0.05)
 
239
#define STICKERDEPTH (CUBELEN+0.01)
 
240
 
 
241
#define ObjCubit        0
 
242
#define MaxObj          1
249
243
typedef struct _RubikLoc {
250
244
        int         face;
251
245
        int         rotation;   /* Not used yet */
306
300
/*-
307
301
 * Examine cubie 0 on each face, its 4 movements (well only 2 since the
308
302
 * other 2 will be opposites) and translate it into slice movements).
309
 
 * Beware.. using this for NxNxN makes some assumptions that referenced
310
 
 * cubes are along the diagonal top-left to bottom-right.
311
303
 * CW = DEEP Depth CCW == SHALLOW Depth with reference to faces 0, 1, and 2
312
304
 */
313
305
static RubikLoc rotateSlice[MAXFACES][MAXORIENT / 2] =
352
344
        {3, 0, 1, 4}
353
345
};
354
346
 
355
 
/* 
 
347
/*
356
348
 * This translates a clockwise move to something more manageable
357
349
 */
358
350
static RubikRowNext rotateToRow[MAXFACES] =     /*CW to min face */
359
351
{
360
352
        {1, LEFT, TOP},
361
 
        {0, BOTTOM, LEFT},
 
353
        {0, BOTTOM, RIGHT},
362
354
        {0, RIGHT, BOTTOM},
363
 
        {0, TOP, RIGHT},
 
355
        {0, TOP, LEFT},
364
356
        {1, RIGHT, BOTTOM},
365
357
        {0, LEFT, TOP}
366
358
};
370
362
        GLfloat     step;
371
363
        RubikMove  *moves;
372
364
        int         storedmoves;
 
365
        int         degreeTurn;
373
366
        int         shufflingmoves;
374
 
#ifdef LMN                      /* Under construction */
375
367
        int         sizex, sizey, sizez;
376
 
        int         avsize, maxsize;
377
 
        int         avsizeSq, maxsizeSq;
378
 
#else
379
 
        int         size, sizeSq;
380
 
#endif
 
368
        float       avsize, avsizeSq;
381
369
        int         action;
382
370
        int         done;
383
371
        GLfloat     anglestep;
385
373
        RubikLoc   *rowLoc[MAXORIENT];
386
374
        RubikMove   movement;
387
375
        GLfloat     rotatestep;
 
376
        GLfloat     PX, PY, VX, VY;
388
377
        GLXContext *glx_context;
389
 
        int         AreObjectsDefined[1];
390
378
} rubikstruct;
391
379
 
392
380
static float front_shininess[] =
439
427
static float MaterialGray7[] =
440
428
{0.7, 0.7, 0.7, 1.0};
441
429
 
442
 
static rubikstruct *rubik = NULL;
443
 
static GLuint objects;
 
430
static rubikstruct *rubik = (rubikstruct *) NULL;
444
431
 
445
 
#define ObjCubit        0
446
432
 
447
433
static void
448
434
pickcolor(int C, int mono)
488
474
        }
489
475
}
490
476
 
491
 
 
492
477
static void
 
478
faceSizes(rubikstruct * rp, int face, int * sizeOfRow, int * sizeOfColumn)
 
479
{
 
480
        switch (face) {
 
481
                case 0: /* TOP */
 
482
                case 4: /* BOTTOM */
 
483
                        *sizeOfRow = MAXSIZEX;
 
484
                        *sizeOfColumn = MAXSIZEZ;
 
485
                        break;
 
486
                case 1: /* LEFT */
 
487
                case 3: /* RIGHT */
 
488
                        *sizeOfRow = MAXSIZEZ;
 
489
                        *sizeOfColumn = MAXSIZEY;
 
490
                        break;
 
491
                case 2: /* FRONT */
 
492
                case 5: /* BACK */
 
493
                        *sizeOfRow = MAXSIZEX;
 
494
                        *sizeOfColumn = MAXSIZEY;
 
495
                        break;
 
496
        }
 
497
}
 
498
 
 
499
static Bool
 
500
checkFaceSquare(rubikstruct * rp, int face)
 
501
{
 
502
        int sizeOfRow, sizeOfColumn;
 
503
 
 
504
        faceSizes(rp, face, &sizeOfRow, &sizeOfColumn);
 
505
        return (sizeOfRow == sizeOfColumn);
 
506
        /* Cubes can be made square with a 4x2 face where 90 degree turns
 
507
         * should be permitted but that is kind of complicated for me.
 
508
         * This can be done in 2 ways where the side of the cubies are
 
509
         * the same size and one where one side (the side with half the
 
510
         * number of cubies) is twice the size of the other.  The first is
 
511
         * complicated because faces of cubies can go under other faces.
 
512
         * The second way is similar to "banded cubes" where scotch tape
 
513
         * restricts the moves of some cubes.  Here you have to keep track
 
514
         * of the restrictions and show banded cubies graphically as one
 
515
         * cube.
 
516
         */
 
517
}
 
518
 
 
519
static int
 
520
sizeFace(rubikstruct * rp, int face)
 
521
{
 
522
        int sizeOfRow, sizeOfColumn;
 
523
 
 
524
        faceSizes(rp, face, &sizeOfRow, &sizeOfColumn);
 
525
        return (sizeOfRow * sizeOfColumn);
 
526
}
 
527
 
 
528
static int
 
529
sizeRow(rubikstruct * rp, int face)
 
530
{
 
531
        int sizeOfRow, sizeOfColumn;  /* sizeOfColumn not used */
 
532
 
 
533
        faceSizes(rp, face, &sizeOfRow, &sizeOfColumn);
 
534
        return sizeOfRow;
 
535
}
 
536
 
 
537
static Bool
 
538
draw_stickerless_cubit(rubikstruct *rp)
 
539
{
 
540
        glBegin(GL_QUADS);
 
541
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
 
542
        /* Put sticker here */
 
543
        glNormal3f(0.00, 0.00, 1.00);
 
544
        glVertex3f(-CUBEROUND, -CUBEROUND, CUBELEN);
 
545
        glVertex3f(CUBEROUND, -CUBEROUND, CUBELEN);
 
546
        glVertex3f(CUBEROUND, CUBEROUND, CUBELEN);
 
547
        glVertex3f(-CUBEROUND, CUBEROUND, CUBELEN);
 
548
        glNormal3f(0.00, 0.00, -1.00);
 
549
        glVertex3f(-CUBEROUND, CUBEROUND, -CUBELEN);
 
550
        glVertex3f(CUBEROUND, CUBEROUND, -CUBELEN);
 
551
        glVertex3f(CUBEROUND, -CUBEROUND, -CUBELEN);
 
552
        glVertex3f(-CUBEROUND, -CUBEROUND, -CUBELEN);
 
553
        glNormal3f(-1.00, 0.00, 0.00);
 
554
        glVertex3f(-CUBELEN, -CUBEROUND, CUBEROUND);
 
555
        glVertex3f(-CUBELEN, CUBEROUND, CUBEROUND);
 
556
        glVertex3f(-CUBELEN, CUBEROUND, -CUBEROUND);
 
557
        glVertex3f(-CUBELEN, -CUBEROUND, -CUBEROUND);
 
558
        glNormal3f(1.00, 0.00, 0.00);
 
559
        glVertex3f(CUBELEN, -CUBEROUND, -CUBEROUND);
 
560
        glVertex3f(CUBELEN, CUBEROUND, -CUBEROUND);
 
561
        glVertex3f(CUBELEN, CUBEROUND, CUBEROUND);
 
562
        glVertex3f(CUBELEN, -CUBEROUND, CUBEROUND);
 
563
        glNormal3f(0.00, -1.00, 0.00);
 
564
        glVertex3f(CUBEROUND, -CUBELEN, -CUBEROUND);
 
565
        glVertex3f(CUBEROUND, -CUBELEN, CUBEROUND);
 
566
        glVertex3f(-CUBEROUND, -CUBELEN, CUBEROUND);
 
567
        glVertex3f(-CUBEROUND, -CUBELEN, -CUBEROUND);
 
568
        glNormal3f(0.00, 1.00, 0.00);
 
569
        glVertex3f(-CUBEROUND, CUBELEN, -CUBEROUND);
 
570
        glVertex3f(-CUBEROUND, CUBELEN, CUBEROUND);
 
571
        glVertex3f(CUBEROUND, CUBELEN, CUBEROUND);
 
572
        glVertex3f(CUBEROUND, CUBELEN, -CUBEROUND);
 
573
 
 
574
        /* Edges of cubit */
 
575
        glNormal3f(-1.00, -1.00, 0.00);
 
576
        glVertex3f(-CUBEROUND, -CUBELEN, -CUBEROUND);
 
577
        glVertex3f(-CUBEROUND, -CUBELEN, CUBEROUND);
 
578
        glVertex3f(-CUBELEN, -CUBEROUND, CUBEROUND);
 
579
        glVertex3f(-CUBELEN, -CUBEROUND, -CUBEROUND);
 
580
        glNormal3f(1.00, 1.00, 0.00);
 
581
        glVertex3f(CUBEROUND, CUBELEN, -CUBEROUND);
 
582
        glVertex3f(CUBEROUND, CUBELEN, CUBEROUND);
 
583
        glVertex3f(CUBELEN, CUBEROUND, CUBEROUND);
 
584
        glVertex3f(CUBELEN, CUBEROUND, -CUBEROUND);
 
585
        glNormal3f(-1.00, 1.00, 0.00);
 
586
        glVertex3f(-CUBELEN, CUBEROUND, -CUBEROUND);
 
587
        glVertex3f(-CUBELEN, CUBEROUND, CUBEROUND);
 
588
        glVertex3f(-CUBEROUND, CUBELEN, CUBEROUND);
 
589
        glVertex3f(-CUBEROUND, CUBELEN, -CUBEROUND);
 
590
        glNormal3f(1.00, -1.00, 0.00);
 
591
        glVertex3f(CUBELEN, -CUBEROUND, -CUBEROUND);
 
592
        glVertex3f(CUBELEN, -CUBEROUND, CUBEROUND);
 
593
        glVertex3f(CUBEROUND, -CUBELEN, CUBEROUND);
 
594
        glVertex3f(CUBEROUND, -CUBELEN, -CUBEROUND);
 
595
        glNormal3f(0.00, -1.00, -1.00);
 
596
        glVertex3f(-CUBEROUND, -CUBEROUND, -CUBELEN);
 
597
        glVertex3f(CUBEROUND, -CUBEROUND, -CUBELEN);
 
598
        glVertex3f(CUBEROUND, -CUBELEN, -CUBEROUND);
 
599
        glVertex3f(-CUBEROUND, -CUBELEN, -CUBEROUND);
 
600
        glNormal3f(0.00, 1.00, 1.00);
 
601
        glVertex3f(-CUBEROUND, CUBEROUND, CUBELEN);
 
602
        glVertex3f(CUBEROUND, CUBEROUND, CUBELEN);
 
603
        glVertex3f(CUBEROUND, CUBELEN, CUBEROUND);
 
604
        glVertex3f(-CUBEROUND, CUBELEN, CUBEROUND);
 
605
        glNormal3f(0.00, -1.00, 1.00);
 
606
        glVertex3f(-CUBEROUND, -CUBELEN, CUBEROUND);
 
607
        glVertex3f(CUBEROUND, -CUBELEN, CUBEROUND);
 
608
        glVertex3f(CUBEROUND, -CUBEROUND, CUBELEN);
 
609
        glVertex3f(-CUBEROUND, -CUBEROUND, CUBELEN);
 
610
        glNormal3f(0.00, 1.00, -1.00);
 
611
        glVertex3f(-CUBEROUND, CUBELEN, -CUBEROUND);
 
612
        glVertex3f(CUBEROUND, CUBELEN, -CUBEROUND);
 
613
        glVertex3f(CUBEROUND, CUBEROUND, -CUBELEN);
 
614
        glVertex3f(-CUBEROUND, CUBEROUND, -CUBELEN);
 
615
        glNormal3f(-1.00, 0.00, -1.00);
 
616
        glVertex3f(-CUBELEN, -CUBEROUND, -CUBEROUND);
 
617
        glVertex3f(-CUBELEN, CUBEROUND, -CUBEROUND);
 
618
        glVertex3f(-CUBEROUND, CUBEROUND, -CUBELEN);
 
619
        glVertex3f(-CUBEROUND, -CUBEROUND, -CUBELEN);
 
620
        glNormal3f(1.00, 0.00, 1.00);
 
621
        glVertex3f(CUBELEN, -CUBEROUND, CUBEROUND);
 
622
        glVertex3f(CUBELEN, CUBEROUND, CUBEROUND);
 
623
        glVertex3f(CUBEROUND, CUBEROUND, CUBELEN);
 
624
        glVertex3f(CUBEROUND, -CUBEROUND, CUBELEN);
 
625
        glNormal3f(1.00, 0.00, -1.00);
 
626
        glVertex3f(CUBEROUND, -CUBEROUND, -CUBELEN);
 
627
        glVertex3f(CUBEROUND, CUBEROUND, -CUBELEN);
 
628
        glVertex3f(CUBELEN, CUBEROUND, -CUBEROUND);
 
629
        glVertex3f(CUBELEN, -CUBEROUND, -CUBEROUND);
 
630
        glNormal3f(-1.00, 0.00, 1.00);
 
631
        glVertex3f(-CUBEROUND, -CUBEROUND, CUBELEN);
 
632
        glVertex3f(-CUBEROUND, CUBEROUND, CUBELEN);
 
633
        glVertex3f(-CUBELEN, CUBEROUND, CUBEROUND);
 
634
        glVertex3f(-CUBELEN, -CUBEROUND, CUBEROUND);
 
635
        glEnd();
 
636
        glBegin(GL_TRIANGLES);
 
637
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
 
638
        /* Corners of cubit */
 
639
        glNormal3f(1.00, 1.00, 1.00);
 
640
        glVertex3f(CUBEROUND, CUBEROUND, CUBELEN);
 
641
        glVertex3f(CUBELEN, CUBEROUND, CUBEROUND);
 
642
        glVertex3f(CUBEROUND, CUBELEN, CUBEROUND);
 
643
        glNormal3f(-1.00, -1.00, -1.00);
 
644
        glVertex3f(-CUBEROUND, -CUBELEN, -CUBEROUND);
 
645
        glVertex3f(-CUBELEN, -CUBEROUND, -CUBEROUND);
 
646
        glVertex3f(-CUBEROUND, -CUBEROUND, -CUBELEN);
 
647
        glNormal3f(-1.00, 1.00, 1.00);
 
648
        glVertex3f(-CUBEROUND, CUBEROUND, CUBELEN);
 
649
        glVertex3f(-CUBEROUND, CUBELEN, CUBEROUND);
 
650
        glVertex3f(-CUBELEN, CUBEROUND, CUBEROUND);
 
651
        glNormal3f(1.00, -1.00, -1.00);
 
652
        glVertex3f(CUBELEN, -CUBEROUND, -CUBEROUND);
 
653
        glVertex3f(CUBEROUND, -CUBELEN, -CUBEROUND);
 
654
        glVertex3f(CUBEROUND, -CUBEROUND, -CUBELEN);
 
655
        glNormal3f(1.00, -1.00, 1.00);
 
656
        glVertex3f(CUBEROUND, -CUBEROUND, CUBELEN);
 
657
        glVertex3f(CUBEROUND, -CUBELEN, CUBEROUND);
 
658
        glVertex3f(CUBELEN, -CUBEROUND, CUBEROUND);
 
659
        glNormal3f(-1.00, 1.00, -1.00);
 
660
        glVertex3f(-CUBELEN, CUBEROUND, -CUBEROUND);
 
661
        glVertex3f(-CUBEROUND, CUBELEN, -CUBEROUND);
 
662
        glVertex3f(-CUBEROUND, CUBEROUND, -CUBELEN);
 
663
        glNormal3f(-1.00, -1.00, 1.00);
 
664
        glVertex3f(-CUBEROUND, -CUBEROUND, CUBELEN);
 
665
        glVertex3f(-CUBELEN, -CUBEROUND, CUBEROUND);
 
666
        glVertex3f(-CUBEROUND, -CUBELEN, CUBEROUND);
 
667
        glNormal3f(1.00, 1.00, -1.00);
 
668
        glVertex3f(CUBELEN, CUBEROUND, -CUBEROUND);
 
669
        glVertex3f(CUBEROUND, CUBEROUND, -CUBELEN);
 
670
        glVertex3f(CUBEROUND, CUBELEN, -CUBEROUND);
 
671
        glEnd();
 
672
        return True;
 
673
}
 
674
 
 
675
static Bool
493
676
draw_cubit(ModeInfo * mi,
494
677
           int back, int front, int left, int right, int bottom, int top)
495
678
{
496
679
        rubikstruct *rp = &rubik[MI_SCREEN(mi)];
497
680
        int         mono = MI_IS_MONO(mi);
498
681
 
499
 
        if (!rp->AreObjectsDefined[ObjCubit]) {
500
 
                glNewList(objects + ObjCubit, GL_COMPILE_AND_EXECUTE);
501
 
                glBegin(GL_QUADS);
502
 
                glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
503
 
                glNormal3f(0.00, 0.00, 1.00);
504
 
                glVertex3f(-0.45, -0.45, 0.50);
505
 
                glVertex3f(0.45, -0.45, 0.50);
506
 
                glVertex3f(0.45, 0.45, 0.50);
507
 
                glVertex3f(-0.45, 0.45, 0.50);
508
 
                glNormal3f(0.00, 0.00, -1.00);
509
 
                glVertex3f(-0.45, 0.45, -0.50);
510
 
                glVertex3f(0.45, 0.45, -0.50);
511
 
                glVertex3f(0.45, -0.45, -0.50);
512
 
                glVertex3f(-0.45, -0.45, -0.50);
513
 
                glNormal3f(-1.00, 0.00, 0.00);
514
 
                glVertex3f(-0.50, -0.45, 0.45);
515
 
                glVertex3f(-0.50, 0.45, 0.45);
516
 
                glVertex3f(-0.50, 0.45, -0.45);
517
 
                glVertex3f(-0.50, -0.45, -0.45);
518
 
                glNormal3f(1.00, 0.00, 0.00);
519
 
                glVertex3f(0.50, -0.45, -0.45);
520
 
                glVertex3f(0.50, 0.45, -0.45);
521
 
                glVertex3f(0.50, 0.45, 0.45);
522
 
                glVertex3f(0.50, -0.45, 0.45);
523
 
                glNormal3f(0.00, -1.00, 0.00);
524
 
                glVertex3f(0.45, -0.50, -0.45);
525
 
                glVertex3f(0.45, -0.50, 0.45);
526
 
                glVertex3f(-0.45, -0.50, 0.45);
527
 
                glVertex3f(-0.45, -0.50, -0.45);
528
 
                glNormal3f(0.00, 1.00, 0.00);
529
 
                glVertex3f(-0.45, 0.50, -0.45);
530
 
                glVertex3f(-0.45, 0.50, 0.45);
531
 
                glVertex3f(0.45, 0.50, 0.45);
532
 
                glVertex3f(0.45, 0.50, -0.45);
533
 
                glNormal3f(-1.00, -1.00, 0.00);
534
 
                glVertex3f(-0.45, -0.50, -0.45);
535
 
                glVertex3f(-0.45, -0.50, 0.45);
536
 
                glVertex3f(-0.50, -0.45, 0.45);
537
 
                glVertex3f(-0.50, -0.45, -0.45);
538
 
                glNormal3f(1.00, 1.00, 0.00);
539
 
                glVertex3f(0.45, 0.50, -0.45);
540
 
                glVertex3f(0.45, 0.50, 0.45);
541
 
                glVertex3f(0.50, 0.45, 0.45);
542
 
                glVertex3f(0.50, 0.45, -0.45);
543
 
                glNormal3f(-1.00, 1.00, 0.00);
544
 
                glVertex3f(-0.50, 0.45, -0.45);
545
 
                glVertex3f(-0.50, 0.45, 0.45);
546
 
                glVertex3f(-0.45, 0.50, 0.45);
547
 
                glVertex3f(-0.45, 0.50, -0.45);
548
 
                glNormal3f(1.00, -1.00, 0.00);
549
 
                glVertex3f(0.50, -0.45, -0.45);
550
 
                glVertex3f(0.50, -0.45, 0.45);
551
 
                glVertex3f(0.45, -0.50, 0.45);
552
 
                glVertex3f(0.45, -0.50, -0.45);
553
 
                glNormal3f(0.00, -1.00, -1.00);
554
 
                glVertex3f(-0.45, -0.45, -0.50);
555
 
                glVertex3f(0.45, -0.45, -0.50);
556
 
                glVertex3f(0.45, -0.50, -0.45);
557
 
                glVertex3f(-0.45, -0.50, -0.45);
558
 
                glNormal3f(0.00, 1.00, 1.00);
559
 
                glVertex3f(-0.45, 0.45, 0.50);
560
 
                glVertex3f(0.45, 0.45, 0.50);
561
 
                glVertex3f(0.45, 0.50, 0.45);
562
 
                glVertex3f(-0.45, 0.50, 0.45);
563
 
                glNormal3f(0.00, -1.00, 1.00);
564
 
                glVertex3f(-0.45, -0.50, 0.45);
565
 
                glVertex3f(0.45, -0.50, 0.45);
566
 
                glVertex3f(0.45, -0.45, 0.50);
567
 
                glVertex3f(-0.45, -0.45, 0.50);
568
 
                glNormal3f(0.00, 1.00, -1.00);
569
 
                glVertex3f(-0.45, 0.50, -0.45);
570
 
                glVertex3f(0.45, 0.50, -0.45);
571
 
                glVertex3f(0.45, 0.45, -0.50);
572
 
                glVertex3f(-0.45, 0.45, -0.50);
573
 
                glNormal3f(-1.00, 0.00, -1.00);
574
 
                glVertex3f(-0.50, -0.45, -0.45);
575
 
                glVertex3f(-0.50, 0.45, -0.45);
576
 
                glVertex3f(-0.45, 0.45, -0.50);
577
 
                glVertex3f(-0.45, -0.45, -0.50);
578
 
                glNormal3f(1.00, 0.00, 1.00);
579
 
                glVertex3f(0.50, -0.45, 0.45);
580
 
                glVertex3f(0.50, 0.45, 0.45);
581
 
                glVertex3f(0.45, 0.45, 0.50);
582
 
                glVertex3f(0.45, -0.45, 0.50);
583
 
                glNormal3f(1.00, 0.00, -1.00);
584
 
                glVertex3f(0.45, -0.45, -0.50);
585
 
                glVertex3f(0.45, 0.45, -0.50);
586
 
                glVertex3f(0.50, 0.45, -0.45);
587
 
                glVertex3f(0.50, -0.45, -0.45);
588
 
                glNormal3f(-1.00, 0.00, 1.00);
589
 
                glVertex3f(-0.45, -0.45, 0.50);
590
 
                glVertex3f(-0.45, 0.45, 0.50);
591
 
                glVertex3f(-0.50, 0.45, 0.45);
592
 
                glVertex3f(-0.50, -0.45, 0.45);
593
 
                glEnd();
594
 
                glBegin(GL_TRIANGLES);
595
 
                glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
596
 
                glNormal3f(1.00, 1.00, 1.00);
597
 
                glVertex3f(0.45, 0.45, 0.50);
598
 
                glVertex3f(0.50, 0.45, 0.45);
599
 
                glVertex3f(0.45, 0.50, 0.45);
600
 
                glNormal3f(-1.00, -1.00, -1.00);
601
 
                glVertex3f(-0.45, -0.50, -0.45);
602
 
                glVertex3f(-0.50, -0.45, -0.45);
603
 
                glVertex3f(-0.45, -0.45, -0.50);
604
 
                glNormal3f(-1.00, 1.00, 1.00);
605
 
                glVertex3f(-0.45, 0.45, 0.50);
606
 
                glVertex3f(-0.45, 0.50, 0.45);
607
 
                glVertex3f(-0.50, 0.45, 0.45);
608
 
                glNormal3f(1.00, -1.00, -1.00);
609
 
                glVertex3f(0.50, -0.45, -0.45);
610
 
                glVertex3f(0.45, -0.50, -0.45);
611
 
                glVertex3f(0.45, -0.45, -0.50);
612
 
                glNormal3f(1.00, -1.00, 1.00);
613
 
                glVertex3f(0.45, -0.45, 0.50);
614
 
                glVertex3f(0.45, -0.50, 0.45);
615
 
                glVertex3f(0.50, -0.45, 0.45);
616
 
                glNormal3f(-1.00, 1.00, -1.00);
617
 
                glVertex3f(-0.50, 0.45, -0.45);
618
 
                glVertex3f(-0.45, 0.50, -0.45);
619
 
                glVertex3f(-0.45, 0.45, -0.50);
620
 
                glNormal3f(-1.00, -1.00, 1.00);
621
 
                glVertex3f(-0.45, -0.45, 0.50);
622
 
                glVertex3f(-0.50, -0.45, 0.45);
623
 
                glVertex3f(-0.45, -0.50, 0.45);
624
 
                glNormal3f(1.00, 1.00, -1.00);
625
 
                glVertex3f(0.50, 0.45, -0.45);
626
 
                glVertex3f(0.45, 0.45, -0.50);
627
 
                glVertex3f(0.45, 0.50, -0.45);
628
 
                glEnd();
629
 
                glEndList();
630
 
                rp->AreObjectsDefined[ObjCubit] = 1;
631
 
#ifdef DEBUG_LISTS
632
 
                (void) printf("Cubit drawn SLOWLY\n");
633
 
#endif
634
 
        } else {
635
 
                glCallList(objects + ObjCubit);
636
 
#ifdef DEBUG_LISTS
637
 
                (void) printf("Cubit drawn quickly\n");
638
 
#endif
639
 
        }
640
 
 
 
682
        if (!draw_stickerless_cubit(rp))
 
683
                return False;
641
684
        if (back != NO_FACE) {
642
685
                glBegin(GL_POLYGON);
643
686
                pickcolor(back, mono);
644
687
                glNormal3f(0.00, 0.00, -1.00);
645
 
                glVertex3f(-0.35, 0.40, -0.51);
646
 
                glVertex3f(0.35, 0.40, -0.51);
647
 
                glVertex3f(0.40, 0.35, -0.51);
648
 
                glVertex3f(0.40, -0.35, -0.51);
649
 
                glVertex3f(0.35, -0.40, -0.51);
650
 
                glVertex3f(-0.35, -0.40, -0.51);
651
 
                glVertex3f(-0.40, -0.35, -0.51);
652
 
                glVertex3f(-0.40, 0.35, -0.51);
 
688
                glVertex3f(-STICKERSHORT, STICKERLONG, -STICKERDEPTH);
 
689
                glVertex3f(STICKERSHORT, STICKERLONG, -STICKERDEPTH);
 
690
                glVertex3f(STICKERLONG, STICKERSHORT, -STICKERDEPTH);
 
691
                glVertex3f(STICKERLONG, -STICKERSHORT, -STICKERDEPTH);
 
692
                glVertex3f(STICKERSHORT, -STICKERLONG, -STICKERDEPTH);
 
693
                glVertex3f(-STICKERSHORT, -STICKERLONG, -STICKERDEPTH);
 
694
                glVertex3f(-STICKERLONG, -STICKERSHORT, -STICKERDEPTH);
 
695
                glVertex3f(-STICKERLONG, STICKERSHORT, -STICKERDEPTH);
653
696
                glEnd();
654
697
        }
655
698
        if (front != NO_FACE) {
656
699
                glBegin(GL_POLYGON);
657
700
                pickcolor(front, mono);
658
701
                glNormal3f(0.00, 0.00, 1.00);
659
 
                glVertex3f(-0.35, -0.40, 0.51);
660
 
                glVertex3f(0.35, -0.40, 0.51);
661
 
                glVertex3f(0.40, -0.35, 0.51);
662
 
                glVertex3f(0.40, 0.35, 0.51);
663
 
                glVertex3f(0.35, 0.40, 0.51);
664
 
                glVertex3f(-0.35, 0.40, 0.51);
665
 
                glVertex3f(-0.40, 0.35, 0.51);
666
 
                glVertex3f(-0.40, -0.35, 0.51);
 
702
                glVertex3f(-STICKERSHORT, -STICKERLONG, STICKERDEPTH);
 
703
                glVertex3f(STICKERSHORT, -STICKERLONG, STICKERDEPTH);
 
704
                glVertex3f(STICKERLONG, -STICKERSHORT, STICKERDEPTH);
 
705
                glVertex3f(STICKERLONG, STICKERSHORT, STICKERDEPTH);
 
706
                glVertex3f(STICKERSHORT, STICKERLONG, STICKERDEPTH);
 
707
                glVertex3f(-STICKERSHORT, STICKERLONG, STICKERDEPTH);
 
708
                glVertex3f(-STICKERLONG, STICKERSHORT, STICKERDEPTH);
 
709
                glVertex3f(-STICKERLONG, -STICKERSHORT, STICKERDEPTH);
667
710
                glEnd();
668
711
        }
669
712
        if (left != NO_FACE) {
670
713
                glBegin(GL_POLYGON);
671
714
                pickcolor(left, mono);
672
715
                glNormal3f(-1.00, 0.00, 0.00);
673
 
                glVertex3f(-0.51, -0.35, 0.40);
674
 
                glVertex3f(-0.51, 0.35, 0.40);
675
 
                glVertex3f(-0.51, 0.40, 0.35);
676
 
                glVertex3f(-0.51, 0.40, -0.35);
677
 
                glVertex3f(-0.51, 0.35, -0.40);
678
 
                glVertex3f(-0.51, -0.35, -0.40);
679
 
                glVertex3f(-0.51, -0.40, -0.35);
680
 
                glVertex3f(-0.51, -0.40, 0.35);
 
716
                glVertex3f(-STICKERDEPTH, -STICKERSHORT, STICKERLONG);
 
717
                glVertex3f(-STICKERDEPTH, STICKERSHORT, STICKERLONG);
 
718
                glVertex3f(-STICKERDEPTH, STICKERLONG, STICKERSHORT);
 
719
                glVertex3f(-STICKERDEPTH, STICKERLONG, -STICKERSHORT);
 
720
                glVertex3f(-STICKERDEPTH, STICKERSHORT, -STICKERLONG);
 
721
                glVertex3f(-STICKERDEPTH, -STICKERSHORT, -STICKERLONG);
 
722
                glVertex3f(-STICKERDEPTH, -STICKERLONG, -STICKERSHORT);
 
723
                glVertex3f(-STICKERDEPTH, -STICKERLONG, STICKERSHORT);
681
724
                glEnd();
682
725
        }
683
726
        if (right != NO_FACE) {
684
727
                glBegin(GL_POLYGON);
685
728
                pickcolor(right, mono);
686
729
                glNormal3f(1.00, 0.00, 0.00);
687
 
                glVertex3f(0.51, -0.35, -0.40);
688
 
                glVertex3f(0.51, 0.35, -0.40);
689
 
                glVertex3f(0.51, 0.40, -0.35);
690
 
                glVertex3f(0.51, 0.40, 0.35);
691
 
                glVertex3f(0.51, 0.35, 0.40);
692
 
                glVertex3f(0.51, -0.35, 0.40);
693
 
                glVertex3f(0.51, -0.40, 0.35);
694
 
                glVertex3f(0.51, -0.40, -0.35);
 
730
                glVertex3f(STICKERDEPTH, -STICKERSHORT, -STICKERLONG);
 
731
                glVertex3f(STICKERDEPTH, STICKERSHORT, -STICKERLONG);
 
732
                glVertex3f(STICKERDEPTH, STICKERLONG, -STICKERSHORT);
 
733
                glVertex3f(STICKERDEPTH, STICKERLONG, STICKERSHORT);
 
734
                glVertex3f(STICKERDEPTH, STICKERSHORT, STICKERLONG);
 
735
                glVertex3f(STICKERDEPTH, -STICKERSHORT, STICKERLONG);
 
736
                glVertex3f(STICKERDEPTH, -STICKERLONG, STICKERSHORT);
 
737
                glVertex3f(STICKERDEPTH, -STICKERLONG, -STICKERSHORT);
695
738
                glEnd();
696
739
        }
697
740
        if (bottom != NO_FACE) {
698
741
                glBegin(GL_POLYGON);
699
742
                pickcolor(bottom, mono);
700
743
                glNormal3f(0.00, -1.00, 0.00);
701
 
                glVertex3f(0.40, -0.51, -0.35);
702
 
                glVertex3f(0.40, -0.51, 0.35);
703
 
                glVertex3f(0.35, -0.51, 0.40);
704
 
                glVertex3f(-0.35, -0.51, 0.40);
705
 
                glVertex3f(-0.40, -0.51, 0.35);
706
 
                glVertex3f(-0.40, -0.51, -0.35);
707
 
                glVertex3f(-0.35, -0.51, -0.40);
708
 
                glVertex3f(0.35, -0.51, -0.40);
 
744
                glVertex3f(STICKERLONG, -STICKERDEPTH, -STICKERSHORT);
 
745
                glVertex3f(STICKERLONG, -STICKERDEPTH, STICKERSHORT);
 
746
                glVertex3f(STICKERSHORT, -STICKERDEPTH, STICKERLONG);
 
747
                glVertex3f(-STICKERSHORT, -STICKERDEPTH, STICKERLONG);
 
748
                glVertex3f(-STICKERLONG, -STICKERDEPTH, STICKERSHORT);
 
749
                glVertex3f(-STICKERLONG, -STICKERDEPTH, -STICKERSHORT);
 
750
                glVertex3f(-STICKERSHORT, -STICKERDEPTH, -STICKERLONG);
 
751
                glVertex3f(STICKERSHORT, -STICKERDEPTH, -STICKERLONG);
709
752
                glEnd();
710
753
        }
711
754
        if (top != NO_FACE) {
712
755
                glBegin(GL_POLYGON);
713
756
                pickcolor(top, mono);
714
757
                glNormal3f(0.00, 1.00, 0.00);
715
 
                glVertex3f(-0.40, 0.51, -0.35);
716
 
                glVertex3f(-0.40, 0.51, 0.35);
717
 
                glVertex3f(-0.35, 0.51, 0.40);
718
 
                glVertex3f(0.35, 0.51, 0.40);
719
 
                glVertex3f(0.40, 0.51, 0.35);
720
 
                glVertex3f(0.40, 0.51, -0.35);
721
 
                glVertex3f(0.35, 0.51, -0.40);
722
 
                glVertex3f(-0.35, 0.51, -0.40);
 
758
                glVertex3f(-STICKERLONG, STICKERDEPTH, -STICKERSHORT);
 
759
                glVertex3f(-STICKERLONG, STICKERDEPTH, STICKERSHORT);
 
760
                glVertex3f(-STICKERSHORT, STICKERDEPTH, STICKERLONG);
 
761
                glVertex3f(STICKERSHORT, STICKERDEPTH, STICKERLONG);
 
762
                glVertex3f(STICKERLONG, STICKERDEPTH, STICKERSHORT);
 
763
                glVertex3f(STICKERLONG, STICKERDEPTH, -STICKERSHORT);
 
764
                glVertex3f(STICKERSHORT, STICKERDEPTH, -STICKERLONG);
 
765
                glVertex3f(-STICKERSHORT, STICKERDEPTH, -STICKERLONG);
723
766
                glEnd();
724
767
        }
 
768
        return True;
725
769
}
726
770
 
727
 
 
728
 
static      RubikSlice
729
 
convertMove(rubikstruct * rp, RubikMove move)
 
771
/* Convert move to weird general notation */
 
772
static void
 
773
convertMove(rubikstruct * rp, RubikMove move, RubikSlice * slice)
730
774
{
731
 
        RubikSlice  slice;
732
775
        RubikLoc    plane;
 
776
        int         sizeOfRow, sizeOfColumn;
733
777
 
734
778
        plane = rotateSlice[(int) move.face][move.direction % 2];
735
 
        slice.face = plane.face;
736
 
        slice.rotation = plane.rotation;
737
 
        if (slice.rotation == CW)       /* I just know this to be true... */
738
 
                slice.depth = AVSIZESQ - 1 - move.position;
739
 
        else
740
 
                slice.depth = move.position;
741
 
        slice.depth = slice.depth / AVSIZE;
742
 
        /* If slice.depth = 0 then face 0, face 1, or face 2 moves */
 
779
        (*slice).face = plane.face;
 
780
        (*slice).rotation = plane.rotation;
 
781
 
 
782
        faceSizes(rp, move.face, &sizeOfRow, &sizeOfColumn);
 
783
        if (plane.face == 1 || /* VERTICAL */
 
784
            (plane.face == 2 && (move.face == 1 || move.face == 3))) {
 
785
                if ((*slice).rotation == CW)
 
786
                        (*slice).depth = sizeOfRow - 1 - move.position %
 
787
                                sizeOfRow;
 
788
                else
 
789
                        (*slice).depth = move.position % sizeOfRow;
 
790
        } else { /* (plane.face == 0 ||  *//* HORIZONTAL *//*
 
791
                (plane.face == 2 && (move.face == 0 || move.face == 4))) */
 
792
                if ((*slice).rotation == CW)
 
793
                        (*slice).depth = sizeOfColumn - 1 - move.position /
 
794
                                sizeOfRow;
 
795
                else
 
796
                        (*slice).depth = move.position / sizeOfRow;
 
797
        }
 
798
        /* If (*slice).depth = 0 then face 0, face 1, or face 2 moves */
743
799
        if (move.direction / 2)
744
 
                slice.rotation = (plane.rotation == CW) ? CCW : CW;
745
 
        return slice;
 
800
                (*slice).rotation = ((*slice).rotation == CW) ? CCW : CW;
746
801
}
747
802
 
748
 
/* Assume for the moment that the size is at least 2 */
749
 
static void
 
803
/* Assume the size is at least 2, or its just not challenging... */
 
804
static Bool
750
805
draw_cube(ModeInfo * mi)
751
806
{
752
807
#define S1 1
759
814
#define MIDX(a) (((GLfloat)(2*a-MAXSIZEX+1))/2.0)
760
815
#define MIDY(a) (((GLfloat)(2*a-MAXSIZEY+1))/2.0)
761
816
#define MIDZ(a) (((GLfloat)(2*a-MAXSIZEZ+1))/2.0)
 
817
#define DRAW_CUBIT(mi,b,f,l,r,bm,t) if (!draw_cubit(mi,b,f,l,r,bm,t)) return False
762
818
        rubikstruct *rp = &rubik[MI_SCREEN(mi)];
763
819
        RubikSlice  slice;
764
820
        GLfloat     rotatestep;
769
825
                slice.rotation = NO_ROTATION;
770
826
                slice.depth = NO_DEPTH;
771
827
        } else {
772
 
                slice = convertMove(rp, rp->movement);
 
828
                convertMove(rp, rp->movement, &slice);
773
829
        }
774
830
        rotatestep = (slice.rotation == CCW) ? rp->rotatestep : -rp->rotatestep;
775
831
 
 
832
 
776
833
/*-
777
834
 * The glRotatef() routine transforms the coordinate system for every future
778
835
 * vertex specification (this is not so simple, but by now comprehending this
789
846
                                glRotatef(rotatestep, 0, HALFY, 0);
790
847
 
791
848
                        glTranslatef(-HALFX, -HALFY, -HALFZ);
792
 
                        draw_cubit(mi,
 
849
                        DRAW_CUBIT(mi,
793
850
                                   rp->cubeLoc[BACK_FACE][FIRSTX + MAXSIZEX * FIRSTY].face, NO_FACE,
794
851
                                   rp->cubeLoc[LEFT_FACE][FIRSTZ + MAXSIZEZ * LASTY].face, NO_FACE,
795
852
                                   rp->cubeLoc[BOTTOM_FACE][FIRSTX + MAXSIZEX * LASTZ].face, NO_FACE);
796
853
                        for (k = 1; k < MAXSIZEZ - 1; k++) {
797
854
                                glTranslatef(0, 0, S1);
798
 
                                draw_cubit(mi,
 
855
                                DRAW_CUBIT(mi,
799
856
                                           NO_FACE, NO_FACE,
800
857
                                           rp->cubeLoc[LEFT_FACE][k + MAXSIZEZ * LASTY].face, NO_FACE,
801
858
                                           rp->cubeLoc[BOTTOM_FACE][FIRSTX + MAXSIZEX * REVZ(k)].face, NO_FACE);
802
859
                        }
803
860
                        glTranslatef(0, 0, S1);
804
 
                        draw_cubit(mi,
 
861
                        DRAW_CUBIT(mi,
805
862
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][FIRSTX + MAXSIZEX * LASTY].face,
806
863
                                   rp->cubeLoc[LEFT_FACE][LASTZ + MAXSIZEZ * LASTY].face, NO_FACE,
807
864
                                   rp->cubeLoc[BOTTOM_FACE][FIRSTX + MAXSIZEX * FIRSTZ].face, NO_FACE);
808
865
                        for (i = 1; i < MAXSIZEX - 1; i++) {
809
866
                                glTranslatef(S1, 0, -SZ);
810
 
                                draw_cubit(mi,
 
867
                                DRAW_CUBIT(mi,
811
868
                                           rp->cubeLoc[BACK_FACE][i + MAXSIZEX * FIRSTY].face, NO_FACE,
812
869
                                           NO_FACE, NO_FACE,
813
870
                                           rp->cubeLoc[BOTTOM_FACE][i + MAXSIZEX * LASTZ].face, NO_FACE);
814
871
                                for (k = 1; k < MAXSIZEZ - 1; k++) {
815
872
                                        glTranslatef(0, 0, S1);
816
 
                                        draw_cubit(mi,
 
873
                                        DRAW_CUBIT(mi,
817
874
                                                   NO_FACE, NO_FACE,
818
875
                                                   NO_FACE, NO_FACE,
819
876
                                                   rp->cubeLoc[BOTTOM_FACE][i + MAXSIZEX * REVZ(k)].face, NO_FACE);
820
877
                                }
821
878
                                glTranslatef(0, 0, S1);
822
 
                                draw_cubit(mi,
 
879
                                DRAW_CUBIT(mi,
823
880
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][i + MAXSIZEX * LASTY].face,
824
881
                                           NO_FACE, NO_FACE,
825
882
                                           rp->cubeLoc[BOTTOM_FACE][i + MAXSIZEX * FIRSTZ].face, NO_FACE);
826
883
                        }
827
 
                        glTranslatef(1, 0, -SZ);
828
 
                        draw_cubit(mi,
 
884
                        glTranslatef(S1, 0, -SZ);
 
885
                        DRAW_CUBIT(mi,
829
886
                                   rp->cubeLoc[BACK_FACE][LASTX + MAXSIZEX * FIRSTY].face, NO_FACE,
830
887
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][LASTZ + MAXSIZEZ * LASTY].face,
831
888
                                   rp->cubeLoc[BOTTOM_FACE][LASTX + MAXSIZEX * LASTZ].face, NO_FACE);
832
889
                        for (k = 1; k < MAXSIZEZ - 1; k++) {
833
890
                                glTranslatef(0, 0, S1);
834
 
                                draw_cubit(mi,
 
891
                                DRAW_CUBIT(mi,
835
892
                                           NO_FACE, NO_FACE,
836
893
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][REVZ(k) + MAXSIZEZ * LASTY].face,
837
894
                                           rp->cubeLoc[BOTTOM_FACE][LASTX + MAXSIZEX * REVZ(k)].face, NO_FACE);
838
895
                        }
839
896
                        glTranslatef(0, 0, S1);
840
 
                        draw_cubit(mi,
 
897
                        DRAW_CUBIT(mi,
841
898
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][LASTX + MAXSIZEX * LASTY].face,
842
899
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][FIRSTZ + MAXSIZEZ * LASTY].face,
843
900
                                   rp->cubeLoc[BOTTOM_FACE][LASTX + MAXSIZEX * FIRSTZ].face, NO_FACE);
847
904
                                if (slice.depth == REVY(j))
848
905
                                        glRotatef(rotatestep, 0, HALFY, 0);
849
906
                                glTranslatef(-HALFX, MIDY(j), -HALFZ);
850
 
                                draw_cubit(mi,
 
907
                                DRAW_CUBIT(mi,
851
908
                                           rp->cubeLoc[BACK_FACE][FIRSTX + MAXSIZEX * j].face, NO_FACE,
852
909
                                           rp->cubeLoc[LEFT_FACE][FIRSTZ + MAXSIZEZ * REVY(j)].face, NO_FACE,
853
910
                                           NO_FACE, NO_FACE);
854
911
                                for (k = 1; k < MAXSIZEZ - 1; k++) {
855
912
                                        glTranslatef(0, 0, S1);
856
 
                                        draw_cubit(mi,
 
913
                                        DRAW_CUBIT(mi,
857
914
                                                   NO_FACE, NO_FACE,
858
915
                                                   rp->cubeLoc[LEFT_FACE][k + MAXSIZEZ * REVY(j)].face, NO_FACE,
859
916
                                                   NO_FACE, NO_FACE);
860
917
                                }
861
918
                                glTranslatef(0, 0, S1);
862
 
                                draw_cubit(mi,
 
919
                                DRAW_CUBIT(mi,
863
920
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][FIRSTX + MAXSIZEX * REVY(j)].face,
864
921
                                           rp->cubeLoc[LEFT_FACE][LASTZ + MAXSIZEZ * REVY(j)].face, NO_FACE,
865
922
                                           NO_FACE, NO_FACE);
866
923
                                for (i = 1; i < MAXSIZEX - 1; i++) {
867
924
                                        glTranslatef(1, 0, -SZ);
868
 
                                        draw_cubit(mi,
 
925
                                        DRAW_CUBIT(mi,
869
926
                                                   rp->cubeLoc[BACK_FACE][i + MAXSIZEX * j].face, NO_FACE,
870
927
                                                   NO_FACE, NO_FACE,
871
928
                                                   NO_FACE, NO_FACE);
872
929
                                        /* Center */
873
930
                                        glTranslatef(0, 0, SZ);
874
 
                                        draw_cubit(mi,
 
931
                                        DRAW_CUBIT(mi,
875
932
                                                   NO_FACE, rp->cubeLoc[FRONT_FACE][i + MAXSIZEX * REVY(j)].face,
876
933
                                                   NO_FACE, NO_FACE,
877
934
                                                   NO_FACE, NO_FACE);
878
935
                                }
879
936
                                glTranslatef(S1, 0, -SZ);
880
 
                                draw_cubit(mi,
 
937
                                DRAW_CUBIT(mi,
881
938
                                           rp->cubeLoc[BACK_FACE][LASTX + MAXSIZEX * j].face, NO_FACE,
882
939
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][LASTZ + MAXSIZEZ * REVY(j)].face,
883
940
                                           NO_FACE, NO_FACE);
884
941
                                for (k = 1; k < MAXSIZEZ - 1; k++) {
885
942
                                        glTranslatef(0, 0, S1);
886
 
                                        draw_cubit(mi,
 
943
                                        DRAW_CUBIT(mi,
887
944
                                                   NO_FACE, NO_FACE,
888
945
                                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][REVZ(k) + MAXSIZEZ * REVY(j)].face,
889
946
                                                   NO_FACE, NO_FACE);
890
947
                                }
891
948
                                glTranslatef(0, 0, S1);
892
 
                                draw_cubit(mi,
 
949
                                DRAW_CUBIT(mi,
893
950
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][LASTX + MAXSIZEX * REVY(j)].face,
894
951
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][FIRSTZ + MAXSIZEZ * REVY(j)].face,
895
952
                                           NO_FACE, NO_FACE);
899
956
                                glRotatef(rotatestep, 0, HALFY, 0);
900
957
 
901
958
                        glTranslatef(-HALFX, HALFY, -HALFZ);
902
 
                        draw_cubit(mi,
 
959
                        DRAW_CUBIT(mi,
903
960
                                   rp->cubeLoc[BACK_FACE][FIRSTX + MAXSIZEX * LASTY].face, NO_FACE,
904
961
                                   rp->cubeLoc[LEFT_FACE][FIRSTZ + MAXSIZEZ * FIRSTY].face, NO_FACE,
905
962
                                   NO_FACE, rp->cubeLoc[TOP_FACE][FIRSTX + MAXSIZEX * FIRSTZ].face);
906
963
                        for (k = 1; k < MAXSIZEZ - 1; k++) {
907
964
                                glTranslatef(0, 0, S1);
908
 
                                draw_cubit(mi,
 
965
                                DRAW_CUBIT(mi,
909
966
                                           NO_FACE, NO_FACE,
910
967
                                           rp->cubeLoc[LEFT_FACE][k + MAXSIZEZ * FIRSTY].face, NO_FACE,
911
968
                                           NO_FACE, rp->cubeLoc[TOP_FACE][FIRSTX + MAXSIZEX * k].face);
912
969
                        }
913
970
                        glTranslatef(0, 0, S1);
914
 
                        draw_cubit(mi,
 
971
                        DRAW_CUBIT(mi,
915
972
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][FIRSTX + MAXSIZEX * FIRSTY].face,
916
973
                                   rp->cubeLoc[LEFT_FACE][LASTZ + MAXSIZEZ * FIRSTY].face, NO_FACE,
917
974
                                   NO_FACE, rp->cubeLoc[TOP_FACE][FIRSTX + MAXSIZEX * LASTZ].face);
918
975
                        for (i = 1; i < MAXSIZEX - 1; i++) {
919
976
                                glTranslatef(S1, 0, -SZ);
920
 
                                draw_cubit(mi,
 
977
                                DRAW_CUBIT(mi,
921
978
                                           rp->cubeLoc[BACK_FACE][i + MAXSIZEX * LASTY].face, NO_FACE,
922
979
                                           NO_FACE, NO_FACE,
923
980
                                           NO_FACE, rp->cubeLoc[TOP_FACE][i + MAXSIZEX * FIRSTZ].face);
924
981
                                for (k = 1; k < MAXSIZEZ - 1; k++) {
925
982
                                        glTranslatef(0, 0, S1);
926
 
                                        draw_cubit(mi,
 
983
                                        DRAW_CUBIT(mi,
927
984
                                                   NO_FACE, NO_FACE,
928
985
                                                   NO_FACE, NO_FACE,
929
986
                                                   NO_FACE, rp->cubeLoc[TOP_FACE][i + MAXSIZEX * k].face);
930
987
                                }
931
988
                                glTranslatef(0, 0, S1);
932
 
                                draw_cubit(mi,
 
989
                                DRAW_CUBIT(mi,
933
990
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][i + MAXSIZEX * FIRSTY].face,
934
991
                                           NO_FACE, NO_FACE,
935
992
                                           NO_FACE, rp->cubeLoc[TOP_FACE][i + MAXSIZEX * LASTZ].face);
936
993
                        }
937
994
                        glTranslatef(S1, 0, -SZ);
938
 
                        draw_cubit(mi,
 
995
                        DRAW_CUBIT(mi,
939
996
                                   rp->cubeLoc[BACK_FACE][LASTX + MAXSIZEX * LASTY].face, NO_FACE,
940
997
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][LASTZ + MAXSIZEZ * FIRSTY].face,
941
998
                                   NO_FACE, rp->cubeLoc[TOP_FACE][LASTX + MAXSIZEX * FIRSTZ].face);
942
999
                        for (k = 1; k < MAXSIZEZ - 1; k++) {
943
1000
                                glTranslatef(0, 0, S1);
944
 
                                draw_cubit(mi,
 
1001
                                DRAW_CUBIT(mi,
945
1002
                                           NO_FACE, NO_FACE,
946
1003
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][REVZ(k) + MAXSIZEZ * FIRSTY].face,
947
1004
                                           NO_FACE, rp->cubeLoc[TOP_FACE][LASTX + MAXSIZEX * k].face);
948
1005
                        }
949
1006
                        glTranslatef(0, 0, S1);
950
 
                        draw_cubit(mi,
 
1007
                        DRAW_CUBIT(mi,
951
1008
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][LASTX + MAXSIZEX * FIRSTY].face,
952
1009
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][FIRSTZ + MAXSIZEZ * FIRSTY].face,
953
1010
                                   NO_FACE, rp->cubeLoc[TOP_FACE][LASTX + MAXSIZEX * LASTZ].face);
959
1016
                                glRotatef(-rotatestep, HALFX, 0, 0);
960
1017
 
961
1018
                        glTranslatef(-HALFX, -HALFY, -HALFZ);
962
 
                        draw_cubit(mi,
 
1019
                        DRAW_CUBIT(mi,
963
1020
                                   rp->cubeLoc[BACK_FACE][FIRSTX + MAXSIZEX * FIRSTY].face, NO_FACE,
964
1021
                                   rp->cubeLoc[LEFT_FACE][FIRSTZ + MAXSIZEZ * LASTY].face, NO_FACE,
965
1022
                                   rp->cubeLoc[BOTTOM_FACE][FIRSTX + MAXSIZEX * LASTZ].face, NO_FACE);
966
1023
                        for (j = 1; j < MAXSIZEY - 1; j++) {
967
1024
                                glTranslatef(0, S1, 0);
968
 
                                draw_cubit(mi,
 
1025
                                DRAW_CUBIT(mi,
969
1026
                                           rp->cubeLoc[BACK_FACE][FIRSTX + MAXSIZEX * j].face, NO_FACE,
970
1027
                                           rp->cubeLoc[LEFT_FACE][FIRSTZ + MAXSIZEZ * REVY(j)].face, NO_FACE,
971
1028
                                           NO_FACE, NO_FACE);
972
1029
                        }
973
1030
                        glTranslatef(0, S1, 0);
974
 
                        draw_cubit(mi,
 
1031
                        DRAW_CUBIT(mi,
975
1032
                                   rp->cubeLoc[BACK_FACE][FIRSTX + MAXSIZEX * LASTY].face, NO_FACE,
976
1033
                                   rp->cubeLoc[LEFT_FACE][FIRSTZ + MAXSIZEZ * FIRSTY].face, NO_FACE,
977
1034
                                   NO_FACE, rp->cubeLoc[TOP_FACE][FIRSTX + MAXSIZEX * FIRSTZ].face);
978
1035
                        for (k = 1; k < MAXSIZEZ - 1; k++) {
979
1036
                                glTranslatef(0, -SY, S1);
980
 
                                draw_cubit(mi,
 
1037
                                DRAW_CUBIT(mi,
981
1038
                                           NO_FACE, NO_FACE,
982
1039
                                           rp->cubeLoc[LEFT_FACE][k + MAXSIZEZ * LASTY].face, NO_FACE,
983
1040
                                           rp->cubeLoc[BOTTOM_FACE][FIRSTX + MAXSIZEX * REVZ(k)].face, NO_FACE);
984
1041
                                for (j = 1; j < MAXSIZEY - 1; j++) {
985
1042
                                        glTranslatef(0, S1, 0);
986
 
                                        draw_cubit(mi,
 
1043
                                        DRAW_CUBIT(mi,
987
1044
                                                   NO_FACE, NO_FACE,
988
1045
                                                   rp->cubeLoc[LEFT_FACE][k + MAXSIZEZ * REVY(j)].face, NO_FACE,
989
1046
                                                   NO_FACE, NO_FACE);
990
1047
                                }
991
1048
                                glTranslatef(0, S1, 0);
992
 
                                draw_cubit(mi,
 
1049
                                DRAW_CUBIT(mi,
993
1050
                                           NO_FACE, NO_FACE,
994
1051
                                           rp->cubeLoc[LEFT_FACE][k + MAXSIZEZ * FIRSTY].face, NO_FACE,
995
1052
                                           NO_FACE, rp->cubeLoc[TOP_FACE][FIRSTX + MAXSIZEX * k].face);
996
1053
                        }
997
1054
                        glTranslatef(0, -SY, S1);
998
 
                        draw_cubit(mi,
 
1055
                        DRAW_CUBIT(mi,
999
1056
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][FIRSTX + MAXSIZEX * LASTY].face,
1000
1057
                                   rp->cubeLoc[LEFT_FACE][LASTZ + MAXSIZEZ * LASTY].face, NO_FACE,
1001
1058
                                   rp->cubeLoc[BOTTOM_FACE][FIRSTX + MAXSIZEX * FIRSTZ].face, NO_FACE);
1002
1059
                        for (j = 1; j < MAXSIZEY - 1; j++) {
1003
1060
                                glTranslatef(0, S1, 0);
1004
 
                                draw_cubit(mi,
 
1061
                                DRAW_CUBIT(mi,
1005
1062
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][FIRSTX + MAXSIZEX * REVY(j)].face,
1006
1063
                                           rp->cubeLoc[LEFT_FACE][LASTZ + MAXSIZEZ * REVY(j)].face, NO_FACE,
1007
1064
                                           NO_FACE, NO_FACE);
1008
1065
                        }
1009
1066
                        glTranslatef(0, S1, 0);
1010
 
                        draw_cubit(mi,
 
1067
                        DRAW_CUBIT(mi,
1011
1068
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][FIRSTX + MAXSIZEX * FIRSTY].face,
1012
1069
                                   rp->cubeLoc[LEFT_FACE][LASTZ + MAXSIZEZ * FIRSTY].face, NO_FACE,
1013
1070
                                   NO_FACE, rp->cubeLoc[TOP_FACE][FIRSTX + MAXSIZEX * LASTZ].face);
1017
1074
                                if (slice.depth == i)
1018
1075
                                        glRotatef(-rotatestep, HALFX, 0, 0);
1019
1076
                                glTranslatef(MIDX(i), -HALFY, -HALFZ);
1020
 
                                draw_cubit(mi,
 
1077
                                DRAW_CUBIT(mi,
1021
1078
                                           rp->cubeLoc[BACK_FACE][i + MAXSIZEX * FIRSTY].face, NO_FACE,
1022
1079
                                           NO_FACE, NO_FACE,
1023
1080
                                           rp->cubeLoc[BOTTOM_FACE][i + MAXSIZEX * LASTZ].face, NO_FACE);
1024
1081
                                for (j = 1; j < MAXSIZEY - 1; j++) {
1025
1082
                                        glTranslatef(0, S1, 0);
1026
 
                                        draw_cubit(mi,
 
1083
                                        DRAW_CUBIT(mi,
1027
1084
                                                   rp->cubeLoc[BACK_FACE][i + MAXSIZEX * j].face, NO_FACE,
1028
1085
                                                   NO_FACE, NO_FACE,
1029
1086
                                                   NO_FACE, NO_FACE);
1030
1087
                                }
1031
1088
                                glTranslatef(0, S1, 0);
1032
 
                                draw_cubit(mi,
 
1089
                                DRAW_CUBIT(mi,
1033
1090
                                           rp->cubeLoc[BACK_FACE][i + MAXSIZEX * LASTY].face, NO_FACE,
1034
1091
                                           NO_FACE, NO_FACE,
1035
1092
                                           NO_FACE, rp->cubeLoc[TOP_FACE][i + MAXSIZEX * FIRSTZ].face);
1036
1093
                                for (k = 1; k < MAXSIZEZ - 1; k++) {
1037
1094
                                        glTranslatef(0, -SY, S1);
1038
 
                                        draw_cubit(mi,
 
1095
                                        DRAW_CUBIT(mi,
1039
1096
                                                   NO_FACE, NO_FACE,
1040
1097
                                                   NO_FACE, NO_FACE,
1041
1098
                                                   rp->cubeLoc[BOTTOM_FACE][i + MAXSIZEX * REVZ(k)].face, NO_FACE);
1042
1099
                                        /* Center */
1043
1100
                                        glTranslatef(0, SY, 0);
1044
 
                                        draw_cubit(mi,
 
1101
                                        DRAW_CUBIT(mi,
1045
1102
                                                   NO_FACE, NO_FACE,
1046
1103
                                                   NO_FACE, NO_FACE,
1047
1104
                                                   NO_FACE, rp->cubeLoc[TOP_FACE][i + MAXSIZEX * k].face);
1048
1105
                                }
1049
1106
                                glTranslatef(0, -SY, S1);
1050
 
                                draw_cubit(mi,
 
1107
                                DRAW_CUBIT(mi,
1051
1108
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][i + MAXSIZEX * LASTY].face,
1052
1109
                                           NO_FACE, NO_FACE,
1053
1110
                                           rp->cubeLoc[BOTTOM_FACE][i + MAXSIZEX * FIRSTZ].face, NO_FACE);
1054
1111
                                for (j = 1; j < MAXSIZEY - 1; j++) {
1055
1112
                                        glTranslatef(0, S1, 0);
1056
 
                                        draw_cubit(mi,
 
1113
                                        DRAW_CUBIT(mi,
1057
1114
                                                   NO_FACE, rp->cubeLoc[FRONT_FACE][i + MAXSIZEX * REVY(j)].face,
1058
1115
                                                   NO_FACE, NO_FACE,
1059
1116
                                                   NO_FACE, NO_FACE);
1060
1117
                                }
1061
1118
                                glTranslatef(0, S1, 0);
1062
 
                                draw_cubit(mi,
 
1119
                                DRAW_CUBIT(mi,
1063
1120
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][i + MAXSIZEX * FIRSTY].face,
1064
1121
                                           NO_FACE, NO_FACE,
1065
1122
                                           NO_FACE, rp->cubeLoc[TOP_FACE][i + MAXSIZEX * LASTZ].face);
1068
1125
                        if (slice.depth == MAXSIZEX - 1)
1069
1126
                                glRotatef(-rotatestep, HALFX, 0, 0);
1070
1127
                        glTranslatef(HALFX, -HALFY, -HALFZ);
1071
 
                        draw_cubit(mi,
 
1128
                        DRAW_CUBIT(mi,
1072
1129
                                   rp->cubeLoc[BACK_FACE][LASTX + MAXSIZEX * FIRSTY].face, NO_FACE,
1073
1130
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][LASTZ + MAXSIZEZ * LASTY].face,
1074
1131
                                   rp->cubeLoc[BOTTOM_FACE][LASTX + MAXSIZEX * LASTZ].face, NO_FACE);
1075
1132
                        for (j = 1; j < MAXSIZEY - 1; j++) {
1076
1133
                                glTranslatef(0, S1, 0);
1077
 
                                draw_cubit(mi,
 
1134
                                DRAW_CUBIT(mi,
1078
1135
                                           rp->cubeLoc[BACK_FACE][LASTX + MAXSIZEX * j].face, NO_FACE,
1079
1136
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][LASTZ + MAXSIZEZ * REVY(j)].face,
1080
1137
                                           NO_FACE, NO_FACE);
1081
1138
                        }
1082
1139
                        glTranslatef(0, S1, 0);
1083
 
                        draw_cubit(mi,
 
1140
                        DRAW_CUBIT(mi,
1084
1141
                                   rp->cubeLoc[BACK_FACE][LASTX + MAXSIZEX * LASTY].face, NO_FACE,
1085
1142
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][LASTZ + MAXSIZEZ * FIRSTY].face,
1086
1143
                                   NO_FACE, rp->cubeLoc[TOP_FACE][LASTX + MAXSIZEX * FIRSTZ].face);
1087
1144
                        for (k = 1; k < MAXSIZEZ - 1; k++) {
1088
1145
                                glTranslatef(0, -SY, S1);
1089
 
                                draw_cubit(mi,
 
1146
                                DRAW_CUBIT(mi,
1090
1147
                                           NO_FACE, NO_FACE,
1091
1148
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][REVZ(k) + MAXSIZEZ * LASTY].face,
1092
1149
                                           rp->cubeLoc[BOTTOM_FACE][LASTX + MAXSIZEX * REVZ(k)].face, NO_FACE);
1093
1150
                                for (j = 1; j < MAXSIZEY - 1; j++) {
1094
1151
                                        glTranslatef(0, S1, 0);
1095
 
                                        draw_cubit(mi,
 
1152
                                        DRAW_CUBIT(mi,
1096
1153
                                                   NO_FACE, NO_FACE,
1097
1154
                                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][REVZ(k) + MAXSIZEZ * REVY(j)].face,
1098
1155
                                                   NO_FACE, NO_FACE);
1099
1156
                                }
1100
1157
                                glTranslatef(0, S1, 0);
1101
 
                                draw_cubit(mi,
 
1158
                                DRAW_CUBIT(mi,
1102
1159
                                           NO_FACE, NO_FACE,
1103
1160
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][REVZ(k) + MAXSIZEZ * FIRSTY].face,
1104
1161
                                           NO_FACE, rp->cubeLoc[TOP_FACE][LASTX + MAXSIZEX * k].face);
1105
1162
                        }
1106
1163
                        glTranslatef(0, -SY, S1);
1107
 
                        draw_cubit(mi,
 
1164
                        DRAW_CUBIT(mi,
1108
1165
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][LASTX + MAXSIZEX * LASTY].face,
1109
1166
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][FIRSTZ + MAXSIZEZ * LASTY].face,
1110
1167
                                   rp->cubeLoc[BOTTOM_FACE][LASTX + MAXSIZEX * FIRSTZ].face, NO_FACE);
1111
1168
                        for (j = 1; j < MAXSIZEY - 1; j++) {
1112
1169
                                glTranslatef(0, S1, 0);
1113
 
                                draw_cubit(mi,
 
1170
                                DRAW_CUBIT(mi,
1114
1171
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][LASTX + MAXSIZEX * REVY(j)].face,
1115
1172
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][FIRSTZ + MAXSIZEZ * REVY(j)].face,
1116
1173
                                           NO_FACE, NO_FACE);
1117
1174
                        }
1118
1175
                        glTranslatef(0, S1, 0);
1119
 
                        draw_cubit(mi,
 
1176
                        DRAW_CUBIT(mi,
1120
1177
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][LASTX + MAXSIZEX * FIRSTY].face,
1121
1178
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][FIRSTZ + MAXSIZEZ * FIRSTY].face,
1122
1179
                                   NO_FACE, rp->cubeLoc[TOP_FACE][LASTX + MAXSIZEX * LASTZ].face);
1127
1184
                                glRotatef(rotatestep, 0, 0, HALFZ);
1128
1185
 
1129
1186
                        glTranslatef(-HALFX, -HALFY, -HALFZ);
1130
 
                        draw_cubit(mi,
 
1187
                        DRAW_CUBIT(mi,
1131
1188
                                   rp->cubeLoc[BACK_FACE][FIRSTX + MAXSIZEX * FIRSTY].face, NO_FACE,
1132
1189
                                   rp->cubeLoc[LEFT_FACE][FIRSTZ + MAXSIZEZ * LASTY].face, NO_FACE,
1133
1190
                                   rp->cubeLoc[BOTTOM_FACE][FIRSTX + MAXSIZEX * LASTZ].face, NO_FACE);
1134
1191
                        for (i = 1; i < MAXSIZEX - 1; i++) {
1135
1192
                                glTranslatef(S1, 0, 0);
1136
 
                                draw_cubit(mi,
 
1193
                                DRAW_CUBIT(mi,
1137
1194
                                           rp->cubeLoc[BACK_FACE][i + MAXSIZEX * FIRSTY].face, NO_FACE,
1138
1195
                                           NO_FACE, NO_FACE,
1139
1196
                                           rp->cubeLoc[BOTTOM_FACE][i + MAXSIZEX * LASTZ].face, NO_FACE);
1140
1197
                        }
1141
1198
                        glTranslatef(S1, 0, 0);
1142
 
                        draw_cubit(mi,
 
1199
                        DRAW_CUBIT(mi,
1143
1200
                                   rp->cubeLoc[BACK_FACE][LASTX + MAXSIZEX * FIRSTY].face, NO_FACE,
1144
1201
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][LASTZ + MAXSIZEZ * LASTY].face,
1145
1202
                                   rp->cubeLoc[BOTTOM_FACE][LASTX + MAXSIZEX * LASTZ].face, NO_FACE);
1146
1203
                        for (j = 1; j < MAXSIZEY - 1; j++) {
1147
1204
                                glTranslatef(-SX, S1, 0);
1148
 
                                draw_cubit(mi,
 
1205
                                DRAW_CUBIT(mi,
1149
1206
                                           rp->cubeLoc[BACK_FACE][FIRSTX + MAXSIZEX * j].face, NO_FACE,
1150
1207
                                           rp->cubeLoc[LEFT_FACE][FIRSTZ + MAXSIZEZ * REVY(j)].face, NO_FACE,
1151
1208
                                           NO_FACE, NO_FACE);
1152
1209
                                for (i = 1; i < MAXSIZEX - 1; i++) {
1153
1210
                                        glTranslatef(S1, 0, 0);
1154
 
                                        draw_cubit(mi,
 
1211
                                        DRAW_CUBIT(mi,
1155
1212
                                                   rp->cubeLoc[BACK_FACE][i + MAXSIZEX * j].face, NO_FACE,
1156
1213
                                                   NO_FACE, NO_FACE,
1157
1214
                                                   NO_FACE, NO_FACE);
1158
1215
                                }
1159
1216
                                glTranslatef(S1, 0, 0);
1160
 
                                draw_cubit(mi,
 
1217
                                DRAW_CUBIT(mi,
1161
1218
                                           rp->cubeLoc[BACK_FACE][LASTX + MAXSIZEX * j].face, NO_FACE,
1162
1219
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][LASTZ + MAXSIZEZ * REVY(j)].face,
1163
1220
                                           NO_FACE, NO_FACE);
1164
1221
                        }
1165
1222
                        glTranslatef(-SX, S1, 0);
1166
 
                        draw_cubit(mi,
 
1223
                        DRAW_CUBIT(mi,
1167
1224
                                   rp->cubeLoc[BACK_FACE][FIRSTX + MAXSIZEX * LASTY].face, NO_FACE,
1168
1225
                                   rp->cubeLoc[LEFT_FACE][FIRSTZ + MAXSIZEZ * FIRSTY].face, NO_FACE,
1169
1226
                                   NO_FACE, rp->cubeLoc[TOP_FACE][FIRSTX + MAXSIZEX * FIRSTZ].face);
1170
1227
                        for (i = 1; i < MAXSIZEX - 1; i++) {
1171
1228
                                glTranslatef(S1, 0, 0);
1172
 
                                draw_cubit(mi,
 
1229
                                DRAW_CUBIT(mi,
1173
1230
                                           rp->cubeLoc[BACK_FACE][i + MAXSIZEX * LASTY].face, NO_FACE,
1174
1231
                                           NO_FACE, NO_FACE,
1175
1232
                                           NO_FACE, rp->cubeLoc[TOP_FACE][i + MAXSIZEX * FIRSTZ].face);
1176
1233
                        }
1177
1234
                        glTranslatef(S1, 0, 0);
1178
 
                        draw_cubit(mi,
 
1235
                        DRAW_CUBIT(mi,
1179
1236
                                   rp->cubeLoc[BACK_FACE][LASTX + MAXSIZEX * LASTY].face, NO_FACE,
1180
1237
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][LASTZ + MAXSIZEZ * FIRSTY].face,
1181
1238
                                   NO_FACE, rp->cubeLoc[TOP_FACE][LASTX + MAXSIZEX * FIRSTZ].face);
1185
1242
                                if (slice.depth == REVZ(k))
1186
1243
                                        glRotatef(rotatestep, 0, 0, HALFZ);
1187
1244
                                glTranslatef(-HALFX, -HALFY, MIDZ(k));
1188
 
                                draw_cubit(mi,
 
1245
                                DRAW_CUBIT(mi,
1189
1246
                                           NO_FACE, NO_FACE,
1190
1247
                                           rp->cubeLoc[LEFT_FACE][k + MAXSIZEZ * LASTY].face, NO_FACE,
1191
1248
                                           rp->cubeLoc[BOTTOM_FACE][FIRSTX + MAXSIZEX * REVZ(k)].face, NO_FACE);
1192
1249
                                for (i = 1; i < MAXSIZEX - 1; i++) {
1193
1250
                                        glTranslatef(S1, 0, 0);
1194
 
                                        draw_cubit(mi,
 
1251
                                        DRAW_CUBIT(mi,
1195
1252
                                                   NO_FACE, NO_FACE,
1196
1253
                                                   NO_FACE, NO_FACE,
1197
1254
                                                   rp->cubeLoc[BOTTOM_FACE][i + MAXSIZEX * REVZ(k)].face, NO_FACE);
1198
1255
                                }
1199
1256
                                glTranslatef(S1, 0, 0);
1200
 
                                draw_cubit(mi,
 
1257
                                DRAW_CUBIT(mi,
1201
1258
                                           NO_FACE, NO_FACE,
1202
1259
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][REVZ(k) + MAXSIZEZ * LASTY].face,
1203
1260
                                           rp->cubeLoc[BOTTOM_FACE][LASTX + MAXSIZEX * REVZ(k)].face, NO_FACE);
1204
1261
                                for (j = 1; j < MAXSIZEY - 1; j++) {
1205
1262
                                        glTranslatef(-SX, S1, 0);
1206
 
                                        draw_cubit(mi,
 
1263
                                        DRAW_CUBIT(mi,
1207
1264
                                                   NO_FACE, NO_FACE,
1208
1265
                                                   rp->cubeLoc[LEFT_FACE][k + MAXSIZEZ * REVY(j)].face, NO_FACE,
1209
1266
                                                   NO_FACE, NO_FACE);
1210
1267
                                        /* Center */
1211
1268
                                        glTranslatef(SX, 0, 0);
1212
 
                                        draw_cubit(mi,
 
1269
                                        DRAW_CUBIT(mi,
1213
1270
                                                   NO_FACE, NO_FACE,
1214
1271
                                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][REVZ(k) + MAXSIZEZ * REVY(j)].face,
1215
1272
                                                   NO_FACE, NO_FACE);
1216
1273
                                }
1217
1274
                                glTranslatef(-SX, S1, 0);
1218
 
                                draw_cubit(mi,
 
1275
                                DRAW_CUBIT(mi,
1219
1276
                                           NO_FACE, NO_FACE,
1220
1277
                                           rp->cubeLoc[LEFT_FACE][k + MAXSIZEZ * FIRSTY].face, NO_FACE,
1221
1278
                                           NO_FACE, rp->cubeLoc[TOP_FACE][FIRSTX + MAXSIZEX * k].face);
1222
1279
                                for (i = 1; i < MAXSIZEX - 1; i++) {
1223
1280
                                        glTranslatef(S1, 0, 0);
1224
 
                                        draw_cubit(mi,
 
1281
                                        DRAW_CUBIT(mi,
1225
1282
                                                   NO_FACE, NO_FACE,
1226
1283
                                                   NO_FACE, NO_FACE,
1227
1284
                                                   NO_FACE, rp->cubeLoc[TOP_FACE][i + MAXSIZEX * k].face);
1228
1285
                                }
1229
1286
                                glTranslatef(S1, 0, 0);
1230
 
                                draw_cubit(mi,
 
1287
                                DRAW_CUBIT(mi,
1231
1288
                                           NO_FACE, NO_FACE,
1232
1289
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][REVZ(k) + MAXSIZEZ * FIRSTY].face,
1233
1290
                                           NO_FACE, rp->cubeLoc[TOP_FACE][LASTX + MAXSIZEX * k].face);
1236
1293
                        if (slice.depth == 0)
1237
1294
                                glRotatef(rotatestep, 0, 0, HALFZ);
1238
1295
                        glTranslatef(-HALFX, -HALFY, HALFZ);
1239
 
                        draw_cubit(mi,
 
1296
                        DRAW_CUBIT(mi,
1240
1297
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][FIRSTX + MAXSIZEX * LASTY].face,
1241
1298
                                   rp->cubeLoc[LEFT_FACE][LASTZ + MAXSIZEZ * LASTY].face, NO_FACE,
1242
1299
                                   rp->cubeLoc[BOTTOM_FACE][FIRSTX + MAXSIZEX * FIRSTZ].face, NO_FACE);
1243
1300
                        for (i = 1; i < MAXSIZEX - 1; i++) {
1244
1301
                                glTranslatef(S1, 0, 0);
1245
 
                                draw_cubit(mi,
 
1302
                                DRAW_CUBIT(mi,
1246
1303
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][i + MAXSIZEX * LASTY].face,
1247
1304
                                           NO_FACE, NO_FACE,
1248
1305
                                           rp->cubeLoc[BOTTOM_FACE][i + MAXSIZEX * FIRSTZ].face, NO_FACE);
1249
1306
                        }
1250
1307
                        glTranslatef(S1, 0, 0);
1251
 
                        draw_cubit(mi,
 
1308
                        DRAW_CUBIT(mi,
1252
1309
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][LASTX + MAXSIZEX * LASTY].face,
1253
1310
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][FIRSTZ + MAXSIZEZ * LASTY].face,
1254
1311
                                   rp->cubeLoc[BOTTOM_FACE][LASTX + MAXSIZEX * FIRSTZ].face, NO_FACE);
1255
1312
                        for (j = 1; j < MAXSIZEY - 1; j++) {
1256
1313
                                glTranslatef(-SX, S1, 0);
1257
 
                                draw_cubit(mi,
 
1314
                                DRAW_CUBIT(mi,
1258
1315
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][FIRSTX + MAXSIZEX * REVY(j)].face,
1259
1316
                                           rp->cubeLoc[LEFT_FACE][LASTZ + MAXSIZEZ * REVY(j)].face, NO_FACE,
1260
1317
                                           NO_FACE, NO_FACE);
1261
1318
                                for (i = 1; i < MAXSIZEX - 1; i++) {
1262
1319
                                        glTranslatef(S1, 0, 0);
1263
 
                                        draw_cubit(mi,
 
1320
                                        DRAW_CUBIT(mi,
1264
1321
                                                   NO_FACE, rp->cubeLoc[FRONT_FACE][i + MAXSIZEX * REVY(j)].face,
1265
1322
                                                   NO_FACE, NO_FACE,
1266
1323
                                                   NO_FACE, NO_FACE);
1267
1324
                                }
1268
1325
                                glTranslatef(S1, 0, 0);
1269
 
                                draw_cubit(mi,
 
1326
                                DRAW_CUBIT(mi,
1270
1327
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][LASTX + MAXSIZEX * REVY(j)].face,
1271
1328
                                           NO_FACE, rp->cubeLoc[RIGHT_FACE][FIRSTZ + MAXSIZEZ * REVY(j)].face,
1272
1329
                                           NO_FACE, NO_FACE);
1273
1330
                        }
1274
1331
                        glTranslatef(-SX, S1, 0);
1275
 
                        draw_cubit(mi,
 
1332
                        DRAW_CUBIT(mi,
1276
1333
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][FIRSTX + MAXSIZEX * FIRSTY].face,
1277
1334
                                   rp->cubeLoc[LEFT_FACE][LASTZ + MAXSIZEZ * FIRSTY].face, NO_FACE,
1278
1335
                                   NO_FACE, rp->cubeLoc[TOP_FACE][FIRSTX + MAXSIZEX * LASTZ].face);
1279
1336
                        for (i = 1; i < MAXSIZEX - 1; i++) {
1280
1337
                                glTranslatef(S1, 0, 0);
1281
 
                                draw_cubit(mi,
 
1338
                                DRAW_CUBIT(mi,
1282
1339
                                           NO_FACE, rp->cubeLoc[FRONT_FACE][i + MAXSIZEX * FIRSTY].face,
1283
1340
                                           NO_FACE, NO_FACE,
1284
1341
                                           NO_FACE, rp->cubeLoc[TOP_FACE][i + MAXSIZEX * LASTZ].face);
1285
1342
                        }
1286
1343
                        glTranslatef(S1, 0, 0);
1287
 
                        draw_cubit(mi,
 
1344
                        DRAW_CUBIT(mi,
1288
1345
                                   NO_FACE, rp->cubeLoc[FRONT_FACE][LASTX + MAXSIZEX * FIRSTY].face,
1289
1346
                                   NO_FACE, rp->cubeLoc[RIGHT_FACE][FIRSTZ + MAXSIZEZ * FIRSTY].face,
1290
1347
                                   NO_FACE, rp->cubeLoc[TOP_FACE][LASTX + MAXSIZEX * LASTZ].face);
1291
1348
                        break;
1292
1349
        }
 
1350
        return True;
1293
1351
#undef S1
1294
1352
}
1295
1353
 
1297
1355
static void
1298
1356
readRC(rubikstruct * rp, int face, int dir, int h, int orient, int size)
1299
1357
{
1300
 
        int         g;
 
1358
        int         g, sizeOfRow;
1301
1359
 
 
1360
        sizeOfRow = sizeRow(rp, face);
1302
1361
        if (dir == TOP || dir == BOTTOM)
1303
1362
                for (g = 0; g < size; g++)
1304
1363
                        rp->rowLoc[orient][g] =
1305
 
                                rp->cubeLoc[face][g * size + h];
 
1364
                                rp->cubeLoc[face][g * sizeOfRow + h];
1306
1365
        else                    /* dir == RIGHT || dir == LEFT */
1307
1366
                for (g = 0; g < size; g++)
1308
1367
                        rp->rowLoc[orient][g] =
1309
 
                                rp->cubeLoc[face][h * size + g];
 
1368
                                rp->cubeLoc[face][h * sizeOfRow + g];
1310
1369
}
1311
1370
 
1312
1371
static void
1335
1394
static void
1336
1395
writeRC(rubikstruct * rp, int face, int dir, int h, int orient, int size)
1337
1396
{
1338
 
        int         g, position;
 
1397
        int         g, position, sizeOfRow;
1339
1398
 
 
1399
        sizeOfRow = sizeRow(rp, face);
1340
1400
        if (dir == TOP || dir == BOTTOM) {
1341
1401
                for (g = 0; g < size; g++) {
1342
 
                        position = g * size + h;
 
1402
                        position = g * sizeOfRow + h;
1343
1403
                        rp->cubeLoc[face][position] = rp->rowLoc[orient][g];
1344
1404
                        /* DrawSquare(face, position); */
1345
1405
                }
1346
1406
        } else {                /* dir == RIGHT || dir == LEFT */
1347
1407
                for (g = 0; g < size; g++) {
1348
 
                        position = h * size + g;
 
1408
                        position = h * sizeOfRow + g;
1349
1409
                        rp->cubeLoc[face][position] = rp->rowLoc[orient][g];
1350
1410
                        /* DrawSquare(face, position); */
1351
1411
                }
1352
1412
        }
1353
1413
}
1354
1414
 
1355
 
static void
 
1415
static Bool
1356
1416
rotateFace(rubikstruct * rp, int face, int direction)
1357
1417
{
1358
 
        int         position, i, j;
1359
 
        RubikLoc   *faceLoc = NULL;
 
1418
        int         position, i, j, sizeOfRow, sizeOfColumn, sizeOnPlane;
 
1419
        RubikLoc   *faceLoc;
1360
1420
 
1361
 
        if ((faceLoc = (RubikLoc *) malloc(AVSIZESQ * sizeof (RubikLoc))) == NULL)
1362
 
                (void) fprintf(stderr,
1363
 
                 "Could not allocate memory for rubik face position info\n");
 
1421
        faceSizes(rp, face, &sizeOfRow, &sizeOfColumn);
 
1422
        sizeOnPlane = sizeOfRow * sizeOfColumn;
 
1423
        if ((faceLoc = (RubikLoc *) malloc(sizeOnPlane *
 
1424
                        sizeof (RubikLoc))) == NULL) {
 
1425
                return False;
 
1426
        }
1364
1427
        /* Read Face */
1365
 
        for (position = 0; position < AVSIZESQ; position++)
 
1428
        for (position = 0; position < sizeOnPlane; position++)
1366
1429
                faceLoc[position] = rp->cubeLoc[face][position];
1367
1430
        /* Write Face */
1368
 
        for (position = 0; position < AVSIZESQ; position++) {
1369
 
                i = position % AVSIZE;
1370
 
                j = position / AVSIZE;
1371
 
                rp->cubeLoc[face][position] = (direction == CW) ?
1372
 
                        faceLoc[(AVSIZE - i - 1) * AVSIZE + j] :
1373
 
                        faceLoc[i * AVSIZE + AVSIZE - j - 1];
 
1431
        for (position = 0; position < sizeOnPlane; position++) {
 
1432
                i = position % sizeOfRow;
 
1433
                j = position / sizeOfRow;
 
1434
                if (direction == CW)
 
1435
                        rp->cubeLoc[face][position] =
 
1436
                                faceLoc[(sizeOfRow - i - 1) * sizeOfRow + j];
 
1437
                else if (direction == CCW)
 
1438
                        rp->cubeLoc[face][position] =
 
1439
                                faceLoc[i * sizeOfRow + sizeOfColumn - j - 1];
 
1440
                else /* (direction == HALF) */
 
1441
                        rp->cubeLoc[face][position] =
 
1442
                                faceLoc[sizeOfRow - i - 1 + (sizeOfColumn - j - 1) * sizeOfRow];
1374
1443
                rp->cubeLoc[face][position].rotation =
1375
 
                        (rp->cubeLoc[face][position].rotation + direction - MAXORIENT) %
1376
 
                        MAXORIENT;
 
1444
                        (rp->cubeLoc[face][position].rotation +
 
1445
                                direction - MAXORIENT) % MAXORIENT;
1377
1446
                /* DrawSquare(face, position); */
1378
1447
        }
1379
1448
        if (faceLoc != NULL)
1380
1449
                (void) free((void *) faceLoc);
 
1450
        return True;
1381
1451
}
1382
1452
 
 
1453
/* Yeah this is big and ugly */
1383
1454
static void
 
1455
slideRC(int face, int direction, int h, int sizeOnOppAxis,
 
1456
        int *newFace, int *newDirection, int *newH,
 
1457
        int *rotate, Bool *reverse)
 
1458
{
 
1459
        *newFace = slideNextRow[face][direction].face;
 
1460
        *rotate = slideNextRow[face][direction].rotation;
 
1461
        *newDirection = (*rotate + direction) % MAXORIENT;
 
1462
        switch (*rotate) {
 
1463
                case TOP:
 
1464
                        *newH = h;
 
1465
                        *reverse = False;
 
1466
                        break;
 
1467
                case RIGHT:
 
1468
                        if (*newDirection == TOP || *newDirection == BOTTOM) {
 
1469
                                *newH = sizeOnOppAxis - 1 - h;
 
1470
                                *reverse = False;
 
1471
                        } else {        /* *newDirection == RIGHT || *newDirection == LEFT */
 
1472
                                *newH = h;
 
1473
                                *reverse = True;
 
1474
                        }
 
1475
                                break;
 
1476
                case BOTTOM:
 
1477
                        *newH = sizeOnOppAxis - 1 - h;
 
1478
                        *reverse = True;
 
1479
                        break;
 
1480
                case LEFT:
 
1481
                        if (*newDirection == TOP || *newDirection == BOTTOM) {
 
1482
                                *newH = h;
 
1483
                                *reverse = True;
 
1484
                        } else {        /* *newDirection == RIGHT || *newDirection == LEFT */
 
1485
                                *newH = sizeOnOppAxis - 1 - h;
 
1486
                                *reverse = False;
 
1487
                        }
 
1488
                        break;
 
1489
                default:
 
1490
                        (void) printf("slideRC: rotate %d\n", *rotate);
 
1491
                        *newH = 0;
 
1492
                        *reverse = False;
 
1493
        }
 
1494
}
 
1495
 
 
1496
static Bool
1384
1497
moveRubik(rubikstruct * rp, int face, int direction, int position)
1385
1498
{
1386
 
        int         newFace, newDirection, rotate, reverse = False;
1387
 
        int         h, k, newH = 0;
1388
 
        int         i, j;
 
1499
        int         newFace, newDirection, rotate, reverse; 
 
1500
        int         h, k, newH;
 
1501
        int         i, j, sizeOfRow, sizeOfColumn, sizeOnAxis, sizeOnOppAxis;
1389
1502
 
 
1503
        faceSizes(rp, face, &sizeOfRow, &sizeOfColumn);
1390
1504
        if (direction == CW || direction == CCW) {
1391
1505
                direction = (direction == CCW) ?
1392
1506
                        (rotateToRow[face].direction + 2) % MAXORIENT :
1393
1507
                        rotateToRow[face].direction;
1394
 
                i = j = (rotateToRow[face].sideFace == RIGHT ||
1395
 
                      rotateToRow[face].sideFace == BOTTOM) ? AVSIZE - 1 : 0;
 
1508
                if (rotateToRow[face].sideFace == RIGHT) {
 
1509
                        i = j = sizeOfColumn - 1;
 
1510
                } else if (rotateToRow[face].sideFace == BOTTOM) {
 
1511
                        i = j = sizeOfRow - 1;
 
1512
                } else {
 
1513
                        i = j = 0;
 
1514
                }
1396
1515
                face = rotateToRow[face].face;
1397
 
                position = j * AVSIZE + i;
 
1516
                position = j * sizeOfRow + i;
1398
1517
        }
1399
 
        i = position % AVSIZE;
1400
 
        j = position / AVSIZE;
 
1518
        i = position % sizeOfRow;
 
1519
        j = position / sizeOfRow;
1401
1520
        h = (direction == TOP || direction == BOTTOM) ? i : j;
1402
 
        /* rotate sides CW or CCW */
1403
 
        if (h == AVSIZE - 1) {
 
1521
        if (direction == TOP || direction == BOTTOM) {
 
1522
                sizeOnAxis = sizeOfColumn;
 
1523
                sizeOnOppAxis = sizeOfRow;
 
1524
        } else {
 
1525
                sizeOnAxis = sizeOfRow;
 
1526
                sizeOnOppAxis = sizeOfColumn;
 
1527
        }
 
1528
        /* rotate sides CW or CCW or HALF) */
 
1529
 
 
1530
        if (h == sizeOnOppAxis - 1) {
1404
1531
                newDirection = (direction == TOP || direction == BOTTOM) ?
1405
1532
                        TOP : RIGHT;
1406
 
                if (direction == TOP || direction == RIGHT)
1407
 
                        rotateFace(rp, rowToRotate[face][newDirection], CW);
1408
 
                else            /* direction == BOTTOM || direction == LEFT */
1409
 
                        rotateFace(rp, rowToRotate[face][newDirection], CCW);
 
1533
                if (rp->degreeTurn == 180) {
 
1534
                        if (!rotateFace(rp, rowToRotate[face][newDirection], HALF))
 
1535
                                return False;
 
1536
                } else if (direction == TOP || direction == RIGHT) {
 
1537
                        if (!rotateFace(rp, rowToRotate[face][newDirection], CW))
 
1538
                                return False;
 
1539
                } else {                /* direction == BOTTOM || direction == LEFT */
 
1540
                        if (!rotateFace(rp, rowToRotate[face][newDirection], CCW))
 
1541
                                return False;
 
1542
                }
1410
1543
        }
1411
1544
        if (h == 0) {
1412
1545
                newDirection = (direction == TOP || direction == BOTTOM) ?
1413
1546
                        BOTTOM : LEFT;
1414
 
                if (direction == TOP || direction == RIGHT)
1415
 
                        rotateFace(rp, rowToRotate[face][newDirection], CCW);
1416
 
                else            /* direction == BOTTOM  || direction == LEFT */
1417
 
                        rotateFace(rp, rowToRotate[face][newDirection], CW);
 
1547
                if (rp->degreeTurn == 180) {
 
1548
                        if (!rotateFace(rp, rowToRotate[face][newDirection], HALF))
 
1549
                                return False;
 
1550
                } else if (direction == TOP || direction == RIGHT) {
 
1551
                        if (!rotateFace(rp, rowToRotate[face][newDirection], CCW))
 
1552
                                return False;
 
1553
                } else {                /* direction == BOTTOM  || direction == LEFT */
 
1554
                        if (!rotateFace(rp, rowToRotate[face][newDirection], CW))
 
1555
                                return False;
 
1556
                }
1418
1557
        }
1419
 
        /* Slide rows */
1420
 
        readRC(rp, face, direction, h, 0, AVSIZE);
1421
 
        for (k = 1; k <= MAXORIENT; k++) {
1422
 
                newFace = slideNextRow[face][direction].face;
1423
 
                rotate = slideNextRow[face][direction].rotation;
1424
 
                newDirection = (rotate + direction) % MAXORIENT;
1425
 
                switch (rotate) {
1426
 
                        case TOP:
1427
 
                                newH = h;
1428
 
                                reverse = False;
1429
 
                                break;
1430
 
                        case RIGHT:
1431
 
                                if (newDirection == TOP || newDirection == BOTTOM) {
1432
 
                                        newH = AVSIZE - 1 - h;
1433
 
                                        reverse = False;
1434
 
                                } else {        /* newDirection == RIGHT || newDirection == LEFT */
1435
 
                                        newH = h;
1436
 
                                        reverse = True;
1437
 
                                }
1438
 
                                break;
1439
 
                        case BOTTOM:
1440
 
                                newH = AVSIZE - 1 - h;
1441
 
                                reverse = True;
1442
 
                                break;
1443
 
                        case LEFT:
1444
 
                                if (newDirection == TOP || newDirection == BOTTOM) {
1445
 
                                        newH = h;
1446
 
                                        reverse = True;
1447
 
                                } else {        /* newDirection == RIGHT || newDirection == LEFT */
1448
 
                                        newH = AVSIZE - 1 - h;
1449
 
                                        reverse = False;
1450
 
                                }
1451
 
                                break;
1452
 
                        default:
1453
 
                                (void) printf("moveRubik: rotate %d\n", rotate);
1454
 
                }
1455
 
                if (k != MAXORIENT)
1456
 
                        readRC(rp, newFace, newDirection, newH, k, AVSIZE);
1457
 
                rotateRC(rp, rotate, k - 1, AVSIZE);
 
1558
        /* Slide rows or columns */
 
1559
        readRC(rp, face, direction, h, 0, sizeOnAxis);
 
1560
        if (rp->degreeTurn == 180) {
 
1561
                int sizeOnDepthAxis;
 
1562
 
 
1563
                slideRC(face, direction, h, sizeOnOppAxis,
 
1564
                        &newFace, &newDirection, &newH, &rotate, &reverse);
 
1565
                sizeOnDepthAxis = sizeFace(rp, newFace) / sizeOnOppAxis;
 
1566
                readRC(rp, newFace, newDirection, newH, 1, sizeOnDepthAxis);
 
1567
                rotateRC(rp, rotate, 0, sizeOnAxis);
1458
1568
                if (reverse == True)
1459
 
                        reverseRC(rp, k - 1, AVSIZE);
1460
 
                writeRC(rp, newFace, newDirection, newH, k - 1, AVSIZE);
 
1569
                        reverseRC(rp, 0, sizeOnAxis);
1461
1570
                face = newFace;
1462
1571
                direction = newDirection;
1463
1572
                h = newH;
1464
 
        }
 
1573
                for (k = 2; k <= MAXORIENT + 1; k++) {
 
1574
                        slideRC(face, direction, h, sizeOnOppAxis,
 
1575
                                &newFace, &newDirection, &newH, &rotate, &reverse);
 
1576
                        if (k != MAXORIENT && k != MAXORIENT + 1)
 
1577
                                readRC(rp, newFace, newDirection, newH, k,
 
1578
                                        (k % 2) ? sizeOnDepthAxis : sizeOnAxis);
 
1579
                        rotateRC(rp, rotate, k - 2,
 
1580
                                        (k % 2) ? sizeOnDepthAxis : sizeOnAxis);
 
1581
                        if (k != MAXORIENT + 1)
 
1582
                                rotateRC(rp, rotate, k - 1,
 
1583
                                        (k % 2) ? sizeOnAxis : sizeOnDepthAxis);
 
1584
                        if (reverse == True) {
 
1585
                                reverseRC(rp, k - 2,
 
1586
                                        (k % 2) ? sizeOnDepthAxis : sizeOnAxis);
 
1587
                                if (k != MAXORIENT + 1)
 
1588
                                        reverseRC(rp, k - 1,
 
1589
                                                (k % 2) ? sizeOnAxis : sizeOnDepthAxis);
 
1590
                        }
 
1591
                        writeRC(rp, newFace, newDirection, newH, k - 2,
 
1592
                                (k % 2) ? sizeOnDepthAxis : sizeOnAxis);
 
1593
                        face = newFace;
 
1594
                        direction = newDirection;
 
1595
                        h = newH;
 
1596
                }
 
1597
        } else {
 
1598
                for (k = 1; k <= MAXORIENT; k++) {
 
1599
                        slideRC(face, direction, h, sizeOnOppAxis,
 
1600
                                &newFace, &newDirection, &newH, &rotate, &reverse);
 
1601
                        if (k != MAXORIENT)
 
1602
                                readRC(rp, newFace, newDirection, newH, k, sizeOnAxis);
 
1603
                        rotateRC(rp, rotate, k - 1, sizeOnAxis);
 
1604
                        if (reverse == True)
 
1605
                                reverseRC(rp, k - 1, sizeOnAxis);
 
1606
                        writeRC(rp, newFace, newDirection, newH, k - 1, sizeOnAxis);
 
1607
                        face = newFace;
 
1608
                        direction = newDirection;
 
1609
                        h = newH;
 
1610
                }
 
1611
        }       
 
1612
        return True;
1465
1613
}
1466
1614
 
1467
1615
#ifdef DEBUG
1468
1616
void
1469
1617
printCube(rubikstruct * rp)
1470
1618
{
1471
 
        int         face, position;
 
1619
        int         face, position, sizeOfRow, sizeOfColumn;
1472
1620
 
1473
1621
        for (face = 0; face < MAXFACES; face++) {
1474
 
                for (position = 0; position < AVSIZESQ; position++) {
 
1622
                faceSizes(rp, face, &sizeOfRow, &sizeOfColumn);
 
1623
                for (position = 0; position < sizeOfRow * sizeOfColumn; position++) {
1475
1624
                        (void) printf("%d %d  ", rp->cubeLoc[face][position].face,
1476
1625
                                      rp->cubeLoc[face][position].rotation);
1477
 
                        if (!((position + 1) % AVSIZE))
 
1626
                        if (!((position + 1) % sizeOfRow))
1478
1627
                                (void) printf("\n");
1479
1628
                }
1480
1629
                (void) printf("\n");
1484
1633
 
1485
1634
#endif
1486
1635
 
1487
 
static void
 
1636
static Bool
1488
1637
evalmovement(ModeInfo * mi, RubikMove movement)
1489
1638
{
1490
1639
        rubikstruct *rp = &rubik[MI_SCREEN(mi)];
1493
1642
        printCube(rp);
1494
1643
#endif
1495
1644
        if (movement.face < 0 || movement.face >= MAXFACES)
1496
 
                return;
1497
 
 
1498
 
        moveRubik(rp, movement.face, movement.direction, movement.position);
1499
 
 
 
1645
                return True;
 
1646
        if (!moveRubik(rp, movement.face, movement.direction, movement.position))
 
1647
                return False;
 
1648
        return True;
1500
1649
}
1501
1650
 
1502
1651
static      Bool
1504
1653
{
1505
1654
        RubikSlice  slice1, slice2;
1506
1655
 
1507
 
        slice1 = convertMove(rp, move1);
1508
 
        slice2 = convertMove(rp, move2);
 
1656
        convertMove(rp, move1, &slice1);
 
1657
        convertMove(rp, move2, &slice2);
1509
1658
        if (slice1.face == slice2.face &&
1510
1659
            slice1.depth == slice2.depth) {
1511
1660
                if (slice1.rotation == slice2.rotation) {       /* CW or CCW */
1519
1668
        return False;
1520
1669
}
1521
1670
 
1522
 
static void
 
1671
static Bool
1523
1672
shuffle(ModeInfo * mi)
1524
1673
{
1525
1674
        rubikstruct *rp = &rubik[MI_SCREEN(mi)];
1526
1675
        int         i, face, position;
1527
1676
        RubikMove   move;
1528
1677
 
1529
 
        AVSIZE = MI_SIZE(mi);
1530
 
        if (AVSIZE < -MINSIZE)
1531
 
                AVSIZE = NRAND(-AVSIZE - MINSIZE + 1) + MINSIZE;
1532
 
        else if (AVSIZE < MINSIZE)
1533
 
                AVSIZE = MINSIZE;
1534
 
        /* Let me waste a little space for the moment */
1535
 
        /* Future cube to be LxMxN and not just NxNxN, but not done yet */
1536
 
        AVSIZESQ = AVSIZE * AVSIZE;
1537
 
#ifdef LMN
1538
 
        MAXSIZEX = AVSIZE;
1539
 
        MAXSIZEY = AVSIZE;
1540
 
        MAXSIZEZ = AVSIZE;
1541
 
        MAXSIZE = AVSIZE;
1542
 
        MAXSIZESQ = AVSIZESQ;
1543
 
#endif
 
1678
        if (sizex)
 
1679
                i = sizex;
 
1680
        else
 
1681
                i = MI_SIZE(mi);
 
1682
        if (i < -MINSIZE)
 
1683
                i = NRAND(-i - MINSIZE + 1) + MINSIZE;
 
1684
        else if (i < MINSIZE)
 
1685
                i = MINSIZE;
 
1686
 
 
1687
        if (LRAND() % 2 && !sizey && !sizez) { /* Make normal (NxNxN) cubes more likely */
 
1688
                MAXSIZEX = MAXSIZEY = MAXSIZEZ = i;
 
1689
        } else {
 
1690
                MAXSIZEX = i;
 
1691
                if (sizey)
 
1692
                        i = sizey;
 
1693
                else
 
1694
                        i = MI_SIZE(mi);
 
1695
                if (i < -MINSIZE)
 
1696
                        i = NRAND(-i - MINSIZE + 1) + MINSIZE;
 
1697
                else if (i < MINSIZE)
 
1698
                        i = MINSIZE;
 
1699
                if (LRAND() % 2 && !sizez) { /* Make more MxNxN more likely than LxMxN */
 
1700
                        MAXSIZEY = MAXSIZEZ = i;
 
1701
                } else {
 
1702
                        MAXSIZEY = i;
 
1703
                        if (sizez)
 
1704
                                i = sizez;
 
1705
                        else
 
1706
                                i = MI_SIZE(mi);
 
1707
                        if (i < -MINSIZE)
 
1708
                                i = NRAND(-i - MINSIZE + 1) + MINSIZE;
 
1709
                        else if (i < MINSIZE)
 
1710
                                i = MINSIZE;
 
1711
                        MAXSIZEZ = i;
 
1712
                }
 
1713
        }
1544
1714
 
1545
1715
        for (face = 0; face < MAXFACES; face++) {
1546
1716
                if (rp->cubeLoc[face] != NULL)
1547
1717
                        (void) free((void *) rp->cubeLoc[face]);
1548
 
                if ((rp->cubeLoc[face] =
1549
 
                  (RubikLoc *) malloc(AVSIZESQ * sizeof (RubikLoc))) == NULL)
1550
 
                        (void) fprintf(stderr,
1551
 
                                       "Could not allocate memory for rubik cube position info\n");
1552
 
                for (position = 0; position < AVSIZESQ; position++) {
 
1718
                if ((rp->cubeLoc[face] = (RubikLoc *) malloc(sizeFace(rp, face) *
 
1719
                                sizeof (RubikLoc))) == NULL) {
 
1720
                        return False;
 
1721
                }
 
1722
                for (position = 0; position < sizeFace(rp, face); position++) {
1553
1723
                        rp->cubeLoc[face][position].face = face;
1554
1724
                        rp->cubeLoc[face][position].rotation = TOP;
1555
1725
                }
1557
1727
        for (i = 0; i < MAXORIENT; i++) {
1558
1728
                if (rp->rowLoc[i] != NULL)
1559
1729
                        (void) free((void *) rp->rowLoc[i]);
1560
 
                if ((rp->rowLoc[i] =
1561
 
                     (RubikLoc *) malloc(AVSIZE * sizeof (RubikLoc))) == NULL)
1562
 
                        (void) fprintf(stderr,
1563
 
                                       "Could not allocate memory for rubik row position info\n");
 
1730
                /* The following is reused so make it the biggest size */
 
1731
                if ((rp->rowLoc[i] = (RubikLoc *) malloc(MAXMAXSIZE *
 
1732
                                sizeof (RubikLoc))) == NULL) {
 
1733
                        return False;
 
1734
                }
1564
1735
        }
1565
1736
        rp->storedmoves = MI_COUNT(mi);
1566
1737
        if (rp->storedmoves < 0) {
1567
1738
                if (rp->moves != NULL)
1568
1739
                        (void) free((void *) rp->moves);
1569
 
                rp->moves = NULL;
 
1740
                rp->moves = (RubikMove *) NULL;
1570
1741
                rp->storedmoves = NRAND(-rp->storedmoves) + 1;
1571
1742
        }
1572
1743
        if ((rp->storedmoves) && (rp->moves == NULL))
1573
 
                if ((rp->moves =
1574
 
                     (RubikMove *) calloc(rp->storedmoves + 1, sizeof (RubikMove))) == NULL)
1575
 
                        (void) fprintf(stderr,
1576
 
                        "Could not allocate memory for rubik move buffer\n");
1577
 
 
 
1744
                if ((rp->moves = (RubikMove *) calloc(rp->storedmoves + 1,
 
1745
                                 sizeof (RubikMove))) == NULL) {
 
1746
                        return False;
 
1747
                }
1578
1748
        if (MI_CYCLES(mi) <= 1) {
1579
1749
                rp->anglestep = 90.0;
1580
1750
        } else {
1582
1752
        }
1583
1753
 
1584
1754
        for (i = 0; i < rp->storedmoves; i++) {
1585
 
                int         condition;
 
1755
                Bool condition;
1586
1756
 
1587
1757
                do {
1588
 
                        move.face = NRAND(6);
1589
 
                        move.direction = NRAND(4);      /* Exclude CW and CCW, its ok */
1590
 
                        /*
1591
 
                         * Randomize position along diagonal, each plane gets an equal chance.
1592
 
                         * This trick will only work for NxNxN cubes
1593
 
                         * draw_cube DEPENDS on that they are chosen this way.
1594
 
                         */
1595
 
                        move.position = NRAND(AVSIZE) * (AVSIZE + 1);
1596
 
 
1597
 
 
1598
 
                        condition = 1;
1599
 
 
1600
 
                        if (i > 0)      /* avoid immediate undoing moves */
 
1758
                        move.face = NRAND(MAXFACES);
 
1759
                        move.direction = NRAND(MAXORIENT);      /* Exclude CW and CCW, its ok */
 
1760
                        move.position = NRAND(sizeFace(rp, move.face));
 
1761
                        rp->degreeTurn = (checkFaceSquare(rp,
 
1762
                                rowToRotate[move.face][move.direction])) ? 90 : 180;
 
1763
                        condition = True;
 
1764
                        if (i > 0) {    /* avoid immediate undoing moves */
1601
1765
                                if (compare_moves(rp, move, rp->moves[i - 1], True))
1602
 
                                        condition = 0;
 
1766
                                        condition = False;
 
1767
                                if (rp->degreeTurn == 180 &&
 
1768
                                    compare_moves(rp, move, rp->moves[i - 1], False))
 
1769
                                        condition = False;
 
1770
                        }
1603
1771
                        if (i > 1)      /* avoid 3 consecutive identical moves */
1604
1772
                                if (compare_moves(rp, move, rp->moves[i - 1], False) &&
1605
1773
                                    compare_moves(rp, move, rp->moves[i - 2], False))
1606
 
                                        condition = 0;
 
1774
                                        condition = False;
1607
1775
                        /*
1608
 
                           * Still some silly moves being made....
 
1776
                         * Still some silly moves being made....
1609
1777
                         */
1610
1778
                } while (!condition);
1611
1779
                if (hideshuffling)
1612
 
                        evalmovement(mi, move);
 
1780
                        if (!evalmovement(mi, move))
 
1781
                                return False;
1613
1782
                rp->moves[i] = move;
1614
1783
        }
1615
 
 
 
1784
        rp->VX = 0.05;
 
1785
        if (NRAND(100) < 50)
 
1786
                rp->VX *= -1;
 
1787
        rp->VY = 0.05;
 
1788
        if (NRAND(100) < 50)
 
1789
                rp->VY *= -1;
1616
1790
        rp->movement.face = NO_FACE;
1617
1791
        rp->rotatestep = 0;
1618
1792
        rp->action = hideshuffling ? ACTION_SOLVE : ACTION_SHUFFLE;
1619
1793
        rp->shufflingmoves = 0;
1620
1794
        rp->done = 0;
 
1795
        return True;
1621
1796
}
1622
1797
 
1623
1798
void
1624
 
reshape_rubik(ModeInfo * mi, int width, int height)
 
1799
reshape(ModeInfo * mi, int width, int height)
1625
1800
{
1626
1801
        rubikstruct *rp = &rubik[MI_SCREEN(mi)];
1627
1802
 
1631
1806
        glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0);
1632
1807
        glMatrixMode(GL_MODELVIEW);
1633
1808
 
1634
 
        rp->AreObjectsDefined[ObjCubit] = 0;
1635
1809
}
1636
1810
 
1637
 
static void
 
1811
static Bool
1638
1812
pinit(ModeInfo * mi)
1639
1813
{
1640
1814
        glClearDepth(1.0);
1660
1834
        glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
1661
1835
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
1662
1836
 
1663
 
        shuffle(mi);
 
1837
        return (shuffle(mi));
 
1838
}
 
1839
 
 
1840
static void
 
1841
free_rubik(rubikstruct *rp)
 
1842
{
 
1843
        int         i;
 
1844
 
 
1845
        for (i = 0; i < MAXFACES; i++)
 
1846
                if (rp->cubeLoc[i] != NULL) {
 
1847
                        (void) free((void *) rp->cubeLoc[i]);
 
1848
                        rp->cubeLoc[i] = (RubikLoc *) NULL;
 
1849
                }
 
1850
        for (i = 0; i < MAXORIENT; i++)
 
1851
                if (rp->rowLoc[i] != NULL) {
 
1852
                        (void) free((void *) rp->rowLoc[i]);
 
1853
                        rp->rowLoc[i] = (RubikLoc *) NULL;
 
1854
                }
 
1855
        if (rp->moves != NULL) {
 
1856
                (void) free((void *) rp->moves);
 
1857
                rp->moves = (RubikMove *) NULL;
 
1858
        }
 
1859
}
 
1860
 
 
1861
void
 
1862
release_rubik(ModeInfo * mi)
 
1863
{
 
1864
        if (rubik != NULL) {
 
1865
                int         screen;
 
1866
 
 
1867
                for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
 
1868
                        rubikstruct *rp = &rubik[screen];
 
1869
 
 
1870
                        free_rubik(rp);
 
1871
                }
 
1872
                (void) free((void *) rubik);
 
1873
                rubik = (rubikstruct *) NULL;
 
1874
        }
 
1875
        FreeAllGL(mi);
1664
1876
}
1665
1877
 
1666
1878
void
1667
1879
init_rubik(ModeInfo * mi)
1668
1880
{
1669
 
        int         screen = MI_SCREEN(mi);
1670
1881
        rubikstruct *rp;
1671
1882
 
1672
1883
        if (rubik == NULL) {
1674
1885
                                              sizeof (rubikstruct))) == NULL)
1675
1886
                        return;
1676
1887
        }
1677
 
        rp = &rubik[screen];
 
1888
        rp = &rubik[MI_SCREEN(mi)];
1678
1889
        rp->step = NRAND(90);
 
1890
        rp->PX = ((float) LRAND() / (float) MAXRAND) * 2.0 - 1.0;
 
1891
        rp->PY = ((float) LRAND() / (float) MAXRAND) * 2.0 - 1.0;
1679
1892
 
1680
1893
        if ((rp->glx_context = init_GL(mi)) != NULL) {
1681
1894
 
1682
 
                reshape_rubik(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
1683
 
                objects = glGenLists(1);
1684
 
                pinit(mi);
 
1895
                reshape(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
 
1896
                glDrawBuffer(GL_BACK);
 
1897
                if (!pinit(mi)) {
 
1898
                        free_rubik(rp);
 
1899
                        if (MI_IS_VERBOSE(mi)) {
 
1900
                                (void) fprintf(stderr,
 
1901
                                        "Could not allocate memory for rubik\n");
 
1902
                        }
 
1903
                        return;
 
1904
                }
1685
1905
        } else {
1686
1906
                MI_CLEARWINDOW(mi);
1687
1907
        }
1690
1910
void
1691
1911
draw_rubik(ModeInfo * mi)
1692
1912
{
1693
 
        rubikstruct *rp = &rubik[MI_SCREEN(mi)];
 
1913
        Bool bounced = False;
1694
1914
        Display    *display = MI_DISPLAY(mi);
1695
1915
        Window      window = MI_WINDOW(mi);
 
1916
        rubikstruct *rp;
 
1917
 
 
1918
        if (rubik == NULL)
 
1919
                return;
 
1920
        rp = &rubik[MI_SCREEN(mi)];
 
1921
        if (rp->cubeLoc[0] == NULL)
 
1922
                return;
1696
1923
 
1697
1924
        MI_IS_DRAWN(mi) = True;
1698
 
 
1699
1925
        if (!rp->glx_context)
1700
1926
                return;
1701
1927
 
1702
 
        glDrawBuffer(GL_BACK);
1703
1928
        glXMakeCurrent(display, window, *(rp->glx_context));
1704
1929
 
1705
1930
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1708
1933
 
1709
1934
        glTranslatef(0.0, 0.0, -10.0);
1710
1935
 
1711
 
    {
1712
 
      static int frame = 0;
1713
 
      GLfloat x, y, z;
1714
 
#     define SINOID(SCALE,SIZE) \
1715
 
        ((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2)
1716
 
      x = SINOID(0.0071, 2.0);
1717
 
      y = SINOID(0.0053, 2.0);
1718
 
      z = SINOID(0.0037, 4.0);
1719
 
      frame++;
1720
 
      glTranslatef(x, y, z);
1721
 
    }
 
1936
        rp->PX += rp->VX;
 
1937
        rp->PY += rp->VY;
1722
1938
 
 
1939
        if (rp->PY < -1) {
 
1940
                rp->PY += (-1) - (rp->PY);
 
1941
                rp->VY = -rp->VY;
 
1942
                bounced = True;
 
1943
        }
 
1944
        if (rp->PY > 1) {
 
1945
                rp->PY -= (rp->PY) - 1;
 
1946
                rp->VY = -rp->VY;
 
1947
                bounced = True;
 
1948
        }
 
1949
        if (rp->PX < -1) {
 
1950
                rp->PX += (-1) - (rp->PX);
 
1951
                rp->VX = -rp->VX;
 
1952
                bounced = True;
 
1953
        }
 
1954
        if (rp->PX > 1) {
 
1955
                rp->PX -= (rp->PX) - 1;
 
1956
                rp->VX = -rp->VX;
 
1957
                bounced = True;
 
1958
        }
 
1959
        if (bounced) {
 
1960
                rp->VX += ((float) LRAND() / (float) MAXRAND) * 0.02 - 0.01;
 
1961
                rp->VX += ((float) LRAND() / (float) MAXRAND) * 0.02 - 0.01;
 
1962
                if (rp->VX > 0.06)
 
1963
                        rp->VX = 0.06;
 
1964
                if (rp->VY > 0.06)
 
1965
                        rp->VY = 0.06;
 
1966
                if (rp->VX < -0.06)
 
1967
                        rp->VX = -0.06;
 
1968
                if (rp->VY < -0.06)
 
1969
                        rp->VY = -0.06;
 
1970
        }
1723
1971
        if (!MI_IS_ICONIC(mi)) {
 
1972
                glTranslatef(rp->PX, rp->PY, 0);
1724
1973
                glScalef(Scale4Window * rp->WindH / rp->WindW, Scale4Window, Scale4Window);
1725
1974
        } else {
1726
1975
                glScalef(Scale4Iconic * rp->WindH / rp->WindW, Scale4Iconic, Scale4Iconic);
1730
1979
        glRotatef(rp->step * 95, 0, 1, 0);
1731
1980
        glRotatef(rp->step * 90, 0, 0, 1);
1732
1981
 
1733
 
        draw_cube(mi);
1734
 
    if (mi->fps_p) do_fps (mi);
 
1982
        if (!draw_cube(mi)) {
 
1983
                release_rubik(mi);
 
1984
                return;
 
1985
        }
 
1986
        if (MI_IS_FPS(mi)) do_fps (mi);
1735
1987
        glXSwapBuffers(display, window);
1736
1988
 
1737
1989
        if (rp->action == ACTION_SHUFFLE) {
1752
2004
                                        rp->done = 1;
1753
2005
                                }
1754
2006
                        } else {
 
2007
                                if (rp->rotatestep == 0) {
 
2008
                                        if (rp->movement.direction == CW || rp->movement.direction == CCW)
 
2009
                                                rp->degreeTurn = (checkFaceSquare(rp, rp->movement.face)) ? 90 : 180;
 
2010
                                        else
 
2011
                                                rp->degreeTurn = (checkFaceSquare(rp, rowToRotate[rp->movement.face][rp->movement.direction])) ? 90 : 180;
 
2012
                                }
1755
2013
                                rp->rotatestep += rp->anglestep;
1756
 
                                if (rp->rotatestep > 90) {
1757
 
                                        evalmovement(mi, rp->movement);
 
2014
                                if (rp->rotatestep > rp->degreeTurn) {
 
2015
                                        if (!evalmovement(mi, rp->movement)) {
 
2016
                                                free_rubik(rp);
 
2017
                                                if (MI_IS_VERBOSE(mi)) {
 
2018
                                                        (void) fprintf(stderr,
 
2019
                                                                "Could not allocate memory for rubik\n");
 
2020
                                                }
 
2021
                                                return;
 
2022
                                        }
1758
2023
                                        rp->shufflingmoves++;
1759
2024
                                        rp->movement.face = NO_FACE;
1760
2025
                                }
1763
2028
        } else {
1764
2029
                if (rp->done) {
1765
2030
                        if (++rp->rotatestep > DELAY_AFTER_SOLVING)
1766
 
                                shuffle(mi);
 
2031
                                if (!shuffle(mi)) {
 
2032
                                        free_rubik(rp);
 
2033
                                        if (MI_IS_VERBOSE(mi)) {
 
2034
                                                (void) fprintf(stderr,
 
2035
                                                        "Could not allocate memory for rubik\n");
 
2036
                                        }
 
2037
                                        return;
 
2038
                                }
1767
2039
                } else {
1768
2040
                        if (rp->movement.face == NO_FACE) {
1769
2041
                                if (rp->storedmoves > 0) {
1770
2042
                                        rp->rotatestep = 0;
1771
2043
                                        rp->movement = rp->moves[rp->storedmoves - 1];
1772
 
                                        rp->movement.direction = (rp->movement.direction + (MAXORIENT / 2)) %
1773
 
                                                MAXORIENT;
 
2044
                                        rp->movement.direction = (rp->movement.direction +
 
2045
                                                (MAXORIENT / 2)) % MAXORIENT;
1774
2046
                                } else {
1775
2047
                                        rp->rotatestep = 0;
1776
2048
                                        rp->done = 1;
1777
2049
                                }
1778
2050
                        } else {
 
2051
                                if (rp->rotatestep == 0) {
 
2052
                                        if (rp->movement.direction == CW || rp->movement.direction == CCW)
 
2053
                                                rp->degreeTurn = (checkFaceSquare(rp, rp->movement.face)) ? 90 : 180;
 
2054
                                        else
 
2055
                                                rp->degreeTurn = (checkFaceSquare(rp, rowToRotate[rp->movement.face][rp->movement.direction])) ? 90 : 180;
 
2056
                                }
1779
2057
                                rp->rotatestep += rp->anglestep;
1780
 
                                if (rp->rotatestep > 90) {
1781
 
                                        evalmovement(mi, rp->movement);
 
2058
                                if (rp->rotatestep > rp->degreeTurn) {
 
2059
                                        if (!evalmovement(mi, rp->movement)) {
 
2060
                                                free_rubik(rp);
 
2061
                                                if (MI_IS_VERBOSE(mi)) {
 
2062
                                                        (void) fprintf(stderr,
 
2063
                                                                "Could not allocate memory for rubik\n");
 
2064
                                                }
 
2065
                                                return;
 
2066
                                        }
1782
2067
                                        rp->storedmoves--;
1783
2068
                                        rp->movement.face = NO_FACE;
1784
2069
                                }
1796
2081
void
1797
2082
change_rubik(ModeInfo * mi)
1798
2083
{
1799
 
        rubikstruct *rp = &rubik[MI_SCREEN(mi)];
 
2084
        rubikstruct *rp;
 
2085
 
 
2086
        if (rubik == NULL)
 
2087
                return;
 
2088
        rp = &rubik[MI_SCREEN(mi)];
1800
2089
 
1801
2090
        if (!rp->glx_context)
1802
2091
                return;
1803
 
        pinit(mi);
1804
 
}
1805
 
 
1806
 
void
1807
 
release_rubik(ModeInfo * mi)
1808
 
{
1809
 
        if (rubik != NULL) {
1810
 
                int         screen;
1811
 
 
1812
 
                for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
1813
 
                        rubikstruct *rp = &rubik[screen];
1814
 
                        int         i;
1815
 
 
1816
 
                        for (i = 0; i < MAXFACES; i++)
1817
 
                                if (rp->cubeLoc[i] != NULL)
1818
 
                                        (void) free((void *) rp->cubeLoc[i]);
1819
 
                        for (i = 0; i < MAXORIENT; i++)
1820
 
                                if (rp->rowLoc[i] != NULL)
1821
 
                                        (void) free((void *) rp->rowLoc[i]);
1822
 
                        if (rp->moves != NULL)
1823
 
                                (void) free((void *) rp->moves);
 
2092
        if (!pinit(mi)) {
 
2093
                free_rubik(rp);
 
2094
                if (MI_IS_VERBOSE(mi)) {
 
2095
                        (void) fprintf(stderr,
 
2096
                                "Could not allocate memory for rubik\n");
1824
2097
                }
1825
 
                (void) free((void *) rubik);
1826
 
                rubik = NULL;
 
2098
                return;
1827
2099
        }
1828
 
        FreeAllGL(mi);
1829
2100
}
1830
2101
 
1831
2102
#endif