Project

General

Profile

« Previous | Next » 

Revision d5380277

Added by Leszek Koltunski over 2 years ago

Remove statics from the Square classes.

View differences:

src/main/java/org/distorted/objects/TwistySquare1.java
35 35

  
36 36
class TwistySquare1 extends TwistySquare
37 37
{
38
  private static final int[] QUAT_NUMBER = new int[]
39
    {
40
      0, 6,
41
      0, 9, 6, 3, 18, 15, 12, 21,
42
      0, 9, 6, 3, 15, 12, 21, 18
43
    };
44

  
45
  // centers of the 2 middles + 8 edges + 8 corners
46
  private static final float[][] CENTERS = new float[][]
47
    {
48
      { 1.5f, 0.0f, 0.0f },
49
      {-1.5f, 0.0f, 0.0f },
50

  
51
      { 0.0f, 1.0f, 1.5f },
52
      { 1.5f, 1.0f, 0.0f },
53
      { 0.0f, 1.0f,-1.5f },
54
      {-1.5f, 1.0f, 0.0f },
55
      { 0.0f,-1.0f, 1.5f },
56
      { 1.5f,-1.0f, 0.0f },
57
      { 0.0f,-1.0f,-1.5f },
58
      {-1.5f,-1.0f, 0.0f },
59

  
60
      { 1.0f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f },
61
      { 1.0f, 1.0f,-2.0f, 2.0f, 1.0f,-1.0f },
62
      {-1.0f, 1.0f,-2.0f,-2.0f, 1.0f,-1.0f },
63
      {-1.0f, 1.0f, 2.0f,-2.0f, 1.0f, 1.0f },
64
      { 1.0f,-1.0f, 2.0f, 2.0f,-1.0f, 1.0f },
65
      { 1.0f,-1.0f,-2.0f, 2.0f,-1.0f,-1.0f },
66
      {-1.0f,-1.0f,-2.0f,-2.0f,-1.0f,-1.0f },
67
      {-1.0f,-1.0f, 2.0f,-2.0f,-1.0f, 1.0f }
68
    };
69

  
70
  private static final double[][] VERTICES_CORNER = new double[][]
71
    {
72
      { X-1.5, 0.5,  0.0 },
73
      {   0.0, 0.5,  0.0 },
74
      {   0.0, 0.5,X-1.5 },
75
      {  -1.5, 0.5, -1.5 },
76
      { X-1.5,-0.5,  0.0 },
77
      {   0.0,-0.5,  0.0 },
78
      {   0.0,-0.5,X-1.5 },
79
      {  -1.5,-0.5, -1.5 }
80
    };
81

  
82
  private static final int[][] VERT_INDEXES_CORNER = new int[][]
83
    {
84
      {0,1,2,3},   // counterclockwise!
85
      {4,5,6,7},
86
      {4,5,1,0},
87
      {5,6,2,1},
88
      {7,4,0,3},
89
      {6,7,3,2}
90
    };
91

  
92
  private static final float[][] STICKERS = new float[][]
93
    {
94
      { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
95
      { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
96
      { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
97
      { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
98
      { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
99
      { -0.2637079f, -0.38185397f, 0.38185397f, -0.38185397f, 0.38185397f, 0.2637079f, -0.5f, 0.5f } // corner top
100
    };
101

  
102
  private static final int NUM_STICKERS = STICKERS.length;
103

  
104
  private static final int[][] mStickerType = new int[][]
105
    {
106
      {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
107
      {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
108
      {             5,NUM_STICKERS,2,           2,NUM_STICKERS,NUM_STICKERS }
109
    };
110

  
111
  // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
112
  private static final int[][] mStickerColor = new int[][]
113
    {
114
      { 0, 0, 4, 0, 5, 0 },
115
      { 0, 0, 5, 1, 4, 0 },
116

  
117
      { 2, 0, 4, 0, 0, 0 },
118
      { 2, 0, 0, 0, 0, 0 },
119
      { 2, 0, 5, 0, 0, 0 },
120
      { 2, 0, 1, 0, 0, 0 },
121
      { 3, 0, 4, 0, 0, 0 },
122
      { 3, 0, 0, 0, 0, 0 },
123
      { 3, 0, 5, 0, 0, 0 },
124
      { 3, 0, 1, 0, 0, 0 },
125

  
126
      { 2, 0, 4, 0, 0, 0 },
127
      { 2, 0, 0, 5, 0, 0 },
128
      { 2, 0, 5, 1, 0, 0 },
129
      { 2, 0, 1, 4, 0, 0 },
130
      { 3, 0, 0, 4, 0, 0 },
131
      { 3, 0, 5, 0, 0, 0 },
132
      { 3, 0, 1, 5, 0, 0 },
133
      { 3, 0, 4, 1, 0, 0 },
134
    };
135

  
136
  // quat indices that make corner cubits bandage the puzzle.
137
  private static final int[][] BAD_CORNER_QUATS = new int[][]
138
    {
139
      { 2, 8,17,23},
140
      { 5,11,14,20},
141
    };
38
  private static final int NUM_STICKERS = 6;
142 39

  
143 40
  private final int[][] mPermittedAngles;
144 41
  private final int[] mCornerQuat;
145 42
  private int mPermittedUp, mPermittedDo;
146

  
147
  private static final ObjectSticker[] mStickers;
148

  
149
  static
150
    {
151
    mStickers = new ObjectSticker[NUM_STICKERS];
152
    final float R1 = 0.06f;
153
    final float R2 = 0.04f;
154
    final float R3 = 0.11f;
155
    final float R4 = 0.03f;
156
    final float R5 = 0.11f;
157
    final float R6 = 0.08f;
158
    final float[][] radii  = { {R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3},{R4,R4,R4},{R5,R5,R5,R5},{R6,R6,R6,R6} };
159
    final float[] strokes = { 0.05f,0.04f,0.09f,0.05f,0.08f,0.08f };
160

  
161
    for(int s=0; s<NUM_STICKERS; s++)
162
      {
163
      mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
164
      }
165
    }
43
  private ObjectSticker[] mStickers;
44
  private int[] mQuatNumber;
45
  private float[][] mCenters;
46
  private int[][] mBadCornerQuats;
47
  private int[][] mStickerColor;
48
  private int[][] mStickerType;
166 49

  
167 50
///////////////////////////////////////////////////////////////////////////////////////////////////
168 51

  
......
171 54
    {
172 55
    super(size, quat, texture, mesh, effects, moves, ObjectList.SQU1, res, scrWidth);
173 56

  
57
    if( mBasicAngle==null ) initializeBasicAngle();
174 58
    mLastRot = LAST_SL;
175
    mPermittedAngles = new int[2][BASIC_ANGLE[0]];
59
    mPermittedAngles = new int[2][mBasicAngle[0]];
176 60
    mCornerQuat = new int[8];
177 61
    }
178 62

  
......
180 64

  
181 65
  int[] getSolvedQuats(int cubit, int numLayers)
182 66
    {
67
    if( mQuats==null ) initializeQuats();
183 68
    int status = retCubitSolvedStatus(cubit,numLayers);
184
    return status<0 ? null : buildSolvedQuats(MovementSquare.FACE_AXIS[status],QUATS);
69
    return status<0 ? null : buildSolvedQuats(MovementSquare.FACE_AXIS[status],mQuats);
185 70
    }
186 71

  
187 72
///////////////////////////////////////////////////////////////////////////////////////////////////
......
192 77

  
193 78
    if( variant==0 )
194 79
      {
80
      double[][] vertices = new double[][]
81
        {
82
         { -1.5-X, 0.5, 1.5 },
83
         {    0.0, 0.5, 1.5 },
84
         {    0.0, 0.5,-1.5 },
85
         { -1.5+X, 0.5,-1.5 },
86
         { -1.5-X,-0.5, 1.5 },
87
         {    0.0,-0.5, 1.5 },
88
         {    0.0,-0.5,-1.5 },
89
         { -1.5+X,-0.5,-1.5 }
90
        };
91

  
92
      int[][] vert_indices = new int[][]
93
        {
94
         {0,1,2,3},
95
         {4,5,6,7},
96
         {4,5,1,0},
97
         {5,6,2,1},
98
         {6,7,3,2},
99
         {7,4,0,3}
100
        };
101

  
195 102
      float[][] bands     = new float[][] { {0.040f,35,0.8f,1.0f,5,2,1}, {0.020f,35,0.8f,1.0f,5,2,1}, {0.001f,35,0.8f,1.0f,5,2,1} };
196 103
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
197 104
      float[][] corners   = new float[][] { {0.03f,0.05f} };
......
199 106
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
200 107
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
201 108

  
202
      return new ObjectShape(VERTICES_MIDDLE,VERT_INDEXES_MIDDLE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
109
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
203 110
      }
204 111
    else if( variant==1 )
205 112
      {
113
      double[][] vertices = new double[][]
114
        {
115
         { -X, 0.5, 0.0 },
116
         { +X, 0.5, 0.0 },
117
         {0.0, 0.5,-1.5 },
118
         { -X,-0.5, 0.0 },
119
         { +X,-0.5, 0.0 },
120
         {0.0,-0.5,-1.5 },
121
        };
122

  
123
      int[][] vert_indices = new int[][]
124
        {
125
         {0,1,2},
126
         {3,4,5},
127
         {3,4,1,0},
128
         {4,5,2,1},
129
         {5,3,0,2}
130
        };
131

  
206 132
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
207 133
      int[] bandIndices   = new int[] { 0,1,0,1,1 };
208 134
      float[][] corners   = new float[][] { {0.04f,0.15f} };
......
210 136
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
211 137
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
212 138

  
213
      return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
139
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
214 140
      }
215 141
    else
216 142
      {
143
      double[][] vertices = new double[][]
144
        {
145
         { X-1.5, 0.5,  0.0 },
146
         {   0.0, 0.5,  0.0 },
147
         {   0.0, 0.5,X-1.5 },
148
         {  -1.5, 0.5, -1.5 },
149
         { X-1.5,-0.5,  0.0 },
150
         {   0.0,-0.5,  0.0 },
151
         {   0.0,-0.5,X-1.5 },
152
         {  -1.5,-0.5, -1.5 }
153
        };
154
      int[][] vert_indices = new int[][]
155
        {
156
         {0,1,2,3},
157
         {4,5,6,7},
158
         {4,5,1,0},
159
         {5,6,2,1},
160
         {7,4,0,3},
161
         {6,7,3,2}
162
        };
163

  
217 164
      float[][] bands     = new float[][] { {0.038f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
218 165
      int[] bandIndices   = new int[] { 0,1,0,0,1,1 };
219 166
      float[][] corners   = new float[][] { {0.05f,0.13f} };
......
221 168
      float[][] centers   = new float[][] { { -0.5f, 0.0f,-0.5f} };
222 169
      int[] centerIndices = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
223 170

  
224
      return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
171
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
225 172
      }
226 173
    }
227 174

  
......
229 176

  
230 177
  Static4D getQuat(int cubit, int numLayers)
231 178
    {
232
    return QUATS[QUAT_NUMBER[cubit]];
179
    if( mQuats==null ) initializeQuats();
180
    if( mQuatNumber ==null )
181
      {
182
      mQuatNumber = new int[]
183
        {
184
        0, 6,
185
        0, 9, 6, 3, 18, 15, 12, 21,
186
        0, 9, 6, 3, 15, 12, 21, 18
187
        };
188
      }
189

  
190
    return mQuats[mQuatNumber[cubit]];
233 191
    }
234 192

  
235 193
///////////////////////////////////////////////////////////////////////////////////////////////////
......
250 208

  
251 209
  ObjectSticker retSticker(int face)
252 210
    {
211
    if( mStickers==null )
212
      {
213
      float[][] STICKERS = new float[][]
214
        {
215
          { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
216
          { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
217
          { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
218
          { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
219
          { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
220
          { -0.2637079f, -0.38185397f, 0.38185397f, -0.38185397f, 0.38185397f, 0.2637079f, -0.5f, 0.5f } // corner top
221
        };
222

  
223
      final float R1 = 0.06f;
224
      final float R2 = 0.04f;
225
      final float R3 = 0.11f;
226
      final float R4 = 0.03f;
227
      final float R5 = 0.11f;
228
      final float R6 = 0.08f;
229
      final float[][] radii  = { {R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3},{R4,R4,R4},{R5,R5,R5,R5},{R6,R6,R6,R6} };
230
      final float[] strokes = { 0.05f,0.04f,0.09f,0.05f,0.08f,0.08f };
231

  
232
      mStickers = new ObjectSticker[NUM_STICKERS];
233

  
234
      for(int s=0; s<NUM_STICKERS; s++)
235
        {
236
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
237
        }
238
      }
239

  
253 240
    return mStickers[face/NUM_FACES];
254 241
    }
255 242

  
......
257 244

  
258 245
  float[][] getCubitPositions(int numLayers)
259 246
    {
260
    return CENTERS;
247
    if( mCenters==null )
248
      {
249
      mCenters = new float[][]
250
        {
251
         { 1.5f, 0.0f, 0.0f },
252
         {-1.5f, 0.0f, 0.0f },
253

  
254
         { 0.0f, 1.0f, 1.5f },
255
         { 1.5f, 1.0f, 0.0f },
256
         { 0.0f, 1.0f,-1.5f },
257
         {-1.5f, 1.0f, 0.0f },
258
         { 0.0f,-1.0f, 1.5f },
259
         { 1.5f,-1.0f, 0.0f },
260
         { 0.0f,-1.0f,-1.5f },
261
         {-1.5f,-1.0f, 0.0f },
262

  
263
         { 1.0f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f },
264
         { 1.0f, 1.0f,-2.0f, 2.0f, 1.0f,-1.0f },
265
         {-1.0f, 1.0f,-2.0f,-2.0f, 1.0f,-1.0f },
266
         {-1.0f, 1.0f, 2.0f,-2.0f, 1.0f, 1.0f },
267
         { 1.0f,-1.0f, 2.0f, 2.0f,-1.0f, 1.0f },
268
         { 1.0f,-1.0f,-2.0f, 2.0f,-1.0f,-1.0f },
269
         {-1.0f,-1.0f,-2.0f,-2.0f,-1.0f,-1.0f },
270
         {-1.0f,-1.0f, 2.0f,-2.0f,-1.0f, 1.0f }
271
        };
272
      }
273
    return mCenters;
261 274
    }
262 275

  
263 276
///////////////////////////////////////////////////////////////////////////////////////////////////
......
278 291

  
279 292
  int getFaceColor(int cubit, int cubitface, int numLayers)
280 293
    {
294
    if( mStickerColor==null )
295
      {
296
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
297
      mStickerColor = new int[][]
298
        {
299
          { 0, 0, 4, 0, 5, 0 },
300
          { 0, 0, 5, 1, 4, 0 },
301

  
302
          { 2, 0, 4, 0, 0, 0 },
303
          { 2, 0, 0, 0, 0, 0 },
304
          { 2, 0, 5, 0, 0, 0 },
305
          { 2, 0, 1, 0, 0, 0 },
306
          { 3, 0, 4, 0, 0, 0 },
307
          { 3, 0, 0, 0, 0, 0 },
308
          { 3, 0, 5, 0, 0, 0 },
309
          { 3, 0, 1, 0, 0, 0 },
310

  
311
          { 2, 0, 4, 0, 0, 0 },
312
          { 2, 0, 0, 5, 0, 0 },
313
          { 2, 0, 5, 1, 0, 0 },
314
          { 2, 0, 1, 4, 0, 0 },
315
          { 3, 0, 0, 4, 0, 0 },
316
          { 3, 0, 5, 0, 0, 0 },
317
          { 3, 0, 1, 5, 0, 0 },
318
          { 3, 0, 4, 1, 0, 0 },
319
        };
320
      }
321

  
322
    if( mStickerType==null )
323
      {
324
      mStickerType = new int[][]
325
        {
326
          {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
327
          {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
328
          {             5,NUM_STICKERS,2,           2,NUM_STICKERS,NUM_STICKERS }
329
        };
330
      }
331

  
281 332
    int variant = getCubitVariant(cubit,numLayers);
282 333
    return mStickerType[variant][cubitface]*FACE_COLORS.length + mStickerColor[cubit][cubitface];
283 334
    }
......
314 365

  
315 366
  private boolean quatIsBad(int quatIndex, int corner)
316 367
    {
368
    if( mBadCornerQuats ==null )
369
      {
370
      // quat indices that make corner cubits bandage the puzzle.
371
      mBadCornerQuats = new int[][] { { 2, 8,17,23}, { 5,11,14,20} };
372
      }
373

  
317 374
    int index = (corner%2);
318 375

  
319
    return ( quatIndex==BAD_CORNER_QUATS[index][0] ||
320
             quatIndex==BAD_CORNER_QUATS[index][1] ||
321
             quatIndex==BAD_CORNER_QUATS[index][2] ||
322
             quatIndex==BAD_CORNER_QUATS[index][3]  );
376
    return ( quatIndex== mBadCornerQuats[index][0] ||
377
             quatIndex== mBadCornerQuats[index][1] ||
378
             quatIndex== mBadCornerQuats[index][2] ||
379
             quatIndex== mBadCornerQuats[index][3]  );
323 380
    }
324 381

  
325 382
///////////////////////////////////////////////////////////////////////////////////////////////////
326 383

  
327 384
  private boolean isPermittedDo(int angle)
328 385
    {
386
    if( mQuatMult==null ) initializeQuatMult();
387

  
329 388
    for(int corner=0; corner<8; corner++)
330 389
      {
331 390
      if( !cornerIsUp(corner) )
332 391
        {
333 392
        int currQuat = mCornerQuat[corner];
334
        int finalQuat= QUAT_MULT[angle][currQuat];
393
        int finalQuat= mQuatMult[angle][currQuat];
335 394
        if( quatIsBad(finalQuat,corner) ) return false;
336 395
        }
337 396
      }
......
343 402

  
344 403
  private boolean isPermittedUp(int angle)
345 404
    {
405
    if( mQuatMult==null ) initializeQuatMult();
406

  
346 407
    for(int corner=0; corner<8; corner++)
347 408
      {
348 409
      if( cornerIsUp(corner) )
349 410
        {
350 411
        int currQuat = mCornerQuat[corner];
351
        int finalQuat= QUAT_MULT[angle][currQuat];
412
        int finalQuat= mQuatMult[angle][currQuat];
352 413
        if( quatIsBad(finalQuat,corner) ) return false;
353 414
        }
354 415
      }
......
360 421

  
361 422
  private void computePermittedAngles()
362 423
    {
424
    if( mBasicAngle==null ) initializeBasicAngle();
425

  
363 426
    mPermittedDo = 0;
364 427

  
365
    for(int angle=0; angle<BASIC_ANGLE[0]; angle++)
428
    for(int angle=0; angle<mBasicAngle[0]; angle++)
366 429
      {
367 430
      if( isPermittedDo(angle ) ) mPermittedAngles[0][mPermittedDo++] = angle;
368 431
      }
369 432

  
370 433
    mPermittedUp = 0;
371 434

  
372
    for(int angle=0; angle<BASIC_ANGLE[0]; angle++)
435
    for(int angle=0; angle<mBasicAngle[0]; angle++)
373 436
      {
374 437
      if( isPermittedUp(angle ) ) mPermittedAngles[1][mPermittedUp++] = angle;
375 438
      }
......
379 442

  
380 443
  private int getNextAngle(Random rnd, int layer)
381 444
    {
382
    int basic = BASIC_ANGLE[0];
445
    if( mBasicAngle==null ) initializeBasicAngle();
446
    int basic = mBasicAngle[0];
383 447
    int num = layer==0 ? mPermittedDo:mPermittedUp;
384 448
    int index = rnd.nextInt(num);
385 449
    int angle = mPermittedAngles[layer][index];
......
390 454

  
391 455
  private int getNextAngleNotZero(Random rnd, int layer)
392 456
    {
393
    int basic = BASIC_ANGLE[0];
457
    if( mBasicAngle==null ) initializeBasicAngle();
458
    int basic = mBasicAngle[0];
394 459
    int num = layer==0 ? mPermittedDo:mPermittedUp;
395 460
    int index = rnd.nextInt(num-1);
396 461
    int angle = mPermittedAngles[layer][index+1];
......
426 491

  
427 492
  private void updateCornerQuats(int[] rotInfo)
428 493
    {
494
    if( mQuatMult==null ) initializeQuatMult();
495

  
429 496
    int axis = rotInfo[0];
430 497
    int layer= rotInfo[1];
431 498
    int index=-rotInfo[2];
......
437 504
      if( cornerBelongs(corner,axis,layer) )
438 505
        {
439 506
        int curr = mCornerQuat[corner];
440
        mCornerQuat[corner] = QUAT_MULT[quat][curr];
507
        mCornerQuat[corner] = mQuatMult[quat][curr];
441 508
        }
442 509
      }
443 510
    }

Also available in: Unified diff