Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyUltimate.java @ 588ace55

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