Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyUltimate.java @ 7ee89540

1 bc649d9a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 967c1d17 Leszek Koltunski
import static org.distorted.objects.Movement.TYPE_NOT_SPLIT;
23
24 bc649d9a Leszek Koltunski
import android.content.res.Resources;
25
26 acf165d9 Leszek Koltunski
import org.distorted.helpers.ObjectShape;
27 9c06394a Leszek Koltunski
import org.distorted.helpers.ObjectSticker;
28 6cf89a3e Leszek Koltunski
import org.distorted.helpers.ScrambleState;
29 bc649d9a Leszek Koltunski
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 efa81f0c Leszek Koltunski
class TwistyUltimate extends Twisty12
39 bc649d9a Leszek Koltunski
{
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 74ffd68e Leszek Koltunski
  private static final float G = (SQ5+3)/4;
47 bc649d9a Leszek Koltunski
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 967c1d17 Leszek Koltunski
  private static final int[][][] ENABLED = new int[][][]
57
    {
58
      {{2,3}},{{1,3}},{{1,3}},{{2,3}},{{0,3}},{{0,2}},{{0,2}},{{0,3}},{{1,2}},{{0,1}},{{0,1}},{{1,2}}
59
    };
60
61 91792184 Leszek Koltunski
  private ScrambleState[] mStates;
62 963921af Leszek Koltunski
  private int[] mBasicAngle;
63
  private Static4D[] mQuats;
64 ef018c1b Leszek Koltunski
  private float[][] mCuts;
65
  private boolean[][] mLayerRotatable;
66 963921af Leszek Koltunski
  private int[][] mFaceMap;
67
  private float[][] mCenters;
68
  private int[] mQuatIndex;
69
  private ObjectSticker[] mStickers;
70 e9a87113 Leszek Koltunski
  private Movement mMovement;
71 0ad6b867 Leszek Koltunski
72 bc649d9a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
73
74
  TwistyUltimate(int size, Static4D quat, DistortedTexture texture,
75
                 MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
76
    {
77
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.ULTI, res, scrWidth);
78 91792184 Leszek Koltunski
    }
79 0ad6b867 Leszek Koltunski
80 91792184 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
81 0ad6b867 Leszek Koltunski
82 91792184 Leszek Koltunski
  ScrambleState[] getScrambleStates()
83
    {
84
    if( mStates==null )
85 0ad6b867 Leszek Koltunski
      {
86 91792184 Leszek Koltunski
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
87
88
      mStates = new ScrambleState[]
89
        {
90
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
91
        };
92
      }
93
94
    return mStates;
95 bc649d9a Leszek Koltunski
    }
96
97 963921af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99
  private void initializeQuats()
100
    {
101
    mQuats = new Static4D[]
102
         {
103
         new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
104
         new Static4D(-0.5f, 0.5f, 0.5f, 0.5f ),
105
         new Static4D( 0.5f,-0.5f,-0.5f, 0.5f ),
106
         new Static4D( 0.0f,    F,   -E, 0.5f ),
107
         new Static4D( 0.0f,   -F,    E, 0.5f ),
108
         new Static4D(    E, 0.0f,    F, 0.5f ),
109
         new Static4D(   -E, 0.0f,   -F, 0.5f ),
110
         new Static4D(    F,    E, 0.0f, 0.5f ),
111
         new Static4D(   -F,   -E, 0.0f, 0.5f ),
112
         new Static4D(    E,    F,-0.5f, 0.0f ),
113
         new Static4D( 0.5f,   -E,    F, 0.0f ),
114
         new Static4D(    F, 0.5f,    E, 0.0f )
115
         };
116
    }
117
118 a480ee80 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
119
120
  int[] getSolvedQuats(int cubit, int numLayers)
121
    {
122 963921af Leszek Koltunski
    if( mQuats==null ) initializeQuats();
123 a480ee80 Leszek Koltunski
    int status = retCubitSolvedStatus(cubit,numLayers);
124 967c1d17 Leszek Koltunski
    return status<0 ? null : buildSolvedQuats(Movement12.FACE_AXIS[status],mQuats);
125 a480ee80 Leszek Koltunski
    }
126
127 bc649d9a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
128
129 acf165d9 Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
130 bc649d9a Leszek Koltunski
    {
131 acf165d9 Leszek Koltunski
    int variant = getCubitVariant(cubit,numLayers);
132 bc649d9a Leszek Koltunski
133 acf165d9 Leszek Koltunski
    if( variant==0 )
134 bc649d9a Leszek Koltunski
      {
135 963921af Leszek Koltunski
      double[][] vertices = new double[][]
136
         {
137 1b32d001 Leszek Koltunski
           { 0.0  , 0.0  , 0.0   },
138
           { -E   , E+0.5, -0.5  },
139
           {-0.5  , -E   , -E-0.5},
140
           { E+0.5, 0.5  , -E    },
141
           { 0.0  , 1    , -2*E-1},
142
           { 0.0  , 1    , 0.0   },
143
           { -E   ,-E+0.5, -0.5  },
144
           {  E   ,-E+0.5, -0.5  }
145 963921af Leszek Koltunski
         };
146
      int[][] vert_indices = new int[][]
147
         {
148
           {6,0,5,1},
149
           {0,7,3,5},
150
           {0,6,2,7},
151
           {4,3,5,1},
152
           {4,2,7,3},
153
           {4,1,6,2},
154
         };
155
156 acf165d9 Leszek Koltunski
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
157
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
158 1b32d001 Leszek Koltunski
      float[][] corners   = new float[][] {  { 0.013f, 0.16f } };
159 acf165d9 Leszek Koltunski
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
160 1b32d001 Leszek Koltunski
      float[][] centers   = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
161 acf165d9 Leszek Koltunski
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
162 963921af Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
163 bc649d9a Leszek Koltunski
      }
164 acf165d9 Leszek Koltunski
    else if( variant==1 )
165 bc649d9a Leszek Koltunski
      {
166 963921af Leszek Koltunski
      double[][] vertices = new double[][]
167
         {
168 1b32d001 Leszek Koltunski
            {         0.00,         0.00,         0.00},
169
            {       - 0.50,-SQ5/4 - 0.25,-SQ5/4 - 0.75},
170
            { SQ5/4 + 0.25,-SQ5/4 - 0.75,       + 0.50},
171
            { SQ5/4 + 0.75,       + 0.50,-SQ5/4 - 0.25},
172
            { SQ5/2 + 0.50,-SQ5/2 - 0.50,-SQ5/2 - 0.50},
173
            { SQ5/4 - 0.25,       + 0.50,-SQ5/4 - 0.25},
174
            {       - 0.50,-SQ5/4 - 0.25,-SQ5/4 + 0.25},
175
            { SQ5/4 + 0.25,-SQ5/4 + 0.25,       + 0.50}
176 963921af Leszek Koltunski
         };
177
      int[][] vert_indices  = new int[][]
178
         {
179
           {6,0,5,1},
180
           {0,7,3,5},
181
           {0,6,2,7},
182
           {1,5,3,4},
183
           {3,7,2,4},
184
           {2,6,1,4},
185
         };
186
187 acf165d9 Leszek Koltunski
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
188
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
189 1b32d001 Leszek Koltunski
      float[][] corners   = new float[][] {  { 0.013f, 0.16f } };
190 acf165d9 Leszek Koltunski
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
191 1b32d001 Leszek Koltunski
      float[][] centers   = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
192 acf165d9 Leszek Koltunski
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
193 963921af Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
194 62efeeae Leszek Koltunski
      }
195
    else
196
      {
197 963921af Leszek Koltunski
      double[][] vertices = new double[][]
198
         {
199 1b32d001 Leszek Koltunski
           {  -E    ,-E+0.5,     0.5},
200
           {   E    , E-0.5,    -0.5},
201
           {-2*E    ,   0.0,     0.0},
202
           {     0.5, E    ,  -E-0.5},
203
           {  -E    ,-E-0.5,     0.5},
204
           {   E+0.5,  -0.5,  -E    },
205
           {-2*E    ,  -1.0,     0.0},
206
           {     1.0,   0.0,-2*E    },
207
           {-2*E+0.5, E    ,  -E-0.5},
208
           {     0.5,-E-1.0,  -E+0.5},
209
           {  -E    ,-E-0.5,-2*E-0.5}
210 963921af Leszek Koltunski
         };
211
      int[][] vert_indices = new int[][]
212
         {
213
           {0,1,3,8,2},   // counterclockwise!
214
           {0,4,9,5,1},
215
           { 0,2,6,4},
216
           { 1,5,7,3},
217
           {10,9,4,6},
218
           {10,9,5,7},
219
           {10,8,3,7},
220
           {10,8,2,6}
221
         };
222
223 acf165d9 Leszek Koltunski
      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} };
224
      int[] bandIndices   = new int[] { 0,0,1,1,2,2,2,2 };
225 1b32d001 Leszek Koltunski
      float[][] corners   = new float[][] { { 0.013f, 0.16f } };
226 acf165d9 Leszek Koltunski
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
227 1b32d001 Leszek Koltunski
      float[][] centers   = new float[][] { { -(SQ5+1)/4, 0.5f, -(SQ5+5)/4 } };
228 acf165d9 Leszek Koltunski
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
229 963921af Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
230 bc649d9a Leszek Koltunski
      }
231 acf165d9 Leszek Koltunski
    }
232 bc649d9a Leszek Koltunski
233 acf165d9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
234 bc649d9a Leszek Koltunski
235 3e605536 Leszek Koltunski
  Static4D getQuat(int cubit, int numLayers)
236 acf165d9 Leszek Koltunski
    {
237 963921af Leszek Koltunski
    if( mQuats     ==null ) initializeQuats();
238
    if( mQuatIndex ==null ) mQuatIndex = new int[] { 0,6,1,2,0,4,6,5,0,1,4,9,5,2 };
239
    return mQuats[mQuatIndex[cubit]];
240 bc649d9a Leszek Koltunski
    }
241
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243
244 3e605536 Leszek Koltunski
  int getNumCubitVariants(int numLayers)
245 bc649d9a Leszek Koltunski
    {
246 acf165d9 Leszek Koltunski
    return 3;
247
    }
248
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250
251
  int getCubitVariant(int cubit, int numLayers)
252
    {
253
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
254 bc649d9a Leszek Koltunski
    }
255
256 acf165d9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
257
258
  float[][] getCubitPositions(int numLayers)
259
    {
260 963921af Leszek Koltunski
    if( mCenters==null )
261
      {
262
      mCenters = new float[][]
263
         {
264 1b32d001 Leszek Koltunski
           {   0,  -1, 2*G },
265
           { 2*E,-2*E,-2*E },
266
           {-2*G,   0,  -1 },
267
           {   1, 2*G,   0 },
268
269
           {-2*E,  2*E, 2*E },
270
           { 2*G,    0,   1 },
271
           {  -1, -2*G,   0 },
272
           {   0,    1,-2*G },
273
274
           {        E, (E+0.5f),    (E+G) },
275
           {   -(E+G),       -E, (E+0.5f) },
276
           { (E+0.5f),   -(E+G),        E },
277
           {       -E,-(E+0.5f),   -(E+G) },
278
           {    (E+G),        E,-(E+0.5f) },
279
           {-(E+0.5f),    (E+G),       -E }
280 963921af Leszek Koltunski
         };
281
      }
282
283
    return mCenters;
284 bc649d9a Leszek Koltunski
    }
285
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287
288 9c06394a Leszek Koltunski
  int getFaceColor(int cubit, int cubitface, int size)
289 bc649d9a Leszek Koltunski
    {
290 963921af Leszek Koltunski
    if( mFaceMap==null )
291
      {
292
      mFaceMap = new int[][]
293
         {
294
           { 25,24,35, 36,36,36,36,36 },
295
           { 27,28,29, 36,36,36,36,36 },
296
           { 31,26,30, 36,36,36,36,36 },
297
           { 32,34,33, 36,36,36,36,36 },
298
299
           { 31,32,25, 36,36,36,36,36 },
300
           { 33,28,24, 36,36,36,36,36 },
301
           { 26,35,27, 36,36,36,36,36 },
302
           { 30,29,34, 36,36,36,36,36 },
303
304
           {  8, 0,13,21, 36,36,36,36 },
305
           {  1, 2,19,23, 36,36,36,36 },
306
           {  4,11,12,15, 36,36,36,36 },
307
           {  3, 6,14,17, 36,36,36,36 },
308
           {  5, 9,22,16, 36,36,36,36 },
309
           {  7,10,20,18, 36,36,36,36 }
310
         };
311
      }
312
313 9c06394a Leszek Koltunski
    return mFaceMap[cubit][cubitface];
314
    }
315 74ffd68e Leszek Koltunski
316 bc649d9a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
317
318 9c06394a Leszek Koltunski
  ObjectSticker retSticker(int face)
319 bc649d9a Leszek Koltunski
    {
320 963921af Leszek Koltunski
    if( mStickers==null )
321
      {
322
      float[][] STICKERS = new float[][]
323
         {
324
           { -0.14400357f, -0.47894150f, 0.50000000f,-0.011045523f, 0.37700626f, 0.36749030f,-0.26699730f, 0.36749026f, -0.46600536f, -0.24499352f }, // Big cubit 1st
325
           {  0.36327127f,  0.26393202f,-0.36327127f, 0.500000000f,-0.36327127f,-0.26393202f, 0.36327127f,-0.50000000f },                             // Big cubit 2nd
326
           { -0.29389262f, -0.50000000f, 0.29389262f,-0.309017000f, 0.29389262f, 0.30901700f,-0.29389262f, 0.50000000f },                             // Small cubit 1st
327
         };
328
329
      final float R1 = 0.08f;
330
      final float R2 = 0.13f;
331
      final float R3 = 0.11f;
332
      final float[][] radii  = { {R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
333
      final float[] strokes = { 0.07f, 0.09f, 0.08f };
334
335
      mStickers = new ObjectSticker[STICKERS.length];
336
337
      for(int s=0; s<STICKERS.length; s++)
338
        {
339
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
340
        }
341
      }
342
343 abf36986 Leszek Koltunski
    return mStickers[face/NUM_FACE_COLORS];
344 bc649d9a Leszek Koltunski
    }
345
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347
348
  Static4D[] getQuats()
349
    {
350 963921af Leszek Koltunski
    if( mQuats==null ) initializeQuats();
351
    return mQuats;
352 bc649d9a Leszek Koltunski
    }
353
354 169219a7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
355
356
  int getSolvedFunctionIndex()
357
    {
358
    return 0;
359
    }
360
361 bc649d9a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
362
363 e6734aa9 Leszek Koltunski
  float[][] getCuts(int numLayers)
364 bc649d9a Leszek Koltunski
    {
365 ef018c1b Leszek Koltunski
    if( mCuts==null )
366
      {
367
      float[] cut = new float[] {0.0f};
368
      mCuts = new float[][] { cut,cut,cut,cut };
369
      }
370
371
    return mCuts;
372
    }
373
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375
376
  private void getLayerRotatable(int numLayers)
377
    {
378
    if( mLayerRotatable==null )
379
      {
380
      int numAxis = ROT_AXIS.length;
381
      boolean[] tmp = new boolean[numLayers];
382
      for(int i=0; i<numLayers; i++) tmp[i] = true;
383
      mLayerRotatable = new boolean[numAxis][];
384
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
385
      }
386 bc649d9a Leszek Koltunski
    }
387
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389
390
  int getNumStickerTypes(int numLayers)
391
    {
392 963921af Leszek Koltunski
    return 3;
393 bc649d9a Leszek Koltunski
    }
394
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396
397
  int getNumCubitFaces()
398
    {
399
    return 8;
400
    }
401
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403 e1dc3366 Leszek Koltunski
// PUBLIC API
404 bc649d9a Leszek Koltunski
405 e1dc3366 Leszek Koltunski
  public Static3D[] getRotationAxis()
406
    {
407
    return ROT_AXIS;
408
    }
409
410 e9a87113 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
411
412
  public Movement getMovement()
413
    {
414 ef018c1b Leszek Koltunski
    if( mMovement==null )
415
      {
416
      int numLayers = getNumLayers();
417
      if( mCuts==null ) getCuts(numLayers);
418
      getLayerRotatable(numLayers);
419 7ee89540 Leszek Koltunski
      mMovement = new Movement12(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_NOT_SPLIT,ENABLED);
420 ef018c1b Leszek Koltunski
      }
421 e9a87113 Leszek Koltunski
    return mMovement;
422
    }
423
424 e1dc3366 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
425
426
  public int[] getBasicAngle()
427
    {
428 963921af Leszek Koltunski
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
429
    return mBasicAngle;
430 e1dc3366 Leszek Koltunski
    }
431
432 bc649d9a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
433
434
  public int getObjectName(int numLayers)
435
    {
436
    return R.string.ulti2;
437
    }
438
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440
441
  public int getInventor(int numLayers)
442
    {
443
    return R.string.ulti2_inventor;
444
    }
445
446
///////////////////////////////////////////////////////////////////////////////////////////////////
447
448
  public int getComplexity(int numLayers)
449
    {
450
    return 6;
451
    }
452
}