Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistySkewb.java @ 7dc57f89

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
import android.graphics.Canvas;
24
import android.graphics.Paint;
25
26 749ef882 Leszek Koltunski
import org.distorted.helpers.FactoryCubit;
27
import org.distorted.helpers.FactorySticker;
28 fb52fae9 Leszek Koltunski
import org.distorted.library.effect.MatrixEffectQuaternion;
29
import org.distorted.library.main.DistortedEffects;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshBase;
32
import org.distorted.library.mesh.MeshSquare;
33
import org.distorted.library.type.Static3D;
34
import org.distorted.library.type.Static4D;
35 6fd4a72c Leszek Koltunski
import org.distorted.main.R;
36 fb52fae9 Leszek Koltunski
37
import java.util.Random;
38
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41 9c2f0c91 Leszek Koltunski
public class TwistySkewb extends TwistyObject
42 fb52fae9 Leszek Koltunski
{
43
  private static final int FACES_PER_CUBIT =6;
44
45
  // the four rotation axis of a RubikSkewb. Must be normalized.
46
  static final Static3D[] ROT_AXIS = new Static3D[]
47
         {
48
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
49
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
50
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
51
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
52
         };
53
54
  private static final int[] FACE_COLORS = new int[]
55
         {
56 ece1b58d Leszek Koltunski
           COLOR_YELLOW, COLOR_WHITE,
57
           COLOR_BLUE  , COLOR_GREEN,
58 323b217c Leszek Koltunski
           COLOR_RED   , COLOR_ORANGE
59 fb52fae9 Leszek Koltunski
         };
60
61
  // All legal rotation quats of a RubikSkewb
62
  private static final Static4D[] QUATS = new Static4D[]
63
         {
64
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
65
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
66
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
67
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
68
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
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
76
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
77
         };
78
79 3f3ff476 Leszek Koltunski
  private static final int[][] mCornerMap =
80
         {
81
           {  4, 2, 0, 18,18,18 },
82
           {  2, 5, 0, 18,18,18 },
83
           {  3, 4, 0, 18,18,18 },
84
           {  5, 3, 0, 18,18,18 },
85
           {  1, 2, 4, 18,18,18 },
86
           {  5, 2, 1, 18,18,18 },
87
           {  4, 3, 1, 18,18,18 },
88
           {  1, 3, 5, 18,18,18 },
89
         };
90 63002261 Leszek Koltunski
91 3f3ff476 Leszek Koltunski
  private static final int[][] mEdgeMap =
92 fb52fae9 Leszek Koltunski
         {
93 3f3ff476 Leszek Koltunski
           { 10, 8, 18,18,18,18 },
94
           {  6,10, 18,18,18,18 },
95
           { 10, 9, 18,18,18,18 },
96
           {  7,10, 18,18,18,18 },
97
           {  8, 6, 18,18,18,18 },
98
           {  9, 6, 18,18,18,18 },
99
           {  9, 7, 18,18,18,18 },
100
           {  8, 7, 18,18,18,18 },
101
           { 11, 8, 18,18,18,18 },
102
           {  6,11, 18,18,18,18 },
103
           { 11, 9, 18,18,18,18 },
104
           {  7,11, 18,18,18,18 }
105 fb52fae9 Leszek Koltunski
         };
106
107 3f3ff476 Leszek Koltunski
  private static final int[][] mCenterMap =
108 fb52fae9 Leszek Koltunski
         {
109 3f3ff476 Leszek Koltunski
           { 12, 18,18,18,18,18 },
110
           { 13, 18,18,18,18,18 },
111
           { 14, 18,18,18,18,18 },
112
           { 15, 18,18,18,18,18 },
113
           { 16, 18,18,18,18,18 },
114
           { 17, 18,18,18,18,18 },
115 fb52fae9 Leszek Koltunski
         };
116
117 596d62a4 Leszek Koltunski
  private static final double[][] VERTICES_CORNER = new double[][]
118
          {
119 7dc57f89 Leszek Koltunski
              {-0.5f, 0.0f, 0.0f},
120
              { 0.0f,-0.5f, 0.0f},
121
              { 0.0f, 0.0f,-0.5f},
122
              {-0.5f,-0.5f,-0.5f},
123
              { 0.0f, 0.0f, 0.0f}
124 596d62a4 Leszek Koltunski
          };
125
126
  private static final int[][] VERT_INDEXES_CORNER = new int[][]
127
          {
128 7dc57f89 Leszek Koltunski
              {0,1,4},
129
              {2,0,4},
130
              {1,2,4},
131
              {3,1,0},
132
              {3,2,1},
133
              {3,0,2}
134 596d62a4 Leszek Koltunski
          };
135
136
  private static final double[][] VERTICES_EDGE = new double[][]
137
          {
138
             {-0.5, 0.0, 0.0},
139
             { 0.5, 0.0, 0.0},
140
             { 0.0,-0.5, 0.0},
141
             { 0.0, 0.0,-0.5}
142
          };
143
144
  private static final int[][] VERT_INDEXES_EDGE = new int[][]
145
          {
146
             {2,1,0},   // counterclockwise!
147
             {3,0,1},
148
             {2,3,1},
149
             {3,2,0},
150
          };
151
152
  private static final double[][] VERTICES_FACE = new double[][]
153
          {
154 7dc57f89 Leszek Koltunski
             {-0.5f, 0.0f, 0.0f },
155
             { 0.0f,-0.5f, 0.0f },
156
             { 0.5f, 0.0f, 0.0f },
157
             { 0.0f, 0.5f, 0.0f },
158
             { 0.0f, 0.0f,-0.5f }
159 596d62a4 Leszek Koltunski
          };
160
161
  private static final int[][] VERT_INDEXES_FACE = new int[][]
162
          {
163 7dc57f89 Leszek Koltunski
             {0,1,2,3},
164
             {4,1,0},
165
             {4,2,1},
166
             {4,3,2},
167
             {4,0,3}
168
          };
169
170
171
  private static final float[][] STICKERS = new float[][]
172
          {
173
             { -0.5f,   0.25f, 0.25f,  -0.5f, 0.25f, 0.25f  },
174
             {  0.0f, -1.0f/3, 0.50f, 1.0f/6, -0.5f, 1.0f/6 },
175
             { -0.5f,    0.0f, 0.00f,  -0.5f, 0.50f, 0.0f, 0.0f, 0.5f }
176 596d62a4 Leszek Koltunski
          };
177
178
  private static MeshBase[] mMeshes;
179 fb52fae9 Leszek Koltunski
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181
182 9c2f0c91 Leszek Koltunski
  TwistySkewb(int size, Static4D quat, DistortedTexture texture,
183
              MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
184 fb52fae9 Leszek Koltunski
    {
185 db875721 Leszek Koltunski
    super(size, 2*size-2, quat, texture, mesh, effects, moves, ObjectList.SKEW, res, scrWidth);
186 fb52fae9 Leszek Koltunski
    }
187
188 b1f2ccf5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
189
190
  double[][] getVertices(int cubitType)
191
    {
192 596d62a4 Leszek Koltunski
    if( cubitType==0 ) return VERTICES_CORNER;
193
    if( cubitType==1 ) return VERTICES_EDGE;
194
    if( cubitType==2 ) return VERTICES_FACE;
195 b1f2ccf5 Leszek Koltunski
    return null;
196
    }
197
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199
200
  int[][] getVertIndexes(int cubitType)
201
    {
202 596d62a4 Leszek Koltunski
    if( cubitType==0 ) return VERT_INDEXES_CORNER;
203
    if( cubitType==1 ) return VERT_INDEXES_EDGE;
204
    if( cubitType==2 ) return VERT_INDEXES_FACE;
205 b1f2ccf5 Leszek Koltunski
    return null;
206
    }
207
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209
210
  int getNumCubitTypes(int numLayers)
211
    {
212
    return numLayers==2 ? 2 : 3;
213
    }
214
215 3f3ff476 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
216
217 d92030e4 Leszek Koltunski
  private int getNumCorners()
218 3f3ff476 Leszek Koltunski
    {
219
    return 8;
220
    }
221
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
224 b89898c5 Leszek Koltunski
  private int getNumEdges(int layers)
225 3f3ff476 Leszek Koltunski
    {
226 b89898c5 Leszek Koltunski
    return (layers-2)*12;
227 3f3ff476 Leszek Koltunski
    }
228
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230
231 d92030e4 Leszek Koltunski
  private int getNumCentersPerFace(int layers)
232 3f3ff476 Leszek Koltunski
    {
233 d92030e4 Leszek Koltunski
    return ((layers-2)*(layers-2) + (layers-1)*(layers-1));
234 3f3ff476 Leszek Koltunski
    }
235
236 fb52fae9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
237
238
  float getScreenRatio()
239
    {
240 d99f3a48 Leszek Koltunski
    return 1.0f;
241 fb52fae9 Leszek Koltunski
    }
242
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244
245
  Static4D[] getQuats()
246
    {
247
    return QUATS;
248
    }
249
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251
252
  int getNumFaces()
253
    {
254
    return FACE_COLORS.length;
255
    }
256
257 eaee1ddc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
258
259
  boolean shouldResetTextureMaps()
260
    {
261
    return false;
262
    }
263
264 eab9d8f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
265
266 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
267 eab9d8f8 Leszek Koltunski
    {
268 3f3ff476 Leszek Koltunski
    return 3;
269 eab9d8f8 Leszek Koltunski
    }
270
271 7403cdfa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
272
273 b89898c5 Leszek Koltunski
  float[] getCuts(int numLayers)
274 7403cdfa Leszek Koltunski
    {
275 b89898c5 Leszek Koltunski
    float[] cuts = new float[numLayers-1];
276 a97e02b7 Leszek Koltunski
277 b89898c5 Leszek Koltunski
    switch(numLayers)
278 a97e02b7 Leszek Koltunski
      {
279
      case 2: cuts[0] = 0;
280
              break;
281
      case 3: cuts[0] = -SQ3/12;
282
              cuts[1] = +SQ3/12;
283
              break;
284 c7e23561 Leszek Koltunski
      case 4: cuts[0] = -SQ3/9;
285
              cuts[1] = 0;
286
              cuts[2] = +SQ3/9;
287
              break;
288 a97e02b7 Leszek Koltunski
      }
289
    return cuts;
290 7403cdfa Leszek Koltunski
    }
291
292 fb52fae9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
293
294
  int getNumCubitFaces()
295
    {
296
    return FACES_PER_CUBIT;
297
    }
298
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300
301 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int numLayers)
302 fb52fae9 Leszek Koltunski
    {
303 b89898c5 Leszek Koltunski
    final float DIST_CORNER = (numLayers-1)*0.50f;
304
    final float DIST_EDGE   = (numLayers-1)*0.50f;
305
    final float DIST_CENTER = (numLayers-1)*0.50f;
306 3f3ff476 Leszek Koltunski
307 d92030e4 Leszek Koltunski
    final int numCorners = getNumCorners();
308 b89898c5 Leszek Koltunski
    final int numEdges   = getNumEdges(numLayers);
309 d92030e4 Leszek Koltunski
    final int numCenters = 6*getNumCentersPerFace(numLayers);
310 3f3ff476 Leszek Koltunski
311 e6cf7283 Leszek Koltunski
    final float[][] CENTERS = new float[numCorners+numEdges+numCenters][];
312 3f3ff476 Leszek Koltunski
313
    /// CORNERS //////////////////////////////////////////////
314
315 e6cf7283 Leszek Koltunski
    CENTERS[0] = new float[] { DIST_CORNER, DIST_CORNER, DIST_CORNER };
316
    CENTERS[1] = new float[] { DIST_CORNER, DIST_CORNER,-DIST_CORNER };
317
    CENTERS[2] = new float[] { DIST_CORNER,-DIST_CORNER, DIST_CORNER };
318
    CENTERS[3] = new float[] { DIST_CORNER,-DIST_CORNER,-DIST_CORNER };
319
    CENTERS[4] = new float[] {-DIST_CORNER, DIST_CORNER, DIST_CORNER };
320
    CENTERS[5] = new float[] {-DIST_CORNER, DIST_CORNER,-DIST_CORNER };
321
    CENTERS[6] = new float[] {-DIST_CORNER,-DIST_CORNER, DIST_CORNER };
322
    CENTERS[7] = new float[] {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER };
323 3f3ff476 Leszek Koltunski
324
    /// EDGES ///////////////////////////////////////////////
325
326
    final float[][]  edgeTable =
327
        {
328
            {0,+DIST_EDGE,+DIST_EDGE},
329
            {+DIST_EDGE,0,+DIST_EDGE},
330
            {0,-DIST_EDGE,+DIST_EDGE},
331
            {-DIST_EDGE,0,+DIST_EDGE},
332
            {+DIST_EDGE,+DIST_EDGE,0},
333
            {+DIST_EDGE,-DIST_EDGE,0},
334
            {-DIST_EDGE,-DIST_EDGE,0},
335
            {-DIST_EDGE,+DIST_EDGE,0},
336
            {0,+DIST_EDGE,-DIST_EDGE},
337
            {+DIST_EDGE,0,-DIST_EDGE},
338
            {0,-DIST_EDGE,-DIST_EDGE},
339
            {-DIST_EDGE,0,-DIST_EDGE}
340
        };
341
342
    int index=8;
343
344
    for (float[] edges : edgeTable)
345
      {
346 b89898c5 Leszek Koltunski
      float c = (3-numLayers)*0.5f;
347 3f3ff476 Leszek Koltunski
348 b89898c5 Leszek Koltunski
      for (int j=0; j<numLayers-2; j++, c+=1.0f, index++)
349 3f3ff476 Leszek Koltunski
        {
350 e6cf7283 Leszek Koltunski
        CENTERS[index] = new float[] { edges[0]==0 ? c : edges[0] ,
351 3f3ff476 Leszek Koltunski
                                       edges[1]==0 ? c : edges[1] ,
352 e6cf7283 Leszek Koltunski
                                       edges[2]==0 ? c : edges[2] };
353 3f3ff476 Leszek Koltunski
        }
354
      }
355
356
    /// CENTERS //////////////////////////////////////////////
357
358
    final float X= -1000.0f;
359
    final float Y= -1001.0f;
360
361
    final float[][]  centerTable =
362
        {
363
            {+DIST_CENTER,X,Y},
364
            {-DIST_CENTER,X,Y},
365
            {X,+DIST_CENTER,Y},
366
            {X,-DIST_CENTER,Y},
367
            {X,Y,+DIST_CENTER},
368
            {X,Y,-DIST_CENTER}
369
        };
370
371
    float x,y, cen0, cen1, cen2;
372
373
    for( float[] centers : centerTable )
374
      {
375 b89898c5 Leszek Koltunski
      x = (2-numLayers)*0.5f;
376 3f3ff476 Leszek Koltunski
377 b89898c5 Leszek Koltunski
      for(int i=0; i<numLayers-1; i++, x+=1.0f)
378 3f3ff476 Leszek Koltunski
        {
379 b89898c5 Leszek Koltunski
        y = (2-numLayers)*0.5f;
380 3f3ff476 Leszek Koltunski
381 b89898c5 Leszek Koltunski
        for(int j=0; j<numLayers-1; j++, y+=1.0f, index++)
382 3f3ff476 Leszek Koltunski
          {
383
               if( centers[0]==Y ) cen0 = y;
384
          else if( centers[0]==X ) cen0 = x;
385
          else                     cen0 = centers[0];
386
387
               if( centers[1]==Y ) cen1 = y;
388
          else if( centers[1]==X ) cen1 = x;
389
          else                     cen1 = centers[1];
390
391
               if( centers[2]==Y ) cen2 = y;
392
          else if( centers[2]==X ) cen2 = x;
393
          else                     cen2 = centers[2];
394
395 e6cf7283 Leszek Koltunski
          CENTERS[index] = new float[] {cen0,cen1,cen2};
396 3f3ff476 Leszek Koltunski
          }
397
        }
398
399 b89898c5 Leszek Koltunski
      x = (3-numLayers)*0.5f;
400 3f3ff476 Leszek Koltunski
401 b89898c5 Leszek Koltunski
      for(int i=0; i<numLayers-2; i++, x+=1.0f)
402 3f3ff476 Leszek Koltunski
        {
403 b89898c5 Leszek Koltunski
        y = (3-numLayers)*0.5f;
404 3f3ff476 Leszek Koltunski
405 b89898c5 Leszek Koltunski
        for(int j=0; j<numLayers-2; j++, y+=1.0f, index++)
406 3f3ff476 Leszek Koltunski
          {
407
               if( centers[0]==Y ) cen0 = y;
408
          else if( centers[0]==X ) cen0 = x;
409
          else                     cen0 = centers[0];
410
411
               if( centers[1]==Y ) cen1 = y;
412
          else if( centers[1]==X ) cen1 = x;
413
          else                     cen1 = centers[1];
414
415
               if( centers[2]==Y ) cen2 = y;
416
          else if( centers[2]==X ) cen2 = x;
417
          else                     cen2 = centers[2];
418
419 e6cf7283 Leszek Koltunski
          CENTERS[index] = new float[] {cen0,cen1,cen2};
420 3f3ff476 Leszek Koltunski
          }
421
        }
422
      }
423
424 fb52fae9 Leszek Koltunski
    return CENTERS;
425
    }
426
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428
429 d92030e4 Leszek Koltunski
  private Static4D getQuat(int cubit, int numLayers)
430 fb52fae9 Leszek Koltunski
    {
431 d92030e4 Leszek Koltunski
    int numCorners = getNumCorners();
432
    int numEdges   = getNumEdges(numLayers);
433 3f3ff476 Leszek Koltunski
434
    if( cubit<numCorners )
435
      {
436
      switch(cubit)
437
        {
438
        case  0: return QUATS[0];                          //  unit quat
439
        case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
440
        case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
441
        case  3: return QUATS[1];                          // 180 along X
442
        case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
443
        case  5: return QUATS[2];                          // 180 along Y
444
        case  6: return QUATS[3];                          // 180 along Z
445
        case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
446
        }
447
      }
448
    else if( cubit<numCorners+numEdges )
449
      {
450 d92030e4 Leszek Koltunski
      int edge = (cubit-numCorners)/(numLayers-2);
451 3f3ff476 Leszek Koltunski
452
      switch(edge)
453
        {
454
        case  0: return QUATS[ 0];
455
        case  1: return QUATS[ 5];
456
        case  2: return QUATS[ 3];
457
        case  3: return QUATS[11];
458
        case  4: return QUATS[ 4];
459
        case  5: return QUATS[ 7];
460
        case  6: return QUATS[ 9];
461
        case  7: return QUATS[10];
462
        case  8: return QUATS[ 2];
463
        case  9: return QUATS[ 8];
464
        case 10: return QUATS[ 1];
465
        case 11: return QUATS[ 6];
466
        }
467
      }
468
    else
469 fb52fae9 Leszek Koltunski
      {
470 d92030e4 Leszek Koltunski
      int center = (cubit-numCorners-numEdges)/getNumCentersPerFace(numLayers);
471 3f3ff476 Leszek Koltunski
472
      switch(center)
473
        {
474
        case 0: return new Static4D(0,-SQ2/2,0,SQ2/2);    // -90 along Y
475
        case 1: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
476
        case 2: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
477
        case 3: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
478
        case 4: return QUATS[0];                          //  unit quaternion
479
        case 5: return QUATS[1];                          // 180 along X
480
        }
481 fb52fae9 Leszek Koltunski
      }
482
483
    return null;
484
    }
485
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487
488 a64e07d0 Leszek Koltunski
  MeshBase createCubitMesh(int cubit, int numLayers)
489 fb52fae9 Leszek Koltunski
    {
490 596d62a4 Leszek Koltunski
    if( mMeshes==null )
491
      {
492
      FactoryCubit factory = FactoryCubit.getInstance();
493
      factory.clear();
494
      mMeshes = new MeshBase[3];
495
      }
496
497 fb52fae9 Leszek Koltunski
    MeshBase mesh;
498
499 d92030e4 Leszek Koltunski
    int numCorners = getNumCorners();
500 d99f3a48 Leszek Koltunski
    int numEdges   = getNumEdges(numLayers);
501 3f3ff476 Leszek Koltunski
502
    if( cubit<numCorners )
503 fb52fae9 Leszek Koltunski
      {
504 596d62a4 Leszek Koltunski
      if( mMeshes[0]==null )
505
        {
506 7dc57f89 Leszek Koltunski
        float[][] bands= new float[][]
507
          {
508
             {0.028f,35,0.16f,0.7f,7,3,3},
509
             {0.000f, 0,1.00f,0.0f,3,1,5}
510
          };
511
        int[] bandIndexes   = new int[] { 0,0,0,1,1,1 };
512
        float[][] corners   = new float[][] { {0.08f,0.15f}, {0.08f,0.20f} };
513
        int[] cornerIndexes = new int[] { 1,1,1,0,0 };
514
        float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.25f} };
515
        int[] centerIndexes = new int[] { 0,0,0,-1,0 };
516
517
        FactoryCubit factory = FactoryCubit.getInstance();
518
        factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
519
        mMeshes[0] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
520
                                                bands, bandIndexes,
521
                                                corners, cornerIndexes,
522
                                                centers, centerIndexes,
523
                                                getNumCubitFaces() );
524
        //mMeshes[0] = FactoryCubit.getInstance().createSkewbCornerMesh();
525 596d62a4 Leszek Koltunski
        }
526
      mesh = mMeshes[0].copy(true);
527 fb52fae9 Leszek Koltunski
      }
528 3f3ff476 Leszek Koltunski
    else if( cubit<numCorners+numEdges )
529
      {
530 596d62a4 Leszek Koltunski
      if( mMeshes[1]==null )
531 3f3ff476 Leszek Koltunski
        {
532 596d62a4 Leszek Koltunski
        float[][] bands= new float[][]
533
          {
534
             {0.035f,30,0.16f,0.8f,7,2,5},
535
             {0.020f,45,0.16f,0.2f,3,1,2}
536
          };
537
        int[] bandIndexes   = new int[] { 0,0,1,1 };
538
        float[][] corners   = new float[][] { {0.07f,0.20f}, {0.02f,0.30f} };
539
        int[] cornerIndexes = new int[] { 0,0,1,1 };
540 b3c9061a Leszek Koltunski
        float[][] centers   = new float[][] { {0.0f, -0.25f, -0.25f} };
541
        int[] centerIndexes = new int[] { 0,0,0,0 };
542 596d62a4 Leszek Koltunski
543
        FactoryCubit factory = FactoryCubit.getInstance();
544
        factory.createNewFaceTransform(VERTICES_EDGE,VERT_INDEXES_EDGE);
545
        mMeshes[1] = factory.createRoundedSolid(VERTICES_EDGE, VERT_INDEXES_EDGE,
546
                                                bands, bandIndexes,
547
                                                corners, cornerIndexes,
548 b3c9061a Leszek Koltunski
                                                centers, centerIndexes,
549 596d62a4 Leszek Koltunski
                                                getNumCubitFaces() );
550 3f3ff476 Leszek Koltunski
        }
551 596d62a4 Leszek Koltunski
      mesh = mMeshes[1].copy(true);
552 3f3ff476 Leszek Koltunski
      }
553 fb52fae9 Leszek Koltunski
    else
554
      {
555 596d62a4 Leszek Koltunski
      if( mMeshes[2]==null )
556
        {
557 7dc57f89 Leszek Koltunski
        float[][] bands= new float[][]
558
          {
559
             {0.051f,35,SQ2/8,0.9f, 7,3,3},
560
             {0.000f, 0,    1,0.0f, 3,0,0}
561
          };
562
        int[] bandIndexes   = new int[] { 0,1,1,1,1 };
563
        float[][] corners   = new float[][] { {0.06f,0.10f} };
564
        int[] cornerIndexes = new int[] { 0,0,0,0,0 };
565
        float[][] centers   = new float[][] { {0,0,-0.2f} };
566
        int[] centerIndexes = new int[] { 0,0,0,0,-1 };
567
568
        FactoryCubit factory = FactoryCubit.getInstance();
569
        factory.createNewFaceTransform(VERTICES_FACE,VERT_INDEXES_FACE);
570
        mMeshes[2] = factory.createRoundedSolid(VERTICES_FACE, VERT_INDEXES_FACE,
571
                                                bands, bandIndexes,
572
                                                corners, cornerIndexes,
573
                                                centers, centerIndexes,
574
                                                getNumCubitFaces() );
575 596d62a4 Leszek Koltunski
        }
576
      mesh = mMeshes[2].copy(true);
577 fb52fae9 Leszek Koltunski
      }
578
579 d99f3a48 Leszek Koltunski
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
580 fb52fae9 Leszek Koltunski
    mesh.apply(quat,0xffffffff,0);
581
582
    return mesh;
583
    }
584
585
///////////////////////////////////////////////////////////////////////////////////////////////////
586
587 d92030e4 Leszek Koltunski
  int getFaceColor(int cubit, int cubitface, int numLayers)
588 fb52fae9 Leszek Koltunski
    {
589 d92030e4 Leszek Koltunski
    int numCorners = getNumCorners();
590
    int numEdges   = getNumEdges(numLayers);
591 3f3ff476 Leszek Koltunski
592
    if( cubit<numCorners )
593
      {
594
      return mCornerMap[cubit][cubitface];
595
      }
596
    else if( cubit<numCorners+numEdges )
597
      {
598 d92030e4 Leszek Koltunski
      int edge = (cubit-numCorners)/(numLayers-2);
599 3f3ff476 Leszek Koltunski
      return mEdgeMap[edge][cubitface];
600
      }
601
    else
602
      {
603 d92030e4 Leszek Koltunski
      int center = (cubit-numCorners-numEdges)/getNumCentersPerFace(numLayers);
604 3f3ff476 Leszek Koltunski
      return mCenterMap[center][cubitface];
605
      }
606 fb52fae9 Leszek Koltunski
    }
607
608
///////////////////////////////////////////////////////////////////////////////////////////////////
609
610 ae755eda Leszek Koltunski
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
611 fb52fae9 Leszek Koltunski
    {
612 eab9d8f8 Leszek Koltunski
    int COLORS = FACE_COLORS.length;
613 7dc57f89 Leszek Koltunski
    float R=0.0f,S=0.0f;
614
    int cubitType = face/COLORS;
615 eab9d8f8 Leszek Koltunski
616 7dc57f89 Leszek Koltunski
    switch(cubitType)
617 eab9d8f8 Leszek Koltunski
      {
618 7dc57f89 Leszek Koltunski
      case 0: R = 0.025f; S = 0.045f; break;
619
      case 1: R = 0.025f; S = 0.035f; break;
620
      case 2: R = 0.055f; S = 0.035f; break;
621 eab9d8f8 Leszek Koltunski
      }
622 ae755eda Leszek Koltunski
623
    FactorySticker factory = FactorySticker.getInstance();
624 7dc57f89 Leszek Koltunski
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[cubitType], S, FACE_COLORS[face%COLORS], R);
625 fb52fae9 Leszek Koltunski
    }
626
627
///////////////////////////////////////////////////////////////////////////////////////////////////
628
629
  float returnMultiplier()
630
    {
631
    return 2.0f;
632
    }
633
634
///////////////////////////////////////////////////////////////////////////////////////////////////
635
636 a64e07d0 Leszek Koltunski
  float[] getRowChances(int numLayers)
637 fb52fae9 Leszek Koltunski
    {
638 d99f3a48 Leszek Koltunski
    float[] chances = new float[numLayers];
639 fb52fae9 Leszek Koltunski
640 b3da2f16 Leszek Koltunski
    switch(numLayers)
641 3f3ff476 Leszek Koltunski
      {
642 b3da2f16 Leszek Koltunski
      case 2: chances[0] = 0.5f;
643
              chances[1] = 1.0f;
644
              break;
645
      case 3: chances[0] = 0.5f;
646
              chances[1] = 0.5f;
647
              chances[2] = 1.0f;
648
              break;
649
      default:for(int i=0; i<numLayers; i++)
650
                {
651
                chances[i] = (float)(i+1)/numLayers;
652
                }
653 3f3ff476 Leszek Koltunski
      }
654 fb52fae9 Leszek Koltunski
655
    return chances;
656
    }
657
658
///////////////////////////////////////////////////////////////////////////////////////////////////
659
// PUBLIC API
660
661
  public Static3D[] getRotationAxis()
662
    {
663
    return ROT_AXIS;
664
    }
665
666
///////////////////////////////////////////////////////////////////////////////////////////////////
667
668
  public int getBasicAngle()
669
    {
670
    return 3;
671
    }
672
673
///////////////////////////////////////////////////////////////////////////////////////////////////
674
675 5043d5d0 Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
676 fb52fae9 Leszek Koltunski
    {
677 5043d5d0 Leszek Koltunski
    if( num==0 )
678 fb52fae9 Leszek Koltunski
      {
679 5043d5d0 Leszek Koltunski
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
680 fb52fae9 Leszek Koltunski
      }
681
    else
682
      {
683 bbc6471c Leszek Koltunski
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
684 5043d5d0 Leszek Koltunski
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
685 fb52fae9 Leszek Koltunski
      }
686
687
    float rowFloat = rnd.nextFloat();
688
689
    for(int row=0; row<mRowChances.length; row++)
690
      {
691 bbc6471c Leszek Koltunski
      if( rowFloat<=mRowChances[row] )
692
        {
693 5043d5d0 Leszek Koltunski
        scramble[num][1] = row;
694 bbc6471c Leszek Koltunski
        break;
695
        }
696 fb52fae9 Leszek Koltunski
      }
697
698 5043d5d0 Leszek Koltunski
    switch( rnd.nextInt(2) )
699
      {
700
      case 0: scramble[num][2] = -1; break;
701
      case 1: scramble[num][2] =  1; break;
702
      }
703 fb52fae9 Leszek Koltunski
    }
704
705
///////////////////////////////////////////////////////////////////////////////////////////////////
706
// The Skewb is solved if and only if:
707
//
708 3f3ff476 Leszek Koltunski
// 1) all of its corner and edge cubits are rotated with the same quat
709 fb52fae9 Leszek Koltunski
// 2) all its face cubits are rotated with the same quat like the corner ones,
710
//    and optionally they also might be upside down.
711
//
712
// i.e.
713
// cubits [ 8] and [ 9] - might be extra QUAT[1]
714
// cubits [10] and [11] - might be extra QUAT[2]
715
// cubits [12] and [13] - might be extra QUAT[3]
716
717
  public boolean isSolved()
718
    {
719
    int q = CUBITS[0].mQuatIndex;
720
721 d92030e4 Leszek Koltunski
    int numLayers      = getNumLayers();
722
    int numCorners     = getNumCorners();
723
    int numEdges       = getNumEdges(numLayers);
724
    int cornersAndEdges= numCorners + numEdges;
725
    int centersPerFace = getNumCentersPerFace(numLayers);
726 b89898c5 Leszek Koltunski
    int cubit, q1=q;
727
728
    for(cubit=0; cubit<cornersAndEdges; cubit++)
729 fb52fae9 Leszek Koltunski
      {
730 b89898c5 Leszek Koltunski
      if( CUBITS[cubit].mQuatIndex != q ) return false;
731 fb52fae9 Leszek Koltunski
      }
732
733 b89898c5 Leszek Koltunski
    for(int face=0; face<6; face++)
734
      {
735
      if( face%2==0 ) q1 = mulQuat(q, (face/2)+1);
736
737 d92030e4 Leszek Koltunski
      for(int center=0; center<centersPerFace; center++)
738 b89898c5 Leszek Koltunski
        {
739
        if( CUBITS[cubit].mQuatIndex != q && CUBITS[cubit].mQuatIndex != q1 ) return false;
740
        cubit++;
741
        }
742
      }
743
744
    return true;
745 fb52fae9 Leszek Koltunski
    }
746
747
///////////////////////////////////////////////////////////////////////////////////////////////////
748 ee35e63c Leszek Koltunski
// only needed for solvers - there are no Skewb solvers ATM)
749 fb52fae9 Leszek Koltunski
750
  public String retObjectString()
751
    {
752
    return "";
753
    }
754 6fd4a72c Leszek Koltunski
755
///////////////////////////////////////////////////////////////////////////////////////////////////
756
757
  public int getObjectName(int numLayers)
758
    {
759
    switch(numLayers)
760
      {
761
      case 2: return R.string.skew2;
762
      case 3: return R.string.skew3;
763
      }
764
    return R.string.skew2;
765
    }
766
767
///////////////////////////////////////////////////////////////////////////////////////////////////
768
769
  public int getInventor(int numLayers)
770
    {
771
    switch(numLayers)
772
      {
773
      case 2: return R.string.skew2_inventor;
774
      case 3: return R.string.skew3_inventor;
775
      }
776
    return R.string.skew2_inventor;
777
    }
778
779
///////////////////////////////////////////////////////////////////////////////////////////////////
780
781
  public int getComplexity(int numLayers)
782
    {
783
    switch(numLayers)
784
      {
785
      case 2: return 5;
786
      case 3: return 9;
787
      }
788
    return 5;
789
    }
790 fb52fae9 Leszek Koltunski
}