Project

General

Profile

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

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

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.ObjectShape;
26
import org.distorted.helpers.ObjectSticker;
27
import org.distorted.library.effect.MatrixEffectQuaternion;
28
import org.distorted.library.main.DistortedEffects;
29
import org.distorted.library.main.DistortedTexture;
30
import org.distorted.library.mesh.MeshBase;
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

    
36
import java.util.Random;
37

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

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
221
  private static final ObjectSticker[] mStickers;
222

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

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

    
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

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

    
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

    
248
  ObjectShape getObjectShape(int cubit, int numLayers)
249
    {
250
    int variant = getCubitVariant(cubit,numLayers);
251

    
252
    if( variant==0 )
253
      {
254
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
255
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
256
      float[][] corners   = new float[][] {  { 0.013f, 0.08f } };
257
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
258
      float[][] centers   = new float[][] { { 0.0f,-0.5f, -(SQ5+3)/4 } };
259
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
260

    
261
      return new ObjectShape(VERTICES_SMALL_RIGHT,VERT_INDEXES_SMALL_RIGHT,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
262
      }
263
    else if( variant==1 )
264
      {
265
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
266
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
267
      float[][] corners   = new float[][] {  { 0.013f, 0.08f } };
268
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
269
      float[][] centers   = new float[][] { { 0.0f,-0.5f, -(SQ5+3)/4 } };
270
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
271
      return new ObjectShape(VERTICES_SMALL_LEFT,VERT_INDEXES_SMALL_LEFT,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
272
      }
273
    else
274
      {
275
      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} };
276
      int[] bandIndices   = new int[] { 0,0,1,1,2,2,2,2 };
277
      float[][] corners   = new float[][] { { 0.013f, 0.08f } };
278
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
279
      float[][] centers   = new float[][] { { -(SQ5+1)/8, 0.25f, -(SQ5+5)/8 } };
280
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
281
      return new ObjectShape(VERTICES_BIG,VERT_INDEXES_BIG,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
282
      }
283
    }
284

    
285
///////////////////////////////////////////////////////////////////////////////////////////////////
286

    
287
  private Static4D getQuat(int cubit, int numLayers)
288
    {
289
    return QUATS[QUAT_INDEX[cubit]];
290
    }
291

    
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

    
294
  private int getNumCubitVariants(int numLayers)
295
    {
296
    return 3;
297
    }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

    
301
  int getCubitVariant(int cubit, int numLayers)
302
    {
303
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
304
    }
305

    
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307

    
308
  MeshBase createCubitMesh(int cubit, int numLayers)
309
    {
310
    int variant = getCubitVariant(cubit,numLayers);
311

    
312
    if( mMeshes==null )
313
      {
314
      FactoryCubit factory = FactoryCubit.getInstance();
315
      factory.clear();
316
      mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
317
      }
318

    
319
    if( mMeshes[variant]==null )
320
      {
321
      ObjectShape shape = getObjectShape(cubit,numLayers);
322
      FactoryCubit factory = FactoryCubit.getInstance();
323
      factory.createNewFaceTransform(shape);
324
      mMeshes[variant] = factory.createRoundedSolid(shape);
325
      }
326

    
327
    MeshBase mesh = mMeshes[variant].copy(true);
328
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
329
    mesh.apply(quat,0xffffffff,0);
330

    
331
    return mesh;
332
    }
333

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

    
336
  float[][] getCubitPositions(int numLayers)
337
    {
338
    return CENTERS;
339
    }
340

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

    
343
  int getFaceColor(int cubit, int cubitface, int size)
344
    {
345
    return mFaceMap[cubit][cubitface];
346
    }
347

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349

    
350
  int getColor(int face)
351
    {
352
    return FACE_COLORS[face];
353
    }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

    
357
  ObjectSticker retSticker(int face)
358
    {
359
    return mStickers[face/NUM_FACES];
360
    }
361

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

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

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

    
371
  Static4D[] getQuats()
372
    {
373
    return QUATS;
374
    }
375

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

    
378
  boolean shouldResetTextureMaps()
379
    {
380
    return false;
381
    }
382

    
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384

    
385
  int getNumFaces()
386
    {
387
    return FACE_COLORS.length;
388
    }
389

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

    
392
  float[][] getCuts(int numLayers)
393
    {
394
    float[] cut = new float[] {0.0f};
395
    return new float[][] { cut,cut,cut,cut };
396
    }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

    
400
  int getNumStickerTypes(int numLayers)
401
    {
402
    return STICKERS.length;
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

    
407
  int getNumCubitFaces()
408
    {
409
    return 8;
410
    }
411

    
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413

    
414
  float getScreenRatio()
415
    {
416
    return 0.67f;
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420
// PUBLIC API
421

    
422
  public Static3D[] getRotationAxis()
423
    {
424
    return ROT_AXIS;
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  public int[] getBasicAngle()
430
    {
431
    return BASIC_ANGLE;
432
    }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
437
    {
438
    if( curr==0 )
439
      {
440
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
441
      }
442
    else
443
      {
444
      int newVector = rnd.nextInt(NUM_AXIS -1);
445
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
446
      }
447

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

    
450
    switch( rnd.nextInt(2) )
451
      {
452
      case 0: scramble[curr][2] =  1; break;
453
      case 1: scramble[curr][2] = -1; break;
454
      }
455
    }
456

    
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458

    
459
  public boolean isSolved()
460
    {
461
    int index = CUBITS[0].mQuatIndex;
462

    
463
    for(int i=1; i<NUM_CUBITS; i++)
464
      {
465
      if( CUBITS[i].mQuatIndex != index ) return false;
466
      }
467

    
468
    return true;
469
    }
470

    
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472

    
473
  public int getObjectName(int numLayers)
474
    {
475
    return R.string.ulti2;
476
    }
477

    
478
///////////////////////////////////////////////////////////////////////////////////////////////////
479

    
480
  public int getInventor(int numLayers)
481
    {
482
    return R.string.ulti2_inventor;
483
    }
484

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486

    
487
  public int getComplexity(int numLayers)
488
    {
489
    return 6;
490
    }
491
}
(41-41/41)