Project

General

Profile

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

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

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.ObjectList;
36
import org.distorted.objectlib.main.ObjectShape;
37
import org.distorted.objectlib.main.ObjectSticker;
38
import org.distorted.objectlib.main.ScrambleState;
39
import org.distorted.objectlib.main.Twisty12;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

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

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

    
61
  private static final int[][][] ENABLED = new int[][][]
62
    {
63
      {{2,3}},{{1,3}},{{1,3}},{{2,3}},{{0,3}},{{0,2}},{{0,2}},{{0,3}},{{1,2}},{{0,1}},{{0,1}},{{1,2}}
64
    };
65

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

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
  public TwistyUltimate(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
80
                        DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
81
    {
82
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.ULTI, res, scrWidth);
83
    }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

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

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

    
99
    return mStates;
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

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

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

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

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  protected ObjectShape getObjectShape(int cubit, int numLayers)
135
    {
136
    int variant = getCubitVariant(cubit,numLayers);
137

    
138
    if( variant==0 )
139
      {
140
      double[][] vertices = new double[][]
141
         {
142
           { 0.0  , 0.0  , 0.0   },
143
           { -E   , E+0.5, -0.5  },
144
           {-0.5  , -E   , -E-0.5},
145
           { E+0.5, 0.5  , -E    },
146
           { 0.0  , 1    , -2*E-1},
147
           { 0.0  , 1    , 0.0   },
148
           { -E   ,-E+0.5, -0.5  },
149
           {  E   ,-E+0.5, -0.5  }
150
         };
151
      int[][] vert_indices = new int[][]
152
         {
153
           {6,0,5,1},
154
           {0,7,3,5},
155
           {0,6,2,7},
156
           {4,3,5,1},
157
           {4,2,7,3},
158
           {4,1,6,2},
159
         };
160

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

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

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

    
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

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

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

    
249
  protected int getNumCubitVariants(int numLayers)
250
    {
251
    return 3;
252
    }
253

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

    
256
  protected int getCubitVariant(int cubit, int numLayers)
257
    {
258
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
259
    }
260

    
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262

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

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

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

    
288
    return mCenters;
289
    }
290

    
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292

    
293
  protected int getFaceColor(int cubit, int cubitface, int size)
294
    {
295
    if( mFaceMap==null )
296
      {
297
      mFaceMap = new int[][]
298
         {
299
           { 25,24,35, 36,36,36,36,36 },
300
           { 27,28,29, 36,36,36,36,36 },
301
           { 31,26,30, 36,36,36,36,36 },
302
           { 32,34,33, 36,36,36,36,36 },
303

    
304
           { 31,32,25, 36,36,36,36,36 },
305
           { 33,28,24, 36,36,36,36,36 },
306
           { 26,35,27, 36,36,36,36,36 },
307
           { 30,29,34, 36,36,36,36,36 },
308

    
309
           {  8, 0,13,21, 36,36,36,36 },
310
           {  1, 2,19,23, 36,36,36,36 },
311
           {  4,11,12,15, 36,36,36,36 },
312
           {  3, 6,14,17, 36,36,36,36 },
313
           {  5, 9,22,16, 36,36,36,36 },
314
           {  7,10,20,18, 36,36,36,36 }
315
         };
316
      }
317

    
318
    return mFaceMap[cubit][cubitface];
319
    }
320

    
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322

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

    
334
      final float R1 = 0.08f;
335
      final float R2 = 0.13f;
336
      final float R3 = 0.11f;
337
      final float[][] radii  = { {R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
338
      final float[] strokes = { 0.07f, 0.09f, 0.08f };
339

    
340
      mStickers = new ObjectSticker[STICKERS.length];
341

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

    
348
    return mStickers[face/NUM_FACE_COLORS];
349
    }
350

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

    
353
  protected Static4D[] getQuats()
354
    {
355
    if( mQuats==null ) initializeQuats();
356
    return mQuats;
357
    }
358

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360

    
361
  protected int getSolvedFunctionIndex()
362
    {
363
    return 0;
364
    }
365

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

    
368
  protected float[][] getCuts(int numLayers)
369
    {
370
    if( mCuts==null )
371
      {
372
      float[] cut = new float[] {0.0f};
373
      mCuts = new float[][] { cut,cut,cut,cut };
374
      }
375

    
376
    return mCuts;
377
    }
378

    
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

    
381
  private void getLayerRotatable(int numLayers)
382
    {
383
    if( mLayerRotatable==null )
384
      {
385
      int numAxis = ROT_AXIS.length;
386
      boolean[] tmp = new boolean[numLayers];
387
      for(int i=0; i<numLayers; i++) tmp[i] = true;
388
      mLayerRotatable = new boolean[numAxis][];
389
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
390
      }
391
    }
392

    
393
///////////////////////////////////////////////////////////////////////////////////////////////////
394

    
395
  protected int getNumStickerTypes(int numLayers)
396
    {
397
    return 3;
398
    }
399

    
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401

    
402
  protected int getNumCubitFaces()
403
    {
404
    return 8;
405
    }
406

    
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408
// PUBLIC API
409

    
410
  public Static3D[] getRotationAxis()
411
    {
412
    return ROT_AXIS;
413
    }
414

    
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416

    
417
  public Movement getMovement()
418
    {
419
    if( mMovement==null )
420
      {
421
      int numLayers = getNumLayers();
422
      if( mCuts==null ) getCuts(numLayers);
423
      getLayerRotatable(numLayers);
424
      mMovement = new Movement12(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_NOT_SPLIT,ENABLED);
425
      }
426
    return mMovement;
427
    }
428

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

    
431
  public int[] getBasicAngle()
432
    {
433
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
434
    return mBasicAngle;
435
    }
436

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

    
439
  public int getObjectName(int numLayers)
440
    {
441
    return R.string.ulti2;
442
    }
443

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

    
446
  public int getInventor(int numLayers)
447
    {
448
    return R.string.ulti2_inventor;
449
    }
450

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

    
453
  public int getComplexity(int numLayers)
454
    {
455
    return 6;
456
    }
457
}
(25-25/25)