Project

General

Profile

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

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

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.FactoryCubit;
25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.library.effect.MatrixEffectQuaternion;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshBase;
30
import org.distorted.library.mesh.MeshSquare;
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33
import org.distorted.main.R;
34

    
35
import java.util.Random;
36

    
37
import static org.distorted.objects.TwistyMinx.MINX_DBLUE;
38
import static org.distorted.objects.TwistyMinx.MINX_DGREEN;
39
import static org.distorted.objects.TwistyMinx.MINX_DRED;
40
import static org.distorted.objects.TwistyMinx.MINX_DYELLOW;
41
import static org.distorted.objects.TwistyMinx.MINX_GREY;
42
import static org.distorted.objects.TwistyMinx.MINX_LBLUE;
43
import static org.distorted.objects.TwistyMinx.MINX_LGREEN;
44
import static org.distorted.objects.TwistyMinx.MINX_ORANGE;
45
import static org.distorted.objects.TwistyMinx.MINX_PINK;
46
import static org.distorted.objects.TwistyMinx.MINX_SANDY;
47
import static org.distorted.objects.TwistyMinx.MINX_VIOLET;
48
import static org.distorted.objects.TwistyMinx.MINX_WHITE;
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
class TwistyUltimate extends TwistyObject
53
{
54
  private static final float A = (float)Math.sqrt(21*SQ5+47);
55
  private static final float B = SQ6*(5*SQ5+11)/(6*A);
56
  private static final float C = SQ6*(  SQ5+ 2)/(3*A);
57
  private static final float D = SQ3/3;
58
  private static final float E = (SQ5+1)/4;
59
  private static final float F = (SQ5-1)/4;
60
  private static final float G = (SQ5+3)/4;
61

    
62
  static final Static3D[] ROT_AXIS = new Static3D[]
63
         {
64
           new Static3D( B,0,C ),
65
           new Static3D( C,B,0 ),
66
           new Static3D(-D,D,D ),
67
           new Static3D( 0,C,-B)
68
         };
69

    
70
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
71

    
72
  private static final int[] FACE_COLORS = new int[]
73
         {
74
           MINX_LGREEN, MINX_PINK   , MINX_SANDY , MINX_LBLUE,
75
           MINX_ORANGE, MINX_VIOLET , MINX_DGREEN, MINX_DRED ,
76
           MINX_DBLUE , MINX_DYELLOW, MINX_WHITE , MINX_GREY
77
         };
78

    
79
  private static final Static4D[] QUATS = new Static4D[]
80
         {
81
           new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
82
           new Static4D(-0.5f, 0.5f, 0.5f, 0.5f ),
83
           new Static4D( 0.5f,-0.5f,-0.5f, 0.5f ),
84
           new Static4D( 0.0f,    F,   -E, 0.5f ),
85
           new Static4D( 0.0f,   -F,    E, 0.5f ),
86
           new Static4D(    E, 0.0f,    F, 0.5f ),
87
           new Static4D(   -E, 0.0f,   -F, 0.5f ),
88
           new Static4D(    F,    E, 0.0f, 0.5f ),
89
           new Static4D(   -F,   -E, 0.0f, 0.5f ),
90
           new Static4D(    E,    F,-0.5f, 0.0f ),
91
           new Static4D( 0.5f,   -E,    F, 0.0f ),
92
           new Static4D(    F, 0.5f,    E, 0.0f )
93
         };
94

    
95
  // Colors of the faces of cubits.
96
  private static final int[][] mFaceMap = new int[][]
97
         {
98
           { 25,24,35, 36,36,36,36,36 },
99
           { 27,28,29, 36,36,36,36,36 },
100
           { 31,26,30, 36,36,36,36,36 },
101
           { 32,34,33, 36,36,36,36,36 },
102

    
103
           { 31,32,25, 36,36,36,36,36 },
104
           { 33,28,24, 36,36,36,36,36 },
105
           { 26,35,27, 36,36,36,36,36 },
106
           { 30,29,34, 36,36,36,36,36 },
107

    
108
           {  8, 0,13,21, 36,36,36,36 },
109
           {  1, 2,19,23, 36,36,36,36 },
110
           {  4,11,12,15, 36,36,36,36 },
111
           {  3, 6,14,17, 36,36,36,36 },
112
           {  5, 9,22,16, 36,36,36,36 },
113
           {  7,10,20,18, 36,36,36,36 }
114
         };
115

    
116
  // centers of the 14 cubits.
117
  static final float[][] CENTERS = new float[][]
118
         {
119
           { 0.0f,-0.5f,    G },
120
           {    E,   -E,   -E },
121
           {   -G, 0.0f,-0.5f },
122
           { 0.5f,    G, 0.0f },
123

    
124
           {   -E,    E,    E },
125
           {    G, 0.0f, 0.5f },
126
           {-0.5f,   -G, 0.0f },
127
           { 0.0f, 0.5f,   -G },
128

    
129
           {        E/2, (E+0.5f)/2,    (E+G)/2 },
130
           {   -(E+G)/2,       -E/2, (E+0.5f)/2 },
131
           { (E+0.5f)/2,   -(E+G)/2,        E/2 },
132
           {       -E/2,-(E+0.5f)/2,   -(E+G)/2 },
133
           {    (E+G)/2,        E/2,-(E+0.5f)/2 },
134
           {-(E+0.5f)/2,    (E+G)/2,       -E/2 }
135
         };
136

    
137
  private static final double[][] VERTICES_SMALL_LEFT = new double[][]
138
         {
139
            {         0.000,         0.000,         0.000},
140
            {       - 0.250,-SQ5/8 - 0.125,-SQ5/8 - 0.375},
141
            { SQ5/8 + 0.125,-SQ5/8 - 0.375,       + 0.250},
142
            { SQ5/8 + 0.375,       + 0.250,-SQ5/8 - 0.125},
143
            { SQ5/4 + 0.250,-SQ5/4 - 0.250,-SQ5/4 - 0.250},
144
            { SQ5/8 - 0.125,       + 0.250,-SQ5/8 - 0.125},
145
            {       - 0.250,-SQ5/8 - 0.125,-SQ5/8 + 0.125},
146
            { SQ5/8 + 0.125,-SQ5/8 + 0.125,       + 0.250}
147
         };
148

    
149
  private static final int[][] VERT_INDEXES_SMALL_LEFT  = new int[][]
150
         {
151
           {6,0,5,1},   // counterclockwise!
152
           {0,7,3,5},
153
           {0,6,2,7},
154
           {1,5,3,4},
155
           {3,7,2,4},
156
           {2,6,1,4},
157
         };
158

    
159
  private static final double[][] VERTICES_SMALL_RIGHT = new double[][]
160
         {
161
           { 0.0       ,  0.0      , 0.0       },
162
           { -0.5*E    , 0.5*E+0.25, -0.25     },
163
           {-0.25      , -E/2      , (-2*E-1)/4},
164
           { 0.5*E+0.25, 0.25      , -E/2      },
165
           { 0.0       , 0.5       , -E-0.5    },
166
           { 0.0       , 0.5       , 0.0       },
167
           { -0.5*E    ,-0.5*E+0.25, -0.25     },
168
           {  0.5*E    ,-0.5*E+0.25, -0.25     }
169
         };
170

    
171
  private static final int[][] VERT_INDEXES_SMALL_RIGHT = new int[][]
172
         {
173
           {6,0,5,1},   // counterclockwise!
174
           {0,7,3,5},
175
           {0,6,2,7},
176
           {4,3,5,1},
177
           {4,2,7,3},
178
           {4,1,6,2},
179
         };
180

    
181
  private static final double[][] VERTICES_BIG = new double[][]
182
         {
183
           {-E/2     ,-E/2+0.25,     0.25},
184
           { E/2     , E/2-0.25,    -0.25},
185
           {-E       ,     0.00,     0.00},
186
           {     0.25, E/2     ,-E/2-0.25},
187
           {-E/2     ,-E/2-0.25,     0.25},
188
           { E/2+0.25,    -0.25,-E/2     },
189
           {-E       ,    -0.50,     0.00},
190
           {     0.50,     0.00,-E       },
191
           {-E  +0.25, E/2     ,-E/2-0.25},
192
           {     0.25,-E/2-0.50,-E/2+0.25},
193
           {-E/2     ,-E/2-0.25,-E  -0.25}
194
         };
195

    
196
  private static final int[][] VERT_INDEXES_BIG = new int[][]
197
         {
198
           {0,1,3,8,2},   // counterclockwise!
199
           {0,4,9,5,1},
200
           { 0,2,6,4},
201
           { 1,5,7,3},
202
           {10,9,4,6},
203
           {10,9,5,7},
204
           {10,8,3,7},
205
           {10,8,2,6}
206
         };
207

    
208
  private static final int[] QUAT_INDEX = new int[]
209
         {
210
           0,6,1,2,0,4,6,5,0,1,4,9,5,2
211
         };
212

    
213
  private static final float[][] STICKERS = new float[][]
214
         {
215
           { -0.14400357f, -0.47894150f, 0.50000000f,-0.011045523f, 0.37700626f, 0.36749030f,-0.26699730f, 0.36749026f, -0.46600536f, -0.24499352f }, // Big cubit 1st
216
           {  0.36327127f,  0.26393202f,-0.36327127f, 0.500000000f,-0.36327127f,-0.26393202f, 0.36327127f,-0.50000000f },                             // Big cubit 2nd
217
           { -0.29389262f, -0.50000000f, 0.29389262f,-0.309017000f, 0.29389262f, 0.30901700f,-0.29389262f, 0.50000000f },                             // Small cubit 1st
218
         };
219

    
220
  private static MeshBase[] mMeshes;
221

    
222
  private static final ObjectSticker[] mStickers;
223

    
224
  static
225
    {
226
    mStickers = new ObjectSticker[STICKERS.length];
227
    final float R1 = 0.08f;
228
    final float R2 = 0.13f;
229
    final float R3 = 0.11f;
230
    final float[][] radii  = { {R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
231
    final float[] strokes = { 0.07f, 0.09f, 0.08f };
232

    
233
    for(int s=0; s<STICKERS.length; s++)
234
      {
235
      mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
236
      }
237
    }
238

    
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

    
241
  TwistyUltimate(int size, Static4D quat, DistortedTexture texture,
242
                 MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
243
    {
244
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.ULTI, res, scrWidth);
245
    }
246

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

    
249
  MeshBase createCubitMesh(int cubit, int numLayers)
250
    {
251
    if( mMeshes==null )
252
      {
253
      FactoryCubit factory = FactoryCubit.getInstance();
254
      factory.clear();
255
      mMeshes = new MeshBase[3];
256
      }
257

    
258
    MeshBase mesh;
259

    
260
    if( cubit<4 )
261
      {
262
      if( mMeshes[0]==null )
263
        {
264
        float[][] bands= new float[][]
265
          {
266
             {0.03f,17,0.5f,0.2f,5,  2,2},
267
             {0.01f, 1,0.5f,0.2f,5,  2,2}
268
          };
269
        int[] bandIndexes   = new int[] { 0,0,0,1,1,1 };
270
        float[][] corners   = new float[][] {  { 0.013f, 0.08f } };
271
        int[] cornerIndexes = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
272
        float[][] centers   = new float[][] { { 0.0f,-0.5f, -(SQ5+3)/4 } };
273
        int[] centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
274

    
275
        FactoryCubit factory = FactoryCubit.getInstance();
276
        factory.createNewFaceTransform(VERTICES_SMALL_RIGHT,VERT_INDEXES_SMALL_RIGHT);
277
        mMeshes[0] = factory.createRoundedSolid(VERTICES_SMALL_RIGHT, VERT_INDEXES_SMALL_RIGHT,
278
                                                bands, bandIndexes,
279
                                                corners, cornerIndexes,
280
                                                centers, centerIndexes,
281
                                                getNumCubitFaces() );
282
        }
283
      mesh = mMeshes[0].copy(true);
284
      }
285
    else if( cubit<8 )
286
      {
287
      if( mMeshes[1]==null )
288
        {
289
        float[][] bands= new float[][]
290
          {
291
             {0.03f,17,0.5f,0.2f,5,  2,2},
292
             {0.01f, 1,0.5f,0.2f,5,  2,2}
293
          };
294
        int[] bandIndexes   = new int[] { 0,0,0,1,1,1 };
295
        float[][] corners   = new float[][] {  { 0.013f, 0.08f } };
296
        int[] cornerIndexes = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
297
        float[][] centers   = new float[][] { { 0.0f,-0.5f, -(SQ5+3)/4 } };
298
        int[] centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
299

    
300
        FactoryCubit factory = FactoryCubit.getInstance();
301
        factory.createNewFaceTransform(VERTICES_SMALL_LEFT,VERT_INDEXES_SMALL_LEFT);
302
        mMeshes[1] = factory.createRoundedSolid(VERTICES_SMALL_LEFT, VERT_INDEXES_SMALL_LEFT,
303
                                                bands, bandIndexes,
304
                                                corners, cornerIndexes,
305
                                                centers, centerIndexes,
306
                                                getNumCubitFaces() );
307
        }
308
      mesh = mMeshes[1].copy(true);
309
      }
310
    else
311
      {
312
      if( mMeshes[2]==null )
313
        {
314
        float[][] bands= new float[][]
315
          {
316
            {0.04f,17,0.5f,0.2f,5,  2,2},
317
            {0.03f,17,0.5f,0.2f,5,  2,2},
318
            {0.01f, 1,0.5f,0.2f,5,  2,2}
319
          };
320
        int[] bandIndexes   = new int[] { 0,0,1,1,2,2,2,2 };
321
        float[][] corners   = new float[][] { { 0.013f, 0.08f } };
322
        int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
323
        float[][] centers   = new float[][] { { -(SQ5+1)/8, 0.25f, -(SQ5+5)/8 } };
324
        int[] centerIndexes = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
325

    
326
        FactoryCubit factory = FactoryCubit.getInstance();
327
        factory.createNewFaceTransform(VERTICES_BIG,VERT_INDEXES_BIG);
328
        mMeshes[2] = factory.createRoundedSolid(VERTICES_BIG, VERT_INDEXES_BIG,
329
                                                bands, bandIndexes,
330
                                                corners, cornerIndexes,
331
                                                centers, centerIndexes,
332
                                                getNumCubitFaces() );
333
        }
334
      mesh = mMeshes[2].copy(true);
335
      }
336

    
337
    Static4D q = QUATS[getQuatIndex(cubit)];
338
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( q, new Static3D(0,0,0) );
339
    mesh.apply(quat,0xffffffff,0);
340

    
341
    return mesh;
342
    }
343

    
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345

    
346
  float[][] getCubitPositions(int numLayers)
347
    {
348
    return CENTERS;
349
    }
350

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

    
353
  private int getQuatIndex(int cubit)
354
    {
355
    return QUAT_INDEX[cubit];
356
    }
357

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

    
360
  int getFaceColor(int cubit, int cubitface, int size)
361
    {
362
    return mFaceMap[cubit][cubitface];
363
    }
364

    
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366

    
367
  int getColor(int face)
368
    {
369
    return FACE_COLORS[face];
370
    }
371

    
372
///////////////////////////////////////////////////////////////////////////////////////////////////
373

    
374
  ObjectSticker retSticker(int face)
375
    {
376
    return mStickers[face/NUM_FACES];
377
    }
378

    
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

    
381
  float returnMultiplier()
382
    {
383
    return 1.0f;
384
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

    
388
  Static4D[] getQuats()
389
    {
390
    return QUATS;
391
    }
392

    
393
///////////////////////////////////////////////////////////////////////////////////////////////////
394

    
395
  boolean shouldResetTextureMaps()
396
    {
397
    return false;
398
    }
399

    
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401

    
402
  int getNumFaces()
403
    {
404
    return FACE_COLORS.length;
405
    }
406

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

    
409
  float[][] getCuts(int numLayers)
410
    {
411
    float[] cut = new float[] {0.0f};
412
    return new float[][] { cut,cut,cut,cut };
413
    }
414

    
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416

    
417
  int getNumStickerTypes(int numLayers)
418
    {
419
    return STICKERS.length;
420
    }
421

    
422
///////////////////////////////////////////////////////////////////////////////////////////////////
423

    
424
  int getNumCubitFaces()
425
    {
426
    return 8;
427
    }
428

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

    
431
  float getScreenRatio()
432
    {
433
    return 0.67f;
434
    }
435

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437
// PUBLIC API
438

    
439
  public Static3D[] getRotationAxis()
440
    {
441
    return ROT_AXIS;
442
    }
443

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

    
446
  public int[] getBasicAngle()
447
    {
448
    return BASIC_ANGLE;
449
    }
450

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

    
453
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
454
    {
455
    if( curr==0 )
456
      {
457
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
458
      }
459
    else
460
      {
461
      int newVector = rnd.nextInt(NUM_AXIS -1);
462
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
463
      }
464

    
465
    scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0 : 1;
466

    
467
    switch( rnd.nextInt(2) )
468
      {
469
      case 0: scramble[curr][2] =  1; break;
470
      case 1: scramble[curr][2] = -1; break;
471
      }
472
    }
473

    
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475

    
476
  public boolean isSolved()
477
    {
478
    int index = CUBITS[0].mQuatIndex;
479

    
480
    for(int i=1; i<NUM_CUBITS; i++)
481
      {
482
      if( CUBITS[i].mQuatIndex != index ) return false;
483
      }
484

    
485
    return true;
486
    }
487

    
488
///////////////////////////////////////////////////////////////////////////////////////////////////
489

    
490
  public int getObjectName(int numLayers)
491
    {
492
    return R.string.ulti2;
493
    }
494

    
495
///////////////////////////////////////////////////////////////////////////////////////////////////
496

    
497
  public int getInventor(int numLayers)
498
    {
499
    return R.string.ulti2_inventor;
500
    }
501

    
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503

    
504
  public int getComplexity(int numLayers)
505
    {
506
    return 6;
507
    }
508
}
(41-41/41)