1 /* -*- c++ -*- 2 FILE: Polymgr.h 3 RCS REVISION: $Revision: 1.15 $ 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 This class manages the rendering of the puzzle as a collection of 16 polygons. 17 */ 18 19 #ifndef POLYMGR_H 20 #define POLYMGR_H 21 22 #include "MagicCube.h" 23 24 class Preferences; 25 26 class PolygonManager4D 27 { 28 public: 29 30 PolygonManager4D(Preferences&); 31 32 // length = -1 means no change to length 33 void reset(int length = -1); 34 35 void setShrinkers(real face_val, real sticker_val); 36 37 void calc3DTo2DFrameInfo( 38 /* INPUTS */ 39 int nverts3, real verts3[][3], int nquads3, int quads3[][4], 40 int stickerids3[], 41 real tilt, real twirl, real eyez, 42 real sunvec[3], int sunvec_is_in_objspace, 43 int cullverts, int cullbackfaces, int zsort, 44 /* OUTPUTS */ 45 int *Nverts2, real verts2[][2], int *Nquads2, int quads2[][4], 46 int quadids2[], real brightnesses[]); 47 48 real getTwistTotalAngle(int dim, int dir); 49 50 int getTwistNFrames(struct stickerspec *grip); 51 52 int makeRangesInt(int slicesmask, int whichaxis, int sgn, int ranges[MAXLENGTH][2]); 53 54 int oppositeFace(int f); 55 56 static int faceOfGrip(int id); 57 58 static void fillStickerspecFromIdAndLength(struct stickerspec *sticker, int length); 59 60 static void fillStickerspecFromId(struct stickerspec *sticker); 61 62 static void fillStickerspecFromFaceAndIdAndLength(struct stickerspec *sticker, int length); 63 64 static void fillStickerspecFromFaceAndId(struct stickerspec *sticker); 65 66 static void fillStickerspecFromCoordsAndLength(struct stickerspec *sticker, int length); 67 68 static void fillStickerspecFromCoords(struct stickerspec *sticker); 69 70 /* 71 * Get a sticker for which a CCW twist is the same transformation 72 * as the given face-to-center rotation. 73 */ 74 int facetocenterToGrip(int facetocenter, struct stickerspec *sticker); 75 76 void calc2DFrameInfo( 77 /* INPUTS */ 78 struct stickerspec *sticker, int dir, int slicesmask, 79 real frac, real (*interp)(real), 80 int nverts4, real untwisted_verts4[][4], 81 real eyew, int cullcells, 82 real tilt, real twirl, real eyez, 83 real sunvec[3], int sunvec_is_in_objspace, 84 int cullverts, int cullbackfaces, int zsort, 85 /* OUTPUTS */ 86 int *Nverts2, real verts2[][2], int *Nquads2, int quads2[][4], 87 int quadids[], 88 real brightnesses[]); /* brightnesses not calculated if NULL */ 89 90 /* 91 * returns 1 if landed on a sticker, 0 otherwise 92 */ 93 int pick(int x, int y, struct frame *frame, struct stickerspec *sticker); 94 95 /* 96 * "grip" is equal to the sticker id 97 * if length=3; otherwise 98 * it's equal to the stickerid on the 3x3x3x3 puzzle 99 * that corresponds to the twist. 100 * NOTE: this is mostly the same as pick(). 101 * returns 1 if landed on a sticker, 0 otherwise 102 */ 103 int pickGrip(int x, int y, struct frame *frame, struct stickerspec *sticker); 104 105 void getUntwistedFrame(struct frame *frame); 106 107 void getFrame(struct stickerspec *sticker, 108 int dir, int slicesmask, int seqno, int outof, 109 struct frame *frame); 110 111 void calc3DFrameInfo( 112 /* INPUTS */ 113 struct stickerspec *grip, int dir, int slicesmask, 114 real frac, real (*interp)(real), 115 int nverts4, 116 real untwisted_verts4[][4], // NULL if use pristine 117 real eyew, int cullcells, 118 /* OUTPUTS */ 119 int *Nverts3, real verts3[][3], 120 int *Nquads3, int quads3[][4], 121 int stickerids3[], 122 int stickers_inverted[]); // NULL if not needed 123 124 125 int getUntwistedVerts4(real verts4[][4], real faceshrink, real stickershrink); 126 127 void incTilt(real inc); 128 129 void incTwirl(real inc); 130 intpow(int x,int y)131 static int intpow(int x, int y) { return y == 0 ? 1 : intpow(x, y - 1) * x; } 132 133 private: 134 135 int makeRangesReal(int slicesmask, int, // whichaxis, 136 int sgn, real ranges[MAXLENGTH][2]); 137 138 Preferences& preferences; 139 140 int n_untwisted_verts4; 141 real untwisted_verts4[MAXVERTS][4]; 142 real faceshrink, stickershrink; /* bleah... need to reuse this when twisting */ 143 int nframes_90, nframes_120, nframes_180; /* FIX THIS-- decide on a 144 consistent way to 145 define variables */ 146 /* 147 * Yes, these should probably be in a data structure: 148 */ 149 int n_untwisted_verts3; 150 real untwisted_verts3[MAXVERTS][3]; 151 int n_untwisted_quads3; 152 int untwisted_quads3[MAXQUADS][4]; 153 int untwisted_stickerids3[MAXSTICKERS]; 154 /* NOTE stickerids3 is indexed by verts/8 whereas quadids2 is indexed by stickers */ 155 }; 156 157 #endif 158 159 // Local Variables: 160 // c-basic-offset: 4 161 // c-comment-only-line-offset: 0 162 // 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)) 163 // indent-tabs-mode: nil 164 // End: 165