1 /*
2  * The Rubik's cube.
3  *
4  * Sed - april 1999 / december 2003.
5  *
6  * This program is in the public domain.
7  *--------------------
8  * The cube related stuff (init, project, rotate, so on)
9  */
10 
11 #ifndef _CUBE_H_
12 #define _CUBE_H_
13 
14 #define IS_ROTATE	1
15 
16 typedef struct {
17   short x, y, z;    /* position of small cube in big cube */
18   short colors[6];  /* colors of faces of small cube */
19 } small_cube;
20 
21 #include <sys/time.h>
22 
23 typedef struct {
24   small_cube cubes[26];   /* list of small cubes */
25   int center;             /* center of active face */
26   int rotated;		  /* the face that is currently rotated */
27   int anim;               /* should we animate rotation */
28   int orient;             /* orient = clockwise/counterclockwise */
29   int letters;            /* use letter signs */
30   double angle;           /* angle for rotate animation */
31   double matrix[3][3];    /* orthogonal matrix = position of cube */
32   struct timeval time;    /* time */
33 } CUBE;
34 
35 /* init pos. all angles=0.
36         x25    x22    x20                               x 1
37       x24           x19
38     x23    x21    x18(                                         x 5
39 
40         x17           x15
41                                                x 2               x 3
42     x16           x14
43                                                     x 4
44         x13    x10    x8(1, -1, -1)
45       x12           x7
46     x11    x9     x6                                    x 0
47  (-1, -1, 1)     (1, -1, 1)
48       -------------------------------->X
49      |      y                                    x2               x6
50      |      |
51      |      |                              x3               x7
52      |      |
53      |      |
54      |       -------x
55      |     /(160,120)
56      |    /                                      x0               x4
57      |   /
58      |  z                                  x1               x5
59      |
60      V
61      Y                           0                            319
62                       y           ---------------------------->x
63                       ^          -1                            1
64                       |
65                       |         1|0
66                       |          |              .(X, Y)
67                ^      |          |
68               1|      |          |
69                |      |        -1|239
70 z <------.------------           v
71          2     1
72 
73 (2-1)/(2-z)=Y/y
74 (2-1)/(2-z)=X/x
75 
76 (2-1)/(2-z)*y=Y
77 (2-1)/(2-z)*x=X
78 
79 319/Xp=2/(X+1)       =>  Xp=319/2*(X+1)
80 239/Yp=-2/(Y-1)      =>  Yp=-239/2*(Y-1)
81 */
82 
83 
84 #include "screen.h"
85 
86 void load_cube(CUBE *, char *);
87 void save_cube(CUBE *);
88 void init_cube(CUBE *, char *, int);
89 void display_cube(CUBE *, SCREEN *);
90 void cube_event(CUBE *);
91 void cube_rotate(SCREEN *, CUBE *, double, double);
92 void reset_cube(CUBE *);
93 void cube_generate_rotate(CUBE *, SCREEN *, int);
94 
95 #endif /* _CUBE_H_ */
96