Project

General

Profile

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

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

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