Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyUltimate.java @ 55fa6993

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.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
import org.distorted.objectlib.main.ObjectControl;
36
import org.distorted.objectlib.main.ObjectType;
37
import org.distorted.objectlib.helpers.ObjectShape;
38
import org.distorted.objectlib.helpers.ObjectSticker;
39
import org.distorted.objectlib.helpers.ScrambleState;
40
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
  public TwistyUltimate(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
74
                        MeshSquare mesh, DistortedEffects effects, Resources res, int surfaceW, int surfaceH)
75
    {
76
    super(numL, numL[0], quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
  public ScrambleState[] getScrambleStates()
82
    {
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
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
  protected int getResource(int[] numLayers)
99
    {
100
    return R.raw.ulti_2;
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
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
  public int[] getSolvedQuats(int cubit, int[] numLayers)
127
    {
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
  public ObjectShape getObjectShape(int variant)
136
    {
137
    if( variant==0 )
138
      {
139
      double[][] vertices = new double[][]
140
         {
141
           { 0.0  , 0.0  , 0.0   },
142
           { -E   , E+0.5, -0.5  },
143
           {-0.5  , -E   , -E-0.5},
144
           { E+0.5, 0.5  , -E    },
145
           { 0.0  , 1    , -2*E-1},
146
           { 0.0  , 1    , 0.0   },
147
           { -E   ,-E+0.5, -0.5  },
148
           {  E   ,-E+0.5, -0.5  }
149
         };
150
      int[][] vert_indices = new int[][]
151
         {
152
           {6,0,5,1},
153
           {0,7,3,5},
154
           {0,6,2,7},
155
           {4,3,5,1},
156
           {4,2,7,3},
157
           {4,1,6,2},
158
         };
159

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

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

    
227
      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} };
228
      int[] bandIndices   = new int[] { 0,0,1,1,2,2,2,2 };
229
      float[][] corners   = new float[][] { { 0.013f, 0.16f } };
230
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
231
      float[][] centers   = new float[][] { { -(SQ5+1)/4, 0.5f, -(SQ5+5)/4 } };
232
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
233
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
234
      }
235
    }
236

    
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

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

    
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

    
248
  public int getNumCubitVariants(int[] numLayers)
249
    {
250
    return 3;
251
    }
252

    
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

    
255
  public int getCubitVariant(int cubit, int[] numLayers)
256
    {
257
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
258
    }
259

    
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

    
262
  public float[][] getCubitPositions(int[] numLayers)
263
    {
264
    if( mCenters==null )
265
      {
266
      mCenters = new float[][]
267
         {
268
           {   0,  -1, 2*G },
269
           { 2*E,-2*E,-2*E },
270
           {-2*G,   0,  -1 },
271
           {   1, 2*G,   0 },
272

    
273
           {-2*E,  2*E, 2*E },
274
           { 2*G,    0,   1 },
275
           {  -1, -2*G,   0 },
276
           {   0,    1,-2*G },
277

    
278
           {        E, (E+0.5f),    (E+G) },
279
           {   -(E+G),       -E, (E+0.5f) },
280
           { (E+0.5f),   -(E+G),        E },
281
           {       -E,-(E+0.5f),   -(E+G) },
282
           {    (E+G),        E,-(E+0.5f) },
283
           {-(E+0.5f),    (E+G),       -E }
284
         };
285
      }
286

    
287
    return mCenters;
288
    }
289

    
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

    
292
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
293
    {
294
    if( variant<2 ) return face<3 ? 2 : -1;
295
    else            return face<2 ? 0 : face<4 ? 1 : -1;
296
    }
297

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

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

    
311
           {  7, 8, 1, -1,-1,-1,-1,-1 },
312
           {  9, 4, 0, -1,-1,-1,-1,-1 },
313
           {  2,11, 3, -1,-1,-1,-1,-1 },
314
           {  6, 5,10, -1,-1,-1,-1,-1 },
315

    
316
           {  8, 0, 1, 9, -1,-1,-1,-1 },
317
           {  1, 2, 7,11, -1,-1,-1,-1 },
318
           {  4,11, 0, 3, -1,-1,-1,-1 },
319
           {  3, 6, 2, 5, -1,-1,-1,-1 },
320
           {  5, 9,10, 4, -1,-1,-1,-1 },
321
           {  7,10, 8, 6, -1,-1,-1,-1 }
322
         };
323
      }
324

    
325
    return mFaceMap[cubit][face];
326
    }
327

    
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329

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

    
341
      final float R1 = 0.08f;
342
      final float R2 = 0.13f;
343
      final float R3 = 0.11f;
344
      final float[][] radii  = { {R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
345
      float[] strokes = { 0.07f, 0.09f, 0.08f };
346

    
347
      if( ObjectControl.isInIconMode() )
348
        {
349
        float mult = 1.5f;
350
        strokes[0]*=mult;
351
        strokes[1]*=mult;
352
        strokes[2]*=mult;
353
        }
354

    
355
      mStickers = new ObjectSticker[STICKERS.length];
356

    
357
      for(int s=0; s<STICKERS.length; s++)
358
        {
359
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
360
        }
361
      }
362

    
363
    return mStickers[sticker];
364
    }
365

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

    
368
  public Static4D[] getQuats()
369
    {
370
    if( mQuats==null ) initializeQuats();
371
    return mQuats;
372
    }
373

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

    
376
  public int getSolvedFunctionIndex()
377
    {
378
    return 0;
379
    }
380

    
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382

    
383
  public float[][] getCuts(int[] numLayers)
384
    {
385
    if( mCuts==null )
386
      {
387
      float[] cut = new float[] {0.0f};
388
      mCuts = new float[][] { cut,cut,cut,cut };
389
      }
390

    
391
    return mCuts;
392
    }
393

    
394
///////////////////////////////////////////////////////////////////////////////////////////////////
395

    
396
  public boolean[][] getLayerRotatable(int[] numLayers)
397
    {
398
    int numAxis = ROT_AXIS.length;
399
    boolean[][] layerRotatable = new boolean[numAxis][];
400

    
401
    for(int i=0; i<numAxis; i++)
402
      {
403
      layerRotatable[i] = new boolean[numLayers[i]];
404
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
405
      }
406

    
407
    return layerRotatable;
408
    }
409

    
410
///////////////////////////////////////////////////////////////////////////////////////////////////
411

    
412
  public int getMovementType()
413
    {
414
    return MOVEMENT_DODECAHEDRON;
415
    }
416

    
417
///////////////////////////////////////////////////////////////////////////////////////////////////
418

    
419
  public int getMovementSplit()
420
    {
421
    return TYPE_NOT_SPLIT;
422
    }
423

    
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425

    
426
  public int[][][] getEnabled()
427
    {
428
    return new int[][][]
429
      {
430
        {{2,3}},{{1,3}},{{1,3}},{{2,3}},{{0,3}},{{0,2}},{{0,2}},{{0,3}},{{1,2}},{{0,1}},{{0,1}},{{1,2}}
431
      };
432
    }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
  public float[] getDist3D(int[] numLayers)
437
    {
438
    return null;
439
    }
440

    
441
///////////////////////////////////////////////////////////////////////////////////////////////////
442

    
443
  public int getNumStickerTypes(int[] numLayers)
444
    {
445
    return 3;
446
    }
447

    
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449

    
450
  public int getNumCubitFaces()
451
    {
452
    return 8;
453
    }
454

    
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456
// PUBLIC API
457

    
458
  public Static3D[] getRotationAxis()
459
    {
460
    return ROT_AXIS;
461
    }
462

    
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464

    
465
  public int[] getBasicAngle()
466
    {
467
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
468
    return mBasicAngle;
469
    }
470

    
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472

    
473
  public ObjectType intGetObjectType(int[] numLayers)
474
    {
475
    return ObjectType.ULTI_2;
476
    }
477

    
478
///////////////////////////////////////////////////////////////////////////////////////////////////
479

    
480
  public int getObjectName(int[] numLayers)
481
    {
482
    return R.string.ulti2;
483
    }
484

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486

    
487
  public int getInventor(int[] numLayers)
488
    {
489
    return R.string.ulti2_inventor;
490
    }
491

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493

    
494
  public int getYearOfInvention(int[] numLayers)
495
    {
496
    return 2000;
497
    }
498

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

    
501
  public int getComplexity(int[] numLayers)
502
    {
503
    return 6;
504
    }
505
}
(25-25/25)