Project

General

Profile

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

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

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