Project

General

Profile

Download (21.6 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyMinx.java @ 967c1d17

1 a64e07d0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.objects;
21
22 967c1d17 Leszek Koltunski
import static org.distorted.objects.Movement.TYPE_SPLIT_EDGE;
23
24 a64e07d0 Leszek Koltunski
import android.content.res.Resources;
25
26 af0de0af Leszek Koltunski
import org.distorted.helpers.ObjectSticker;
27 aa26ba7f Leszek Koltunski
import org.distorted.helpers.ScrambleState;
28 a64e07d0 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
29
import org.distorted.library.main.DistortedTexture;
30
import org.distorted.library.mesh.MeshSquare;
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36 efa81f0c Leszek Koltunski
abstract class TwistyMinx extends Twisty12
37 a64e07d0 Leszek Koltunski
{
38 ead91342 Leszek Koltunski
  static final int NUM_CORNERS = 20;
39
  static final int NUM_CENTERS = 12;
40
  static final int NUM_EDGES   = 30;
41
42 bb11be2a Leszek Koltunski
  static final float C2       = (SQ5+3)/4;
43
  static final float LEN      = (float)(Math.sqrt(1.25f+0.5f*SQ5));
44
  static final float SIN54    = (SQ5+1)/4;
45
  static final float COS54    = (float)(Math.sqrt(10-2*SQ5)/4);
46
  static final float SIN18    = (SQ5-1)/4;
47
  static final float COS18    = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
48
  static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
49
  static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
50 a64e07d0 Leszek Koltunski
51
  // the six rotation axis of a Minx. Must be normalized.
52
  static final Static3D[] ROT_AXIS = new Static3D[]
53
         {
54 bb11be2a Leszek Koltunski
           new Static3D(    C2/LEN, SIN54/LEN,    0      ),
55
           new Static3D(   -C2/LEN, SIN54/LEN,    0      ),
56
           new Static3D( 0        ,    C2/LEN, SIN54/LEN ),
57
           new Static3D( 0        ,   -C2/LEN, SIN54/LEN ),
58
           new Static3D( SIN54/LEN,    0     ,    C2/LEN ),
59
           new Static3D( SIN54/LEN,    0     ,   -C2/LEN )
60 a64e07d0 Leszek Koltunski
         };
61
62 967c1d17 Leszek Koltunski
  private static final int[] NUM_ENABLED = {2,2,2,2,2,2,2,2,2,2,2,2};
63
64
  private static final int[][][] ENABLED = new int[][][]
65
      {
66
          {{2,3},{3,5},{1,5},{1,4},{2,4}},
67
          {{0,5},{2,5},{2,3},{3,4},{0,4}},
68
          {{2,3},{2,5},{0,5},{0,4},{3,4}},
69
          {{1,5},{3,5},{2,3},{2,4},{1,4}},
70
          {{0,3},{0,4},{4,5},{1,5},{1,3}},
71
          {{1,2},{1,4},{4,5},{0,5},{0,2}},
72
          {{4,5},{1,4},{1,2},{0,2},{0,5}},
73
          {{4,5},{0,4},{0,3},{1,3},{1,5}},
74
          {{0,2},{0,1},{1,3},{3,5},{2,5}},
75
          {{3,4},{2,4},{1,2},{0,1},{0,3}},
76
          {{2,4},{3,4},{0,3},{0,1},{1,2}},
77
          {{1,3},{0,1},{0,2},{2,5},{3,5}},
78
      };
79
80 af0de0af Leszek Koltunski
  private ScrambleState[] mStates;
81
  private int[] mBasicAngle;
82
  private int[] mFaceMap;
83 ef018c1b Leszek Koltunski
  private float[][] mCuts;
84
  private boolean[][] mLayerRotatable;
85 e9a87113 Leszek Koltunski
  private Movement mMovement;
86 af0de0af Leszek Koltunski
  Static4D[] mQuats;
87
  float[][] mCenterCoords;
88
  float[][] mCorners;
89
  int[][] mCornerFaceMap;
90
  int[] mQuatEdgeIndices;
91
  int[] mQuatCornerIndices;
92
  int[][] mEdgeMap;
93
  int[][] mCenterMap;
94
  Static4D[] mBasicCornerV, mCurrCornerV;
95
  ObjectSticker[] mStickers;
96 a480ee80 Leszek Koltunski
97 af0de0af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
98 a64e07d0 Leszek Koltunski
99 af0de0af Leszek Koltunski
  TwistyMinx(int numLayers, int realSize, Static4D quat, DistortedTexture texture, MeshSquare mesh,
100
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
101
    {
102
    super(numLayers, realSize, quat, texture, mesh, effects, moves, obj, res, scrWidth);
103
    }
104 a64e07d0 Leszek Koltunski
105 91792184 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
106
107
  ScrambleState[] getScrambleStates()
108
    {
109
    if( mStates==null )
110
      {
111
      int numLayers = getNumLayers();
112
      initializeScrambleStates(numLayers);
113
      }
114
115
    return mStates;
116
    }
117 7764a67a Leszek Koltunski
118 af0de0af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
119 7764a67a Leszek Koltunski
120 af0de0af Leszek Koltunski
  void initializeCornerV()
121
    {
122
    mBasicCornerV = new Static4D[3];
123
    mCurrCornerV  = new Static4D[3];
124
125 387b6326 Leszek Koltunski
    mBasicCornerV[0] = new Static4D( (SQ5+1)*0.375f, (SQ5-1)*0.375f, -0.750f, 0.0f );
126
    mBasicCornerV[1] = new Static4D(-(SQ5+1)*0.375f, (SQ5-1)*0.375f, -0.750f, 0.0f );
127
    mBasicCornerV[2] = new Static4D(              0,        -1.500f,    0.0f, 0.0f );
128 af0de0af Leszek Koltunski
    }
129
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
// the five vertices that form a given face. Order: the same as colors of the faces in TwistyMinx.
132
133
  void initializeCenterMap()
134
    {
135
    mCenterMap = new int[][]
136
         {
137
           { 0, 12,  4, 14,  2},
138
           { 0,  2, 18,  6, 16},
139
           { 6, 18, 11, 19,  7},
140
           { 3, 15,  9, 11, 19},
141
           { 4,  5, 15,  9, 14},
142
           { 1, 13,  5, 15,  3},
143
           { 1,  3, 19,  7, 17},
144
           {10, 16,  6,  7, 17},
145
           { 0, 12,  8, 10, 16},
146
           { 8, 13,  5,  4, 12},
147
           { 1, 13,  8, 10, 17},
148
           { 2, 14,  9, 11, 18},
149
         };
150
    }
151 d38f1397 Leszek Koltunski
152 af0de0af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
153
// the quadruple ( corner1, corner2, face1, face2 ) defining an edge.
154
// In fact the 2 corners already define it, the faces only provide easy
155
// way to get to know the colors. Order: arbitrary. Face1 arbitrarily on
156
// the 'left' or right of vector corner1 --> corner2, according to Quat.
157
158
  void initializeEdgeMap()
159
    {
160
    mEdgeMap = new int[][]
161 ead91342 Leszek Koltunski
         {
162 7a606778 Leszek Koltunski
           {  0, 12,  0,  8}, //0
163 ead91342 Leszek Koltunski
           { 12,  4,  0,  9},
164
           {  4, 14,  0,  4},
165
           { 14,  2,  0, 11},
166
           {  2,  0,  0,  1},
167 7a606778 Leszek Koltunski
           { 14,  9, 11,  4}, //5
168
           {  9, 11, 11,  3},
169
           { 11, 18, 11,  2},
170
           { 18,  2, 11,  1},
171 ead91342 Leszek Koltunski
           { 18,  6,  1,  2},
172 7a606778 Leszek Koltunski
           {  6, 16,  1,  7}, //10
173
           { 16,  0,  1,  8},
174
           { 16, 10,  8,  7},
175
           { 10,  8,  8, 10},
176
           {  8, 12,  8,  9},
177
           {  8, 13,  9, 10}, //15
178 ead91342 Leszek Koltunski
           { 13,  5,  9,  5},
179
           {  5,  4,  9,  4},
180 7a606778 Leszek Koltunski
           {  5, 15,  4,  5},
181
           { 15,  9,  4,  3},
182
           { 11, 19,  2,  3}, //20
183 ead91342 Leszek Koltunski
           { 19,  7,  2,  6},
184
           {  7,  6,  2,  7},
185
           {  7, 17,  7,  6},
186
           { 17, 10,  7, 10},
187 7a606778 Leszek Koltunski
           { 17,  1, 10,  6}, //25
188 ead91342 Leszek Koltunski
           {  1,  3,  5,  6},
189
           {  3, 19,  3,  6},
190
           {  1, 13, 10,  5},
191 7a606778 Leszek Koltunski
           {  3, 15,  5,  3},
192 ead91342 Leszek Koltunski
         };
193 af0de0af Leszek Koltunski
    }
194 ead91342 Leszek Koltunski
195 af0de0af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
196 ead91342 Leszek Koltunski
197 af0de0af Leszek Koltunski
  void initializeQuatIndices()
198 ead91342 Leszek Koltunski
    {
199 af0de0af Leszek Koltunski
    mQuatEdgeIndices = new int[]
200 ead91342 Leszek Koltunski
      {
201 af0de0af Leszek Koltunski
        56, 40, 43, 59,  0, 19,  9, 54, 58, 49,
202
        48, 24, 52,  4, 16, 32, 20, 11, 21, 35,
203
        37, 30,  8, 28, 36, 44,  1, 46, 12, 47
204
      };
205
    mQuatCornerIndices = new int[]
206
      {
207
         0,  2,  3,  1, 40, 31, 41, 30, 39, 35,
208
        36, 34, 56, 32, 43, 21, 48, 28, 42, 23
209
      };
210
    }
211 ead91342 Leszek Koltunski
212 af0de0af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
213 ead91342 Leszek Koltunski
214 af0de0af Leszek Koltunski
  void initializeCornerFaceMap()
215
    {
216
    mCornerFaceMap = new int[][]
217
         {
218
           {  0, 1, 8 },
219
           {  6, 5,10 },
220
           {  1, 0,11 },
221
           {  5, 6, 3 },
222
           {  0, 9, 4 },
223
           {  5, 4, 9 },
224
           {  7, 1, 2 },
225
           {  2, 6, 7 },
226
           { 10, 9, 8 },
227
           {  4, 3,11 },
228
           {  7,10, 8 },
229
           {  3, 2,11 },
230
           {  0, 8, 9 },
231
           {  9,10, 5 },
232
           {  0, 4,11 },
233
           {  4, 5, 3 },
234
           {  1, 7, 8 },
235
           {  7, 6,10 },
236
           {  2, 1,11 },
237
           {  6, 2, 3 },
238
         };
239
    }
240 ead91342 Leszek Koltunski
241 af0de0af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
242 ead91342 Leszek Koltunski
243 af0de0af Leszek Koltunski
  void initializeQuats()
244
    {
245
    mQuats = new Static4D[]
246
         {
247
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),  //0
248
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
249
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
250
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
251
252
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),  //4
253
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
254
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
255
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
256
         new Static4D( -0.5f,  0.5f,  0.5f,  0.5f ),
257
         new Static4D( -0.5f,  0.5f, -0.5f,  0.5f ),
258
         new Static4D( -0.5f, -0.5f,  0.5f,  0.5f ),
259
         new Static4D( -0.5f, -0.5f, -0.5f,  0.5f ),
260
261
         new Static4D(  0.5f, SIN54, SIN18,  0.0f ), // 12
262
         new Static4D(  0.5f, SIN54,-SIN18,  0.0f ),
263
         new Static4D(  0.5f,-SIN54, SIN18,  0.0f ),
264
         new Static4D(  0.5f,-SIN54,-SIN18,  0.0f ),
265
         new Static4D( SIN18,  0.5f, SIN54,  0.0f ),
266
         new Static4D( SIN18,  0.5f,-SIN54,  0.0f ),
267
         new Static4D(-SIN18,  0.5f, SIN54,  0.0f ),
268
         new Static4D(-SIN18,  0.5f,-SIN54,  0.0f ),
269
         new Static4D( SIN54, SIN18,  0.5f,  0.0f ),
270
         new Static4D( SIN54,-SIN18,  0.5f,  0.0f ),
271
         new Static4D(-SIN54, SIN18,  0.5f,  0.0f ),
272
         new Static4D(-SIN54,-SIN18,  0.5f,  0.0f ),
273
274
         new Static4D(  0.0f, SIN18, SIN54,  0.5f ), //24
275
         new Static4D(  0.0f, SIN18,-SIN54,  0.5f ),
276
         new Static4D(  0.0f,-SIN18, SIN54,  0.5f ),
277
         new Static4D(  0.0f,-SIN18,-SIN54,  0.5f ),
278
         new Static4D( SIN18, SIN54,  0.0f,  0.5f ),
279
         new Static4D( SIN18,-SIN54,  0.0f,  0.5f ),
280
         new Static4D(-SIN18, SIN54,  0.0f,  0.5f ),
281
         new Static4D(-SIN18,-SIN54,  0.0f,  0.5f ),
282
         new Static4D( SIN54,  0.0f, SIN18,  0.5f ),
283
         new Static4D( SIN54,  0.0f,-SIN18,  0.5f ),
284
         new Static4D(-SIN54,  0.0f, SIN18,  0.5f ),
285
         new Static4D(-SIN54,  0.0f,-SIN18,  0.5f ),
286
287
         new Static4D(  0.0f, SIN54,  0.5f, SIN18 ), //36
288
         new Static4D(  0.0f, SIN54, -0.5f, SIN18 ),
289
         new Static4D(  0.0f,-SIN54,  0.5f, SIN18 ),
290
         new Static4D(  0.0f,-SIN54, -0.5f, SIN18 ),
291
         new Static4D(  0.5f,  0.0f, SIN54, SIN18 ),
292
         new Static4D(  0.5f,  0.0f,-SIN54, SIN18 ),
293
         new Static4D( -0.5f,  0.0f, SIN54, SIN18 ),
294
         new Static4D( -0.5f,  0.0f,-SIN54, SIN18 ),
295
         new Static4D( SIN54,  0.5f,  0.0f, SIN18 ),
296
         new Static4D( SIN54, -0.5f,  0.0f, SIN18 ),
297
         new Static4D(-SIN54,  0.5f,  0.0f, SIN18 ),
298
         new Static4D(-SIN54, -0.5f,  0.0f, SIN18 ),
299
300
         new Static4D(  0.0f,  0.5f, SIN18, SIN54 ), //48
301
         new Static4D(  0.0f,  0.5f,-SIN18, SIN54 ),
302
         new Static4D(  0.0f, -0.5f, SIN18, SIN54 ),
303
         new Static4D(  0.0f, -0.5f,-SIN18, SIN54 ),
304
         new Static4D(  0.5f, SIN18,  0.0f, SIN54 ),
305
         new Static4D(  0.5f,-SIN18,  0.0f, SIN54 ),
306
         new Static4D( -0.5f, SIN18,  0.0f, SIN54 ),
307
         new Static4D( -0.5f,-SIN18,  0.0f, SIN54 ),
308
         new Static4D( SIN18,  0.0f,  0.5f, SIN54 ),
309
         new Static4D( SIN18,  0.0f, -0.5f, SIN54 ),
310
         new Static4D(-SIN18,  0.0f,  0.5f, SIN54 ),
311
         new Static4D(-SIN18,  0.0f, -0.5f, SIN54 ),
312
         };
313 ead91342 Leszek Koltunski
    }
314
315 af0de0af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
316
// Coordinates of all 20 corners of a Minx
317 ead91342 Leszek Koltunski
318 af0de0af Leszek Koltunski
  void initializeCorners()
319 ead91342 Leszek Koltunski
    {
320 387b6326 Leszek Koltunski
    float cA = 1.5f;
321
    float cB = 3*C2;
322
    float cC = 3*SIN54;
323
324 af0de0af Leszek Koltunski
    mCorners = new float[][]
325
         {
326 387b6326 Leszek Koltunski
             {  0, cA, cB},
327
             {  0, cA,-cB},
328
             {  0,-cA, cB},
329
             {  0,-cA,-cB},
330
             { cB,  0, cA},
331
             { cB,  0,-cA},
332
             {-cB,  0, cA},
333
             {-cB,  0,-cA},
334
             { cA, cB,  0},
335
             { cA,-cB,  0},
336
             {-cA, cB,  0},
337
             {-cA,-cB,  0},
338
             { cC, cC, cC},
339
             { cC, cC,-cC},
340
             { cC,-cC, cC},
341
             { cC,-cC,-cC},
342
             {-cC, cC, cC},
343
             {-cC, cC,-cC},
344
             {-cC,-cC, cC},
345
             {-cC,-cC,-cC},
346 af0de0af Leszek Koltunski
         };
347 ead91342 Leszek Koltunski
    }
348
349 a64e07d0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
350
351 af0de0af Leszek Koltunski
  void initializeCenterCoords()
352 a64e07d0 Leszek Koltunski
    {
353 af0de0af Leszek Koltunski
    if( mCorners==null ) initializeCorners();
354
    if( mCenterMap==null ) initializeCenterMap();
355 aa26ba7f Leszek Koltunski
356 af0de0af Leszek Koltunski
    mCenterCoords = new float[NUM_CENTERS][3];
357
358
    for(int center=0; center<NUM_CENTERS; center++)
359
      {
360
      int[] map = mCenterMap[center];
361
362
      float x = mCorners[map[0]][0] +
363
                mCorners[map[1]][0] +
364
                mCorners[map[2]][0] +
365
                mCorners[map[3]][0] +
366
                mCorners[map[4]][0] ;
367
368
      float y = mCorners[map[0]][1] +
369
                mCorners[map[1]][1] +
370
                mCorners[map[2]][1] +
371
                mCorners[map[3]][1] +
372
                mCorners[map[4]][1] ;
373
374
      float z = mCorners[map[0]][2] +
375
                mCorners[map[1]][2] +
376
                mCorners[map[2]][2] +
377
                mCorners[map[3]][2] +
378
                mCorners[map[4]][2] ;
379
380
      mCenterCoords[center][0] = x/5;
381
      mCenterCoords[center][1] = y/5;
382
      mCenterCoords[center][2] = z/5;
383
      }
384 a64e07d0 Leszek Koltunski
    }
385
386 a480ee80 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
387
388 aa26ba7f Leszek Koltunski
  private int[] generateL(int numLayers, int index)
389 a480ee80 Leszek Koltunski
    {
390 aa26ba7f Leszek Koltunski
    int rows = (numLayers-1)/2;
391
    int[] ret = new int[3*4*rows];
392
393
    for(int i=0; i<rows; i++)
394
      {
395
      ret[12*i   ] = i;
396
      ret[12*i+ 1] =-2;
397
      ret[12*i+ 2] = index;
398
      ret[12*i+ 3] = i;
399
      ret[12*i+ 4] =-1;
400
      ret[12*i+ 5] = index;
401
      ret[12*i+ 6] = i;
402
      ret[12*i+ 7] =+1;
403
      ret[12*i+ 8] = index;
404
      ret[12*i+ 9] = i;
405
      ret[12*i+10] =+2;
406
      ret[12*i+11] = index;
407
      }
408
409
    return ret;
410 a480ee80 Leszek Koltunski
    }
411
412 a64e07d0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
413
414 aa26ba7f Leszek Koltunski
  private int[] generateR(int numLayers, int index)
415 a64e07d0 Leszek Koltunski
    {
416 aa26ba7f Leszek Koltunski
    int rows = (numLayers-1)/2;
417
    int[] ret = new int[3*4*rows];
418
419
    for(int i=0; i<rows; i++)
420
      {
421
      int lay = rows+i+1;
422
423
      ret[12*i   ] = lay;
424
      ret[12*i+ 1] =-2;
425
      ret[12*i+ 2] = index;
426
      ret[12*i+ 3] = lay;
427
      ret[12*i+ 4] =-1;
428
      ret[12*i+ 5] = index;
429
      ret[12*i+ 6] = lay;
430
      ret[12*i+ 7] =+1;
431
      ret[12*i+ 8] = index;
432
      ret[12*i+ 9] = lay;
433
      ret[12*i+10] =+2;
434
      ret[12*i+11] = index;
435
      }
436
437
    return ret;
438 a64e07d0 Leszek Koltunski
    }
439
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441
442 aa26ba7f Leszek Koltunski
  private int[] generateB(int numLayers, int index)
443 a64e07d0 Leszek Koltunski
    {
444 aa26ba7f Leszek Koltunski
    int rows = (numLayers-1);
445
    int half = rows/2;
446
    int[] ret = new int[3*4*rows];
447
448
    for(int i=0; i<rows; i++)
449
      {
450
      int ind = i<half? index : index+1;
451
      int lay = i<half? i : i+1;
452
453
      ret[12*i   ] = lay;
454
      ret[12*i+ 1] =-2;
455
      ret[12*i+ 2] = ind;
456
      ret[12*i+ 3] = lay;
457
      ret[12*i+ 4] =-1;
458
      ret[12*i+ 5] = ind;
459
      ret[12*i+ 6] = lay;
460
      ret[12*i+ 7] =+1;
461
      ret[12*i+ 8] = ind;
462
      ret[12*i+ 9] = lay;
463
      ret[12*i+10] =+2;
464
      ret[12*i+11] = ind;
465
      }
466
467
    return ret;
468 a64e07d0 Leszek Koltunski
    }
469
470 169219a7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
471
472 aa26ba7f Leszek Koltunski
  private void initializeScrambleStates(int numLayers)
473 169219a7 Leszek Koltunski
    {
474 aa26ba7f Leszek Koltunski
    int[] LEFT0 = generateL(numLayers,1);
475
    int[] RIGH0 = generateR(numLayers,2);
476
    int[] LEFT1 = generateL(numLayers,3);
477
    int[] RIGH1 = generateR(numLayers,4);
478
    int[] LEFT2 = generateL(numLayers,5);
479
    int[] RIGH2 = generateR(numLayers,6);
480
    int[] LEFT3 = generateL(numLayers,7);
481
    int[] RIGH3 = generateR(numLayers,8);
482
    int[] LEFT4 = generateL(numLayers,9);
483
    int[] RIGH4 = generateR(numLayers,10);
484
    int[] LEFT5 = generateL(numLayers,11);
485
    int[] RIGH5 = generateR(numLayers,12);
486
487
    int[] BOTH1 = generateB(numLayers,1);
488
    int[] BOTH3 = generateB(numLayers,3);
489
    int[] BOTH5 = generateB(numLayers,5);
490
    int[] BOTH7 = generateB(numLayers,7);
491
    int[] BOTH9 = generateB(numLayers,9);
492
    int[] BOTH11= generateB(numLayers,11);
493
494
    mStates = new ScrambleState[]
495
      {
496
      new ScrambleState( new int[][] { BOTH1,BOTH3,BOTH5,BOTH7,BOTH9,BOTH11 } ), // beg
497
      new ScrambleState( new int[][] { {}   ,RIGH1,LEFT2,RIGH3,LEFT4,LEFT5  } ), // 0L
498
      new ScrambleState( new int[][] { {}   ,LEFT1,RIGH2,LEFT3,RIGH4,RIGH5  } ), // 0R
499
      new ScrambleState( new int[][] { RIGH0,{}   ,LEFT2,RIGH3,RIGH4,RIGH5  } ), // 1L
500
      new ScrambleState( new int[][] { LEFT0,{}   ,RIGH2,LEFT3,LEFT4,LEFT5  } ), // 1R
501
      new ScrambleState( new int[][] { LEFT0,LEFT1,{}   ,RIGH3,LEFT4,RIGH5  } ), // 2L
502
      new ScrambleState( new int[][] { RIGH0,RIGH1,{}   ,LEFT3,RIGH4,LEFT5  } ), // 2R
503
      new ScrambleState( new int[][] { RIGH0,RIGH1,RIGH2,{}   ,LEFT4,RIGH5  } ), // 3L
504
      new ScrambleState( new int[][] { LEFT0,LEFT1,LEFT2,{}   ,RIGH4,LEFT5  } ), // 3R
505
      new ScrambleState( new int[][] { LEFT0,RIGH1,LEFT2,LEFT3,{}   ,RIGH5  } ), // 4L
506
      new ScrambleState( new int[][] { RIGH0,LEFT1,RIGH2,RIGH3,{}   ,LEFT5  } ), // 4R
507
      new ScrambleState( new int[][] { LEFT0,RIGH1,RIGH2,RIGH3,RIGH4,{}     } ), // 5L
508
      new ScrambleState( new int[][] { RIGH0,LEFT1,LEFT2,LEFT3,LEFT4,{}     } ), // 5R
509
      };
510 169219a7 Leszek Koltunski
    }
511
512 a64e07d0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
513
514 aa26ba7f Leszek Koltunski
  int[] getSolvedQuats(int cubit, int numLayers)
515 a64e07d0 Leszek Koltunski
    {
516 af0de0af Leszek Koltunski
    if( mQuats==null ) initializeQuats();
517
    if( mFaceMap==null ) mFaceMap = new int[] {8,10,3,7,1,11,9,2,4,0,5,6};
518 aa26ba7f Leszek Koltunski
    int status = retCubitSolvedStatus(cubit,numLayers);
519 967c1d17 Leszek Koltunski
    return status<0 ? null : buildSolvedQuats(Movement12.FACE_AXIS[mFaceMap[status]],mQuats);
520 a64e07d0 Leszek Koltunski
    }
521
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523
524 aa26ba7f Leszek Koltunski
  Static4D[] getQuats()
525 a64e07d0 Leszek Koltunski
    {
526 af0de0af Leszek Koltunski
    if( mQuats==null ) initializeQuats();
527
    return mQuats;
528 a64e07d0 Leszek Koltunski
    }
529 ef018c1b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
530
531
  float[][] genericGetCuts(int numLayers, float dist)
532
    {
533
    if( mCuts==null )
534
      {
535
      mCuts = new float[6][numLayers-1];
536 967c1d17 Leszek Koltunski
      float D = numLayers*Movement12.DIST3D;
537 a76d9cb4 Leszek Koltunski
      float X = 2*D/(2+SIN18);  // height of the 'upper' part of a dodecahedron, i.e. put it on a table,
538
                                // its height is then 2D, it has one 'lower' part of height X, one
539 ef018c1b Leszek Koltunski
                                // 'middle' part of height Y and one upper part of height X again.
540
      int num = (numLayers-1)/2;
541
      float G = X*dist/num;     // height of one Layer
542
543
      for(int i=0; i<num; i++)
544
        {
545 a76d9cb4 Leszek Koltunski
        float cut = -D + (i+0.85f)*G;  // 0.85? not fully correct; attempt to make it
546
                                       // easier to rotate the outer layers
547 ef018c1b Leszek Koltunski
        int j = 2*num-1-i;
548
        mCuts[0][i] = +cut;
549
        mCuts[0][j] = -cut;
550
        mCuts[1][i] = +cut;
551
        mCuts[1][j] = -cut;
552
        mCuts[2][i] = +cut;
553
        mCuts[2][j] = -cut;
554
        mCuts[3][i] = +cut;
555
        mCuts[3][j] = -cut;
556
        mCuts[4][i] = +cut;
557
        mCuts[4][j] = -cut;
558
        mCuts[5][i] = +cut;
559
        mCuts[5][j] = -cut;
560
        }
561
      }
562
563
    return mCuts;
564
    }
565
566
///////////////////////////////////////////////////////////////////////////////////////////////////
567
568
  private void getLayerRotatable(int numLayers)
569
    {
570
    if( mLayerRotatable==null )
571
      {
572
      int numAxis = ROT_AXIS.length;
573
      boolean[] tmp = new boolean[numLayers];
574
      for(int i=0; i<numLayers; i++) tmp[i] = true;
575
      tmp[numLayers/2] = false;
576
      mLayerRotatable = new boolean[numAxis][];
577
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
578
      }
579
    }
580 a64e07d0 Leszek Koltunski
581
///////////////////////////////////////////////////////////////////////////////////////////////////
582
583 aa26ba7f Leszek Koltunski
  int getSolvedFunctionIndex()
584 a64e07d0 Leszek Koltunski
    {
585 aa26ba7f Leszek Koltunski
    return 0;
586 a64e07d0 Leszek Koltunski
    }
587
588 0812242b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
589
590 aa26ba7f Leszek Koltunski
  int getNumCubitFaces()
591 0812242b Leszek Koltunski
    {
592 efa81f0c Leszek Koltunski
    return 6;
593 4c737817 Leszek Koltunski
    }
594
595 0812242b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
596
// PUBLIC API
597
598
  public Static3D[] getRotationAxis()
599
    {
600
    return ROT_AXIS;
601
    }
602
603 e9a87113 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
604
605
  public Movement getMovement()
606
    {
607 ef018c1b Leszek Koltunski
    if( mMovement==null )
608
      {
609
      int numLayers = getNumLayers();
610
      if( mCuts==null ) getCuts(numLayers);
611
      getLayerRotatable(numLayers);
612 967c1d17 Leszek Koltunski
      mMovement = new Movement12(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_SPLIT_EDGE,NUM_ENABLED,ENABLED);
613 ef018c1b Leszek Koltunski
      }
614 e9a87113 Leszek Koltunski
    return mMovement;
615
    }
616
617 0812242b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
618
619
  public int[] getBasicAngle()
620
    {
621 af0de0af Leszek Koltunski
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 5,5,5,5,5,5 };
622
    return mBasicAngle;
623 0812242b Leszek Koltunski
    }
624 a64e07d0 Leszek Koltunski
}