Project

General

Profile

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

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

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.TYPE_NOT_SPLIT;
23

    
24
import android.content.res.Resources;
25

    
26
import org.distorted.library.main.DistortedEffects;
27
import org.distorted.library.main.DistortedTexture;
28
import org.distorted.library.mesh.MeshSquare;
29
import org.distorted.library.type.Static3D;
30
import org.distorted.library.type.Static4D;
31

    
32
import org.distorted.objectlib.R;
33
import org.distorted.objectlib.main.Movement;
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 static final int[][][] ENABLED = new int[][][]
63
    {
64
      {{2,3}},{{1,3}},{{1,3}},{{2,3}},{{0,3}},{{0,2}},{{0,2}},{{0,3}},{{1,2}},{{0,1}},{{0,1}},{{1,2}}
65
    };
66

    
67
  private ScrambleState[] mStates;
68
  private int[] mBasicAngle;
69
  private Static4D[] mQuats;
70
  private float[][] mCuts;
71
  private boolean[][] mLayerRotatable;
72
  private int[][] mFaceMap;
73
  private float[][] mCenters;
74
  private int[] mQuatIndex;
75
  private ObjectSticker[] mStickers;
76
  private Movement mMovement;
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
  public TwistyUltimate(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
81
                        MeshSquare mesh, DistortedEffects effects, Resources res, int scrWidth)
82
    {
83
    super(numL, numL[0], quat, move, texture, mesh, effects, res, scrWidth);
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  protected ScrambleState[] getScrambleStates()
89
    {
90
    if( mStates==null )
91
      {
92
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
93

    
94
      mStates = new ScrambleState[]
95
        {
96
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
97
        };
98
      }
99

    
100
    return mStates;
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  protected int getResource(int[] numLayers)
106
    {
107
    return R.raw.ulti;
108
    }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

    
112
  private void initializeQuats()
113
    {
114
    mQuats = new Static4D[]
115
         {
116
         new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
117
         new Static4D(-0.5f, 0.5f, 0.5f, 0.5f ),
118
         new Static4D( 0.5f,-0.5f,-0.5f, 0.5f ),
119
         new Static4D( 0.0f,    F,   -E, 0.5f ),
120
         new Static4D( 0.0f,   -F,    E, 0.5f ),
121
         new Static4D(    E, 0.0f,    F, 0.5f ),
122
         new Static4D(   -E, 0.0f,   -F, 0.5f ),
123
         new Static4D(    F,    E, 0.0f, 0.5f ),
124
         new Static4D(   -F,   -E, 0.0f, 0.5f ),
125
         new Static4D(    E,    F,-0.5f, 0.0f ),
126
         new Static4D( 0.5f,   -E,    F, 0.0f ),
127
         new Static4D(    F, 0.5f,    E, 0.0f )
128
         };
129
    }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
  protected int[] getSolvedQuats(int cubit, int[] numLayers)
134
    {
135
    if( mQuats==null ) initializeQuats();
136
    int status = retCubitSolvedStatus(cubit,numLayers);
137
    return status<0 ? null : buildSolvedQuats(Movement12.FACE_AXIS[status],mQuats);
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
  protected ObjectShape getObjectShape(int cubit, int[] numLayers)
143
    {
144
    int variant = getCubitVariant(cubit,numLayers);
145

    
146
    if( variant==0 )
147
      {
148
      double[][] vertices = new double[][]
149
         {
150
           { 0.0  , 0.0  , 0.0   },
151
           { -E   , E+0.5, -0.5  },
152
           {-0.5  , -E   , -E-0.5},
153
           { E+0.5, 0.5  , -E    },
154
           { 0.0  , 1    , -2*E-1},
155
           { 0.0  , 1    , 0.0   },
156
           { -E   ,-E+0.5, -0.5  },
157
           {  E   ,-E+0.5, -0.5  }
158
         };
159
      int[][] vert_indices = new int[][]
160
         {
161
           {6,0,5,1},
162
           {0,7,3,5},
163
           {0,6,2,7},
164
           {4,3,5,1},
165
           {4,2,7,3},
166
           {4,1,6,2},
167
         };
168

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

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

    
236
      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} };
237
      int[] bandIndices   = new int[] { 0,0,1,1,2,2,2,2 };
238
      float[][] corners   = new float[][] { { 0.013f, 0.16f } };
239
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
240
      float[][] centers   = new float[][] { { -(SQ5+1)/4, 0.5f, -(SQ5+5)/4 } };
241
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
242
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
243
      }
244
    }
245

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

    
248
  protected Static4D getQuat(int cubit, int[] numLayers)
249
    {
250
    if( mQuats     ==null ) initializeQuats();
251
    if( mQuatIndex ==null ) mQuatIndex = new int[] { 0,6,1,2,0,4,6,5,0,1,4,9,5,2 };
252
    return mQuats[mQuatIndex[cubit]];
253
    }
254

    
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

    
257
  protected int getNumCubitVariants(int[] numLayers)
258
    {
259
    return 3;
260
    }
261

    
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

    
264
  protected int getCubitVariant(int cubit, int[] numLayers)
265
    {
266
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
267
    }
268

    
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270

    
271
  protected float[][] getCubitPositions(int[] numLayers)
272
    {
273
    if( mCenters==null )
274
      {
275
      mCenters = new float[][]
276
         {
277
           {   0,  -1, 2*G },
278
           { 2*E,-2*E,-2*E },
279
           {-2*G,   0,  -1 },
280
           {   1, 2*G,   0 },
281

    
282
           {-2*E,  2*E, 2*E },
283
           { 2*G,    0,   1 },
284
           {  -1, -2*G,   0 },
285
           {   0,    1,-2*G },
286

    
287
           {        E, (E+0.5f),    (E+G) },
288
           {   -(E+G),       -E, (E+0.5f) },
289
           { (E+0.5f),   -(E+G),        E },
290
           {       -E,-(E+0.5f),   -(E+G) },
291
           {    (E+G),        E,-(E+0.5f) },
292
           {-(E+0.5f),    (E+G),       -E }
293
         };
294
      }
295

    
296
    return mCenters;
297
    }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

    
301
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
302
    {
303
    if( mFaceMap==null )
304
      {
305
      mFaceMap = new int[][]
306
         {
307
           { 25,24,35, 36,36,36,36,36 },
308
           { 27,28,29, 36,36,36,36,36 },
309
           { 31,26,30, 36,36,36,36,36 },
310
           { 32,34,33, 36,36,36,36,36 },
311

    
312
           { 31,32,25, 36,36,36,36,36 },
313
           { 33,28,24, 36,36,36,36,36 },
314
           { 26,35,27, 36,36,36,36,36 },
315
           { 30,29,34, 36,36,36,36,36 },
316

    
317
           {  8, 0,13,21, 36,36,36,36 },
318
           {  1, 2,19,23, 36,36,36,36 },
319
           {  4,11,12,15, 36,36,36,36 },
320
           {  3, 6,14,17, 36,36,36,36 },
321
           {  5, 9,22,16, 36,36,36,36 },
322
           {  7,10,20,18, 36,36,36,36 }
323
         };
324
      }
325

    
326
    return mFaceMap[cubit][cubitface];
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

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

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

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

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

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

    
364
    return mStickers[face/NUM_FACE_COLORS];
365
    }
366

    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368

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

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376

    
377
  protected int getSolvedFunctionIndex()
378
    {
379
    return 0;
380
    }
381

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

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

    
392
    return mCuts;
393
    }
394

    
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396

    
397
  private void getLayerRotatable(int[] numLayers)
398
    {
399
    if( mLayerRotatable==null )
400
      {
401
      int numAxis = ROT_AXIS.length;
402
      mLayerRotatable = new boolean[numAxis][];
403

    
404
      for(int i=0; i<numAxis; i++)
405
        {
406
        mLayerRotatable[i] = new boolean[numLayers[i]];
407
        for(int j=0; j<numLayers[i]; j++) mLayerRotatable[i][j] = true;
408
        }
409
      }
410
    }
411

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

    
414
  protected int getNumStickerTypes(int[] numLayers)
415
    {
416
    return 3;
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

    
421
  protected int getNumCubitFaces()
422
    {
423
    return 8;
424
    }
425

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427
// PUBLIC API
428

    
429
  public Static3D[] getRotationAxis()
430
    {
431
    return ROT_AXIS;
432
    }
433

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

    
436
  public Movement getMovement()
437
    {
438
    if( mMovement==null )
439
      {
440
      int[] numLayers = getNumLayers();
441
      if( mCuts==null ) getCuts(numLayers);
442
      getLayerRotatable(numLayers);
443
      mMovement = new Movement12(ROT_AXIS,mCuts,mLayerRotatable,numLayers[0],TYPE_NOT_SPLIT,ENABLED);
444
      }
445
    return mMovement;
446
    }
447

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

    
450
  public int[] getBasicAngle()
451
    {
452
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
453
    return mBasicAngle;
454
    }
455

    
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457

    
458
  public ObjectType intGetObjectType(int[] numLayers)
459
    {
460
    return ObjectType.ULTI_2;
461
    }
462

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

    
465
  public int getObjectName(int[] numLayers)
466
    {
467
    return R.string.ulti2;
468
    }
469

    
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471

    
472
  public int getInventor(int[] numLayers)
473
    {
474
    return R.string.ulti2_inventor;
475
    }
476

    
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478

    
479
  public int getComplexity(int[] numLayers)
480
    {
481
    return 6;
482
    }
483
}
(25-25/25)