Project

General

Profile

Download (23.1 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyCuboid.java @ e26eb4e7

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.objectlib.objects;
21
22 59c20632 Leszek Koltunski
import static org.distorted.objectlib.main.Movement.MOVEMENT_SHAPECHANGE;
23 29b82486 Leszek Koltunski
import static org.distorted.objectlib.main.Movement.TYPE_NOT_SPLIT;
24
25
import android.content.res.Resources;
26
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29
30
import org.distorted.objectlib.R;
31 ab31cf6f Leszek Koltunski
import org.distorted.objectlib.main.MovementC;
32 8592461c Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
33 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
34 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ObjectSticker;
36
import org.distorted.objectlib.helpers.ScrambleState;
37 29b82486 Leszek Koltunski
import org.distorted.objectlib.main.Twisty6;
38
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41 d6998705 Leszek Koltunski
public class TwistyCuboid extends Twisty6
42 29b82486 Leszek Koltunski
{
43
  static final Static3D[] ROT_AXIS = new Static3D[]
44
         {
45
           new Static3D(1,0,0),
46
           new Static3D(0,1,0),
47
           new Static3D(0,0,1)
48
         };
49
50
  private ScrambleState[] mStates;
51
  private Static4D[] mQuats;
52
  private float[][] mCuts;
53
  private int[] mBasicAngle;
54
  private ObjectSticker[] mStickers;
55
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58 7ba38dd4 Leszek Koltunski
  public TwistyCuboid(int[] numL, Static4D quat, Static3D move, Resources res)
59 29b82486 Leszek Koltunski
    {
60 7ba38dd4 Leszek Koltunski
    super(numL, (numL[0]+numL[1]+numL[2])/3.0f, quat, move, res);
61 29b82486 Leszek Koltunski
    }
62
63 dfdb26a9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
64
65 d6998705 Leszek Koltunski
  private int[] createEdges(int size, boolean full, int vertex)
66 dfdb26a9 Leszek Koltunski
    {
67 4a5157a1 Leszek Koltunski
    if( size==1 ) return null;
68
69 d6998705 Leszek Koltunski
    if( full )
70 dfdb26a9 Leszek Koltunski
      {
71 d6998705 Leszek Koltunski
      int[] ret = new int[9*size];
72
73
      for(int l=0; l<size; l++)
74
        {
75
        ret[9*l  ] = l;
76
        ret[9*l+1] =-1;
77
        ret[9*l+2] = vertex;
78
        ret[9*l+3] = l;
79
        ret[9*l+4] = 1;
80
        ret[9*l+5] = vertex;
81
        ret[9*l+6] = l;
82
        ret[9*l+7] = 2;
83
        ret[9*l+8] = vertex;
84
        }
85
86
      return ret;
87 dfdb26a9 Leszek Koltunski
      }
88 d6998705 Leszek Koltunski
    else
89
      {
90
      int[] ret = new int[6*size];
91 dfdb26a9 Leszek Koltunski
92 d6998705 Leszek Koltunski
      for(int l=0; l<size; l++)
93
        {
94
        ret[6*l  ] = l;
95
        ret[6*l+1] = 1;
96
        ret[6*l+2] = vertex;
97
        ret[6*l+3] = l;
98
        ret[6*l+4] =-1;
99
        ret[6*l+5] = vertex;
100
        }
101
102
      return ret;
103
      }
104 dfdb26a9 Leszek Koltunski
    }
105
106 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
107
108 f9a81f52 Leszek Koltunski
  public ScrambleState[] getScrambleStates()
109 29b82486 Leszek Koltunski
    {
110
    if( mStates==null )
111
      {
112 d6998705 Leszek Koltunski
      int[] numLayers = getNumLayers();
113
114
      int X = numLayers[0];
115
      int Y = numLayers[1];
116
      int Z = numLayers[2];
117
118
      int[][] mX = new int[16][];
119
      int[][] mY = new int[16][];
120
      int[][] mZ = new int[16][];
121
122 4a5157a1 Leszek Koltunski
      for(int i=0; i<16; i++)
123
        {
124
        mX[i] = createEdges(X,Y==Z,i);
125
        mY[i] = createEdges(Y,X==Z,i);
126
        mZ[i] = createEdges(Z,X==Y,i);
127
        }
128
129
      if( X>1 && Y>1 && Z>1 )
130
        {
131
        mStates = new ScrambleState[]
132
          {
133
          new ScrambleState( new int[][] { mX[ 1], mY[ 2], mZ[ 3] } ),  //  0 0
134
          new ScrambleState( new int[][] {   null, mY[ 4], mZ[ 5] } ),  //  1 x
135
          new ScrambleState( new int[][] { mX[ 6],   null, mZ[ 7] } ),  //  2 y
136
          new ScrambleState( new int[][] { mX[ 8], mY[ 9],   null } ),  //  3 z
137
          new ScrambleState( new int[][] { mX[10],   null, mZ[ 7] } ),  //  4 xy
138
          new ScrambleState( new int[][] { mX[11], mY[ 9],   null } ),  //  5 xz
139
          new ScrambleState( new int[][] {   null, mY[12], mZ[ 5] } ),  //  6 yx
140
          new ScrambleState( new int[][] { mX[ 8], mY[13],   null } ),  //  7 yz
141
          new ScrambleState( new int[][] {   null, mY[ 4], mZ[14] } ),  //  8 zx
142
          new ScrambleState( new int[][] { mX[ 6],   null, mZ[15] } ),  //  9 zy
143
          new ScrambleState( new int[][] {   null,   null, mZ[ 5] } ),  // 10 xyx
144
          new ScrambleState( new int[][] {   null, mY[ 4],   null } ),  // 11 xzx
145
          new ScrambleState( new int[][] {   null,   null, mZ[ 7] } ),  // 12 yxy
146
          new ScrambleState( new int[][] { mX[ 6],   null,   null } ),  // 13 yzy
147
          new ScrambleState( new int[][] {   null, mY[ 9],   null } ),  // 14 zxz
148
          new ScrambleState( new int[][] { mX[ 8],   null,   null } ),  // 15 zyz
149
          };
150
        }
151
      else if( X==1 && Y==1 && Z==1 )
152
        {
153
        int[] state = new int[] {0,-1,0,0,1,0,0,2,0};
154 29b82486 Leszek Koltunski
155 4a5157a1 Leszek Koltunski
        mStates = new ScrambleState[]
156
          {
157
          new ScrambleState( new int[][] { state, state, state } )
158
          };
159
        }
160
      else
161 29b82486 Leszek Koltunski
        {
162 4a5157a1 Leszek Koltunski
        mStates = new ScrambleState[]
163
          {
164
          new ScrambleState( new int[][] { mX[ 0], mY[ 0], mZ[ 0] } )
165
          };
166
        }
167
168 29b82486 Leszek Koltunski
      }
169
170
    return mStates;
171
    }
172
173 4e1dc313 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
174
175 a57e6870 Leszek Koltunski
  protected int getResource(int[] numLayers)
176 4e1dc313 Leszek Koltunski
    {
177 7dab2aea Leszek Koltunski
    int x = numLayers[0];
178
    int y = numLayers[1];
179
180 b19a1d32 Leszek Koltunski
    switch(x)
181 4e1dc313 Leszek Koltunski
      {
182 55fa6993 Leszek Koltunski
      case 2: return y==2 ? R.raw.cube_2 : R.raw.cu_232;
183 b19a1d32 Leszek Koltunski
      case 3: switch(y)
184
                {
185
                case 2: return R.raw.cu_323;
186 55fa6993 Leszek Koltunski
                case 3: return R.raw.cube_3;
187 b19a1d32 Leszek Koltunski
                case 4: return R.raw.cu_343;
188
                }
189 55fa6993 Leszek Koltunski
      case 4: return R.raw.cube_4;
190
      case 5: return R.raw.cube_5;
191 4e1dc313 Leszek Koltunski
      }
192
193
    return 0;
194
    }
195
196 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
197
198
  private void initializeQuats()
199
    {
200
    mQuats = new Static4D[]
201
         {
202
         new Static4D(  0.0f,   0.0f,   0.0f,   1.0f),
203
         new Static4D(  1.0f,   0.0f,   0.0f,   0.0f),
204
         new Static4D(  0.0f,   1.0f,   0.0f,   0.0f),
205
         new Static4D(  0.0f,   0.0f,   1.0f,   0.0f),
206
207
         new Static4D( SQ2/2,  SQ2/2,  0.0f ,   0.0f),
208
         new Static4D( SQ2/2, -SQ2/2,  0.0f ,   0.0f),
209
         new Static4D( SQ2/2,   0.0f,  SQ2/2,   0.0f),
210
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,   0.0f),
211
         new Static4D( SQ2/2,   0.0f,   0.0f,  SQ2/2),
212
         new Static4D( SQ2/2,   0.0f,   0.0f, -SQ2/2),
213
         new Static4D(  0.0f,  SQ2/2,  SQ2/2,   0.0f),
214
         new Static4D(  0.0f,  SQ2/2, -SQ2/2,   0.0f),
215
         new Static4D(  0.0f,  SQ2/2,   0.0f,  SQ2/2),
216
         new Static4D(  0.0f,  SQ2/2,   0.0f, -SQ2/2),
217
         new Static4D(  0.0f,   0.0f,  SQ2/2,  SQ2/2),
218
         new Static4D(  0.0f,   0.0f,  SQ2/2, -SQ2/2),
219
220
         new Static4D(  0.5f,   0.5f,   0.5f,   0.5f),
221
         new Static4D(  0.5f,   0.5f,  -0.5f,   0.5f),
222
         new Static4D(  0.5f,   0.5f,  -0.5f,  -0.5f),
223
         new Static4D(  0.5f,  -0.5f,   0.5f,  -0.5f),
224
         new Static4D( -0.5f,  -0.5f,  -0.5f,   0.5f),
225
         new Static4D( -0.5f,   0.5f,  -0.5f,  -0.5f),
226
         new Static4D( -0.5f,   0.5f,   0.5f,  -0.5f),
227
         new Static4D( -0.5f,   0.5f,   0.5f,   0.5f)
228
         };
229
    }
230
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232
233 7b832206 Leszek Koltunski
  public int[] getSolvedQuats(int cubit, int[] numLayers)
234 29b82486 Leszek Koltunski
    {
235
    if( mQuats ==null ) initializeQuats();
236
    int status = retCubitSolvedStatus(cubit,numLayers);
237 ab31cf6f Leszek Koltunski
    return status<0 ? null : buildSolvedQuats(MovementC.FACE_AXIS[status], mQuats);
238 29b82486 Leszek Koltunski
    }
239
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241
242 e30c522a Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
243 29b82486 Leszek Koltunski
    {
244 e30c522a Leszek Koltunski
    int extraI, extraV, num, numL = getNumLayers()[0];
245 29b82486 Leszek Koltunski
    float height;
246
247 a57e6870 Leszek Koltunski
    switch(numL)
248 8396c548 Leszek Koltunski
        {
249
        case 2 : num = 6; extraI = 2; extraV = 2; height = 0.045f; break;
250
        case 3 : num = 5; extraI = 2; extraV = 2; height = 0.045f; break;
251
        case 4 : num = 5; extraI = 1; extraV = 1; height = 0.045f; break;
252
        default: num = 5; extraI = 0; extraV = 0; height = 0.045f; break;
253
        }
254 29b82486 Leszek Koltunski
255
    double[][] vertices = new double[][]
256
          {
257
              { 0.5, 0.5, 0.5 },
258
              { 0.5, 0.5,-0.5 },
259
              { 0.5,-0.5, 0.5 },
260
              { 0.5,-0.5,-0.5 },
261
              {-0.5, 0.5, 0.5 },
262
              {-0.5, 0.5,-0.5 },
263
              {-0.5,-0.5, 0.5 },
264
              {-0.5,-0.5,-0.5 },
265
          };
266
267
    int[][] vert_indices = new int[][]
268
          {
269
              {2,3,1,0},
270
              {7,6,4,5},
271
              {4,0,1,5},
272
              {7,3,2,6},
273
              {6,2,0,4},
274
              {3,7,5,1}
275
          };
276
277
    float[][] corners   = new float[][] { {0.036f,0.12f} };
278
    int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
279
    float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
280
    int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
281
282 8396c548 Leszek Koltunski
    if( variant==0 )
283
      {
284
      float[][] bands   = new float[][] { {height,35,0.5f,0.7f,num,extraI,extraV} };
285
      int[] bandIndices = new int[] { 0,0,0,0,0,0};
286
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
287
      }
288
    else
289
      {
290
      int extraI2, extraV2, num2;
291
292 a57e6870 Leszek Koltunski
      switch(numL)
293 8396c548 Leszek Koltunski
        {
294
        case 2 : num2 = 6; extraI2 = 2; extraV2 = 2; break;
295
        case 3 : num2 = 5; extraI2 = 1; extraV2 = 0; break;
296
        case 4 : num2 = 4; extraI2 = 0; extraV2 = 0; break;
297
        default: num2 = 3; extraI2 = 0; extraV2 = 0; break;
298
        }
299
300 d309baa5 Leszek Koltunski
      float[][] bands   = new float[][]
301
        {
302
          {height,35,0.5f,0.7f,num ,extraI ,extraV },
303
          {height,35,0.5f,0.7f,num2,extraI2,extraV2},
304
          {height,35,0.5f,0.7f,   2,      0,      0},
305
        };
306
      int[] bandIndices = new int[] { 1,1,1,1,0,2};
307 8396c548 Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
308
      }
309 29b82486 Leszek Koltunski
    }
310
311 dfdb26a9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
312
313
  private int getCenterNum(int cubit, int[] numLayers)
314
    {
315
    int num = cubit - getNumCornersAndEdges(numLayers);
316
317
    if( num>=0 )
318
      {
319
      int numLR = (numLayers[1]-2)*(numLayers[2]-2);
320
      if( num<  numLR ) return 0;
321
      if( num<2*numLR ) return 1;
322
      num -= 2*numLR;
323
324
      int numTD = (numLayers[0]-2)*(numLayers[2]-2);
325
      if( num<  numTD ) return 2;
326
      if( num<2*numTD ) return 3;
327
      num -= 2*numTD;
328
329
      int numFB = (numLayers[0]-2)*(numLayers[1]-2);
330
      if( num<  numFB ) return 4;
331
      if( num<2*numFB ) return 5;
332
      }
333
334
    return -1;
335
    }
336
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338
339
  private int getNumCornersAndEdges(int[] numLayers)
340
    {
341
    int x = numLayers[0];
342
    int y = numLayers[1];
343
    int z = numLayers[2];
344
345
    return ( x==1 || y==1 || z==1 ) ? x*y*z : 4*( (x-2)+(y-2)+(z-2) ) + 8;
346
    }
347
348 8da6b1c9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
349
350 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
351 8da6b1c9 Leszek Koltunski
    {
352 dfdb26a9 Leszek Koltunski
    final int X = numLayers[0];
353
    final int Y = numLayers[1];
354
    final int Z = numLayers[2];
355
356
    final float lenX = 0.5f*(X-1);
357
    final float lenY = 0.5f*(Y-1);
358
    final float lenZ = 0.5f*(Z-1);
359 8da6b1c9 Leszek Koltunski
360 a135652b Leszek Koltunski
    int curPos = 0;
361
362
    if( X==1 )
363
      {
364
      float[][] pos = new float[X*Y*Z][];
365
366
      for(int y=0; y<Y; y++)
367
        for(int z=0; z<Z; z++) pos[curPos++] = new float[] {+lenX,y-lenY,z-lenZ};
368
369
      return pos;
370
      }
371
372
    if( Y==1 )
373 dfdb26a9 Leszek Koltunski
      {
374 a135652b Leszek Koltunski
      float[][] pos = new float[X*Y*Z][];
375
376
      for(int x=0; x<X; x++)
377
        for(int z=0; z<Z; z++) pos[curPos++] = new float[] {x-lenX,+lenY,z-lenZ};
378
379
      return pos;
380
      }
381
382
    if( Z==1 )
383
      {
384
      float[][] pos = new float[X*Y*Z][];
385
386
      for(int x=0; x<X; x++)
387
        for(int y=0; y<Y; y++) pos[curPos++] = new float[] {x-lenX,y-lenY,+lenZ};
388 dfdb26a9 Leszek Koltunski
389 a135652b Leszek Koltunski
      return pos;
390 dfdb26a9 Leszek Koltunski
      }
391 a57e6870 Leszek Koltunski
392 dfdb26a9 Leszek Koltunski
    int numCubits = X*Y*Z - (X-2)*(Y-2)*(Z-2);
393 a135652b Leszek Koltunski
    float[][] pos = new float[numCubits][];
394
395
    pos[curPos++] = new float[] {-lenX,-lenY,-lenZ};
396
    pos[curPos++] = new float[] {-lenX,-lenY,+lenZ};
397
    pos[curPos++] = new float[] {-lenX,+lenY,-lenZ};
398
    pos[curPos++] = new float[] {-lenX,+lenY,+lenZ};
399
    pos[curPos++] = new float[] {+lenX,-lenY,-lenZ};
400
    pos[curPos++] = new float[] {+lenX,-lenY,+lenZ};
401
    pos[curPos++] = new float[] {+lenX,+lenY,-lenZ};
402
    pos[curPos++] = new float[] {+lenX,+lenY,+lenZ};
403
404
    for(int i=1; i<X-1; i++) pos[curPos++] = new float[] { i-lenX,  -lenY,  -lenZ };
405
    for(int i=1; i<X-1; i++) pos[curPos++] = new float[] { i-lenX,  -lenY,  +lenZ };
406
    for(int i=1; i<X-1; i++) pos[curPos++] = new float[] { i-lenX,  +lenY,  -lenZ };
407
    for(int i=1; i<X-1; i++) pos[curPos++] = new float[] { i-lenX,  +lenY,  +lenZ };
408
    for(int i=1; i<Y-1; i++) pos[curPos++] = new float[] {  -lenX, i-lenY,  -lenZ };
409
    for(int i=1; i<Y-1; i++) pos[curPos++] = new float[] {  -lenX, i-lenY,  +lenZ };
410
    for(int i=1; i<Y-1; i++) pos[curPos++] = new float[] {  +lenX, i-lenY,  -lenZ };
411
    for(int i=1; i<Y-1; i++) pos[curPos++] = new float[] {  +lenX, i-lenY,  +lenZ };
412
    for(int i=1; i<Z-1; i++) pos[curPos++] = new float[] {  -lenX,  -lenY, i-lenZ };
413
    for(int i=1; i<Z-1; i++) pos[curPos++] = new float[] {  -lenX,  +lenY, i-lenZ };
414
    for(int i=1; i<Z-1; i++) pos[curPos++] = new float[] {  +lenX,  -lenY, i-lenZ };
415
    for(int i=1; i<Z-1; i++) pos[curPos++] = new float[] {  +lenX,  +lenY, i-lenZ };
416 dfdb26a9 Leszek Koltunski
417
    for(int y=1; y<Y-1; y++)
418 a135652b Leszek Koltunski
      for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {+lenX,y-lenY,z-lenZ};
419 dfdb26a9 Leszek Koltunski
420
    for(int y=1; y<Y-1; y++)
421 a135652b Leszek Koltunski
      for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {-lenX,y-lenY,z-lenZ};
422 dfdb26a9 Leszek Koltunski
423
    for(int x=1; x<X-1; x++)
424 a135652b Leszek Koltunski
      for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {x-lenX,+lenY,z-lenZ};
425 dfdb26a9 Leszek Koltunski
426
    for(int x=1; x<X-1; x++)
427 a135652b Leszek Koltunski
      for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {x-lenX,-lenY,z-lenZ};
428 dfdb26a9 Leszek Koltunski
429
    for(int x=1; x<X-1; x++)
430 a135652b Leszek Koltunski
      for(int y=1; y<Y-1; y++) pos[curPos++] = new float[] {x-lenX,y-lenY,+lenZ};
431 dfdb26a9 Leszek Koltunski
432
    for(int x=1; x<X-1; x++)
433 a135652b Leszek Koltunski
      for(int y=1; y<Y-1; y++) pos[curPos++] = new float[] {x-lenX,y-lenY,-lenZ};
434 8da6b1c9 Leszek Koltunski
435 a135652b Leszek Koltunski
    return pos;
436 8da6b1c9 Leszek Koltunski
    }
437
438 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
439
440 7b832206 Leszek Koltunski
  public Static4D getQuat(int cubit, int[] numLayers)
441 29b82486 Leszek Koltunski
    {
442
    if( mQuats ==null ) initializeQuats();
443 8da6b1c9 Leszek Koltunski
444 dfdb26a9 Leszek Koltunski
    int centerNum = getCenterNum(cubit,numLayers);
445 8da6b1c9 Leszek Koltunski
446 dfdb26a9 Leszek Koltunski
    switch(centerNum)
447 8da6b1c9 Leszek Koltunski
      {
448 dfdb26a9 Leszek Koltunski
      case 0 : return mQuats[13];
449
      case 1 : return mQuats[12];
450
      case 2 : return mQuats[ 8];
451
      case 3 : return mQuats[ 9];
452
      case 4 : return mQuats[ 0];
453
      case 5 : return mQuats[ 1];
454
      default: return mQuats[ 0];
455 8da6b1c9 Leszek Koltunski
      }
456 29b82486 Leszek Koltunski
    }
457
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459
460 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
461 29b82486 Leszek Koltunski
    {
462 a57e6870 Leszek Koltunski
    return numLayers[0]>2 ? 2:1;
463 29b82486 Leszek Koltunski
    }
464
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466
467 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
468 29b82486 Leszek Koltunski
    {
469 dfdb26a9 Leszek Koltunski
    return cubit < getNumCornersAndEdges(numLayers) ? 0 : 1;
470 8da6b1c9 Leszek Koltunski
    }
471
472
///////////////////////////////////////////////////////////////////////////////////////////////////
473
474 a75ae1ee Leszek Koltunski
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
475
    {
476
    return 0;
477
    }
478
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480
481
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
482 8da6b1c9 Leszek Koltunski
    {
483 dfdb26a9 Leszek Koltunski
    int centerNum = getCenterNum(cubit,numLayers);
484 8da6b1c9 Leszek Koltunski
485 dfdb26a9 Leszek Koltunski
    if( centerNum<0 )
486 8da6b1c9 Leszek Koltunski
      {
487 a75ae1ee Leszek Koltunski
      int axis = face/2;
488
      return CUBITS[cubit].getRotRow(axis) == (face%2==0 ? (1<<(numLayers[axis]-1)):1) ? face : -1;
489 8da6b1c9 Leszek Koltunski
      }
490
    else
491
      {
492 a75ae1ee Leszek Koltunski
      return face==4 ? centerNum : -1;
493 8da6b1c9 Leszek Koltunski
      }
494 29b82486 Leszek Koltunski
    }
495
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497
498 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
499 29b82486 Leszek Koltunski
    {
500
    if( mStickers==null )
501
      {
502
      final float[][] STICKERS = new float[][]  { { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f } };
503
      final float radius = 0.10f;
504
      final float[] radii = {radius,radius,radius,radius};
505
      mStickers = new ObjectSticker[STICKERS.length];
506 8592461c Leszek Koltunski
      float stroke = 0.08f;
507
508
      if( ObjectControl.isInIconMode() )
509
        {
510 a57e6870 Leszek Koltunski
        int[] numLayers = getNumLayers();
511
512
        switch(numLayers[0])
513 8592461c Leszek Koltunski
          {
514
          case 2: stroke*=1.8f; break;
515
          case 3: stroke*=2.0f; break;
516
          case 4: stroke*=2.1f; break;
517
          default:stroke*=2.2f; break;
518
          }
519
        }
520
521 29b82486 Leszek Koltunski
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke );
522
      }
523
524 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
525 29b82486 Leszek Koltunski
    }
526
527 1bb09f88 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
528
529
  public Static4D[] getQuats()
530 29b82486 Leszek Koltunski
    {
531
    if( mQuats ==null ) initializeQuats();
532
    return mQuats;
533
    }
534
535
///////////////////////////////////////////////////////////////////////////////////////////////////
536
537 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
538 29b82486 Leszek Koltunski
    {
539
    if( mCuts==null )
540
      {
541 dfdb26a9 Leszek Koltunski
      mCuts = new float[3][];
542
543 ba6d9ee9 Leszek Koltunski
      for(int axis=0; axis<3; axis++)
544 dfdb26a9 Leszek Koltunski
        {
545 ba6d9ee9 Leszek Koltunski
        int len = numLayers[axis];
546
        float start = (2-len)*0.5f;
547 29b82486 Leszek Koltunski
548 ba6d9ee9 Leszek Koltunski
        if( len>=2 )
549
          {
550
          mCuts[axis] = new float[len-1];
551
          for(int i=0; i<len-1; i++) mCuts[axis][i] = start+i;
552
          }
553 29b82486 Leszek Koltunski
        }
554
      }
555
556
    return mCuts;
557
    }
558
559
///////////////////////////////////////////////////////////////////////////////////////////////////
560
561 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
562 29b82486 Leszek Koltunski
    {
563 59c20632 Leszek Koltunski
    int numAxis = ROT_AXIS.length;
564
    boolean[][] layerRotatable = new boolean[numAxis][];
565 a57e6870 Leszek Koltunski
566 59c20632 Leszek Koltunski
    for(int i=0; i<numAxis; i++)
567
      {
568
      layerRotatable[i] = new boolean[numLayers[i]];
569
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
570 29b82486 Leszek Koltunski
      }
571
572 59c20632 Leszek Koltunski
    return layerRotatable;
573 29b82486 Leszek Koltunski
    }
574
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576
577 59c20632 Leszek Koltunski
  public int getMovementType()
578 29b82486 Leszek Koltunski
    {
579 59c20632 Leszek Koltunski
    return MOVEMENT_SHAPECHANGE;
580 29b82486 Leszek Koltunski
    }
581
582
///////////////////////////////////////////////////////////////////////////////////////////////////
583
584 59c20632 Leszek Koltunski
  public int getMovementSplit()
585 29b82486 Leszek Koltunski
    {
586 59c20632 Leszek Koltunski
    return TYPE_NOT_SPLIT;
587 29b82486 Leszek Koltunski
    }
588
589
///////////////////////////////////////////////////////////////////////////////////////////////////
590
591 59c20632 Leszek Koltunski
  public int[][][] getEnabled()
592 29b82486 Leszek Koltunski
    {
593 59c20632 Leszek Koltunski
    return new int[][][]
594
      {
595
          {{1,2}},{{1,2}},{{0,2}},{{0,2}},{{0,1}},{{0,1}},
596
      };
597 29b82486 Leszek Koltunski
    }
598
599
///////////////////////////////////////////////////////////////////////////////////////////////////
600
601 59c20632 Leszek Koltunski
  public float[] getDist3D(int[] numLayers)
602 29b82486 Leszek Koltunski
    {
603 59c20632 Leszek Koltunski
    float avg = (numLayers[0]+numLayers[1]+numLayers[2])/3.0f;
604 ab31cf6f Leszek Koltunski
605 59c20632 Leszek Koltunski
    return new float[]
606 ab31cf6f Leszek Koltunski
        {
607
        0.5f*numLayers[0]/avg,
608
        0.5f*numLayers[0]/avg,
609
        0.5f*numLayers[1]/avg,
610
        0.5f*numLayers[1]/avg,
611
        0.5f*numLayers[2]/avg,
612
        0.5f*numLayers[2]/avg,
613
        };
614 59c20632 Leszek Koltunski
    }
615 ab31cf6f Leszek Koltunski
616 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
617
618
  public int getSolvedFunctionIndex()
619
    {
620
    return 0;
621
    }
622
623
///////////////////////////////////////////////////////////////////////////////////////////////////
624
625 1bb09f88 Leszek Koltunski
  public int getNumStickerTypes(int[] numLayers)
626 59c20632 Leszek Koltunski
    {
627
    return 1;
628
    }
629
630
///////////////////////////////////////////////////////////////////////////////////////////////////
631
632 a75ae1ee Leszek Koltunski
  public int getNumCubitFaces()
633 59c20632 Leszek Koltunski
    {
634
    return 6;
635
    }
636
637
///////////////////////////////////////////////////////////////////////////////////////////////////
638
// PUBLIC API
639
640
  public Static3D[] getRotationAxis()
641
    {
642
    return ROT_AXIS;
643 29b82486 Leszek Koltunski
    }
644
645
///////////////////////////////////////////////////////////////////////////////////////////////////
646
647
  public int[] getBasicAngle()
648
    {
649 dfdb26a9 Leszek Koltunski
    if( mBasicAngle==null )
650
      {
651
      int[] num = getNumLayers();
652
      int x = num[1]==num[2] ? 4 : 2;
653
      int y = num[0]==num[2] ? 4 : 2;
654
      int z = num[0]==num[1] ? 4 : 2;
655
656
      mBasicAngle = new int[] { x,y,z };
657
      }
658 29b82486 Leszek Koltunski
    return mBasicAngle;
659
    }
660
661 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
662
663 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
664 61aa85e4 Leszek Koltunski
    {
665 b19a1d32 Leszek Koltunski
    int x = numLayers[0];
666
    int y = numLayers[1];
667
668
    switch(x)
669 61aa85e4 Leszek Koltunski
      {
670 b19a1d32 Leszek Koltunski
      case 2: switch(y)
671
                {
672
                case 2: return ObjectType.CUBE_2;
673
                case 3: return ObjectType.CU_232;
674
                }
675
      case 3: switch(y)
676
                {
677
                case 2: return ObjectType.CU_323;
678
                case 3: return ObjectType.CUBE_3;
679
                case 4: return ObjectType.CU_343;
680
                }
681 8005e762 Leszek Koltunski
      case 4: return ObjectType.CUBE_4;
682
      case 5: return ObjectType.CUBE_5;
683 61aa85e4 Leszek Koltunski
      }
684
685 8005e762 Leszek Koltunski
    return ObjectType.CUBE_3;
686 61aa85e4 Leszek Koltunski
    }
687
688 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
689
690 e26eb4e7 Leszek Koltunski
  public String getObjectName()
691 29b82486 Leszek Koltunski
    {
692 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
693 29b82486 Leszek Koltunski
      {
694 e26eb4e7 Leszek Koltunski
      case 2: return "Pocket Cube";
695
      case 3: return "Rubik Cube";
696
      case 4: return "Rubik's Revenge";
697
      case 5: return "Professor's Cube";
698 29b82486 Leszek Koltunski
      }
699 e26eb4e7 Leszek Koltunski
    return "Rubik Cube";
700 29b82486 Leszek Koltunski
    }
701
702
///////////////////////////////////////////////////////////////////////////////////////////////////
703
704 e26eb4e7 Leszek Koltunski
  public String getInventor()
705 29b82486 Leszek Koltunski
    {
706 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
707 29b82486 Leszek Koltunski
      {
708 e26eb4e7 Leszek Koltunski
      case 2: return "Larry Nichols";
709
      case 3: return "Ernő Rubik";
710
      case 4: return "Péter Sebestény";
711
      case 5: return "Udo Krell";
712 29b82486 Leszek Koltunski
      }
713 e26eb4e7 Leszek Koltunski
    return "Ernő Rubik";
714 29b82486 Leszek Koltunski
    }
715
716 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
717
718 e26eb4e7 Leszek Koltunski
  public int getYearOfInvention()
719 59c20632 Leszek Koltunski
    {
720 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
721 59c20632 Leszek Koltunski
      {
722
      case 2: return 1970;
723
      case 3: return 1974;
724
      case 4: return 1981;
725
      case 5: return 1981;
726
      }
727
    return 1974;
728
    }
729
730 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
731
732 e26eb4e7 Leszek Koltunski
  public int getComplexity()
733 29b82486 Leszek Koltunski
    {
734 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
735 29b82486 Leszek Koltunski
      {
736
      case 2: return 4;
737
      case 3: return 6;
738
      case 4: return 8;
739
      case 5: return 10;
740
      }
741
    return 6;
742
    }
743
}