Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyUltimate.java @ ef018c1b

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 android.content.res.Resources;
23

    
24
import org.distorted.helpers.ObjectShape;
25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.ScrambleState;
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
import org.distorted.main.R;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

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

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

    
54
  private ScrambleState[] mStates;
55
  private int[] mBasicAngle;
56
  private Static4D[] mQuats;
57
  private float[][] mCuts;
58
  private boolean[][] mLayerRotatable;
59
  private int[][] mFaceMap;
60
  private float[][] mCenters;
61
  private int[] mQuatIndex;
62
  private ObjectSticker[] mStickers;
63
  private Movement mMovement;
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  TwistyUltimate(int size, Static4D quat, DistortedTexture texture,
68
                 MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
69
    {
70
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.ULTI, res, scrWidth);
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  ScrambleState[] getScrambleStates()
76
    {
77
    if( mStates==null )
78
      {
79
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
80

    
81
      mStates = new ScrambleState[]
82
        {
83
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
84
        };
85
      }
86

    
87
    return mStates;
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  private void initializeQuats()
93
    {
94
    mQuats = new Static4D[]
95
         {
96
         new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
97
         new Static4D(-0.5f, 0.5f, 0.5f, 0.5f ),
98
         new Static4D( 0.5f,-0.5f,-0.5f, 0.5f ),
99
         new Static4D( 0.0f,    F,   -E, 0.5f ),
100
         new Static4D( 0.0f,   -F,    E, 0.5f ),
101
         new Static4D(    E, 0.0f,    F, 0.5f ),
102
         new Static4D(   -E, 0.0f,   -F, 0.5f ),
103
         new Static4D(    F,    E, 0.0f, 0.5f ),
104
         new Static4D(   -F,   -E, 0.0f, 0.5f ),
105
         new Static4D(    E,    F,-0.5f, 0.0f ),
106
         new Static4D( 0.5f,   -E,    F, 0.0f ),
107
         new Static4D(    F, 0.5f,    E, 0.0f )
108
         };
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  int[] getSolvedQuats(int cubit, int numLayers)
114
    {
115
    if( mQuats==null ) initializeQuats();
116
    int status = retCubitSolvedStatus(cubit,numLayers);
117
    return status<0 ? null : buildSolvedQuats(MovementUltimate.FACE_AXIS[status],mQuats);
118
    }
119

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

    
122
  ObjectShape getObjectShape(int cubit, int numLayers)
123
    {
124
    int variant = getCubitVariant(cubit,numLayers);
125

    
126
    if( variant==0 )
127
      {
128
      double[][] vertices = new double[][]
129
         {
130
           { 0.0  , 0.0  , 0.0   },
131
           { -E   , E+0.5, -0.5  },
132
           {-0.5  , -E   , -E-0.5},
133
           { E+0.5, 0.5  , -E    },
134
           { 0.0  , 1    , -2*E-1},
135
           { 0.0  , 1    , 0.0   },
136
           { -E   ,-E+0.5, -0.5  },
137
           {  E   ,-E+0.5, -0.5  }
138
         };
139
      int[][] vert_indices = new int[][]
140
         {
141
           {6,0,5,1},
142
           {0,7,3,5},
143
           {0,6,2,7},
144
           {4,3,5,1},
145
           {4,2,7,3},
146
           {4,1,6,2},
147
         };
148

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

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

    
216
      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} };
217
      int[] bandIndices   = new int[] { 0,0,1,1,2,2,2,2 };
218
      float[][] corners   = new float[][] { { 0.013f, 0.16f } };
219
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
220
      float[][] centers   = new float[][] { { -(SQ5+1)/4, 0.5f, -(SQ5+5)/4 } };
221
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
222
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
223
      }
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
  Static4D getQuat(int cubit, int numLayers)
229
    {
230
    if( mQuats     ==null ) initializeQuats();
231
    if( mQuatIndex ==null ) mQuatIndex = new int[] { 0,6,1,2,0,4,6,5,0,1,4,9,5,2 };
232
    return mQuats[mQuatIndex[cubit]];
233
    }
234

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

    
237
  int getNumCubitVariants(int numLayers)
238
    {
239
    return 3;
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
  int getCubitVariant(int cubit, int numLayers)
245
    {
246
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
247
    }
248

    
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

    
251
  float[][] getCubitPositions(int numLayers)
252
    {
253
    if( mCenters==null )
254
      {
255
      mCenters = new float[][]
256
         {
257
           {   0,  -1, 2*G },
258
           { 2*E,-2*E,-2*E },
259
           {-2*G,   0,  -1 },
260
           {   1, 2*G,   0 },
261

    
262
           {-2*E,  2*E, 2*E },
263
           { 2*G,    0,   1 },
264
           {  -1, -2*G,   0 },
265
           {   0,    1,-2*G },
266

    
267
           {        E, (E+0.5f),    (E+G) },
268
           {   -(E+G),       -E, (E+0.5f) },
269
           { (E+0.5f),   -(E+G),        E },
270
           {       -E,-(E+0.5f),   -(E+G) },
271
           {    (E+G),        E,-(E+0.5f) },
272
           {-(E+0.5f),    (E+G),       -E }
273
         };
274
      }
275

    
276
    return mCenters;
277
    }
278

    
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280

    
281
  int getFaceColor(int cubit, int cubitface, int size)
282
    {
283
    if( mFaceMap==null )
284
      {
285
      mFaceMap = new int[][]
286
         {
287
           { 25,24,35, 36,36,36,36,36 },
288
           { 27,28,29, 36,36,36,36,36 },
289
           { 31,26,30, 36,36,36,36,36 },
290
           { 32,34,33, 36,36,36,36,36 },
291

    
292
           { 31,32,25, 36,36,36,36,36 },
293
           { 33,28,24, 36,36,36,36,36 },
294
           { 26,35,27, 36,36,36,36,36 },
295
           { 30,29,34, 36,36,36,36,36 },
296

    
297
           {  8, 0,13,21, 36,36,36,36 },
298
           {  1, 2,19,23, 36,36,36,36 },
299
           {  4,11,12,15, 36,36,36,36 },
300
           {  3, 6,14,17, 36,36,36,36 },
301
           {  5, 9,22,16, 36,36,36,36 },
302
           {  7,10,20,18, 36,36,36,36 }
303
         };
304
      }
305

    
306
    return mFaceMap[cubit][cubitface];
307
    }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

    
311
  ObjectSticker retSticker(int face)
312
    {
313
    if( mStickers==null )
314
      {
315
      float[][] STICKERS = new float[][]
316
         {
317
           { -0.14400357f, -0.47894150f, 0.50000000f,-0.011045523f, 0.37700626f, 0.36749030f,-0.26699730f, 0.36749026f, -0.46600536f, -0.24499352f }, // Big cubit 1st
318
           {  0.36327127f,  0.26393202f,-0.36327127f, 0.500000000f,-0.36327127f,-0.26393202f, 0.36327127f,-0.50000000f },                             // Big cubit 2nd
319
           { -0.29389262f, -0.50000000f, 0.29389262f,-0.309017000f, 0.29389262f, 0.30901700f,-0.29389262f, 0.50000000f },                             // Small cubit 1st
320
         };
321

    
322
      final float R1 = 0.08f;
323
      final float R2 = 0.13f;
324
      final float R3 = 0.11f;
325
      final float[][] radii  = { {R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
326
      final float[] strokes = { 0.07f, 0.09f, 0.08f };
327

    
328
      mStickers = new ObjectSticker[STICKERS.length];
329

    
330
      for(int s=0; s<STICKERS.length; s++)
331
        {
332
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
333
        }
334
      }
335

    
336
    return mStickers[face/NUM_FACE_COLORS];
337
    }
338

    
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340

    
341
  Static4D[] getQuats()
342
    {
343
    if( mQuats==null ) initializeQuats();
344
    return mQuats;
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
  int getSolvedFunctionIndex()
350
    {
351
    return 0;
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

    
356
  float[][] getCuts(int numLayers)
357
    {
358
    if( mCuts==null )
359
      {
360
      float[] cut = new float[] {0.0f};
361
      mCuts = new float[][] { cut,cut,cut,cut };
362
      }
363

    
364
    return mCuts;
365
    }
366

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

    
369
  private void getLayerRotatable(int numLayers)
370
    {
371
    if( mLayerRotatable==null )
372
      {
373
      int numAxis = ROT_AXIS.length;
374
      boolean[] tmp = new boolean[numLayers];
375
      for(int i=0; i<numLayers; i++) tmp[i] = true;
376
      mLayerRotatable = new boolean[numAxis][];
377
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
378
      }
379
    }
380

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

    
383
  int getNumStickerTypes(int numLayers)
384
    {
385
    return 3;
386
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

    
390
  int getNumCubitFaces()
391
    {
392
    return 8;
393
    }
394

    
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396
// PUBLIC API
397

    
398
  public Static3D[] getRotationAxis()
399
    {
400
    return ROT_AXIS;
401
    }
402

    
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404

    
405
  public Movement getMovement()
406
    {
407
    if( mMovement==null )
408
      {
409
      int numLayers = getNumLayers();
410
      if( mCuts==null ) getCuts(numLayers);
411
      getLayerRotatable(numLayers);
412

    
413
      mMovement = new MovementUltimate(mCuts,mLayerRotatable,numLayers);
414
      }
415
    return mMovement;
416
    }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419

    
420
  public int[] getBasicAngle()
421
    {
422
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
423
    return mBasicAngle;
424
    }
425

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

    
428
  public int getObjectName(int numLayers)
429
    {
430
    return R.string.ulti2;
431
    }
432

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

    
435
  public int getInventor(int numLayers)
436
    {
437
    return R.string.ulti2_inventor;
438
    }
439

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

    
442
  public int getComplexity(int numLayers)
443
    {
444
    return 6;
445
    }
446
}
(48-48/48)