Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistySkewb.java @ abe288a3

1 fb52fae9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.objects;
21
22
import android.content.res.Resources;
23
24 8655f3fe Leszek Koltunski
import org.distorted.helpers.ObjectShape;
25 9c06394a Leszek Koltunski
import org.distorted.helpers.ObjectSticker;
26 fb52fae9 Leszek Koltunski
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 6fd4a72c Leszek Koltunski
import org.distorted.main.R;
32 fb52fae9 Leszek Koltunski
33
import java.util.Random;
34
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37 9c2f0c91 Leszek Koltunski
public class TwistySkewb extends TwistyObject
38 fb52fae9 Leszek Koltunski
{
39
  private static final int FACES_PER_CUBIT =6;
40
41
  // the four rotation axis of a RubikSkewb. Must be normalized.
42
  static final Static3D[] ROT_AXIS = new Static3D[]
43
         {
44
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
45
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
46
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
47
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
48
         };
49
50 925ed78f Leszek Koltunski
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
51
52 fb52fae9 Leszek Koltunski
  private static final int[] FACE_COLORS = new int[]
53
         {
54 ece1b58d Leszek Koltunski
           COLOR_YELLOW, COLOR_WHITE,
55
           COLOR_BLUE  , COLOR_GREEN,
56 323b217c Leszek Koltunski
           COLOR_RED   , COLOR_ORANGE
57 fb52fae9 Leszek Koltunski
         };
58
59
  // All legal rotation quats of a RubikSkewb
60
  private static final Static4D[] QUATS = new Static4D[]
61
         {
62
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
63
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
64
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
65
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
66
67
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
68
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
69
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
70
           new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
71
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
72
           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
73
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
74
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
75
         };
76
77 3f3ff476 Leszek Koltunski
  private static final int[][] mCornerMap =
78
         {
79
           {  4, 2, 0, 18,18,18 },
80
           {  2, 5, 0, 18,18,18 },
81
           {  3, 4, 0, 18,18,18 },
82
           {  5, 3, 0, 18,18,18 },
83
           {  1, 2, 4, 18,18,18 },
84
           {  5, 2, 1, 18,18,18 },
85
           {  4, 3, 1, 18,18,18 },
86
           {  1, 3, 5, 18,18,18 },
87
         };
88 63002261 Leszek Koltunski
89 3f3ff476 Leszek Koltunski
  private static final int[][] mEdgeMap =
90 fb52fae9 Leszek Koltunski
         {
91 3f3ff476 Leszek Koltunski
           { 10, 8, 18,18,18,18 },
92
           {  6,10, 18,18,18,18 },
93
           { 10, 9, 18,18,18,18 },
94
           {  7,10, 18,18,18,18 },
95
           {  8, 6, 18,18,18,18 },
96
           {  9, 6, 18,18,18,18 },
97
           {  9, 7, 18,18,18,18 },
98
           {  8, 7, 18,18,18,18 },
99
           { 11, 8, 18,18,18,18 },
100
           {  6,11, 18,18,18,18 },
101
           { 11, 9, 18,18,18,18 },
102
           {  7,11, 18,18,18,18 }
103 fb52fae9 Leszek Koltunski
         };
104
105 3f3ff476 Leszek Koltunski
  private static final int[][] mCenterMap =
106 fb52fae9 Leszek Koltunski
         {
107 3f3ff476 Leszek Koltunski
           { 12, 18,18,18,18,18 },
108
           { 13, 18,18,18,18,18 },
109
           { 14, 18,18,18,18,18 },
110
           { 15, 18,18,18,18,18 },
111
           { 16, 18,18,18,18,18 },
112
           { 17, 18,18,18,18,18 },
113 fb52fae9 Leszek Koltunski
         };
114
115 596d62a4 Leszek Koltunski
  private static final double[][] VERTICES_CORNER = new double[][]
116
          {
117 7dc57f89 Leszek Koltunski
              {-0.5f, 0.0f, 0.0f},
118
              { 0.0f,-0.5f, 0.0f},
119
              { 0.0f, 0.0f,-0.5f},
120
              {-0.5f,-0.5f,-0.5f},
121
              { 0.0f, 0.0f, 0.0f}
122 596d62a4 Leszek Koltunski
          };
123
124
  private static final int[][] VERT_INDEXES_CORNER = new int[][]
125
          {
126 7dc57f89 Leszek Koltunski
              {0,1,4},
127
              {2,0,4},
128
              {1,2,4},
129
              {3,1,0},
130
              {3,2,1},
131
              {3,0,2}
132 596d62a4 Leszek Koltunski
          };
133
134
  private static final double[][] VERTICES_EDGE = new double[][]
135
          {
136
             {-0.5, 0.0, 0.0},
137
             { 0.5, 0.0, 0.0},
138
             { 0.0,-0.5, 0.0},
139
             { 0.0, 0.0,-0.5}
140
          };
141
142
  private static final int[][] VERT_INDEXES_EDGE = new int[][]
143
          {
144
             {2,1,0},   // counterclockwise!
145
             {3,0,1},
146
             {2,3,1},
147
             {3,2,0},
148
          };
149
150
  private static final double[][] VERTICES_FACE = new double[][]
151
          {
152 7dc57f89 Leszek Koltunski
             {-0.5f, 0.0f, 0.0f },
153
             { 0.0f,-0.5f, 0.0f },
154
             { 0.5f, 0.0f, 0.0f },
155
             { 0.0f, 0.5f, 0.0f },
156
             { 0.0f, 0.0f,-0.5f }
157 596d62a4 Leszek Koltunski
          };
158
159
  private static final int[][] VERT_INDEXES_FACE = new int[][]
160
          {
161 7dc57f89 Leszek Koltunski
             {0,1,2,3},
162
             {4,1,0},
163
             {4,2,1},
164
             {4,3,2},
165
             {4,0,3}
166
          };
167
168
  private static final float[][] STICKERS = new float[][]
169
          {
170 be56193c Leszek Koltunski
             { -0.5f, 0.25f, 0.25f,  -0.5f, 0.25f, 0.25f  },
171
             { -0.5f, 0.00f, 0.00f,  -0.5f, 0.50f, 0.0f, 0.0f, 0.5f }
172 596d62a4 Leszek Koltunski
          };
173
174 9c06394a Leszek Koltunski
  private static final ObjectSticker[] mStickers;
175
176
  static
177
    {
178
    mStickers = new ObjectSticker[STICKERS.length+1];
179
    final float R1 = 0.025f;
180
    final float R2 = 0.025f;
181
    final float R3 = 0.055f;
182
    final float[][] radii  = { { R1,R1,R1 },{ R2,R2,R2 },{ R3,R3,R3,R3 } };
183
    final float[] strokes = { 0.045f, 0.035f, 0.035f };
184
185
    for(int s=0; s<STICKERS.length+1; s++)
186
      {
187
      int index = s<2 ? 0:1;
188
      mStickers[s] = new ObjectSticker(STICKERS[index],null,radii[s],strokes[s]);
189
      }
190
    }
191
192 fb52fae9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
193
194 9c2f0c91 Leszek Koltunski
  TwistySkewb(int size, Static4D quat, DistortedTexture texture,
195
              MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
196 fb52fae9 Leszek Koltunski
    {
197 db875721 Leszek Koltunski
    super(size, 2*size-2, quat, texture, mesh, effects, moves, ObjectList.SKEW, res, scrWidth);
198 fb52fae9 Leszek Koltunski
    }
199
200 3f3ff476 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
201
202 d92030e4 Leszek Koltunski
  private int getNumCorners()
203 3f3ff476 Leszek Koltunski
    {
204
    return 8;
205
    }
206
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208
209 b89898c5 Leszek Koltunski
  private int getNumEdges(int layers)
210 3f3ff476 Leszek Koltunski
    {
211 b89898c5 Leszek Koltunski
    return (layers-2)*12;
212 3f3ff476 Leszek Koltunski
    }
213
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215
216 d92030e4 Leszek Koltunski
  private int getNumCentersPerFace(int layers)
217 3f3ff476 Leszek Koltunski
    {
218 d92030e4 Leszek Koltunski
    return ((layers-2)*(layers-2) + (layers-1)*(layers-1));
219 3f3ff476 Leszek Koltunski
    }
220
221 fb52fae9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
222
223
  float getScreenRatio()
224
    {
225 d99f3a48 Leszek Koltunski
    return 1.0f;
226 fb52fae9 Leszek Koltunski
    }
227
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
230
  Static4D[] getQuats()
231
    {
232
    return QUATS;
233
    }
234
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236
237
  int getNumFaces()
238
    {
239
    return FACE_COLORS.length;
240
    }
241
242 eaee1ddc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
243
244
  boolean shouldResetTextureMaps()
245
    {
246
    return false;
247
    }
248
249 eab9d8f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
250
251 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
252 eab9d8f8 Leszek Koltunski
    {
253 3f3ff476 Leszek Koltunski
    return 3;
254 eab9d8f8 Leszek Koltunski
    }
255
256 7403cdfa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
257
258 e6734aa9 Leszek Koltunski
  float[][] getCuts(int numLayers)
259 7403cdfa Leszek Koltunski
    {
260 b89898c5 Leszek Koltunski
    switch(numLayers)
261 a97e02b7 Leszek Koltunski
      {
262 e6734aa9 Leszek Koltunski
      case 2: float[] c2 = new float[] {0.0f};
263
              return new float[][] { c2,c2,c2,c2 };
264
      case 3: float[] c3 = new float[] {-SQ3/12,+SQ3/12};
265
              return new float[][] { c3,c3,c3,c3 };
266 a97e02b7 Leszek Koltunski
      }
267 e6734aa9 Leszek Koltunski
    return null;
268 7403cdfa Leszek Koltunski
    }
269
270 fb52fae9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
271
272
  int getNumCubitFaces()
273
    {
274
    return FACES_PER_CUBIT;
275
    }
276
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278
279 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int numLayers)
280 fb52fae9 Leszek Koltunski
    {
281 b89898c5 Leszek Koltunski
    final float DIST_CORNER = (numLayers-1)*0.50f;
282
    final float DIST_EDGE   = (numLayers-1)*0.50f;
283
    final float DIST_CENTER = (numLayers-1)*0.50f;
284 3f3ff476 Leszek Koltunski
285 d92030e4 Leszek Koltunski
    final int numCorners = getNumCorners();
286 b89898c5 Leszek Koltunski
    final int numEdges   = getNumEdges(numLayers);
287 d92030e4 Leszek Koltunski
    final int numCenters = 6*getNumCentersPerFace(numLayers);
288 3f3ff476 Leszek Koltunski
289 e6cf7283 Leszek Koltunski
    final float[][] CENTERS = new float[numCorners+numEdges+numCenters][];
290 3f3ff476 Leszek Koltunski
291
    /// CORNERS //////////////////////////////////////////////
292
293 e6cf7283 Leszek Koltunski
    CENTERS[0] = new float[] { DIST_CORNER, DIST_CORNER, DIST_CORNER };
294
    CENTERS[1] = new float[] { DIST_CORNER, DIST_CORNER,-DIST_CORNER };
295
    CENTERS[2] = new float[] { DIST_CORNER,-DIST_CORNER, DIST_CORNER };
296
    CENTERS[3] = new float[] { DIST_CORNER,-DIST_CORNER,-DIST_CORNER };
297
    CENTERS[4] = new float[] {-DIST_CORNER, DIST_CORNER, DIST_CORNER };
298
    CENTERS[5] = new float[] {-DIST_CORNER, DIST_CORNER,-DIST_CORNER };
299
    CENTERS[6] = new float[] {-DIST_CORNER,-DIST_CORNER, DIST_CORNER };
300
    CENTERS[7] = new float[] {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER };
301 3f3ff476 Leszek Koltunski
302
    /// EDGES ///////////////////////////////////////////////
303
304
    final float[][]  edgeTable =
305
        {
306
            {0,+DIST_EDGE,+DIST_EDGE},
307
            {+DIST_EDGE,0,+DIST_EDGE},
308
            {0,-DIST_EDGE,+DIST_EDGE},
309
            {-DIST_EDGE,0,+DIST_EDGE},
310
            {+DIST_EDGE,+DIST_EDGE,0},
311
            {+DIST_EDGE,-DIST_EDGE,0},
312
            {-DIST_EDGE,-DIST_EDGE,0},
313
            {-DIST_EDGE,+DIST_EDGE,0},
314
            {0,+DIST_EDGE,-DIST_EDGE},
315
            {+DIST_EDGE,0,-DIST_EDGE},
316
            {0,-DIST_EDGE,-DIST_EDGE},
317
            {-DIST_EDGE,0,-DIST_EDGE}
318
        };
319
320
    int index=8;
321
322
    for (float[] edges : edgeTable)
323
      {
324 b89898c5 Leszek Koltunski
      float c = (3-numLayers)*0.5f;
325 3f3ff476 Leszek Koltunski
326 b89898c5 Leszek Koltunski
      for (int j=0; j<numLayers-2; j++, c+=1.0f, index++)
327 3f3ff476 Leszek Koltunski
        {
328 e6cf7283 Leszek Koltunski
        CENTERS[index] = new float[] { edges[0]==0 ? c : edges[0] ,
329 3f3ff476 Leszek Koltunski
                                       edges[1]==0 ? c : edges[1] ,
330 e6cf7283 Leszek Koltunski
                                       edges[2]==0 ? c : edges[2] };
331 3f3ff476 Leszek Koltunski
        }
332
      }
333
334
    /// CENTERS //////////////////////////////////////////////
335
336
    final float X= -1000.0f;
337
    final float Y= -1001.0f;
338
339
    final float[][]  centerTable =
340
        {
341
            {+DIST_CENTER,X,Y},
342
            {-DIST_CENTER,X,Y},
343
            {X,+DIST_CENTER,Y},
344
            {X,-DIST_CENTER,Y},
345
            {X,Y,+DIST_CENTER},
346
            {X,Y,-DIST_CENTER}
347
        };
348
349
    float x,y, cen0, cen1, cen2;
350
351
    for( float[] centers : centerTable )
352
      {
353 b89898c5 Leszek Koltunski
      x = (2-numLayers)*0.5f;
354 3f3ff476 Leszek Koltunski
355 b89898c5 Leszek Koltunski
      for(int i=0; i<numLayers-1; i++, x+=1.0f)
356 3f3ff476 Leszek Koltunski
        {
357 b89898c5 Leszek Koltunski
        y = (2-numLayers)*0.5f;
358 3f3ff476 Leszek Koltunski
359 b89898c5 Leszek Koltunski
        for(int j=0; j<numLayers-1; j++, y+=1.0f, index++)
360 3f3ff476 Leszek Koltunski
          {
361
               if( centers[0]==Y ) cen0 = y;
362
          else if( centers[0]==X ) cen0 = x;
363
          else                     cen0 = centers[0];
364
365
               if( centers[1]==Y ) cen1 = y;
366
          else if( centers[1]==X ) cen1 = x;
367
          else                     cen1 = centers[1];
368
369
               if( centers[2]==Y ) cen2 = y;
370
          else if( centers[2]==X ) cen2 = x;
371
          else                     cen2 = centers[2];
372
373 e6cf7283 Leszek Koltunski
          CENTERS[index] = new float[] {cen0,cen1,cen2};
374 3f3ff476 Leszek Koltunski
          }
375
        }
376
377 b89898c5 Leszek Koltunski
      x = (3-numLayers)*0.5f;
378 3f3ff476 Leszek Koltunski
379 b89898c5 Leszek Koltunski
      for(int i=0; i<numLayers-2; i++, x+=1.0f)
380 3f3ff476 Leszek Koltunski
        {
381 b89898c5 Leszek Koltunski
        y = (3-numLayers)*0.5f;
382 3f3ff476 Leszek Koltunski
383 b89898c5 Leszek Koltunski
        for(int j=0; j<numLayers-2; j++, y+=1.0f, index++)
384 3f3ff476 Leszek Koltunski
          {
385
               if( centers[0]==Y ) cen0 = y;
386
          else if( centers[0]==X ) cen0 = x;
387
          else                     cen0 = centers[0];
388
389
               if( centers[1]==Y ) cen1 = y;
390
          else if( centers[1]==X ) cen1 = x;
391
          else                     cen1 = centers[1];
392
393
               if( centers[2]==Y ) cen2 = y;
394
          else if( centers[2]==X ) cen2 = x;
395
          else                     cen2 = centers[2];
396
397 e6cf7283 Leszek Koltunski
          CENTERS[index] = new float[] {cen0,cen1,cen2};
398 3f3ff476 Leszek Koltunski
          }
399
        }
400
      }
401
402 fb52fae9 Leszek Koltunski
    return CENTERS;
403
    }
404
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406
407 3e605536 Leszek Koltunski
  Static4D getQuat(int cubit, int numLayers)
408 fb52fae9 Leszek Koltunski
    {
409 d92030e4 Leszek Koltunski
    int numCorners = getNumCorners();
410
    int numEdges   = getNumEdges(numLayers);
411 3f3ff476 Leszek Koltunski
412
    if( cubit<numCorners )
413
      {
414
      switch(cubit)
415
        {
416
        case  0: return QUATS[0];                          //  unit quat
417
        case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
418
        case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
419
        case  3: return QUATS[1];                          // 180 along X
420
        case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
421
        case  5: return QUATS[2];                          // 180 along Y
422
        case  6: return QUATS[3];                          // 180 along Z
423
        case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
424
        }
425
      }
426
    else if( cubit<numCorners+numEdges )
427
      {
428 d92030e4 Leszek Koltunski
      int edge = (cubit-numCorners)/(numLayers-2);
429 3f3ff476 Leszek Koltunski
430
      switch(edge)
431
        {
432
        case  0: return QUATS[ 0];
433
        case  1: return QUATS[ 5];
434
        case  2: return QUATS[ 3];
435
        case  3: return QUATS[11];
436
        case  4: return QUATS[ 4];
437
        case  5: return QUATS[ 7];
438
        case  6: return QUATS[ 9];
439
        case  7: return QUATS[10];
440
        case  8: return QUATS[ 2];
441
        case  9: return QUATS[ 8];
442
        case 10: return QUATS[ 1];
443
        case 11: return QUATS[ 6];
444
        }
445
      }
446
    else
447 fb52fae9 Leszek Koltunski
      {
448 d92030e4 Leszek Koltunski
      int center = (cubit-numCorners-numEdges)/getNumCentersPerFace(numLayers);
449 3f3ff476 Leszek Koltunski
450
      switch(center)
451
        {
452
        case 0: return new Static4D(0,-SQ2/2,0,SQ2/2);    // -90 along Y
453
        case 1: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
454
        case 2: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
455
        case 3: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
456
        case 4: return QUATS[0];                          //  unit quaternion
457
        case 5: return QUATS[1];                          // 180 along X
458
        }
459 fb52fae9 Leszek Koltunski
      }
460
461
    return null;
462
    }
463
464
///////////////////////////////////////////////////////////////////////////////////////////////////
465
466 8655f3fe Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
467 fb52fae9 Leszek Koltunski
    {
468 8655f3fe Leszek Koltunski
    int variant = getCubitVariant(cubit,numLayers);
469 fb52fae9 Leszek Koltunski
470 8655f3fe Leszek Koltunski
    if( variant==0 )
471 fb52fae9 Leszek Koltunski
      {
472 8655f3fe Leszek Koltunski
      int N = numLayers==2 ? 7:5;
473
      int E1= numLayers==2 ? 3:2;
474
      int E2= numLayers==2 ? 5:3;
475 3e605536 Leszek Koltunski
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,N,E1,E1}, {0.000f, 0,1.00f,0.0f,3,1,E2} };
476 8655f3fe Leszek Koltunski
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
477
      float[][] corners   = new float[][] { {0.08f,0.15f}, {0.08f,0.20f} };
478
      int[] cornerIndices = new int[] { 1,1,1,0,0 };
479
      float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.25f} };
480
      int[] centerIndices = new int[] { 0,0,0,-1,0 };
481
      return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
482 fb52fae9 Leszek Koltunski
      }
483 8655f3fe Leszek Koltunski
    else if( variant==1 )
484 3f3ff476 Leszek Koltunski
      {
485 8655f3fe Leszek Koltunski
      int N = numLayers==2 ? 7:5;
486
      int E = numLayers==2 ? 5:2;
487 3e605536 Leszek Koltunski
      float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,N,2,E}, {0.020f,45,0.16f,0.2f,3,1,2} };
488 8655f3fe Leszek Koltunski
      int[] bandIndices   = new int[] { 0,0,1,1 };
489
      float[][] corners   = new float[][] { {0.07f,0.20f}, {0.02f,0.30f} };
490
      int[] cornerIndices = new int[] { 0,0,1,1 };
491
      float[][] centers   = new float[][] { {0.0f, -0.25f, -0.25f} };
492
      int[] centerIndices = new int[] { 0,0,0,0 };
493
      return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
494 3f3ff476 Leszek Koltunski
      }
495 fb52fae9 Leszek Koltunski
    else
496
      {
497 8655f3fe Leszek Koltunski
      int N = numLayers==2 ? 7:6;
498
      int E = numLayers==2 ? 3:1;
499 3e605536 Leszek Koltunski
      float[][] bands     = new float[][] { {0.051f,35,SQ2/8,0.9f,N,E,E}, {0.000f,0,1,0.0f,3,0,0} };
500 8655f3fe Leszek Koltunski
      int[] bandIndices   = new int[] { 0,1,1,1,1 };
501
      float[][] corners   = new float[][] { {0.06f,0.10f} };
502
      int[] cornerIndices = new int[] { 0,0,0,0,0 };
503
      float[][] centers   = new float[][] { {0,0,-0.2f} };
504
      int[] centerIndices = new int[] { 0,0,0,0,-1 };
505
      return new ObjectShape(VERTICES_FACE,VERT_INDEXES_FACE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
506
      }
507
    }
508
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510
511 3e605536 Leszek Koltunski
  int getNumCubitVariants(int numLayers)
512 8655f3fe Leszek Koltunski
    {
513
    return 3;
514
    }
515
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517
518
  int getCubitVariant(int cubit, int numLayers)
519
    {
520
    int numCorners = getNumCorners();
521
    if( cubit<numCorners ) return 0;
522
    int numEdges = getNumEdges(numLayers);
523
    return cubit<numCorners+numEdges ? 1:2;
524
    }
525
526 fb52fae9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
527
528 d92030e4 Leszek Koltunski
  int getFaceColor(int cubit, int cubitface, int numLayers)
529 fb52fae9 Leszek Koltunski
    {
530 d92030e4 Leszek Koltunski
    int numCorners = getNumCorners();
531
    int numEdges   = getNumEdges(numLayers);
532 3f3ff476 Leszek Koltunski
533
    if( cubit<numCorners )
534
      {
535
      return mCornerMap[cubit][cubitface];
536
      }
537
    else if( cubit<numCorners+numEdges )
538
      {
539 d92030e4 Leszek Koltunski
      int edge = (cubit-numCorners)/(numLayers-2);
540 3f3ff476 Leszek Koltunski
      return mEdgeMap[edge][cubitface];
541
      }
542
    else
543
      {
544 d92030e4 Leszek Koltunski
      int center = (cubit-numCorners-numEdges)/getNumCentersPerFace(numLayers);
545 3f3ff476 Leszek Koltunski
      return mCenterMap[center][cubitface];
546
      }
547 fb52fae9 Leszek Koltunski
    }
548
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550
551 9c06394a Leszek Koltunski
  int getColor(int face)
552 fb52fae9 Leszek Koltunski
    {
553 9c06394a Leszek Koltunski
    return FACE_COLORS[face];
554
    }
555 eab9d8f8 Leszek Koltunski
556 9c06394a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
557 ae755eda Leszek Koltunski
558 9c06394a Leszek Koltunski
  ObjectSticker retSticker(int face)
559
    {
560
    return mStickers[face/NUM_FACES];
561 fb52fae9 Leszek Koltunski
    }
562
563
///////////////////////////////////////////////////////////////////////////////////////////////////
564
565
  float returnMultiplier()
566
    {
567
    return 2.0f;
568
    }
569
570
///////////////////////////////////////////////////////////////////////////////////////////////////
571
// PUBLIC API
572
573
  public Static3D[] getRotationAxis()
574
    {
575
    return ROT_AXIS;
576
    }
577
578
///////////////////////////////////////////////////////////////////////////////////////////////////
579
580 925ed78f Leszek Koltunski
  public int[] getBasicAngle()
581 fb52fae9 Leszek Koltunski
    {
582 925ed78f Leszek Koltunski
    return BASIC_ANGLE;
583 fb52fae9 Leszek Koltunski
    }
584
585
///////////////////////////////////////////////////////////////////////////////////////////////////
586
587 9f171eba Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
588 fb52fae9 Leszek Koltunski
    {
589 9f171eba Leszek Koltunski
    if( curr==0 )
590 fb52fae9 Leszek Koltunski
      {
591 9f171eba Leszek Koltunski
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
592 fb52fae9 Leszek Koltunski
      }
593
    else
594
      {
595 582617c1 Leszek Koltunski
      int newVector = rnd.nextInt(NUM_AXIS -1);
596 9f171eba Leszek Koltunski
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
597 fb52fae9 Leszek Koltunski
      }
598
599 9f171eba Leszek Koltunski
    scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0 : getNumLayers()-1;
600 fb52fae9 Leszek Koltunski
601 5043d5d0 Leszek Koltunski
    switch( rnd.nextInt(2) )
602
      {
603 9f171eba Leszek Koltunski
      case 0: scramble[curr][2] = -1; break;
604
      case 1: scramble[curr][2] =  1; break;
605 5043d5d0 Leszek Koltunski
      }
606 fb52fae9 Leszek Koltunski
    }
607
608
///////////////////////////////////////////////////////////////////////////////////////////////////
609
// The Skewb is solved if and only if:
610
//
611 3f3ff476 Leszek Koltunski
// 1) all of its corner and edge cubits are rotated with the same quat
612 fb52fae9 Leszek Koltunski
// 2) all its face cubits are rotated with the same quat like the corner ones,
613
//    and optionally they also might be upside down.
614
//
615
// i.e.
616
// cubits [ 8] and [ 9] - might be extra QUAT[1]
617
// cubits [10] and [11] - might be extra QUAT[2]
618
// cubits [12] and [13] - might be extra QUAT[3]
619
620
  public boolean isSolved()
621
    {
622
    int q = CUBITS[0].mQuatIndex;
623
624 d92030e4 Leszek Koltunski
    int numLayers      = getNumLayers();
625
    int numCorners     = getNumCorners();
626
    int numEdges       = getNumEdges(numLayers);
627
    int cornersAndEdges= numCorners + numEdges;
628
    int centersPerFace = getNumCentersPerFace(numLayers);
629 b89898c5 Leszek Koltunski
    int cubit, q1=q;
630
631
    for(cubit=0; cubit<cornersAndEdges; cubit++)
632 fb52fae9 Leszek Koltunski
      {
633 b89898c5 Leszek Koltunski
      if( CUBITS[cubit].mQuatIndex != q ) return false;
634 fb52fae9 Leszek Koltunski
      }
635
636 b89898c5 Leszek Koltunski
    for(int face=0; face<6; face++)
637
      {
638
      if( face%2==0 ) q1 = mulQuat(q, (face/2)+1);
639
640 d92030e4 Leszek Koltunski
      for(int center=0; center<centersPerFace; center++)
641 b89898c5 Leszek Koltunski
        {
642
        if( CUBITS[cubit].mQuatIndex != q && CUBITS[cubit].mQuatIndex != q1 ) return false;
643
        cubit++;
644
        }
645
      }
646
647
    return true;
648 fb52fae9 Leszek Koltunski
    }
649
650 6fd4a72c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
651
652
  public int getObjectName(int numLayers)
653
    {
654
    switch(numLayers)
655
      {
656
      case 2: return R.string.skew2;
657
      case 3: return R.string.skew3;
658
      }
659
    return R.string.skew2;
660
    }
661
662
///////////////////////////////////////////////////////////////////////////////////////////////////
663
664
  public int getInventor(int numLayers)
665
    {
666
    switch(numLayers)
667
      {
668
      case 2: return R.string.skew2_inventor;
669
      case 3: return R.string.skew3_inventor;
670
      }
671
    return R.string.skew2_inventor;
672
    }
673
674
///////////////////////////////////////////////////////////////////////////////////////////////////
675
676
  public int getComplexity(int numLayers)
677
    {
678
    switch(numLayers)
679
      {
680 d5ca9927 Leszek Koltunski
      case 2: return 4;
681
      case 3: return 8;
682 6fd4a72c Leszek Koltunski
      }
683
    return 5;
684
    }
685 fb52fae9 Leszek Koltunski
}