Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyUltimate.java @ 7ba38dd4

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objectlib.objects;
21

    
22
import static org.distorted.objectlib.main.Movement.MOVEMENT_DODECAHEDRON;
23
import static org.distorted.objectlib.main.Movement.TYPE_NOT_SPLIT;
24

    
25
import android.content.res.Resources;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.R;
31
import org.distorted.objectlib.main.Movement12;
32
import org.distorted.objectlib.main.ObjectControl;
33
import org.distorted.objectlib.main.ObjectType;
34
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ObjectSticker;
36
import org.distorted.objectlib.helpers.ScrambleState;
37
import org.distorted.objectlib.main.Twisty12;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
public class TwistyUltimate extends Twisty12
42
{
43
  private static final float A = (float)Math.sqrt(21*SQ5+47);
44
  private static final float B = SQ6*(5*SQ5+11)/(6*A);
45
  private static final float C = SQ6*(  SQ5+ 2)/(3*A);
46
  private static final float D = SQ3/3;
47
  private static final float E = (SQ5+1)/4;
48
  private static final float F = (SQ5-1)/4;
49
  private static final float G = (SQ5+3)/4;
50

    
51
  static final Static3D[] ROT_AXIS = new Static3D[]
52
         {
53
           new Static3D( B,0,C ),
54
           new Static3D( C,B,0 ),
55
           new Static3D(-D,D,D ),
56
           new Static3D( 0,C,-B)
57
         };
58

    
59
  private ScrambleState[] mStates;
60
  private int[] mBasicAngle;
61
  private Static4D[] mQuats;
62
  private float[][] mCuts;
63
  private int[][] mFaceMap;
64
  private float[][] mCenters;
65
  private int[] mQuatIndex;
66
  private ObjectSticker[] mStickers;
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
  public TwistyUltimate(int[] numL, Static4D quat, Static3D move, Resources res)
71
    {
72
    super(numL, numL[0], quat, move, res);
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  public ScrambleState[] getScrambleStates()
78
    {
79
    if( mStates==null )
80
      {
81
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
82

    
83
      mStates = new ScrambleState[]
84
        {
85
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
86
        };
87
      }
88

    
89
    return mStates;
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  protected int getResource(int[] numLayers)
95
    {
96
    return R.raw.ulti_2;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  private void initializeQuats()
102
    {
103
    mQuats = new Static4D[]
104
         {
105
         new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
106
         new Static4D(-0.5f, 0.5f, 0.5f, 0.5f ),
107
         new Static4D( 0.5f,-0.5f,-0.5f, 0.5f ),
108
         new Static4D( 0.0f,    F,   -E, 0.5f ),
109
         new Static4D( 0.0f,   -F,    E, 0.5f ),
110
         new Static4D(    E, 0.0f,    F, 0.5f ),
111
         new Static4D(   -E, 0.0f,   -F, 0.5f ),
112
         new Static4D(    F,    E, 0.0f, 0.5f ),
113
         new Static4D(   -F,   -E, 0.0f, 0.5f ),
114
         new Static4D(    E,    F,-0.5f, 0.0f ),
115
         new Static4D( 0.5f,   -E,    F, 0.0f ),
116
         new Static4D(    F, 0.5f,    E, 0.0f )
117
         };
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  public int[] getSolvedQuats(int cubit, int[] numLayers)
123
    {
124
    if( mQuats==null ) initializeQuats();
125
    int status = retCubitSolvedStatus(cubit,numLayers);
126
    return status<0 ? null : buildSolvedQuats(Movement12.FACE_AXIS[status],mQuats);
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public ObjectShape getObjectShape(int variant)
132
    {
133
    if( variant==0 )
134
      {
135
      double[][] vertices = new double[][]
136
         {
137
           { 0.0  , 0.0  , 0.0   },
138
           { -E   , E+0.5, -0.5  },
139
           {-0.5  , -E   , -E-0.5},
140
           { E+0.5, 0.5  , -E    },
141
           { 0.0  , 1    , -2*E-1},
142
           { 0.0  , 1    , 0.0   },
143
           { -E   ,-E+0.5, -0.5  },
144
           {  E   ,-E+0.5, -0.5  }
145
         };
146
      int[][] vert_indices = new int[][]
147
         {
148
           {6,0,5,1},
149
           {0,7,3,5},
150
           {0,6,2,7},
151
           {4,3,5,1},
152
           {4,2,7,3},
153
           {4,1,6,2},
154
         };
155

    
156
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
157
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
158
      float[][] corners   = new float[][] {  { 0.013f, 0.16f } };
159
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
160
      float[][] centers   = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
161
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
162
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
163
      }
164
    else if( variant==1 )
165
      {
166
      double[][] vertices = new double[][]
167
         {
168
            {         0.00,         0.00,         0.00},
169
            {       - 0.50,-SQ5/4 - 0.25,-SQ5/4 - 0.75},
170
            { SQ5/4 + 0.25,-SQ5/4 - 0.75,       + 0.50},
171
            { SQ5/4 + 0.75,       + 0.50,-SQ5/4 - 0.25},
172
            { SQ5/2 + 0.50,-SQ5/2 - 0.50,-SQ5/2 - 0.50},
173
            { SQ5/4 - 0.25,       + 0.50,-SQ5/4 - 0.25},
174
            {       - 0.50,-SQ5/4 - 0.25,-SQ5/4 + 0.25},
175
            { SQ5/4 + 0.25,-SQ5/4 + 0.25,       + 0.50}
176
         };
177
      int[][] vert_indices  = new int[][]
178
         {
179
           {6,0,5,1},
180
           {0,7,3,5},
181
           {0,6,2,7},
182
           {1,5,3,4},
183
           {3,7,2,4},
184
           {2,6,1,4},
185
         };
186

    
187
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
188
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
189
      float[][] corners   = new float[][] {  { 0.013f, 0.16f } };
190
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
191
      float[][] centers   = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
192
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
193
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
194
      }
195
    else
196
      {
197
      double[][] vertices = new double[][]
198
         {
199
           {  -E    ,-E+0.5,     0.5},
200
           {   E    , E-0.5,    -0.5},
201
           {-2*E    ,   0.0,     0.0},
202
           {     0.5, E    ,  -E-0.5},
203
           {  -E    ,-E-0.5,     0.5},
204
           {   E+0.5,  -0.5,  -E    },
205
           {-2*E    ,  -1.0,     0.0},
206
           {     1.0,   0.0,-2*E    },
207
           {-2*E+0.5, E    ,  -E-0.5},
208
           {     0.5,-E-1.0,  -E+0.5},
209
           {  -E    ,-E-0.5,-2*E-0.5}
210
         };
211
      int[][] vert_indices = new int[][]
212
         {
213
           {0,1,3,8,2},   // counterclockwise!
214
           {0,4,9,5,1},
215
           { 0,2,6,4},
216
           { 1,5,7,3},
217
           {10,9,4,6},
218
           {10,9,5,7},
219
           {10,8,3,7},
220
           {10,8,2,6}
221
         };
222

    
223
      float[][] bands     = new float[][] { {0.04f,17,0.5f,0.2f,5,2,2}, {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
224
      int[] bandIndices   = new int[] { 0,0,1,1,2,2,2,2 };
225
      float[][] corners   = new float[][] { { 0.013f, 0.16f } };
226
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
227
      float[][] centers   = new float[][] { { -(SQ5+1)/4, 0.5f, -(SQ5+5)/4 } };
228
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
229
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
230
      }
231
    }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
  public Static4D getQuat(int cubit, int[] numLayers)
236
    {
237
    if( mQuats     ==null ) initializeQuats();
238
    if( mQuatIndex ==null ) mQuatIndex = new int[] { 0,6,1,2,0,4,6,5,0,1,4,9,5,2 };
239
    return mQuats[mQuatIndex[cubit]];
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
  public int getNumCubitVariants(int[] numLayers)
245
    {
246
    return 3;
247
    }
248

    
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

    
251
  public int getCubitVariant(int cubit, int[] numLayers)
252
    {
253
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
254
    }
255

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

    
258
  public float[][] getCubitPositions(int[] numLayers)
259
    {
260
    if( mCenters==null )
261
      {
262
      mCenters = new float[][]
263
         {
264
           {   0,  -1, 2*G },
265
           { 2*E,-2*E,-2*E },
266
           {-2*G,   0,  -1 },
267
           {   1, 2*G,   0 },
268

    
269
           {-2*E,  2*E, 2*E },
270
           { 2*G,    0,   1 },
271
           {  -1, -2*G,   0 },
272
           {   0,    1,-2*G },
273

    
274
           {        E, (E+0.5f),    (E+G) },
275
           {   -(E+G),       -E, (E+0.5f) },
276
           { (E+0.5f),   -(E+G),        E },
277
           {       -E,-(E+0.5f),   -(E+G) },
278
           {    (E+G),        E,-(E+0.5f) },
279
           {-(E+0.5f),    (E+G),       -E }
280
         };
281
      }
282

    
283
    return mCenters;
284
    }
285

    
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287

    
288
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
289
    {
290
    if( variant<2 ) return face<3 ? 2 : -1;
291
    else            return face<2 ? 0 : face<4 ? 1 : -1;
292
    }
293

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

    
296
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
297
    {
298
    if( mFaceMap==null )
299
      {
300
      mFaceMap = new int[][]
301
         {
302
           {  1, 0,11, -1,-1,-1,-1,-1 },
303
           {  3, 4, 5, -1,-1,-1,-1,-1 },
304
           {  7, 2, 6, -1,-1,-1,-1,-1 },
305
           {  8,10, 9, -1,-1,-1,-1,-1 },
306

    
307
           {  7, 8, 1, -1,-1,-1,-1,-1 },
308
           {  9, 4, 0, -1,-1,-1,-1,-1 },
309
           {  2,11, 3, -1,-1,-1,-1,-1 },
310
           {  6, 5,10, -1,-1,-1,-1,-1 },
311

    
312
           {  8, 0, 1, 9, -1,-1,-1,-1 },
313
           {  1, 2, 7,11, -1,-1,-1,-1 },
314
           {  4,11, 0, 3, -1,-1,-1,-1 },
315
           {  3, 6, 2, 5, -1,-1,-1,-1 },
316
           {  5, 9,10, 4, -1,-1,-1,-1 },
317
           {  7,10, 8, 6, -1,-1,-1,-1 }
318
         };
319
      }
320

    
321
    return mFaceMap[cubit][face];
322
    }
323

    
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

    
326
  public ObjectSticker retSticker(int sticker)
327
    {
328
    if( mStickers==null )
329
      {
330
      float[][] STICKERS = new float[][]
331
         {
332
           { -0.14400357f, -0.47894150f, 0.50000000f,-0.011045523f, 0.37700626f, 0.36749030f,-0.26699730f, 0.36749026f, -0.46600536f, -0.24499352f }, // Big cubit 1st
333
           {  0.36327127f,  0.26393202f,-0.36327127f, 0.500000000f,-0.36327127f,-0.26393202f, 0.36327127f,-0.50000000f },                             // Big cubit 2nd
334
           { -0.29389262f, -0.50000000f, 0.29389262f,-0.309017000f, 0.29389262f, 0.30901700f,-0.29389262f, 0.50000000f },                             // Small cubit 1st
335
         };
336

    
337
      final float R1 = 0.08f;
338
      final float R2 = 0.13f;
339
      final float R3 = 0.11f;
340
      final float[][] radii  = { {R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
341
      float[] strokes = { 0.07f, 0.09f, 0.08f };
342

    
343
      if( ObjectControl.isInIconMode() )
344
        {
345
        float mult = 1.5f;
346
        strokes[0]*=mult;
347
        strokes[1]*=mult;
348
        strokes[2]*=mult;
349
        }
350

    
351
      mStickers = new ObjectSticker[STICKERS.length];
352

    
353
      for(int s=0; s<STICKERS.length; s++)
354
        {
355
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
356
        }
357
      }
358

    
359
    return mStickers[sticker];
360
    }
361

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

    
364
  public Static4D[] getQuats()
365
    {
366
    if( mQuats==null ) initializeQuats();
367
    return mQuats;
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  public int getSolvedFunctionIndex()
373
    {
374
    return 0;
375
    }
376

    
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

    
379
  public float[][] getCuts(int[] numLayers)
380
    {
381
    if( mCuts==null )
382
      {
383
      float[] cut = new float[] {0.0f};
384
      mCuts = new float[][] { cut,cut,cut,cut };
385
      }
386

    
387
    return mCuts;
388
    }
389

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

    
392
  public boolean[][] getLayerRotatable(int[] numLayers)
393
    {
394
    int numAxis = ROT_AXIS.length;
395
    boolean[][] layerRotatable = new boolean[numAxis][];
396

    
397
    for(int i=0; i<numAxis; i++)
398
      {
399
      layerRotatable[i] = new boolean[numLayers[i]];
400
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
401
      }
402

    
403
    return layerRotatable;
404
    }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
  public int getMovementType()
409
    {
410
    return MOVEMENT_DODECAHEDRON;
411
    }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

    
415
  public int getMovementSplit()
416
    {
417
    return TYPE_NOT_SPLIT;
418
    }
419

    
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421

    
422
  public int[][][] getEnabled()
423
    {
424
    return new int[][][]
425
      {
426
        {{2,3}},{{1,3}},{{1,3}},{{2,3}},{{0,3}},{{0,2}},{{0,2}},{{0,3}},{{1,2}},{{0,1}},{{0,1}},{{1,2}}
427
      };
428
    }
429

    
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431

    
432
  public float[] getDist3D(int[] numLayers)
433
    {
434
    return null;
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

    
439
  public int getNumStickerTypes(int[] numLayers)
440
    {
441
    return 3;
442
    }
443

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445

    
446
  public int getNumCubitFaces()
447
    {
448
    return 8;
449
    }
450

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452
// PUBLIC API
453

    
454
  public Static3D[] getRotationAxis()
455
    {
456
    return ROT_AXIS;
457
    }
458

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

    
461
  public int[] getBasicAngle()
462
    {
463
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
464
    return mBasicAngle;
465
    }
466

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

    
469
  public ObjectType intGetObjectType(int[] numLayers)
470
    {
471
    return ObjectType.ULTI_2;
472
    }
473

    
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475

    
476
  public int getObjectName(int[] numLayers)
477
    {
478
    return R.string.ulti2;
479
    }
480

    
481
///////////////////////////////////////////////////////////////////////////////////////////////////
482

    
483
  public int getInventor(int[] numLayers)
484
    {
485
    return R.string.ulti2_inventor;
486
    }
487

    
488
///////////////////////////////////////////////////////////////////////////////////////////////////
489

    
490
  public int getYearOfInvention(int[] numLayers)
491
    {
492
    return 2000;
493
    }
494

    
495
///////////////////////////////////////////////////////////////////////////////////////////////////
496

    
497
  public int getComplexity(int[] numLayers)
498
    {
499
    return 6;
500
    }
501
}
(25-25/25)