Project

General

Profile

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

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

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