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/TwistySquare2.java
36 36

  
37 37
class TwistySquare2 extends TwistySquare
38 38
{
39
  private static final float Y = 0.75f + X/2;
40
  private static final float Z = 0.75f - X/2;
41

  
42
  private static final int[] QUAT_NUMBER = new int[]
43
    {
44
      0, 6,
45
      0, 9, 6, 3, 18, 15, 12, 21,
46
      0, 9, 6, 3, 0, 9, 6, 3,
47
      15, 12, 21, 18, 15, 12, 21, 18
48
    };
49

  
50
  // centers of the 2 middles + 8 edges + 8 left corners + 8 right corners
51
  private static final float[][] CENTERS = new float[][]
52
    {
53
      { 1.5f, 0.0f, 0.0f },
54
      {-1.5f, 0.0f, 0.0f },
55

  
56
      { 0.0f, 1.0f, 1.5f },
57
      { 1.5f, 1.0f, 0.0f },
58
      { 0.0f, 1.0f,-1.5f },
59
      {-1.5f, 1.0f, 0.0f },
60
      { 0.0f,-1.0f, 1.5f },
61
      { 1.5f,-1.0f, 0.0f },
62
      { 0.0f,-1.0f,-1.5f },
63
      {-1.5f,-1.0f, 0.0f },
64

  
65
      {    Y, 1.0f, 1.5f },
66
      { 1.5f, 1.0f,   -Y },
67
      {   -Y, 1.0f,-1.5f },
68
      {-1.5f, 1.0f,    Y },
69
      {    Y,-1.0f, 1.5f },
70
      { 1.5f,-1.0f,   -Y },
71
      {   -Y,-1.0f,-1.5f },
72
      {-1.5f,-1.0f,    Y },
73

  
74
      { 1.5f, 1.0f,    Y },
75
      {    Y, 1.0f,-1.5f },
76
      {-1.5f, 1.0f,   -Y },
77
      {   -Y, 1.0f, 1.5f },
78
      { 1.5f,-1.0f,    Y },
79
      {    Y,-1.0f,-1.5f },
80
      {-1.5f,-1.0f,   -Y },
81
      {   -Y,-1.0f, 1.5f },
82
    };
83

  
84
  private static final double[][] VERTICES_CORNER = new double[][]
85
    {
86
      { X-1.5+Z, 0.5,  0.0 },
87
      {       Z, 0.5,  0.0 },
88
      {  -1.5+Z, 0.5, -1.5 },
89
      { X-1.5+Z,-0.5,  0.0 },
90
      {       Z,-0.5,  0.0 },
91
      {  -1.5+Z,-0.5, -1.5 }
92
    };
93

  
94
  private static final int[][] VERT_INDEXES_CORNER = new int[][]
95
    {
96
      {0,1,2},   // counterclockwise!
97
      {5,4,3},
98
      {3,4,1,0},
99
      {4,5,2,1},
100
      {5,3,0,2}
101
    };
102

  
103
  private static final float[][] STICKERS = new float[][]
104
    {
105
      { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
106
      { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
107
      { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
108
      { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
109
      { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
110
      { -0.11602539f, -0.25f, 0.4330127f, -0.25f, -0.3169873f, 0.5f }                     // corner top
111
    };
112

  
113
  private static final int NUM_STICKERS = STICKERS.length;
114

  
115
  private static final int[][] mStickerType = new int[][]
116
    {
117
      {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
118
      {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
119
      {             5,NUM_STICKERS,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
120
      {  NUM_STICKERS,           5,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS }
121
    };
122

  
123
  // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
124
  private static final int[][] mStickerColor = new int[][]
125
    {
126
      { 0, 0, 4, 0, 5, 0 }, // 0
127
      { 0, 0, 5, 1, 4, 0 },
128

  
129
      { 2, 0, 4, 0, 0, 0 }, // 2
130
      { 2, 0, 0, 0, 0, 0 },
131
      { 2, 0, 5, 0, 0, 0 },
132
      { 2, 0, 1, 0, 0, 0 },
133
      { 3, 0, 4, 0, 0, 0 },
134
      { 3, 0, 0, 0, 0, 0 },
135
      { 3, 0, 5, 0, 0, 0 },
136
      { 3, 0, 1, 0, 0, 0 },
137

  
138
      { 2, 0, 4, 0, 0, 0 }, // 10
139
      { 2, 0, 0, 0, 0, 0 },
140
      { 2, 0, 5, 0, 0, 0 },
141
      { 2, 0, 1, 0, 0, 0 },
142
      { 0, 3, 4, 0, 0, 0 },
143
      { 0, 3, 0, 0, 0, 0 },
144
      { 0, 3, 5, 0, 0, 0 },
145
      { 0, 3, 1, 0, 0, 0 },
146

  
147
      { 0, 2, 0, 0, 0, 0 }, // 18
148
      { 0, 2, 5, 0, 0, 0 },
149
      { 0, 2, 1, 0, 0, 0 },
150
      { 0, 2, 4, 0, 0, 0 },
151
      { 3, 0, 0, 0, 0, 0 },
152
      { 3, 0, 5, 0, 0, 0 },
153
      { 3, 0, 1, 0, 0, 0 },
154
      { 3, 0, 4, 0, 0, 0 },
155
    };
156

  
157
  private static final ObjectSticker[] mStickers;
158

  
159
  static
160
    {
161
    mStickers = new ObjectSticker[NUM_STICKERS];
162
    final float R1 = 0.06f;
163
    final float R2 = 0.04f;
164
    final float R3 = 0.11f;
165
    final float R4 = 0.03f;
166
    final float R5 = 0.11f;
167
    final float R6 = 0.025f;
168
    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} };
169
    final float[] strokes = { 0.05f,0.04f,0.09f,0.05f,0.08f,0.06f };
170

  
171
    for(int s=0; s<NUM_STICKERS; s++)
172
      {
173
      mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
174
      }
175
    }
39
  private static final int NUM_STICKERS = 6;
176 40

  
177 41
  private int mCurrState;
178 42
  private int mIndexExcluded;
179 43
  private final ScrambleState[] mStates;
180 44
  private int[][] mScrambleTable;
181 45
  private int[] mNumOccurences;
46
  private int[] mQuatNumber;
47
  private float[][] mCenters;
48
  private int[][] mStickerColor;
49
  private int[][] mStickerType;
50
  private ObjectSticker[] mStickers;
182 51

  
183 52
///////////////////////////////////////////////////////////////////////////////////////////////////
184 53

  
......
218 87

  
219 88
    if( variant==0 )
220 89
      {
90
      double[][] vertices = new double[][]
91
        {
92
         { -1.5-X, 0.5, 1.5 },
93
         {    0.0, 0.5, 1.5 },
94
         {    0.0, 0.5,-1.5 },
95
         { -1.5+X, 0.5,-1.5 },
96
         { -1.5-X,-0.5, 1.5 },
97
         {    0.0,-0.5, 1.5 },
98
         {    0.0,-0.5,-1.5 },
99
         { -1.5+X,-0.5,-1.5 }
100
        };
101

  
102
      int[][] vert_indices = new int[][]
103
        {
104
         {0,1,2,3},
105
         {4,5,6,7},
106
         {4,5,1,0},
107
         {5,6,2,1},
108
         {6,7,3,2},
109
         {7,4,0,3}
110
        };
111

  
221 112
      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} };
222 113
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
223 114
      float[][] corners   = new float[][] { {0.03f,0.05f} };
224 115
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
225 116
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
226 117
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
227
      return new ObjectShape(VERTICES_MIDDLE,VERT_INDEXES_MIDDLE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
118
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
228 119
      }
229 120
    else if( variant==1 )
230 121
      {
122
      double[][] vertices = new double[][]
123
        {
124
         { -X, 0.5, 0.0 },
125
         { +X, 0.5, 0.0 },
126
         {0.0, 0.5,-1.5 },
127
         { -X,-0.5, 0.0 },
128
         { +X,-0.5, 0.0 },
129
         {0.0,-0.5,-1.5 },
130
        };
131

  
132
      int[][] vert_indices = new int[][]
133
        {
134
         {0,1,2},
135
         {3,4,5},
136
         {3,4,1,0},
137
         {4,5,2,1},
138
         {5,3,0,2}
139
        };
140

  
231 141
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
232 142
      int[] bandIndices   = new int[] { 0,1,0,1,1 };
233 143
      float[][] corners   = new float[][] { {0.04f,0.15f} };
234 144
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
235 145
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
236 146
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
237
      return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
147
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
238 148
      }
239 149
    else
240 150
      {
151
      double[][] vertices = new double[][]
152
        {
153
         {-0.75f+X/2, 0.5,  0.0 },
154
         { 0.75f-X/2, 0.5,  0.0 },
155
         {-0.75f-X/2, 0.5, -1.5 },
156
         {-0.75f+X/2,-0.5,  0.0 },
157
         { 0.75f-X/2,-0.5,  0.0 },
158
         {-0.75f-X/2,-0.5, -1.5 }
159
        };
160
      int[][] vert_indices = new int[][]
161
        {
162
         {0,1,2},
163
         {5,4,3},
164
         {3,4,1,0},
165
         {4,5,2,1},
166
         {5,3,0,2}
167
        };
168

  
241 169
      float[][] bands     = new float[][] { {0.030f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
242 170
      int[] bandIndices   = new int[] { 0,0,0,1,1 };
243 171
      float[][] corners   = new float[][] { {0.05f,0.13f} };
244 172
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
245 173
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
246 174
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
247
      return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
175
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
248 176
      }
249 177
    }
250 178

  
......
252 180

  
253 181
  Static4D getQuat(int cubit, int numLayers)
254 182
    {
255
    return QUATS[QUAT_NUMBER[cubit]];
183
    if( mQuats==null ) initializeQuats();
184

  
185
    if( mQuatNumber ==null )
186
      {
187
      mQuatNumber = new int[]
188
        {
189
        0, 6,
190
        0, 9, 6, 3, 18, 15, 12, 21,
191
        0, 9, 6, 3, 0, 9, 6, 3,
192
        15, 12, 21, 18, 15, 12, 21, 18
193
        };
194
      }
195

  
196
    return mQuats[mQuatNumber[cubit]];
256 197
    }
257 198

  
258 199
///////////////////////////////////////////////////////////////////////////////////////////////////
......
273 214

  
274 215
  ObjectSticker retSticker(int face)
275 216
    {
217
    if( mStickers==null )
218
      {
219
      float[][] STICKERS = new float[][]
220
        {
221
          { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
222
          { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
223
          { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
224
          { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
225
          { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
226
          { -0.11602539f, -0.25f, 0.4330127f, -0.25f, -0.3169873f, 0.5f }                     // corner top
227
        };
228

  
229
      final float R1 = 0.06f;
230
      final float R2 = 0.04f;
231
      final float R3 = 0.11f;
232
      final float R4 = 0.03f;
233
      final float R5 = 0.11f;
234
      final float R6 = 0.025f;
235
      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} };
236
      final float[] strokes = { 0.05f,0.04f,0.09f,0.05f,0.08f,0.06f };
237

  
238
      mStickers = new ObjectSticker[NUM_STICKERS];
239

  
240
      for(int s=0; s<NUM_STICKERS; s++)
241
        {
242
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
243
        }
244
      }
245

  
276 246
    return mStickers[face/NUM_FACES];
277 247
    }
278 248

  
......
280 250

  
281 251
  float[][] getCubitPositions(int numLayers)
282 252
    {
283
    return CENTERS;
253
    if( mCenters ==null )
254
      {
255
      float Y = 0.75f + X/2;
256

  
257
      mCenters = new float[][]
258
        {
259
         { 1.5f, 0.0f, 0.0f },
260
         {-1.5f, 0.0f, 0.0f },
261

  
262
         { 0.0f, 1.0f, 1.5f },
263
         { 1.5f, 1.0f, 0.0f },
264
         { 0.0f, 1.0f,-1.5f },
265
         {-1.5f, 1.0f, 0.0f },
266
         { 0.0f,-1.0f, 1.5f },
267
         { 1.5f,-1.0f, 0.0f },
268
         { 0.0f,-1.0f,-1.5f },
269
         {-1.5f,-1.0f, 0.0f },
270

  
271
         {    Y, 1.0f, 1.5f },
272
         { 1.5f, 1.0f,   -Y },
273
         {   -Y, 1.0f,-1.5f },
274
         {-1.5f, 1.0f,    Y },
275
         {    Y,-1.0f, 1.5f },
276
         { 1.5f,-1.0f,   -Y },
277
         {   -Y,-1.0f,-1.5f },
278
         {-1.5f,-1.0f,    Y },
279

  
280
         { 1.5f, 1.0f,    Y },
281
         {    Y, 1.0f,-1.5f },
282
         {-1.5f, 1.0f,   -Y },
283
         {   -Y, 1.0f, 1.5f },
284
         { 1.5f,-1.0f,    Y },
285
         {    Y,-1.0f,-1.5f },
286
         {-1.5f,-1.0f,   -Y },
287
         {   -Y,-1.0f, 1.5f },
288
        };
289
      }
290

  
291
    return mCenters;
284 292
    }
285 293

  
286 294
///////////////////////////////////////////////////////////////////////////////////////////////////
......
301 309

  
302 310
  int getFaceColor(int cubit, int cubitface, int numLayers)
303 311
    {
312
    if( mStickerColor==null )
313
      {
314
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
315
      mStickerColor = new int[][]
316
        {
317
         { 0, 0, 4, 0, 5, 0 }, // 0
318
         { 0, 0, 5, 1, 4, 0 },
319

  
320
         { 2, 0, 4, 0, 0, 0 }, // 2
321
         { 2, 0, 0, 0, 0, 0 },
322
         { 2, 0, 5, 0, 0, 0 },
323
         { 2, 0, 1, 0, 0, 0 },
324
         { 3, 0, 4, 0, 0, 0 },
325
         { 3, 0, 0, 0, 0, 0 },
326
         { 3, 0, 5, 0, 0, 0 },
327
         { 3, 0, 1, 0, 0, 0 },
328

  
329
         { 2, 0, 4, 0, 0, 0 }, // 10
330
         { 2, 0, 0, 0, 0, 0 },
331
         { 2, 0, 5, 0, 0, 0 },
332
         { 2, 0, 1, 0, 0, 0 },
333
         { 0, 3, 4, 0, 0, 0 },
334
         { 0, 3, 0, 0, 0, 0 },
335
         { 0, 3, 5, 0, 0, 0 },
336
         { 0, 3, 1, 0, 0, 0 },
337

  
338
         { 0, 2, 0, 0, 0, 0 }, // 18
339
         { 0, 2, 5, 0, 0, 0 },
340
         { 0, 2, 1, 0, 0, 0 },
341
         { 0, 2, 4, 0, 0, 0 },
342
         { 3, 0, 0, 0, 0, 0 },
343
         { 3, 0, 5, 0, 0, 0 },
344
         { 3, 0, 1, 0, 0, 0 },
345
         { 3, 0, 4, 0, 0, 0 },
346
        };
347
      }
348

  
349
    if( mStickerType==null )
350
      {
351
      mStickerType = new int[][]
352
        {
353
         {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
354
         {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
355
         {             5,NUM_STICKERS,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
356
         {  NUM_STICKERS,           5,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS }
357
        };
358
      }
359

  
304 360
    int type;
305 361

  
306 362
         if( cubit< 2             ) type = 0;

Also available in: Unified diff