Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyUltimate.java @ 23afe4c4

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.movement.Movement.MOVEMENT_DODECAHEDRON;
23
import static org.distorted.objectlib.movement.Movement.TYPE_NOT_SPLIT;
24

    
25
import java.io.InputStream;
26

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

    
30
import org.distorted.objectlib.movement.MovementDodecahedron;
31
import org.distorted.objectlib.main.ObjectControl;
32
import org.distorted.objectlib.main.ObjectType;
33
import org.distorted.objectlib.helpers.ObjectShape;
34
import org.distorted.objectlib.helpers.ObjectSticker;
35
import org.distorted.objectlib.helpers.ScrambleState;
36
import org.distorted.objectlib.main.ShapeDodecahedron;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

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

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

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

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  public TwistyUltimate(int[] numL, Static4D quat, Static3D move, float scale, InputStream stream)
70
    {
71
    super(numL, numL[0], quat, move, scale, stream);
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

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

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

    
88
    return mStates;
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  private void initializeQuats()
94
    {
95
    mQuats = new Static4D[]
96
         {
97
         new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
98
         new Static4D(-0.5f, 0.5f, 0.5f, 0.5f ),
99
         new Static4D( 0.5f,-0.5f,-0.5f, 0.5f ),
100
         new Static4D( 0.0f,    F,   -E, 0.5f ),
101
         new Static4D( 0.0f,   -F,    E, 0.5f ),
102
         new Static4D(    E, 0.0f,    F, 0.5f ),
103
         new Static4D(   -E, 0.0f,   -F, 0.5f ),
104
         new Static4D(    F,    E, 0.0f, 0.5f ),
105
         new Static4D(   -F,   -E, 0.0f, 0.5f ),
106
         new Static4D(    E,    F,-0.5f, 0.0f ),
107
         new Static4D( 0.5f,   -E,    F, 0.0f ),
108
         new Static4D(    F, 0.5f,    E, 0.0f )
109
         };
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  public int[] getSolvedQuats(int cubit, int[] numLayers)
115
    {
116
    if( mQuats==null ) initializeQuats();
117
    int status = retCubitSolvedStatus(cubit,numLayers);
118
    return status<0 ? null : buildSolvedQuats(MovementDodecahedron.FACE_AXIS[status],mQuats);
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  public ObjectShape getObjectShape(int variant)
124
    {
125
    if( variant==0 )
126
      {
127
      double[][] vertices = new double[][]
128
         {
129
           { 0.0  , 0.0  , 0.0   },
130
           { -E   , E+0.5, -0.5  },
131
           {-0.5  , -E   , -E-0.5},
132
           { E+0.5, 0.5  , -E    },
133
           { 0.0  , 1    , -2*E-1},
134
           { 0.0  , 1    , 0.0   },
135
           { -E   ,-E+0.5, -0.5  },
136
           {  E   ,-E+0.5, -0.5  }
137
         };
138
      int[][] vert_indices = new int[][]
139
         {
140
           {6,0,5,1},
141
           {0,7,3,5},
142
           {0,6,2,7},
143
           {4,3,5,1},
144
           {4,2,7,3},
145
           {4,1,6,2},
146
         };
147

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

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

    
215
      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} };
216
      int[] bandIndices   = new int[] { 0,0,1,1,2,2,2,2 };
217
      float[][] corners   = new float[][] { { 0.013f, 0.16f } };
218
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
219
      float[][] centers   = new float[][] { { -(SQ5+1)/4, 0.5f, -(SQ5+5)/4 } };
220
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
221
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
222
      }
223
    }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
  public Static4D getQuat(int cubit, int[] numLayers)
228
    {
229
    if( mQuats     ==null ) initializeQuats();
230
    if( mQuatIndex ==null ) mQuatIndex = new int[] { 0,6,1,2,0,4,6,5,0,1,4,9,5,2 };
231
    return mQuats[mQuatIndex[cubit]];
232
    }
233

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

    
236
  public int getNumCubitVariants(int[] numLayers)
237
    {
238
    return 3;
239
    }
240

    
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

    
243
  public int getCubitVariant(int cubit, int[] numLayers)
244
    {
245
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
246
    }
247

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

    
250
  public float[][] getCubitPositions(int[] numLayers)
251
    {
252
    if( mCenters==null )
253
      {
254
      mCenters = new float[][]
255
         {
256
           {   0,  -1, 2*G },
257
           { 2*E,-2*E,-2*E },
258
           {-2*G,   0,  -1 },
259
           {   1, 2*G,   0 },
260

    
261
           {-2*E,  2*E, 2*E },
262
           { 2*G,    0,   1 },
263
           {  -1, -2*G,   0 },
264
           {   0,    1,-2*G },
265

    
266
           {        E, (E+0.5f),    (E+G) },
267
           {   -(E+G),       -E, (E+0.5f) },
268
           { (E+0.5f),   -(E+G),        E },
269
           {       -E,-(E+0.5f),   -(E+G) },
270
           {    (E+G),        E,-(E+0.5f) },
271
           {-(E+0.5f),    (E+G),       -E }
272
         };
273
      }
274

    
275
    return mCenters;
276
    }
277

    
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279

    
280
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
281
    {
282
    if( variant<2 ) return face<3 ? 2 : -1;
283
    else            return face<2 ? 0 : face<4 ? 1 : -1;
284
    }
285

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

    
288
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
289
    {
290
    if( mFaceMap==null )
291
      {
292
      mFaceMap = new int[][]
293
         {
294
           {  1, 0,11, -1,-1,-1,-1,-1 },
295
           {  3, 4, 5, -1,-1,-1,-1,-1 },
296
           {  7, 2, 6, -1,-1,-1,-1,-1 },
297
           {  8,10, 9, -1,-1,-1,-1,-1 },
298

    
299
           {  7, 8, 1, -1,-1,-1,-1,-1 },
300
           {  9, 4, 0, -1,-1,-1,-1,-1 },
301
           {  2,11, 3, -1,-1,-1,-1,-1 },
302
           {  6, 5,10, -1,-1,-1,-1,-1 },
303

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

    
313
    return mFaceMap[cubit][face];
314
    }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

    
318
  public ObjectSticker retSticker(int sticker)
319
    {
320
    if( mStickers==null )
321
      {
322
      float[][] STICKERS = new float[][]
323
         {
324
           { -0.14400357f, -0.47894150f, 0.50000000f,-0.011045523f, 0.37700626f, 0.36749030f,-0.26699730f, 0.36749026f, -0.46600536f, -0.24499352f }, // Big cubit 1st
325
           {  0.36327127f,  0.26393202f,-0.36327127f, 0.500000000f,-0.36327127f,-0.26393202f, 0.36327127f,-0.50000000f },                             // Big cubit 2nd
326
           { -0.29389262f, -0.50000000f, 0.29389262f,-0.309017000f, 0.29389262f, 0.30901700f,-0.29389262f, 0.50000000f },                             // Small cubit 1st
327
         };
328

    
329
      final float R1 = 0.08f;
330
      final float R2 = 0.13f;
331
      final float R3 = 0.11f;
332
      final float[][] radii  = { {R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
333
      float[] strokes = { 0.07f, 0.09f, 0.08f };
334

    
335
      if( ObjectControl.isInIconMode() )
336
        {
337
        float mult = 1.5f;
338
        strokes[0]*=mult;
339
        strokes[1]*=mult;
340
        strokes[2]*=mult;
341
        }
342

    
343
      mStickers = new ObjectSticker[STICKERS.length];
344

    
345
      for(int s=0; s<STICKERS.length; s++)
346
        {
347
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
348
        }
349
      }
350

    
351
    return mStickers[sticker];
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

    
356
  public Static4D[] getQuats()
357
    {
358
    if( mQuats==null ) initializeQuats();
359
    return mQuats;
360
    }
361

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

    
364
  public int getSolvedFunctionIndex()
365
    {
366
    return 0;
367
    }
368

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

    
371
  public float[][] getCuts(int[] numLayers)
372
    {
373
    if( mCuts==null )
374
      {
375
      float[] cut = new float[] {0.0f};
376
      mCuts = new float[][] { cut,cut,cut,cut };
377
      }
378

    
379
    return mCuts;
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

    
384
  public boolean[][] getLayerRotatable(int[] numLayers)
385
    {
386
    int numAxis = ROT_AXIS.length;
387
    boolean[][] layerRotatable = new boolean[numAxis][];
388

    
389
    for(int i=0; i<numAxis; i++)
390
      {
391
      layerRotatable[i] = new boolean[numLayers[i]];
392
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
393
      }
394

    
395
    return layerRotatable;
396
    }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

    
400
  public int getMovementType()
401
    {
402
    return MOVEMENT_DODECAHEDRON;
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

    
407
  public int getMovementSplit()
408
    {
409
    return TYPE_NOT_SPLIT;
410
    }
411

    
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413

    
414
  public int[][][] getEnabled()
415
    {
416
    return new int[][][]
417
      {
418
        {{2,3}},{{1,3}},{{1,3}},{{2,3}},{{0,3}},{{0,2}},{{0,2}},{{0,3}},{{1,2}},{{0,1}},{{0,1}},{{1,2}}
419
      };
420
    }
421

    
422
///////////////////////////////////////////////////////////////////////////////////////////////////
423

    
424
  public float[] getDist3D(int[] numLayers)
425
    {
426
    return null;
427
    }
428

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

    
431
  public int getNumStickerTypes(int[] numLayers)
432
    {
433
    return 3;
434
    }
435

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

    
438
  public int getNumCubitFaces()
439
    {
440
    return 8;
441
    }
442

    
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444
// PUBLIC API
445

    
446
  public Static3D[] getRotationAxis()
447
    {
448
    return ROT_AXIS;
449
    }
450

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452

    
453
  public int[] getBasicAngle()
454
    {
455
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
456
    return mBasicAngle;
457
    }
458

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

    
461
  public ObjectType intGetObjectType(int[] numLayers)
462
    {
463
    return ObjectType.ULTI_2;
464
    }
465

    
466
///////////////////////////////////////////////////////////////////////////////////////////////////
467

    
468
  public String getObjectName()
469
    {
470
    return "Skewb Ultimate";
471
    }
472

    
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474

    
475
  public String getInventor()
476
    {
477
    return "Tony Fisher";
478
    }
479

    
480
///////////////////////////////////////////////////////////////////////////////////////////////////
481

    
482
  public int getYearOfInvention()
483
    {
484
    return 2000;
485
    }
486

    
487
///////////////////////////////////////////////////////////////////////////////////////////////////
488

    
489
  public int getComplexity()
490
    {
491
    return 6;
492
    }
493
}
(25-25/25)