Project

General

Profile

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

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

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 f9a81f52 Leszek Koltunski
  public ScrambleState[] getScrambleStates()
113 29b82486 Leszek Koltunski
    {
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 7b832206 Leszek Koltunski
  public 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 e30c522a Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
247 29b82486 Leszek Koltunski
    {
248 e30c522a Leszek Koltunski
    int extraI, extraV, num, numL = getNumLayers()[0];
249 29b82486 Leszek Koltunski
    float height;
250
251 a57e6870 Leszek Koltunski
    switch(numL)
252 8396c548 Leszek Koltunski
        {
253
        case 2 : num = 6; extraI = 2; extraV = 2; height = 0.045f; break;
254
        case 3 : num = 5; extraI = 2; extraV = 2; height = 0.045f; break;
255
        case 4 : num = 5; extraI = 1; extraV = 1; height = 0.045f; break;
256
        default: num = 5; extraI = 0; extraV = 0; height = 0.045f; break;
257
        }
258 29b82486 Leszek Koltunski
259
    double[][] vertices = new double[][]
260
          {
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
              {-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
          };
270
271
    int[][] vert_indices = new int[][]
272
          {
273
              {2,3,1,0},
274
              {7,6,4,5},
275
              {4,0,1,5},
276
              {7,3,2,6},
277
              {6,2,0,4},
278
              {3,7,5,1}
279
          };
280
281
    float[][] corners   = new float[][] { {0.036f,0.12f} };
282
    int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
283
    float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
284
    int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
285
286 8396c548 Leszek Koltunski
    if( variant==0 )
287
      {
288
      float[][] bands   = new float[][] { {height,35,0.5f,0.7f,num,extraI,extraV} };
289
      int[] bandIndices = new int[] { 0,0,0,0,0,0};
290
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
291
      }
292
    else
293
      {
294
      int extraI2, extraV2, num2;
295
296 a57e6870 Leszek Koltunski
      switch(numL)
297 8396c548 Leszek Koltunski
        {
298
        case 2 : num2 = 6; extraI2 = 2; extraV2 = 2; break;
299
        case 3 : num2 = 5; extraI2 = 1; extraV2 = 0; break;
300
        case 4 : num2 = 4; extraI2 = 0; extraV2 = 0; break;
301
        default: num2 = 3; extraI2 = 0; extraV2 = 0; break;
302
        }
303
304 d309baa5 Leszek Koltunski
      float[][] bands   = new float[][]
305
        {
306
          {height,35,0.5f,0.7f,num ,extraI ,extraV },
307
          {height,35,0.5f,0.7f,num2,extraI2,extraV2},
308
          {height,35,0.5f,0.7f,   2,      0,      0},
309
        };
310
      int[] bandIndices = new int[] { 1,1,1,1,0,2};
311 8396c548 Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
312
      }
313 29b82486 Leszek Koltunski
    }
314
315 dfdb26a9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
316
317
  private int getCenterNum(int cubit, int[] numLayers)
318
    {
319
    int num = cubit - getNumCornersAndEdges(numLayers);
320
321
    if( num>=0 )
322
      {
323
      int numLR = (numLayers[1]-2)*(numLayers[2]-2);
324
      if( num<  numLR ) return 0;
325
      if( num<2*numLR ) return 1;
326
      num -= 2*numLR;
327
328
      int numTD = (numLayers[0]-2)*(numLayers[2]-2);
329
      if( num<  numTD ) return 2;
330
      if( num<2*numTD ) return 3;
331
      num -= 2*numTD;
332
333
      int numFB = (numLayers[0]-2)*(numLayers[1]-2);
334
      if( num<  numFB ) return 4;
335
      if( num<2*numFB ) return 5;
336
      }
337
338
    return -1;
339
    }
340
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342
343
  private int getNumCornersAndEdges(int[] numLayers)
344
    {
345
    int x = numLayers[0];
346
    int y = numLayers[1];
347
    int z = numLayers[2];
348
349
    return ( x==1 || y==1 || z==1 ) ? x*y*z : 4*( (x-2)+(y-2)+(z-2) ) + 8;
350
    }
351
352 8da6b1c9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
353
354 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
355 8da6b1c9 Leszek Koltunski
    {
356 dfdb26a9 Leszek Koltunski
    final int X = numLayers[0];
357
    final int Y = numLayers[1];
358
    final int Z = numLayers[2];
359
360
    final float lenX = 0.5f*(X-1);
361
    final float lenY = 0.5f*(Y-1);
362
    final float lenZ = 0.5f*(Z-1);
363 8da6b1c9 Leszek Koltunski
364 a135652b Leszek Koltunski
    int curPos = 0;
365
366
    if( X==1 )
367
      {
368
      float[][] pos = new float[X*Y*Z][];
369
370
      for(int y=0; y<Y; y++)
371
        for(int z=0; z<Z; z++) pos[curPos++] = new float[] {+lenX,y-lenY,z-lenZ};
372
373
      return pos;
374
      }
375
376
    if( Y==1 )
377 dfdb26a9 Leszek Koltunski
      {
378 a135652b Leszek Koltunski
      float[][] pos = new float[X*Y*Z][];
379
380
      for(int x=0; x<X; x++)
381
        for(int z=0; z<Z; z++) pos[curPos++] = new float[] {x-lenX,+lenY,z-lenZ};
382
383
      return pos;
384
      }
385
386
    if( Z==1 )
387
      {
388
      float[][] pos = new float[X*Y*Z][];
389
390
      for(int x=0; x<X; x++)
391
        for(int y=0; y<Y; y++) pos[curPos++] = new float[] {x-lenX,y-lenY,+lenZ};
392 dfdb26a9 Leszek Koltunski
393 a135652b Leszek Koltunski
      return pos;
394 dfdb26a9 Leszek Koltunski
      }
395 a57e6870 Leszek Koltunski
396 dfdb26a9 Leszek Koltunski
    int numCubits = X*Y*Z - (X-2)*(Y-2)*(Z-2);
397 a135652b Leszek Koltunski
    float[][] pos = new float[numCubits][];
398
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
    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
408
    for(int i=1; i<X-1; i++) pos[curPos++] = new float[] { i-lenX,  -lenY,  -lenZ };
409
    for(int i=1; i<X-1; i++) pos[curPos++] = new float[] { i-lenX,  -lenY,  +lenZ };
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<Y-1; i++) pos[curPos++] = new float[] {  -lenX, i-lenY,  -lenZ };
413
    for(int i=1; i<Y-1; i++) pos[curPos++] = new float[] {  -lenX, i-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<Z-1; i++) pos[curPos++] = new float[] {  -lenX,  -lenY, i-lenZ };
417
    for(int i=1; i<Z-1; i++) pos[curPos++] = new float[] {  -lenX,  +lenY, i-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 dfdb26a9 Leszek Koltunski
421
    for(int y=1; y<Y-1; y++)
422 a135652b Leszek Koltunski
      for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {+lenX,y-lenY,z-lenZ};
423 dfdb26a9 Leszek Koltunski
424
    for(int y=1; y<Y-1; y++)
425 a135652b Leszek Koltunski
      for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {-lenX,y-lenY,z-lenZ};
426 dfdb26a9 Leszek Koltunski
427
    for(int x=1; x<X-1; x++)
428 a135652b Leszek Koltunski
      for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {x-lenX,+lenY,z-lenZ};
429 dfdb26a9 Leszek Koltunski
430
    for(int x=1; x<X-1; x++)
431 a135652b Leszek Koltunski
      for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {x-lenX,-lenY,z-lenZ};
432 dfdb26a9 Leszek Koltunski
433
    for(int x=1; x<X-1; x++)
434 a135652b Leszek Koltunski
      for(int y=1; y<Y-1; y++) pos[curPos++] = new float[] {x-lenX,y-lenY,+lenZ};
435 dfdb26a9 Leszek Koltunski
436
    for(int x=1; x<X-1; x++)
437 a135652b Leszek Koltunski
      for(int y=1; y<Y-1; y++) pos[curPos++] = new float[] {x-lenX,y-lenY,-lenZ};
438 8da6b1c9 Leszek Koltunski
439 a135652b Leszek Koltunski
    return pos;
440 8da6b1c9 Leszek Koltunski
    }
441
442 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
443
444 7b832206 Leszek Koltunski
  public Static4D getQuat(int cubit, int[] numLayers)
445 29b82486 Leszek Koltunski
    {
446
    if( mQuats ==null ) initializeQuats();
447 8da6b1c9 Leszek Koltunski
448 dfdb26a9 Leszek Koltunski
    int centerNum = getCenterNum(cubit,numLayers);
449 8da6b1c9 Leszek Koltunski
450 dfdb26a9 Leszek Koltunski
    switch(centerNum)
451 8da6b1c9 Leszek Koltunski
      {
452 dfdb26a9 Leszek Koltunski
      case 0 : return mQuats[13];
453
      case 1 : return mQuats[12];
454
      case 2 : return mQuats[ 8];
455
      case 3 : return mQuats[ 9];
456
      case 4 : return mQuats[ 0];
457
      case 5 : return mQuats[ 1];
458
      default: return mQuats[ 0];
459 8da6b1c9 Leszek Koltunski
      }
460 29b82486 Leszek Koltunski
    }
461
462
///////////////////////////////////////////////////////////////////////////////////////////////////
463
464 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
465 29b82486 Leszek Koltunski
    {
466 a57e6870 Leszek Koltunski
    return numLayers[0]>2 ? 2:1;
467 29b82486 Leszek Koltunski
    }
468
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470
471 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
472 29b82486 Leszek Koltunski
    {
473 dfdb26a9 Leszek Koltunski
    return cubit < getNumCornersAndEdges(numLayers) ? 0 : 1;
474 8da6b1c9 Leszek Koltunski
    }
475
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477
478 a57e6870 Leszek Koltunski
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
479 8da6b1c9 Leszek Koltunski
    {
480 dfdb26a9 Leszek Koltunski
    int centerNum = getCenterNum(cubit,numLayers);
481 8da6b1c9 Leszek Koltunski
482 dfdb26a9 Leszek Koltunski
    if( centerNum<0 )
483 8da6b1c9 Leszek Koltunski
      {
484 dfdb26a9 Leszek Koltunski
      int axis = cubitface/2;
485
      return CUBITS[cubit].getRotRow(axis) == (cubitface%2==0 ? (1<<(numLayers[axis]-1)):1) ? cubitface : NUM_TEXTURES;
486 8da6b1c9 Leszek Koltunski
      }
487
    else
488
      {
489 dfdb26a9 Leszek Koltunski
      return cubitface == 4 ? centerNum : NUM_TEXTURES;
490 8da6b1c9 Leszek Koltunski
      }
491 29b82486 Leszek Koltunski
    }
492
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494
495 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
496 29b82486 Leszek Koltunski
    {
497
    if( mStickers==null )
498
      {
499
      final float[][] STICKERS = new float[][]  { { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f } };
500
      final float radius = 0.10f;
501
      final float[] radii = {radius,radius,radius,radius};
502
      mStickers = new ObjectSticker[STICKERS.length];
503 8592461c Leszek Koltunski
      float stroke = 0.08f;
504
505
      if( ObjectControl.isInIconMode() )
506
        {
507 a57e6870 Leszek Koltunski
        int[] numLayers = getNumLayers();
508
509
        switch(numLayers[0])
510 8592461c Leszek Koltunski
          {
511
          case 2: stroke*=1.8f; break;
512
          case 3: stroke*=2.0f; break;
513
          case 4: stroke*=2.1f; break;
514
          default:stroke*=2.2f; break;
515
          }
516
        }
517
518 29b82486 Leszek Koltunski
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke );
519
      }
520
521 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
522 29b82486 Leszek Koltunski
    }
523
524
///////////////////////////////////////////////////////////////////////////////////////////////////
525
526 1bb09f88 Leszek Koltunski
  protected int getStickerIndex(int face)
527
    {
528
    return face/NUM_FACE_COLORS;
529
    }
530
531
///////////////////////////////////////////////////////////////////////////////////////////////////
532
533
  public Static4D[] getQuats()
534 29b82486 Leszek Koltunski
    {
535
    if( mQuats ==null ) initializeQuats();
536
    return mQuats;
537
    }
538
539
///////////////////////////////////////////////////////////////////////////////////////////////////
540
541 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
542 29b82486 Leszek Koltunski
    {
543
    if( mCuts==null )
544
      {
545 dfdb26a9 Leszek Koltunski
      mCuts = new float[3][];
546
547 ba6d9ee9 Leszek Koltunski
      for(int axis=0; axis<3; axis++)
548 dfdb26a9 Leszek Koltunski
        {
549 ba6d9ee9 Leszek Koltunski
        int len = numLayers[axis];
550
        float start = (2-len)*0.5f;
551 29b82486 Leszek Koltunski
552 ba6d9ee9 Leszek Koltunski
        if( len>=2 )
553
          {
554
          mCuts[axis] = new float[len-1];
555
          for(int i=0; i<len-1; i++) mCuts[axis][i] = start+i;
556
          }
557 29b82486 Leszek Koltunski
        }
558
      }
559
560
    return mCuts;
561
    }
562
563
///////////////////////////////////////////////////////////////////////////////////////////////////
564
565 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
566 29b82486 Leszek Koltunski
    {
567 59c20632 Leszek Koltunski
    int numAxis = ROT_AXIS.length;
568
    boolean[][] layerRotatable = new boolean[numAxis][];
569 a57e6870 Leszek Koltunski
570 59c20632 Leszek Koltunski
    for(int i=0; i<numAxis; i++)
571
      {
572
      layerRotatable[i] = new boolean[numLayers[i]];
573
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
574 29b82486 Leszek Koltunski
      }
575
576 59c20632 Leszek Koltunski
    return layerRotatable;
577 29b82486 Leszek Koltunski
    }
578
579
///////////////////////////////////////////////////////////////////////////////////////////////////
580
581 59c20632 Leszek Koltunski
  public int getMovementType()
582 29b82486 Leszek Koltunski
    {
583 59c20632 Leszek Koltunski
    return MOVEMENT_SHAPECHANGE;
584 29b82486 Leszek Koltunski
    }
585
586
///////////////////////////////////////////////////////////////////////////////////////////////////
587
588 59c20632 Leszek Koltunski
  public int getMovementSplit()
589 29b82486 Leszek Koltunski
    {
590 59c20632 Leszek Koltunski
    return TYPE_NOT_SPLIT;
591 29b82486 Leszek Koltunski
    }
592
593
///////////////////////////////////////////////////////////////////////////////////////////////////
594
595 59c20632 Leszek Koltunski
  public int[][][] getEnabled()
596 29b82486 Leszek Koltunski
    {
597 59c20632 Leszek Koltunski
    return new int[][][]
598
      {
599
          {{1,2}},{{1,2}},{{0,2}},{{0,2}},{{0,1}},{{0,1}},
600
      };
601 29b82486 Leszek Koltunski
    }
602
603
///////////////////////////////////////////////////////////////////////////////////////////////////
604
605 59c20632 Leszek Koltunski
  public float[] getDist3D(int[] numLayers)
606 29b82486 Leszek Koltunski
    {
607 59c20632 Leszek Koltunski
    float avg = (numLayers[0]+numLayers[1]+numLayers[2])/3.0f;
608 ab31cf6f Leszek Koltunski
609 59c20632 Leszek Koltunski
    return new float[]
610 ab31cf6f Leszek Koltunski
        {
611
        0.5f*numLayers[0]/avg,
612
        0.5f*numLayers[0]/avg,
613
        0.5f*numLayers[1]/avg,
614
        0.5f*numLayers[1]/avg,
615
        0.5f*numLayers[2]/avg,
616
        0.5f*numLayers[2]/avg,
617
        };
618 59c20632 Leszek Koltunski
    }
619 ab31cf6f Leszek Koltunski
620 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
621
622
  public int getSolvedFunctionIndex()
623
    {
624
    return 0;
625
    }
626
627
///////////////////////////////////////////////////////////////////////////////////////////////////
628
629 1bb09f88 Leszek Koltunski
  public int getNumStickerTypes(int[] numLayers)
630 59c20632 Leszek Koltunski
    {
631
    return 1;
632
    }
633
634
///////////////////////////////////////////////////////////////////////////////////////////////////
635
636
  protected int getNumCubitFaces()
637
    {
638
    return 6;
639
    }
640
641
///////////////////////////////////////////////////////////////////////////////////////////////////
642
// PUBLIC API
643
644
  public Static3D[] getRotationAxis()
645
    {
646
    return ROT_AXIS;
647 29b82486 Leszek Koltunski
    }
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
667 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
668 61aa85e4 Leszek Koltunski
    {
669 b19a1d32 Leszek Koltunski
    int x = numLayers[0];
670
    int y = numLayers[1];
671
672
    switch(x)
673 61aa85e4 Leszek Koltunski
      {
674 b19a1d32 Leszek Koltunski
      case 2: switch(y)
675
                {
676
                case 2: return ObjectType.CUBE_2;
677
                case 3: return ObjectType.CU_232;
678
                }
679
      case 3: switch(y)
680
                {
681
                case 2: return ObjectType.CU_323;
682
                case 3: return ObjectType.CUBE_3;
683
                case 4: return ObjectType.CU_343;
684
                }
685 8005e762 Leszek Koltunski
      case 4: return ObjectType.CUBE_4;
686
      case 5: return ObjectType.CUBE_5;
687 61aa85e4 Leszek Koltunski
      }
688
689 8005e762 Leszek Koltunski
    return ObjectType.CUBE_3;
690 61aa85e4 Leszek Koltunski
    }
691
692 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
693
694 a57e6870 Leszek Koltunski
  public int getObjectName(int[] numLayers)
695 29b82486 Leszek Koltunski
    {
696 a57e6870 Leszek Koltunski
    switch(numLayers[0])
697 29b82486 Leszek Koltunski
      {
698
      case 2: return R.string.cube2;
699
      case 3: return R.string.cube3;
700
      case 4: return R.string.cube4;
701
      case 5: return R.string.cube5;
702
      }
703
    return R.string.cube3;
704
    }
705
706
///////////////////////////////////////////////////////////////////////////////////////////////////
707
708 a57e6870 Leszek Koltunski
  public int getInventor(int[] numLayers)
709 29b82486 Leszek Koltunski
    {
710 a57e6870 Leszek Koltunski
    switch(numLayers[0])
711 29b82486 Leszek Koltunski
      {
712
      case 2: return R.string.cube2_inventor;
713
      case 3: return R.string.cube3_inventor;
714
      case 4: return R.string.cube4_inventor;
715
      case 5: return R.string.cube5_inventor;
716
      }
717
    return R.string.cube3_inventor;
718
    }
719
720 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
721
722
  public int getYearOfInvention(int[] numLayers)
723
    {
724
    switch(numLayers[0])
725
      {
726
      case 2: return 1970;
727
      case 3: return 1974;
728
      case 4: return 1981;
729
      case 5: return 1981;
730
      }
731
    return 1974;
732
    }
733
734 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
735
736 a57e6870 Leszek Koltunski
  public int getComplexity(int[] numLayers)
737 29b82486 Leszek Koltunski
    {
738 a57e6870 Leszek Koltunski
    switch(numLayers[0])
739 29b82486 Leszek Koltunski
      {
740
      case 2: return 4;
741
      case 3: return 6;
742
      case 4: return 8;
743
      case 5: return 10;
744
      }
745
    return 6;
746
    }
747
}