Project

General

Profile

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

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

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