/* -*- c++ -*- FILE: MagicCube.h RCS REVISION: $Revision: 1.26 $ COPYRIGHT: (c) 1999 -- 2003 Melinda Green, Don Hatch, and Jay Berkenbilt - Superliminal Software LICENSE: Free to use and modify for non-commercial purposes as long as the following conditions are adhered to: 1) Obvious credit for the source of this code and the designs it embodies are clearly made, and 2) Ports and derived versions of 4D Magic Cube programs are not distributed without the express written permission of the authors. DESCRIPTION: Global parameters, macros, etc. */ #ifndef MAGICCUBE_H #define MAGICCUBE_H #include #include #include #include #include #include "Vec.h" // Version number of this program. Must also be updated in // MagicCube4d.rc (search for version) and readme-*.txt. #define VERSION "2.2" /* File format version number */ #define MAGICCUBE_FILE_VERSION 1 /* File "magic number" (identification string) */ #define MAGIC_NUMBER "MagicCube4D" /* User preferences (environment variables) */ #define M4D_ALL_AT_ONCE "M4D_ALL_AT_ONCE" #define M4D_CULLVERTS "M4D_CULLVERTS" #define M4D_DONT_CHECK_BBOX "M4D_DONT_CHECK_BBOX" #define M4D_DONT_DRAW_FRAME "M4D_DONT_DRAW_FRAME" #define M4D_DRAW_NEW_STATE "M4D_DRAW_NEW_STATE" #define M4D_EYEW "M4D_EYEW" #define M4D_EYEZ "M4D_EYEZ" #define M4D_FACESHRINK "M4D_FACESHRINK" #define M4D_FAST_AUTOMOVES "M4D_FAST_AUTOMOVES" #define M4D_HISTORY_DEBUG "M4D_HISTORY_DEBUG" #define M4D_INC "M4D_INC" #define M4D_LENGTH "M4D_LENGTH" #define M4D_LOGFILE "M4D_LOGFILE" #define M4D_MACROS_ON_RIGHT "M4D_MACROS_ON_RIGHT" #define M4D_NFRAMES_120 "M4D_NFRAMES_120" #define M4D_NFRAMES_180 "M4D_NFRAMES_180" #define M4D_NFRAMES_90 "M4D_NFRAMES_90" #define M4D_NOCOMPRESSMOTION "M4D_NOCOMPRESSMOTION" #define M4D_NO_BUTTONS "M4D_NO_BUTTONS" #define M4D_NOCULLCELLS "M4D_NOCULLCELLS" #define M4D_NOCULLFACES "M4D_NOCULLFACES" #define M4D_NOZSORT "M4D_NOZSORT" #define M4D_NO_STRDUP_FIX "M4D_NO_STRDUP_FIX" #define M4D_NSCRAMBLECHEN "M4D_NSCRAMBLECHEN" #define M4D_NSHADES "M4D_NSHADES" #define M4D_OUTLINE "M4D_OUTLINE" #define M4D_STICKERSHRINK "M4D_STICKERSHRINK" #define M4D_TILT "M4D_TILT" #define M4D_TWIRL "M4D_TWIRL" #define M4D_XVERBOSE "M4D_XVERBOSE" #ifndef M_PI # define M_PI 3.14159265 #endif typedef double real; /* * All the good macros */ #define FOR(i,n) for ((i) = 0; (i) < (n); ++(i)) #define FORLIST(ptr,list,next) for ((ptr) = (list); (ptr); (ptr) = (ptr)->next) #define FORLISTPTR(ptrptr,listptr,next) \ for ((ptrptr) = (listptr); *(ptrptr); (ptrptr) = &(*(ptrptr))->next) #ifndef EPS #define EPS (1e-6) #endif /* !EPS */ #define LEQ(a,b) (-EPS <= (b)-(a)) /* <= with tolerance of EPS */ #define GEQ(a,b) ((b)-(a) <= EPS) /* >= with tolerance of EPS */ #define EQ(a,b) (LEQ(a,b) && GEQ(a,b)) /* == with tolerance of EPS */ #define LT(a,b) (!GEQ(a,b)) /* < with tolerance of EPS */ #define GT(a,b) (!LEQ(a,b)) /* > with tolerance of EPS */ #define PI M_PI #define DTOR(d) ((d)*PI/180) #define RTOD(d) ((d)/PI*180) #define ROUND(x) (int)floor((x)+.5) #define INRANGE(foo,bar,baz) ((foo(bar))&&((bar)baz)) #define ABS(x) ((x)<0 ? -(x) : (x)) #define SGN(x) ((x)<0 ? -1 : (x)>0 ? 1 :0) #define SQR(x) ((x)*(x)) #define MIN(a,b) ((a)<(b) ? (a) : (b)) #define MAX(a,b) ((a)>(b) ? (a) : (b)) #define MIN3(a,b,c) ((a)<(b) ? MIN(a,c) : MIN(b,c)) #define MAX3(a,b,c) ((a)>(b) ? MAX(a,c) : MAX(b,c)) #define MIN4(a,b,c,d) ((a)<(b) ? MIN3(a,c,d) : MIN3(b,c,d)) #define MAX4(a,b,c,d) ((a)>(b) ? MAX3(a,c,d) : MAX3(b,c,d)) #define CLAMP(a,x,b) ((x)<(a) ? (a) : MIN(x,b)) #define LERP(a,b,t) ((a) + (t)*((b)-(a))) #define SWAP(a,b,temp) ((temp)=(a), (a)=(b), (b)=(temp)) #define numberof(sextoys) (sizeof(sextoys)/sizeof(*(sextoys))) #define MCBITS(A) (sizeof(A) * 8) #define BIT(A,i) (((A)[(i)/MCBITS(*(A))] >> ((i)%MCBITS(*(A)))) & 1) #define BITON(A,i) ((A)[(i)/MCBITS(*(A))] |= (1<<((i)%MCBITS(*(A))))) #define BITOFF(A,i) ((A)[(i)/MCBITS(*(A))] &=~ (1<<((i)%MCBITS(*(A))))) #define BITSET(A,i,val) ((i) ? BITON(A,i) : BITOFF(A,i)) #define MOD(a,b) (((a)%(b)+(b))%(b)) /* always >= 0 if b is >= 0 */ #define DIV(a,b) (((a)-MOD(a,b))/(b)) /* maybe there's a better way? */ #define HOWMANY(x,mod) (((x)+((mod)-1))/(mod)) #define ROUNDUP(x,mod) (HOWMANY(x,mod)*(mod)) /* only works for >= 0 */ #define ROUNDDOWN(x,mod) ((x)/(mod)*(mod)) /* ditto */ #define PRINT(x) printf("x = %d\n", x) #define PRD(x) printf("x = %g\n", x) #define PRVEC2(fmt, v) printf("v = ("#fmt" "#fmt")", EXPAND2(v)) #define PRVEC3(fmt, v) printf("v = ("#fmt" "#fmt" "#fmt")", EXPAND3(v)) #define PRVEC4(fmt, v) printf("v = ("#fmt" "#fmt" "#fmt" "#fmt")", EXPAND4(v)) /* * Axes */ #define X 0 #define Y 1 #define Z 2 #define W 3 /* * Rotation directions */ #define CCW 1 #define CW (-1) /* * Constants that probably shouldn't be changed */ #define NDIMS 4 #define LENGTH 3 /* default */ /* * max length below used to be 5, but I changed it to 3 to save * memory since other lengths are currently not supported. - DG */ #define MAXLENGTH 5 /* 5 uses uses lots of unnecessary memory */ #define NFACES (2 * NDIMS) #define MAXSTICKERS (NFACES * MAXLENGTH * MAXLENGTH * MAXLENGTH) /* NDIMS = 4 */ #define MAXVERTS (MAXSTICKERS * 8) #define MAXQUADS (MAXSTICKERS * 6) /* * default 4d viewing parameters */ #define FACESHRINK .4 #define STICKERSHRINK .5 #define EYEW (2.*LENGTH) /* * 3d viewing parameters */ #define TILT 30 // degrees #define TWIRL -42 // degrees #define EYEZ 10. /* should really be dependent on LENGTH and EYEW */ /* * Default number of frames for a twist or rotate. * Even numbers are sometimes bad. */ #ifdef sgi #define NFRAMES_90 11 #define NFRAMES_120 15 #define NFRAMES_180 23 #else #define NFRAMES_90 5 #define NFRAMES_120 7 #define NFRAMES_180 11 #endif /* * Default number of twists to twist when scrambling */ #define NSCRAMBLECHEN 40 #define LOGFILE "~/.magiccube4dlog" /* expands to home dir */ /* * structures */ struct stickerspec { int coords[NDIMS]; int face; int dim; /* 0 for "vertex", 1 for "edge", etc. */ // int depth; /* 0 if on surface of hyperface, positive otherwise */ int id_within_cube; int id_within_face; }; struct frame { int nverts; unsigned short verts[MAXVERTS][2]; int nquads; unsigned short quads[MAXQUADS][4]; unsigned short quadids[MAXQUADS]; real brightnesses[MAXQUADS]; }; /* disables warnings of precision loss assigning from double to int */ #ifdef _WINDOWS_ # pragma warning (disable : 4244) #endif #endif // Local Variables: // c-basic-offset: 4 // c-comment-only-line-offset: 0 // 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)) // indent-tabs-mode: nil // End: