Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyUltimate.java @ 1b32d001

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
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
  private static final float G = (SQ5+3)/4;
58

    
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
  private ScrambleState[] mStates;
75
  private int[] mBasicAngle;
76
  private Static4D[] mQuats;
77
  private int[][] mFaceMap;
78
  private float[][] mCenters;
79
  private int[] mQuatIndex;
80
  private ObjectSticker[] mStickers;
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  TwistyUltimate(int size, Static4D quat, DistortedTexture texture,
85
                 MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
86
    {
87
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.ULTI, res, scrWidth);
88
    }
89

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

    
92
  ScrambleState[] getScrambleStates()
93
    {
94
    if( mStates==null )
95
      {
96
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
97

    
98
      mStates = new ScrambleState[]
99
        {
100
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
101
        };
102
      }
103

    
104
    return mStates;
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  private void initializeQuats()
110
    {
111
    mQuats = new Static4D[]
112
         {
113
         new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
114
         new Static4D(-0.5f, 0.5f, 0.5f, 0.5f ),
115
         new Static4D( 0.5f,-0.5f,-0.5f, 0.5f ),
116
         new Static4D( 0.0f,    F,   -E, 0.5f ),
117
         new Static4D( 0.0f,   -F,    E, 0.5f ),
118
         new Static4D(    E, 0.0f,    F, 0.5f ),
119
         new Static4D(   -E, 0.0f,   -F, 0.5f ),
120
         new Static4D(    F,    E, 0.0f, 0.5f ),
121
         new Static4D(   -F,   -E, 0.0f, 0.5f ),
122
         new Static4D(    E,    F,-0.5f, 0.0f ),
123
         new Static4D( 0.5f,   -E,    F, 0.0f ),
124
         new Static4D(    F, 0.5f,    E, 0.0f )
125
         };
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  int[] getSolvedQuats(int cubit, int numLayers)
131
    {
132
    if( mQuats==null ) initializeQuats();
133
    int status = retCubitSolvedStatus(cubit,numLayers);
134
    return status<0 ? null : buildSolvedQuats(MovementUltimate.FACE_AXIS[status],mQuats);
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  ObjectShape getObjectShape(int cubit, int numLayers)
140
    {
141
    int variant = getCubitVariant(cubit,numLayers);
142

    
143
    if( variant==0 )
144
      {
145
      double[][] vertices = new double[][]
146
         {
147
           { 0.0  , 0.0  , 0.0   },
148
           { -E   , E+0.5, -0.5  },
149
           {-0.5  , -E   , -E-0.5},
150
           { E+0.5, 0.5  , -E    },
151
           { 0.0  , 1    , -2*E-1},
152
           { 0.0  , 1    , 0.0   },
153
           { -E   ,-E+0.5, -0.5  },
154
           {  E   ,-E+0.5, -0.5  }
155
         };
156
      int[][] vert_indices = new int[][]
157
         {
158
           {6,0,5,1},
159
           {0,7,3,5},
160
           {0,6,2,7},
161
           {4,3,5,1},
162
           {4,2,7,3},
163
           {4,1,6,2},
164
         };
165

    
166
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
167
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
168
      float[][] corners   = new float[][] {  { 0.013f, 0.16f } };
169
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
170
      float[][] centers   = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
171
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
172
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
173
      }
174
    else if( variant==1 )
175
      {
176
      double[][] vertices = new double[][]
177
         {
178
            {         0.00,         0.00,         0.00},
179
            {       - 0.50,-SQ5/4 - 0.25,-SQ5/4 - 0.75},
180
            { SQ5/4 + 0.25,-SQ5/4 - 0.75,       + 0.50},
181
            { SQ5/4 + 0.75,       + 0.50,-SQ5/4 - 0.25},
182
            { SQ5/2 + 0.50,-SQ5/2 - 0.50,-SQ5/2 - 0.50},
183
            { SQ5/4 - 0.25,       + 0.50,-SQ5/4 - 0.25},
184
            {       - 0.50,-SQ5/4 - 0.25,-SQ5/4 + 0.25},
185
            { SQ5/4 + 0.25,-SQ5/4 + 0.25,       + 0.50}
186
         };
187
      int[][] vert_indices  = new int[][]
188
         {
189
           {6,0,5,1},
190
           {0,7,3,5},
191
           {0,6,2,7},
192
           {1,5,3,4},
193
           {3,7,2,4},
194
           {2,6,1,4},
195
         };
196

    
197
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
198
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
199
      float[][] corners   = new float[][] {  { 0.013f, 0.16f } };
200
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
201
      float[][] centers   = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
202
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
203
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
204
      }
205
    else
206
      {
207
      double[][] vertices = new double[][]
208
         {
209
           {  -E    ,-E+0.5,     0.5},
210
           {   E    , E-0.5,    -0.5},
211
           {-2*E    ,   0.0,     0.0},
212
           {     0.5, E    ,  -E-0.5},
213
           {  -E    ,-E-0.5,     0.5},
214
           {   E+0.5,  -0.5,  -E    },
215
           {-2*E    ,  -1.0,     0.0},
216
           {     1.0,   0.0,-2*E    },
217
           {-2*E+0.5, E    ,  -E-0.5},
218
           {     0.5,-E-1.0,  -E+0.5},
219
           {  -E    ,-E-0.5,-2*E-0.5}
220
         };
221
      int[][] vert_indices = new int[][]
222
         {
223
           {0,1,3,8,2},   // counterclockwise!
224
           {0,4,9,5,1},
225
           { 0,2,6,4},
226
           { 1,5,7,3},
227
           {10,9,4,6},
228
           {10,9,5,7},
229
           {10,8,3,7},
230
           {10,8,2,6}
231
         };
232

    
233
      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} };
234
      int[] bandIndices   = new int[] { 0,0,1,1,2,2,2,2 };
235
      float[][] corners   = new float[][] { { 0.013f, 0.16f } };
236
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
237
      float[][] centers   = new float[][] { { -(SQ5+1)/4, 0.5f, -(SQ5+5)/4 } };
238
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
239
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
240
      }
241
    }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

    
245
  Static4D getQuat(int cubit, int numLayers)
246
    {
247
    if( mQuats     ==null ) initializeQuats();
248
    if( mQuatIndex ==null ) mQuatIndex = new int[] { 0,6,1,2,0,4,6,5,0,1,4,9,5,2 };
249
    return mQuats[mQuatIndex[cubit]];
250
    }
251

    
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

    
254
  int getNumCubitVariants(int numLayers)
255
    {
256
    return 3;
257
    }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

    
261
  int getCubitVariant(int cubit, int numLayers)
262
    {
263
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
264
    }
265

    
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

    
268
  float[][] getCubitPositions(int numLayers)
269
    {
270
    if( mCenters==null )
271
      {
272
      mCenters = new float[][]
273
         {
274
           {   0,  -1, 2*G },
275
           { 2*E,-2*E,-2*E },
276
           {-2*G,   0,  -1 },
277
           {   1, 2*G,   0 },
278

    
279
           {-2*E,  2*E, 2*E },
280
           { 2*G,    0,   1 },
281
           {  -1, -2*G,   0 },
282
           {   0,    1,-2*G },
283

    
284
           {        E, (E+0.5f),    (E+G) },
285
           {   -(E+G),       -E, (E+0.5f) },
286
           { (E+0.5f),   -(E+G),        E },
287
           {       -E,-(E+0.5f),   -(E+G) },
288
           {    (E+G),        E,-(E+0.5f) },
289
           {-(E+0.5f),    (E+G),       -E }
290
         };
291
      }
292

    
293
    return mCenters;
294
    }
295

    
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

    
298
  int getFaceColor(int cubit, int cubitface, int size)
299
    {
300
    if( mFaceMap==null )
301
      {
302
      mFaceMap = new int[][]
303
         {
304
           { 25,24,35, 36,36,36,36,36 },
305
           { 27,28,29, 36,36,36,36,36 },
306
           { 31,26,30, 36,36,36,36,36 },
307
           { 32,34,33, 36,36,36,36,36 },
308

    
309
           { 31,32,25, 36,36,36,36,36 },
310
           { 33,28,24, 36,36,36,36,36 },
311
           { 26,35,27, 36,36,36,36,36 },
312
           { 30,29,34, 36,36,36,36,36 },
313

    
314
           {  8, 0,13,21, 36,36,36,36 },
315
           {  1, 2,19,23, 36,36,36,36 },
316
           {  4,11,12,15, 36,36,36,36 },
317
           {  3, 6,14,17, 36,36,36,36 },
318
           {  5, 9,22,16, 36,36,36,36 },
319
           {  7,10,20,18, 36,36,36,36 }
320
         };
321
      }
322

    
323
    return mFaceMap[cubit][cubitface];
324
    }
325

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327

    
328
  int getColor(int face)
329
    {
330
    return FACE_COLORS[face];
331
    }
332

    
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334

    
335
  ObjectSticker retSticker(int face)
336
    {
337
    if( mStickers==null )
338
      {
339
      float[][] STICKERS = new float[][]
340
         {
341
           { -0.14400357f, -0.47894150f, 0.50000000f,-0.011045523f, 0.37700626f, 0.36749030f,-0.26699730f, 0.36749026f, -0.46600536f, -0.24499352f }, // Big cubit 1st
342
           {  0.36327127f,  0.26393202f,-0.36327127f, 0.500000000f,-0.36327127f,-0.26393202f, 0.36327127f,-0.50000000f },                             // Big cubit 2nd
343
           { -0.29389262f, -0.50000000f, 0.29389262f,-0.309017000f, 0.29389262f, 0.30901700f,-0.29389262f, 0.50000000f },                             // Small cubit 1st
344
         };
345

    
346
      final float R1 = 0.08f;
347
      final float R2 = 0.13f;
348
      final float R3 = 0.11f;
349
      final float[][] radii  = { {R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
350
      final float[] strokes = { 0.07f, 0.09f, 0.08f };
351

    
352
      mStickers = new ObjectSticker[STICKERS.length];
353

    
354
      for(int s=0; s<STICKERS.length; s++)
355
        {
356
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
357
        }
358
      }
359

    
360
    return mStickers[face/NUM_FACE_COLORS];
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

    
365
  float returnMultiplier()
366
    {
367
    return 1.0f;
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  Static4D[] getQuats()
373
    {
374
    if( mQuats==null ) initializeQuats();
375
    return mQuats;
376
    }
377

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

    
380
  int getSolvedFunctionIndex()
381
    {
382
    return 0;
383
    }
384

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386

    
387
  boolean shouldResetTextureMaps()
388
    {
389
    return false;
390
    }
391

    
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393

    
394
  int getNumFaceColors()
395
    {
396
    return FACE_COLORS.length;
397
    }
398

    
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400

    
401
  float[][] getCuts(int numLayers)
402
    {
403
    float[] cut = new float[] {0.0f};
404
    return new float[][] { cut,cut,cut,cut };
405
    }
406

    
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408

    
409
  int getNumStickerTypes(int numLayers)
410
    {
411
    return 3;
412
    }
413

    
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415

    
416
  int getNumCubitFaces()
417
    {
418
    return 8;
419
    }
420

    
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422

    
423
  float getScreenRatio()
424
    {
425
    return 0.33f;
426
    }
427

    
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429
// PUBLIC API
430

    
431
  public Static3D[] getRotationAxis()
432
    {
433
    return ROT_AXIS;
434
    }
435

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

    
438
  public int[] getBasicAngle()
439
    {
440
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
441
    return mBasicAngle;
442
    }
443

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445

    
446
  public int getObjectName(int numLayers)
447
    {
448
    return R.string.ulti2;
449
    }
450

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452

    
453
  public int getInventor(int numLayers)
454
    {
455
    return R.string.ulti2_inventor;
456
    }
457

    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

    
460
  public int getComplexity(int numLayers)
461
    {
462
    return 6;
463
    }
464
}
(43-43/43)