Project

General

Profile

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

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

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.objectlib.objects;
21
22 59c20632 Leszek Koltunski
import static org.distorted.objectlib.main.Movement.MOVEMENT_DODECAHEDRON;
23 29b82486 Leszek Koltunski
import static org.distorted.objectlib.main.Movement.TYPE_NOT_SPLIT;
24
25
import android.content.res.Resources;
26
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32
33
import org.distorted.objectlib.R;
34
import org.distorted.objectlib.main.Movement12;
35 8592461c Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
36 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
37 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
38
import org.distorted.objectlib.helpers.ObjectSticker;
39
import org.distorted.objectlib.helpers.ScrambleState;
40 29b82486 Leszek Koltunski
import org.distorted.objectlib.main.Twisty12;
41
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
44
public class TwistyUltimate extends Twisty12
45
{
46
  private static final float A = (float)Math.sqrt(21*SQ5+47);
47
  private static final float B = SQ6*(5*SQ5+11)/(6*A);
48
  private static final float C = SQ6*(  SQ5+ 2)/(3*A);
49
  private static final float D = SQ3/3;
50
  private static final float E = (SQ5+1)/4;
51
  private static final float F = (SQ5-1)/4;
52
  private static final float G = (SQ5+3)/4;
53
54
  static final Static3D[] ROT_AXIS = new Static3D[]
55
         {
56
           new Static3D( B,0,C ),
57
           new Static3D( C,B,0 ),
58
           new Static3D(-D,D,D ),
59
           new Static3D( 0,C,-B)
60
         };
61
62
  private ScrambleState[] mStates;
63
  private int[] mBasicAngle;
64
  private Static4D[] mQuats;
65
  private float[][] mCuts;
66
  private int[][] mFaceMap;
67
  private float[][] mCenters;
68
  private int[] mQuatIndex;
69
  private ObjectSticker[] mStickers;
70
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73 a57e6870 Leszek Koltunski
  public TwistyUltimate(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
74 e7daa161 Leszek Koltunski
                        MeshSquare mesh, DistortedEffects effects, Resources res, int surfaceW, int surfaceH)
75 29b82486 Leszek Koltunski
    {
76 e7daa161 Leszek Koltunski
    super(numL, numL[0], quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
77 29b82486 Leszek Koltunski
    }
78
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80
81 f9a81f52 Leszek Koltunski
  public ScrambleState[] getScrambleStates()
82 29b82486 Leszek Koltunski
    {
83
    if( mStates==null )
84
      {
85
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
86
87
      mStates = new ScrambleState[]
88
        {
89
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
90
        };
91
      }
92
93
    return mStates;
94
    }
95
96 4e1dc313 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
97
98 a57e6870 Leszek Koltunski
  protected int getResource(int[] numLayers)
99 4e1dc313 Leszek Koltunski
    {
100
    return R.raw.ulti;
101
    }
102
103 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
104
105
  private void initializeQuats()
106
    {
107
    mQuats = new Static4D[]
108
         {
109
         new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
110
         new Static4D(-0.5f, 0.5f, 0.5f, 0.5f ),
111
         new Static4D( 0.5f,-0.5f,-0.5f, 0.5f ),
112
         new Static4D( 0.0f,    F,   -E, 0.5f ),
113
         new Static4D( 0.0f,   -F,    E, 0.5f ),
114
         new Static4D(    E, 0.0f,    F, 0.5f ),
115
         new Static4D(   -E, 0.0f,   -F, 0.5f ),
116
         new Static4D(    F,    E, 0.0f, 0.5f ),
117
         new Static4D(   -F,   -E, 0.0f, 0.5f ),
118
         new Static4D(    E,    F,-0.5f, 0.0f ),
119
         new Static4D( 0.5f,   -E,    F, 0.0f ),
120
         new Static4D(    F, 0.5f,    E, 0.0f )
121
         };
122
    }
123
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125
126 a57e6870 Leszek Koltunski
  protected int[] getSolvedQuats(int cubit, int[] numLayers)
127 29b82486 Leszek Koltunski
    {
128
    if( mQuats==null ) initializeQuats();
129
    int status = retCubitSolvedStatus(cubit,numLayers);
130
    return status<0 ? null : buildSolvedQuats(Movement12.FACE_AXIS[status],mQuats);
131
    }
132
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134
135 a57e6870 Leszek Koltunski
  protected ObjectShape getObjectShape(int cubit, int[] numLayers)
136 29b82486 Leszek Koltunski
    {
137
    int variant = getCubitVariant(cubit,numLayers);
138
139
    if( variant==0 )
140
      {
141
      double[][] vertices = new double[][]
142
         {
143
           { 0.0  , 0.0  , 0.0   },
144
           { -E   , E+0.5, -0.5  },
145
           {-0.5  , -E   , -E-0.5},
146
           { E+0.5, 0.5  , -E    },
147
           { 0.0  , 1    , -2*E-1},
148
           { 0.0  , 1    , 0.0   },
149
           { -E   ,-E+0.5, -0.5  },
150
           {  E   ,-E+0.5, -0.5  }
151
         };
152
      int[][] vert_indices = new int[][]
153
         {
154
           {6,0,5,1},
155
           {0,7,3,5},
156
           {0,6,2,7},
157
           {4,3,5,1},
158
           {4,2,7,3},
159
           {4,1,6,2},
160
         };
161
162
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
163
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
164
      float[][] corners   = new float[][] {  { 0.013f, 0.16f } };
165
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
166
      float[][] centers   = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
167
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
168
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
169
      }
170
    else if( variant==1 )
171
      {
172
      double[][] vertices = new double[][]
173
         {
174
            {         0.00,         0.00,         0.00},
175
            {       - 0.50,-SQ5/4 - 0.25,-SQ5/4 - 0.75},
176
            { SQ5/4 + 0.25,-SQ5/4 - 0.75,       + 0.50},
177
            { SQ5/4 + 0.75,       + 0.50,-SQ5/4 - 0.25},
178
            { SQ5/2 + 0.50,-SQ5/2 - 0.50,-SQ5/2 - 0.50},
179
            { SQ5/4 - 0.25,       + 0.50,-SQ5/4 - 0.25},
180
            {       - 0.50,-SQ5/4 - 0.25,-SQ5/4 + 0.25},
181
            { SQ5/4 + 0.25,-SQ5/4 + 0.25,       + 0.50}
182
         };
183
      int[][] vert_indices  = new int[][]
184
         {
185
           {6,0,5,1},
186
           {0,7,3,5},
187
           {0,6,2,7},
188
           {1,5,3,4},
189
           {3,7,2,4},
190
           {2,6,1,4},
191
         };
192
193
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
194
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
195
      float[][] corners   = new float[][] {  { 0.013f, 0.16f } };
196
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
197
      float[][] centers   = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
198
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
199
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
200
      }
201
    else
202
      {
203
      double[][] vertices = new double[][]
204
         {
205
           {  -E    ,-E+0.5,     0.5},
206
           {   E    , E-0.5,    -0.5},
207
           {-2*E    ,   0.0,     0.0},
208
           {     0.5, E    ,  -E-0.5},
209
           {  -E    ,-E-0.5,     0.5},
210
           {   E+0.5,  -0.5,  -E    },
211
           {-2*E    ,  -1.0,     0.0},
212
           {     1.0,   0.0,-2*E    },
213
           {-2*E+0.5, E    ,  -E-0.5},
214
           {     0.5,-E-1.0,  -E+0.5},
215
           {  -E    ,-E-0.5,-2*E-0.5}
216
         };
217
      int[][] vert_indices = new int[][]
218
         {
219
           {0,1,3,8,2},   // counterclockwise!
220
           {0,4,9,5,1},
221
           { 0,2,6,4},
222
           { 1,5,7,3},
223
           {10,9,4,6},
224
           {10,9,5,7},
225
           {10,8,3,7},
226
           {10,8,2,6}
227
         };
228
229
      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} };
230
      int[] bandIndices   = new int[] { 0,0,1,1,2,2,2,2 };
231
      float[][] corners   = new float[][] { { 0.013f, 0.16f } };
232
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
233
      float[][] centers   = new float[][] { { -(SQ5+1)/4, 0.5f, -(SQ5+5)/4 } };
234
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
235
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
236
      }
237
    }
238
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240
241 a57e6870 Leszek Koltunski
  protected Static4D getQuat(int cubit, int[] numLayers)
242 29b82486 Leszek Koltunski
    {
243
    if( mQuats     ==null ) initializeQuats();
244
    if( mQuatIndex ==null ) mQuatIndex = new int[] { 0,6,1,2,0,4,6,5,0,1,4,9,5,2 };
245
    return mQuats[mQuatIndex[cubit]];
246
    }
247
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249
250 a57e6870 Leszek Koltunski
  protected int getNumCubitVariants(int[] numLayers)
251 29b82486 Leszek Koltunski
    {
252
    return 3;
253
    }
254
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256
257 a57e6870 Leszek Koltunski
  protected int getCubitVariant(int cubit, int[] numLayers)
258 29b82486 Leszek Koltunski
    {
259
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
260
    }
261
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263
264 a57e6870 Leszek Koltunski
  protected float[][] getCubitPositions(int[] numLayers)
265 29b82486 Leszek Koltunski
    {
266
    if( mCenters==null )
267
      {
268
      mCenters = new float[][]
269
         {
270
           {   0,  -1, 2*G },
271
           { 2*E,-2*E,-2*E },
272
           {-2*G,   0,  -1 },
273
           {   1, 2*G,   0 },
274
275
           {-2*E,  2*E, 2*E },
276
           { 2*G,    0,   1 },
277
           {  -1, -2*G,   0 },
278
           {   0,    1,-2*G },
279
280
           {        E, (E+0.5f),    (E+G) },
281
           {   -(E+G),       -E, (E+0.5f) },
282
           { (E+0.5f),   -(E+G),        E },
283
           {       -E,-(E+0.5f),   -(E+G) },
284
           {    (E+G),        E,-(E+0.5f) },
285
           {-(E+0.5f),    (E+G),       -E }
286
         };
287
      }
288
289
    return mCenters;
290
    }
291
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293
294 a57e6870 Leszek Koltunski
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
295 29b82486 Leszek Koltunski
    {
296
    if( mFaceMap==null )
297
      {
298
      mFaceMap = new int[][]
299
         {
300
           { 25,24,35, 36,36,36,36,36 },
301
           { 27,28,29, 36,36,36,36,36 },
302
           { 31,26,30, 36,36,36,36,36 },
303
           { 32,34,33, 36,36,36,36,36 },
304
305
           { 31,32,25, 36,36,36,36,36 },
306
           { 33,28,24, 36,36,36,36,36 },
307
           { 26,35,27, 36,36,36,36,36 },
308
           { 30,29,34, 36,36,36,36,36 },
309
310
           {  8, 0,13,21, 36,36,36,36 },
311
           {  1, 2,19,23, 36,36,36,36 },
312
           {  4,11,12,15, 36,36,36,36 },
313
           {  3, 6,14,17, 36,36,36,36 },
314
           {  5, 9,22,16, 36,36,36,36 },
315
           {  7,10,20,18, 36,36,36,36 }
316
         };
317
      }
318
319
    return mFaceMap[cubit][cubitface];
320
    }
321
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323
324
  protected ObjectSticker retSticker(int face)
325
    {
326
    if( mStickers==null )
327
      {
328
      float[][] STICKERS = new float[][]
329
         {
330
           { -0.14400357f, -0.47894150f, 0.50000000f,-0.011045523f, 0.37700626f, 0.36749030f,-0.26699730f, 0.36749026f, -0.46600536f, -0.24499352f }, // Big cubit 1st
331
           {  0.36327127f,  0.26393202f,-0.36327127f, 0.500000000f,-0.36327127f,-0.26393202f, 0.36327127f,-0.50000000f },                             // Big cubit 2nd
332
           { -0.29389262f, -0.50000000f, 0.29389262f,-0.309017000f, 0.29389262f, 0.30901700f,-0.29389262f, 0.50000000f },                             // Small cubit 1st
333
         };
334
335
      final float R1 = 0.08f;
336
      final float R2 = 0.13f;
337
      final float R3 = 0.11f;
338
      final float[][] radii  = { {R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
339 8592461c Leszek Koltunski
      float[] strokes = { 0.07f, 0.09f, 0.08f };
340
341
      if( ObjectControl.isInIconMode() )
342
        {
343
        float mult = 1.5f;
344
        strokes[0]*=mult;
345
        strokes[1]*=mult;
346
        strokes[2]*=mult;
347
        }
348 29b82486 Leszek Koltunski
349
      mStickers = new ObjectSticker[STICKERS.length];
350
351
      for(int s=0; s<STICKERS.length; s++)
352
        {
353
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
354
        }
355
      }
356
357
    return mStickers[face/NUM_FACE_COLORS];
358
    }
359
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361
362
  protected Static4D[] getQuats()
363
    {
364
    if( mQuats==null ) initializeQuats();
365
    return mQuats;
366
    }
367
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369
370 59c20632 Leszek Koltunski
  public int getSolvedFunctionIndex()
371 29b82486 Leszek Koltunski
    {
372
    return 0;
373
    }
374
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376
377 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
378 29b82486 Leszek Koltunski
    {
379
    if( mCuts==null )
380
      {
381
      float[] cut = new float[] {0.0f};
382
      mCuts = new float[][] { cut,cut,cut,cut };
383
      }
384
385
    return mCuts;
386
    }
387
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389
390 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
391 29b82486 Leszek Koltunski
    {
392 59c20632 Leszek Koltunski
    int numAxis = ROT_AXIS.length;
393
    boolean[][] layerRotatable = new boolean[numAxis][];
394 a57e6870 Leszek Koltunski
395 59c20632 Leszek Koltunski
    for(int i=0; i<numAxis; i++)
396
      {
397
      layerRotatable[i] = new boolean[numLayers[i]];
398
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
399 29b82486 Leszek Koltunski
      }
400 59c20632 Leszek Koltunski
401
    return layerRotatable;
402
    }
403
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405
406
  public int getMovementType()
407
    {
408
    return MOVEMENT_DODECAHEDRON;
409
    }
410
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412
413
  public int getMovementSplit()
414
    {
415
    return TYPE_NOT_SPLIT;
416
    }
417
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419
420
  public int[][][] getEnabled()
421
    {
422
    return new int[][][]
423
      {
424
        {{2,3}},{{1,3}},{{1,3}},{{2,3}},{{0,3}},{{0,2}},{{0,2}},{{0,3}},{{1,2}},{{0,1}},{{0,1}},{{1,2}}
425
      };
426
    }
427
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429
430
  public float[] getDist3D(int[] numLayers)
431
    {
432
    return null;
433 29b82486 Leszek Koltunski
    }
434
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436
437 a57e6870 Leszek Koltunski
  protected int getNumStickerTypes(int[] numLayers)
438 29b82486 Leszek Koltunski
    {
439
    return 3;
440
    }
441
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443
444
  protected int getNumCubitFaces()
445
    {
446
    return 8;
447
    }
448
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450
// PUBLIC API
451
452
  public Static3D[] getRotationAxis()
453
    {
454
    return ROT_AXIS;
455
    }
456
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458
459
  public int[] getBasicAngle()
460
    {
461
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
462
    return mBasicAngle;
463
    }
464
465 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
466
467 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
468 61aa85e4 Leszek Koltunski
    {
469 8005e762 Leszek Koltunski
    return ObjectType.ULTI_2;
470 61aa85e4 Leszek Koltunski
    }
471
472 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
473
474 a57e6870 Leszek Koltunski
  public int getObjectName(int[] numLayers)
475 29b82486 Leszek Koltunski
    {
476
    return R.string.ulti2;
477
    }
478
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480
481 a57e6870 Leszek Koltunski
  public int getInventor(int[] numLayers)
482 29b82486 Leszek Koltunski
    {
483
    return R.string.ulti2_inventor;
484
    }
485
486 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
487
488
  public int getYearOfInvention(int[] numLayers)
489
    {
490
    return 2000;
491
    }
492
493 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
494
495 a57e6870 Leszek Koltunski
  public int getComplexity(int[] numLayers)
496 29b82486 Leszek Koltunski
    {
497
    return 6;
498
    }
499
}