Project

General

Profile

Download (15.6 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyUltimate.java @ 967c1d17

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.objects;
21

    
22
import static org.distorted.objects.Movement.TYPE_NOT_SPLIT;
23

    
24
import android.content.res.Resources;
25

    
26
import org.distorted.helpers.ObjectShape;
27
import org.distorted.helpers.ObjectSticker;
28
import org.distorted.helpers.ScrambleState;
29
import org.distorted.library.main.DistortedEffects;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshSquare;
32
import org.distorted.library.type.Static3D;
33
import org.distorted.library.type.Static4D;
34
import org.distorted.main.R;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

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

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

    
56
  private static final int[] NUM_ENABLED = {2,2,2,2,2,2,2,2,2,2,2,2};
57

    
58
  private static final int[][][] ENABLED = new int[][][]
59
    {
60
      {{2,3}},{{1,3}},{{1,3}},{{2,3}},{{0,3}},{{0,2}},{{0,2}},{{0,3}},{{1,2}},{{0,1}},{{0,1}},{{1,2}}
61
    };
62

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

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

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

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  ScrambleState[] getScrambleStates()
85
    {
86
    if( mStates==null )
87
      {
88
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
89

    
90
      mStates = new ScrambleState[]
91
        {
92
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
93
        };
94
      }
95

    
96
    return mStates;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

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

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

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

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  ObjectShape getObjectShape(int cubit, int numLayers)
132
    {
133
    int variant = getCubitVariant(cubit,numLayers);
134

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

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

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

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

    
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

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

    
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245

    
246
  int getNumCubitVariants(int numLayers)
247
    {
248
    return 3;
249
    }
250

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

    
253
  int getCubitVariant(int cubit, int numLayers)
254
    {
255
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
256
    }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

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

    
271
           {-2*E,  2*E, 2*E },
272
           { 2*G,    0,   1 },
273
           {  -1, -2*G,   0 },
274
           {   0,    1,-2*G },
275

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

    
285
    return mCenters;
286
    }
287

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

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

    
301
           { 31,32,25, 36,36,36,36,36 },
302
           { 33,28,24, 36,36,36,36,36 },
303
           { 26,35,27, 36,36,36,36,36 },
304
           { 30,29,34, 36,36,36,36,36 },
305

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

    
315
    return mFaceMap[cubit][cubitface];
316
    }
317

    
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

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

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

    
337
      mStickers = new ObjectSticker[STICKERS.length];
338

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

    
345
    return mStickers[face/NUM_FACE_COLORS];
346
    }
347

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349

    
350
  Static4D[] getQuats()
351
    {
352
    if( mQuats==null ) initializeQuats();
353
    return mQuats;
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

    
358
  int getSolvedFunctionIndex()
359
    {
360
    return 0;
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

    
365
  float[][] getCuts(int numLayers)
366
    {
367
    if( mCuts==null )
368
      {
369
      float[] cut = new float[] {0.0f};
370
      mCuts = new float[][] { cut,cut,cut,cut };
371
      }
372

    
373
    return mCuts;
374
    }
375

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

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

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

    
392
  int getNumStickerTypes(int numLayers)
393
    {
394
    return 3;
395
    }
396

    
397
///////////////////////////////////////////////////////////////////////////////////////////////////
398

    
399
  int getNumCubitFaces()
400
    {
401
    return 8;
402
    }
403

    
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405
// PUBLIC API
406

    
407
  public Static3D[] getRotationAxis()
408
    {
409
    return ROT_AXIS;
410
    }
411

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

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

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

    
428
  public int[] getBasicAngle()
429
    {
430
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
431
    return mBasicAngle;
432
    }
433

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

    
436
  public int getObjectName(int numLayers)
437
    {
438
    return R.string.ulti2;
439
    }
440

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

    
443
  public int getInventor(int numLayers)
444
    {
445
    return R.string.ulti2_inventor;
446
    }
447

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

    
450
  public int getComplexity(int numLayers)
451
    {
452
    return 6;
453
    }
454
}
(38-38/38)