1 /* -*- c++ -*-
2 FILE: MagicCube.h
3 RCS REVISION: $Revision: 1.26 $
4 
5 COPYRIGHT: (c) 1999 -- 2003 Melinda Green, Don Hatch, and Jay Berkenbilt - Superliminal Software
6 
7 LICENSE: Free to use and modify for non-commercial purposes as long as the
8     following conditions are adhered to:
9     1) Obvious credit for the source of this code and the designs it embodies
10        are clearly made, and
11     2) Ports and derived versions of 4D Magic Cube programs are not distributed
12        without the express written permission of the authors.
13 
14 DESCRIPTION:
15     Global parameters, macros, etc.
16 */
17 
18 #ifndef MAGICCUBE_H
19 #define MAGICCUBE_H
20 
21 #include <stdlib.h>
22 #include <assert.h>
23 #include <math.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include "Vec.h"
27 
28 // Version number of this program.  Must also be updated in
29 // MagicCube4d.rc (search for version) and readme-*.txt.
30 #define VERSION "2.2"
31 
32 /* File format version number */
33 #define MAGICCUBE_FILE_VERSION 1
34 /* File "magic number" (identification string) */
35 #define MAGIC_NUMBER "MagicCube4D"
36 
37 /* User preferences (environment variables) */
38 #define M4D_ALL_AT_ONCE "M4D_ALL_AT_ONCE"
39 #define M4D_CULLVERTS "M4D_CULLVERTS"
40 #define M4D_DONT_CHECK_BBOX "M4D_DONT_CHECK_BBOX"
41 #define M4D_DONT_DRAW_FRAME "M4D_DONT_DRAW_FRAME"
42 #define M4D_DRAW_NEW_STATE "M4D_DRAW_NEW_STATE"
43 #define M4D_EYEW "M4D_EYEW"
44 #define M4D_EYEZ "M4D_EYEZ"
45 #define M4D_FACESHRINK "M4D_FACESHRINK"
46 #define M4D_FAST_AUTOMOVES "M4D_FAST_AUTOMOVES"
47 #define M4D_HISTORY_DEBUG "M4D_HISTORY_DEBUG"
48 #define M4D_INC "M4D_INC"
49 #define M4D_LENGTH "M4D_LENGTH"
50 #define M4D_LOGFILE "M4D_LOGFILE"
51 #define M4D_MACROS_ON_RIGHT "M4D_MACROS_ON_RIGHT"
52 #define M4D_NFRAMES_120 "M4D_NFRAMES_120"
53 #define M4D_NFRAMES_180 "M4D_NFRAMES_180"
54 #define M4D_NFRAMES_90 "M4D_NFRAMES_90"
55 #define M4D_NOCOMPRESSMOTION "M4D_NOCOMPRESSMOTION"
56 #define M4D_NO_BUTTONS "M4D_NO_BUTTONS"
57 #define M4D_NOCULLCELLS "M4D_NOCULLCELLS"
58 #define M4D_NOCULLFACES "M4D_NOCULLFACES"
59 #define M4D_NOZSORT "M4D_NOZSORT"
60 #define M4D_NO_STRDUP_FIX "M4D_NO_STRDUP_FIX"
61 #define M4D_NSCRAMBLECHEN "M4D_NSCRAMBLECHEN"
62 #define M4D_NSHADES "M4D_NSHADES"
63 #define M4D_OUTLINE "M4D_OUTLINE"
64 #define M4D_STICKERSHRINK "M4D_STICKERSHRINK"
65 #define M4D_TILT "M4D_TILT"
66 #define M4D_TWIRL "M4D_TWIRL"
67 #define M4D_XVERBOSE "M4D_XVERBOSE"
68 
69 #ifndef M_PI
70 #   define M_PI 3.14159265
71 #endif
72 
73 typedef double real;
74 
75 /*
76  * All the good macros
77  */
78 #define FOR(i,n)        for ((i) = 0; (i) < (n); ++(i))
79 #define FORLIST(ptr,list,next)  for ((ptr) = (list); (ptr); (ptr) = (ptr)->next)
80 #define FORLISTPTR(ptrptr,listptr,next) \
81     for ((ptrptr) = (listptr); *(ptrptr); (ptrptr) = &(*(ptrptr))->next)
82 #ifndef EPS
83 #define EPS (1e-6)
84 #endif /* !EPS */
85 #define LEQ(a,b)    (-EPS <= (b)-(a))   /* <= with tolerance of EPS */
86 #define GEQ(a,b)    ((b)-(a) <= EPS)    /* >= with tolerance of EPS */
87 #define EQ(a,b)     (LEQ(a,b) && GEQ(a,b))  /* == with tolerance of EPS */
88 #define LT(a,b)     (!GEQ(a,b)) /* <  with tolerance of EPS */
89 #define GT(a,b)     (!LEQ(a,b)) /* > with tolerance of EPS */
90 
91 #define PI M_PI
92 #define DTOR(d)     ((d)*PI/180)
93 #define RTOD(d)     ((d)/PI*180)
94 #define ROUND(x)    (int)floor((x)+.5)
95 #define INRANGE(foo,bar,baz)    ((foo(bar))&&((bar)baz))
96 #define ABS(x)      ((x)<0 ? -(x) : (x))
97 #define SGN(x)      ((x)<0 ? -1 : (x)>0 ? 1 :0)
98 #define SQR(x)      ((x)*(x))
99 #define MIN(a,b)    ((a)<(b) ? (a) : (b))
100 #define MAX(a,b)    ((a)>(b) ? (a) : (b))
101 #define MIN3(a,b,c) ((a)<(b) ? MIN(a,c) : MIN(b,c))
102 #define MAX3(a,b,c) ((a)>(b) ? MAX(a,c) : MAX(b,c))
103 #define MIN4(a,b,c,d)   ((a)<(b) ? MIN3(a,c,d) : MIN3(b,c,d))
104 #define MAX4(a,b,c,d)   ((a)>(b) ? MAX3(a,c,d) : MAX3(b,c,d))
105 #define CLAMP(a,x,b)    ((x)<(a) ? (a) : MIN(x,b))
106 #define LERP(a,b,t) ((a) + (t)*((b)-(a)))
107 #define SWAP(a,b,temp)  ((temp)=(a), (a)=(b), (b)=(temp))
108 #define numberof(sextoys) (sizeof(sextoys)/sizeof(*(sextoys)))
109 #define MCBITS(A)       (sizeof(A) * 8)
110 #define BIT(A,i)    (((A)[(i)/MCBITS(*(A))] >> ((i)%MCBITS(*(A)))) & 1)
111 #define BITON(A,i)  ((A)[(i)/MCBITS(*(A))] |=  (1<<((i)%MCBITS(*(A)))))
112 #define BITOFF(A,i) ((A)[(i)/MCBITS(*(A))] &=~ (1<<((i)%MCBITS(*(A)))))
113 #define BITSET(A,i,val) ((i) ? BITON(A,i) : BITOFF(A,i))
114 #define MOD(a,b)    (((a)%(b)+(b))%(b)) /* always >= 0 if b is >= 0 */
115 #define DIV(a,b)    (((a)-MOD(a,b))/(b))    /* maybe there's a better way? */
116 #define HOWMANY(x,mod)  (((x)+((mod)-1))/(mod))
117 #define ROUNDUP(x,mod)  (HOWMANY(x,mod)*(mod))  /* only works for >= 0 */
118 #define ROUNDDOWN(x,mod) ((x)/(mod)*(mod))  /* ditto */
119 #define PRINT(x) printf("x = %d\n", x)
120 #define PRD(x)   printf("x = %g\n", x)
121 #define PRVEC2(fmt, v) printf("v = ("#fmt" "#fmt")", EXPAND2(v))
122 #define PRVEC3(fmt, v) printf("v = ("#fmt" "#fmt" "#fmt")", EXPAND3(v))
123 #define PRVEC4(fmt, v) printf("v = ("#fmt" "#fmt" "#fmt" "#fmt")", EXPAND4(v))
124 
125 
126 /*
127  * Axes
128  */
129 #define X 0
130 #define Y 1
131 #define Z 2
132 #define W 3
133 /*
134  * Rotation directions
135  */
136 #define CCW 1
137 #define CW (-1)
138 
139 
140 /*
141  * Constants that probably shouldn't be changed
142  */
143 #define NDIMS   4
144 #define LENGTH  3               /* default */
145 /*
146  * max length below used to be 5, but I changed it to 3 to save
147  * memory since other lengths are currently not supported. - DG
148  */
149 #define MAXLENGTH 5             /* 5 uses uses lots of unnecessary memory */
150 #define NFACES (2 * NDIMS)
151 #define MAXSTICKERS (NFACES * MAXLENGTH * MAXLENGTH * MAXLENGTH)    /* NDIMS
152                                                                        = 4 */
153 #define MAXVERTS (MAXSTICKERS * 8)
154 #define MAXQUADS (MAXSTICKERS * 6)
155 
156 
157 /*
158  * default 4d viewing parameters
159  */
160 #define FACESHRINK  .4
161 #define STICKERSHRINK   .5
162 #define EYEW        (2.*LENGTH)
163 
164 /*
165  * 3d viewing parameters
166  */
167 #define TILT    30              // degrees
168 #define TWIRL   -42             // degrees
169 #define EYEZ    10.             /* should really be dependent on LENGTH and
170                                    EYEW */
171 
172 
173 /*
174  * Default number of frames for a twist or rotate.
175  * Even numbers are sometimes bad.
176  */
177 #ifdef sgi
178 #define NFRAMES_90  11
179 #define NFRAMES_120 15
180 #define NFRAMES_180 23
181 #else
182 #define NFRAMES_90  5
183 #define NFRAMES_120 7
184 #define NFRAMES_180 11
185 #endif
186 
187 
188 /*
189  * Default number of twists to twist when scrambling
190  */
191 #define NSCRAMBLECHEN   40
192 
193 #define LOGFILE "~/.magiccube4dlog" /* expands to home dir */
194 
195 
196 /*
197  * structures
198  */
199 struct stickerspec
200 {
201     int         coords[NDIMS];
202     int         face;
203     int         dim;            /* 0 for "vertex", 1 for "edge", etc. */
204     // int depth;   /* 0 if on surface of hyperface, positive otherwise */
205     int         id_within_cube;
206     int         id_within_face;
207 };
208 
209 struct frame
210 {
211     int         nverts;
212     unsigned short verts[MAXVERTS][2];
213     int         nquads;
214     unsigned short quads[MAXQUADS][4];
215     unsigned short quadids[MAXQUADS];
216     real        brightnesses[MAXQUADS];
217 };
218 
219 /* disables warnings of precision loss assigning from double to int */
220 #ifdef _WINDOWS_
221 # pragma warning (disable : 4244)
222 #endif
223 
224 #endif
225 
226 // Local Variables:
227 // c-basic-offset: 4
228 // c-comment-only-line-offset: 0
229 // c-file-offsets: ((defun-block-intro . +) (block-open . 0) (substatement-open . 0) (statement-cont . +) (statement-case-open . +4) (arglist-intro . +) (arglist-close . +) (inline-open . 0))
230 // indent-tabs-mode: nil
231 // End:
232