Project

General

Profile

Download (19.2 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyRedi.java @ e707966d

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.objects;
11

    
12
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
14

    
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17

    
18
import org.distorted.objectlib.helpers.FactoryCubit;
19
import org.distorted.objectlib.helpers.ObjectFaceShape;
20
import org.distorted.objectlib.helpers.ObjectSignature;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitAssets;
23
import org.distorted.objectlib.main.InitData;
24
import org.distorted.objectlib.main.ObjectSignatures;
25
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
26
import org.distorted.objectlib.main.ObjectType;
27
import org.distorted.objectlib.helpers.ObjectShape;
28
import org.distorted.objectlib.shape.ShapeHexahedron;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
public class TwistyRedi extends ShapeHexahedron
33
{
34
  static final Static3D[] ROT_AXIS = new Static3D[]
35
         {
36
           new Static3D( SQ3/3, SQ3/3, SQ3/3),
37
           new Static3D( SQ3/3, SQ3/3,-SQ3/3),
38
           new Static3D( SQ3/3,-SQ3/3, SQ3/3),
39
           new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
40
         };
41

    
42
  private int[][] mEdges;
43
  private int[][] mBasicAngle;
44
  private float[][] mCuts;
45
  private float[][] mPosition;
46
  private int[] mQuatIndex;
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
  public TwistyRedi(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
51
    {
52
    super(meshState, iconMode, (data.getNumLayers()[0]+3)*0.5f, quat, move, scale, data, asset);
53
    }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  @Override
58
  public float[][] returnRotationFactor()
59
    {
60
    float C = 1.5f;
61
    int numL = getNumLayers()[0];
62
    float[] f = new float[numL];
63
    for(int i=0; i<numL; i++) f[i] = C;
64
    return new float[][] { f,f,f,f };
65
    }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  public int[][] getScrambleEdges()
70
    {
71
    if( mEdges==null )
72
      {
73
      mEdges = new int[][]
74
        {
75
          { 0,8,1,8, 4,1,5,1, 6,7,7,7, 10,2,11,2, 12,6,13,6, 16,3,17,3, 18,5,19,5, 22,4,23,4 },  // 0
76
          {                            10,2,11,2,            16,3,17,3, 18,5,19,5            },  // 1
77
          {          4,1,5,1,                     12,6,13,6,                       22,4,23,4 },  // 2
78
          {          4,1,5,1, 6,7,7,7,                                             22,4,23,4 },  // 3
79
          { 0,8,1,8,                   10,2,11,2,            16,3,17,3                       },  // 4
80
          {          4,1,5,1, 6,7,7,7,            12,6,13,6                                  },  // 5
81
          { 0,8,1,8,                   10,2,11,2,                       18,5,19,5            },  // 6
82
          { 0,8,1,8,                                         16,3,17,3, 18,5,19,5            },  // 7
83
          {                   6,7,7,7,            12,6,13,6,                       22,4,23,4 },  // 8
84
        };
85
      }
86

    
87
    return mEdges;
88
    }
89

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

    
92
  public float[][] getCuts(int[] numLayers)
93
    {
94
    if( mCuts==null )
95
      {
96
      switch( numLayers[0] )
97
        {
98
        case 3: float C3 = SQ3/2 + 0.05f;
99
                float[] c3 = new float[] {-C3,C3};
100
                mCuts = new float[][] { c3,c3,c3,c3 };
101
                break;
102
        case 5: float A5 = 5*SQ3/4;
103
                float B5 = 5*SQ3/3;
104
                float[] c5 = new float[] {-A5,-B5, B5, A5};
105
                mCuts = new float[][] { c5,c5,c5,c5 };
106
                break;
107
        }
108

    
109
      }
110

    
111
    return mCuts;
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  public boolean[][] getLayerRotatable(int[] numLayers)
117
    {
118
    switch( numLayers[0] )
119
      {
120
      case 3: boolean[] t3 = new boolean[] {true,false,true};
121
              return new boolean[][] { t3,t3,t3,t3 };
122
      case 5: boolean[] t5 = new boolean[] {true,true,false,true,true};
123
              return new boolean[][] { t5,t5,t5,t5 };
124
      }
125
    return null;
126
    }
127

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

    
130
  public int getTouchControlType()
131
    {
132
    return TC_HEXAHEDRON;
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  public int getTouchControlSplit()
138
    {
139
    return TYPE_SPLIT_CORNER;
140
    }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
  public int[][][] getEnabled()
145
    {
146
    return new int[][][]
147
      {
148
          {{0,1},{3,1},{2,3},{0,2}},
149
          {{2,3},{3,1},{0,1},{0,2}},
150
          {{1,2},{0,1},{0,3},{2,3}},
151
          {{1,2},{2,3},{0,3},{0,1}},
152
          {{0,3},{0,2},{1,2},{1,3}},
153
          {{1,2},{0,2},{0,3},{1,3}},
154
      };
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  public float[] getDist3D(int[] numLayers)
160
    {
161
    return TouchControlHexahedron.D3D;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

    
166
  public Static3D[] getFaceAxis()
167
    {
168
    return TouchControlHexahedron.FACE_AXIS;
169
    }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

    
173
  public float[][] getCubitPositions(int[] numLayers)
174
    {
175
    if( mPosition==null )
176
      {
177
      if( numLayers[0]==3 )
178
        {
179
        final float C = 1.0f;
180
        final float E = 1.5f;
181

    
182
        mPosition = new float[][]
183
          {
184
             { C, C, C },
185
             { C, C,-C },
186
             { C,-C, C },
187
             { C,-C,-C },
188
             {-C, C, C },
189
             {-C, C,-C },
190
             {-C,-C, C },
191
             {-C,-C,-C },
192

    
193
             { 0, E, E },
194
             { E, 0, E },
195
             { 0,-E, E },
196
             {-E, 0, E },
197
             { E, E, 0 },
198
             { E,-E, 0 },
199
             {-E,-E, 0 },
200
             {-E, E, 0 },
201
             { 0, E,-E },
202
             { E, 0,-E },
203
             { 0,-E,-E },
204
             {-E, 0,-E }
205
          };
206
        }
207
      else if( numLayers[0]==5 )
208
        {
209
        final float C = 1.5f;
210
        final float E = 2.0f;
211
        final float F = 0.5f;
212

    
213
        mPosition = new float[][]
214
          {
215
             { C, C, C },
216
             { C, C,-C },
217
             { C,-C, C },
218
             { C,-C,-C },
219
             {-C, C, C },
220
             {-C, C,-C },
221
             {-C,-C, C },
222
             {-C,-C,-C },
223

    
224
             {-F, E, E },
225
             { F, E, E },
226
             { E,-F, E },
227
             { E, F, E },
228
             {-F,-E, E },
229
             { F,-E, E },
230
             {-E,-F, E },
231
             {-E, F, E },
232
             { E, E,-F },
233
             { E, E, F },
234
             { E,-E,-F },
235
             { E,-E, F },
236
             {-E,-E,-F },
237
             {-E,-E, F },
238
             {-E, E,-F },
239
             {-E, E, F },
240
             {-F, E,-E },
241
             { F, E,-E },
242
             { E,-F,-E },
243
             { E, F,-E },
244
             {-F,-E,-E },
245
             { F,-E,-E },
246
             {-E,-F,-E },
247
             {-E, F,-E },
248

    
249
             { 0, F, E },
250
             { 0,-F, E },
251
             { F, 0, E },
252
             {-F, 0, E },
253
             { 0, F,-E },
254
             { 0,-F,-E },
255
             { F, 0,-E },
256
             {-F, 0,-E },
257
             { E, 0, F },
258
             { E, 0,-F },
259
             { E, F, 0 },
260
             { E,-F, 0 },
261
             {-E, 0, F },
262
             {-E, 0,-F },
263
             {-E, F, 0 },
264
             {-E,-F, 0 },
265

    
266
             { 0,-E, F },
267
             { 0,-E,-F },
268
             { F,-E, 0 },
269
             {-F,-E, 0 },
270
             { 0, E, F },
271
             { 0, E,-F },
272
             { F, E, 0 },
273
             {-F, E, 0 },
274
          };
275
        }
276
      }
277

    
278
    return mPosition;
279
    }
280

    
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

    
283
  public Static4D getCubitQuats(int cubit, int[] numLayers)
284
    {
285
    if( cubit<8 )
286
      switch(cubit)
287
        {
288
        case  0: return mObjectQuats[0];                   //  unit quat
289
        case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
290
        case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
291
        case  3: return mObjectQuats[9];                   // 180 along X
292
        case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
293
        case  5: return mObjectQuats[11];                  // 180 along Y
294
        case  6: return mObjectQuats[10];                  // 180 along Z
295
        case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
296
        }
297

    
298
    if( mQuatIndex==null )
299
      {
300
      mQuatIndex = new int[]
301
        {
302
        0,2,10,8,1,4,6,7,11,5,9,3,
303
        0,11,2,3,4,1
304
        };
305
      }
306

    
307
    int index = numLayers[0]==3 ? (cubit-8) : (cubit<32 ? (cubit-8)/2 : (cubit-32)/4 + 12);
308
    return mObjectQuats[mQuatIndex[index]];
309
    }
310

    
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312

    
313
  private float[][] getVertices(int variant)
314
    {
315
    if( variant==0 )
316
      {
317
      return new float[][]
318
          {
319
             { 0.0f, 0.0f, 0.0f },
320
             {-0.5f, 0.5f, 0.5f },
321
             {-0.5f,-0.5f, 0.5f },
322
             { 0.5f, 0.5f, 0.5f },
323
             { 0.5f,-0.5f, 0.5f },
324
             { 0.5f, 0.5f,-0.5f },
325
             { 0.5f,-0.5f,-0.5f },
326
             {-0.5f, 0.5f,-0.5f },
327
          };
328
      }
329
    else if( variant==1 )
330
      {
331
      return new float[][]
332
          {
333
             {-0.5f, 0.0f, 0.0f},
334
             { 0.5f, 0.0f, 0.0f},
335
             {-0.5f,-1.0f, 0.0f},
336
             { 0.5f,-1.0f, 0.0f},
337
             { 0.0f,-1.5f, 0.0f},
338
             {-0.5f, 0.0f,-1.0f},
339
             { 0.5f, 0.0f,-1.0f},
340
             { 0.0f, 0.0f,-1.5f},
341
          };
342
      }
343
    else
344
      {
345
      return new float[][]
346
          {
347
             {-0.5f, 0.0f, 0.0f},
348
             { 0.0f,-0.5f, 0.0f},
349
             { 0.5f, 0.0f, 0.0f},
350
             { 0.0f, 0.5f, 0.0f},
351
             { 0.0f, 0.0f,-0.5f}
352

    
353
          };
354
      }
355
    }
356

    
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358

    
359
  public ObjectShape getObjectShape(int variant)
360
    {
361
    if( variant==0 )
362
      {
363
      int[][] indices =
364
          {
365
             { 2,4,3,1 },
366
             { 1,3,5,7 },
367
             { 4,6,5,3 },
368

    
369
             { 0,4,2 },
370
             { 0,7,5 },
371
             { 0,6,4 },
372
             { 0,1,7 },
373
             { 0,2,1 },
374
             { 0,5,6 }
375
          };
376

    
377
      return new ObjectShape(getVertices(variant), indices);
378
      }
379
    else if( variant==1 )
380
      {
381
      int[][] indices =
382
          {
383
             { 0,2,4,3,1 },
384
             { 0,1,6,7,5 },
385
             { 1,3,6 },
386
             { 5,2,0 },
387
             { 4,7,6,3 },
388
             { 2,5,7,4 }
389
          };
390

    
391
      return new ObjectShape(getVertices(variant), indices);
392
      }
393
    else
394
      {
395
      int[][] indices = { {0,1,2,3},{4,1,0},{4,2,1},{4,3,2},{4,0,3} };
396
      return new ObjectShape(getVertices(variant), indices);
397
      }
398
    }
399

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

    
402
  public ObjectFaceShape getObjectFaceShape(int variant)
403
    {
404
    if( variant==0 )
405
      {
406
      float h1 = isInIconMode() ? 0.001f : 0.06f;
407
      float h2 = isInIconMode() ? 0.001f : 0.01f;
408
      float[][] bands = { {h1,35,0.5f,0.7f,5,2,1}, {h2,35,0.2f,0.4f,5,2,1} };
409
      int[] indices   = { 0,0,0,1,1,1,1,1,1 };
410
      return new ObjectFaceShape(bands,indices,null);
411
      }
412
    else if( variant==1 )
413
      {
414
      float h1 = isInIconMode() ? 0.001f : 0.038f;
415
      float h2 = isInIconMode() ? 0.001f : 0.020f;
416
      float[][] bands = { {h1,35,0.250f,0.7f,6,1,1}, {h2,35,0.125f,0.2f,3,1,1}, {h2,35,0.125f,0.2f,3,1,1} };
417
      int[] indices   = { 0,0,1,1,2,2 };
418
      return new ObjectFaceShape(bands,indices,null);
419
      }
420
    else
421
      {
422
      float height = isInIconMode() ? 0.001f : 0.04f;
423
      float[][] bands = { {height,35,SQ2/8,0.9f,6,1,1}, {0.001f,35,1,0.0f,3,0,0} };
424
      int[] indices   = { 0,1,1,1,1 };
425
      return new ObjectFaceShape(bands,indices,null);
426
      }
427
    }
428

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

    
431
  public ObjectVertexEffects getVertexEffects(int variant)
432
    {
433
    if( variant==0 )
434
      {
435
      float[][] corners = { {0.06f,0.12f} };
436
      int[] indices     = { -1,0,-1,0,0,0,-1,-1 };
437
      float[][] centers = { { 0.0f, 0.0f, 0.0f} };
438
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
439
      }
440
    else if( variant==1 )
441
      {
442
      float[][] corners = { {0.06f,0.20f} };
443
      int[] indices     = { 0,0,-1,-1,-1,-1,-1,-1 };
444
      float[][] centers = { { 0.0f,-0.75f,-0.75f} };
445
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
446
      }
447
    else
448
      {
449
      return null;
450
      }
451
    }
452

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

    
455
  public int getNumCubitVariants(int[] numLayers)
456
    {
457
    return numLayers[0]==3 ? 2 : 3;
458
    }
459

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

    
462
  public int getCubitVariant(int cubit, int[] numLayers)
463
    {
464
    switch( numLayers[0] )
465
      {
466
      case 3: return cubit<8 ? 0:1;
467
      case 5: return cubit<8 ? 0 : cubit<32 ? 1:2;
468
      }
469
    return 0;
470
    }
471

    
472
///////////////////////////////////////////////////////////////////////////////////////////////////
473

    
474
  public float getStickerRadius()
475
    {
476
    return 0.09f;
477
    }
478

    
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480

    
481
  public float getStickerStroke()
482
    {
483
    return isInIconMode() ? 0.20f : 0.09f;
484
    }
485

    
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487

    
488
  public float[][][] getStickerAngles()
489
    {
490
    return null;
491
    }
492

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494
// PUBLIC API
495

    
496
  public Static3D[] getRotationAxis()
497
    {
498
    return ROT_AXIS;
499
    }
500

    
501
///////////////////////////////////////////////////////////////////////////////////////////////////
502

    
503
  public int[][] getBasicAngles()
504
    {
505
    if( mBasicAngle ==null )
506
      {
507
      int num = getNumLayers()[0];
508
      int[] tmp = new int[num];
509
      for(int i=0; i<num; i++) tmp[i] = 3;
510
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
511
      }
512

    
513
    return mBasicAngle;
514
    }
515

    
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517

    
518
  public String getShortName()
519
    {
520
    switch(getNumLayers()[0])
521
      {
522
      case 3: ObjectType.REDI_3.name();
523
      case 5: ObjectType.FADI_5.name();
524
      }
525

    
526
    return null;
527
    }
528

    
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530

    
531
  public ObjectSignature getSignature()
532
    {
533
    switch(getNumLayers()[0])
534
      {
535
      case 3: new ObjectSignature(ObjectSignatures.REDI_3);
536
      case 5: new ObjectSignature(ObjectSignatures.FADI_5);
537
      }
538

    
539
    return null;
540
    }
541

    
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543

    
544
  public String getObjectName()
545
    {
546
    switch(getNumLayers()[0])
547
      {
548
      case 3: return "Redi Cube";
549
      case 5: return "Mosaic Cube";
550
      }
551
    return null;
552
    }
553

    
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555

    
556
  public String getInventor()
557
    {
558
    return "Oskar van Deventer";
559
    }
560

    
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562

    
563
  public int getYearOfInvention()
564
    {
565
    return 2009;
566
    }
567

    
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569

    
570
  public int getComplexity()
571
    {
572
    switch(getNumLayers()[0])
573
      {
574
      case 3: return 1;
575
      case 5: return 2;
576
      }
577
    return 1;
578
    }
579

    
580
///////////////////////////////////////////////////////////////////////////////////////////////////
581

    
582
  public String[][] getTutorials()
583
    {
584
    switch(getNumLayers()[0])
585
      {
586
      case 3: return new String[][] {
587
                                {"gb", "Qn7TJED6O-4", "How to Solve the MoYu Redi Cube", "Z3"},
588
                                {"es", "g0M38Aotgac", "Resolver Redi Cube", "Cuby"},
589
                                {"ru", "dlNRbE-hyzU", "Как собрать Реди Куб", "Алексей Ярыгин"},
590
                                {"fr", "zw7UZcqqsgA", "Comment résoudre le Redi Cube", "ValentinoCube"},
591
                                {"de", "YU8riouyC2w", "Redi Cube Solve", "CubaroCubing"},
592
                                {"pl", "vxo3lXMsWQI", "Jak ułożyć Redi Cube?", "DJ rubiks"},
593
                                {"br", "muQ8U_G4LmM", "Como resolver o Redi Cube", "Rafael Cinoto"},
594
                                {"kr", "a5CzDMbRzbY", "레디큐브를 배우기", "vincentcube"},
595
                                {"vn", "2JZxtmrKUn4", "Tutorial N.6 - Redi", "Duy Thích Rubik"},
596
                                {"tw", "LBKPL01IHD8", "Redi Cube盲解教學", "1hrBLD"},
597
                               };
598
      case 5: return new String[][]{
599
                                {"gb", "Lp63Pn6q4vM", "Mosaic Cube", "Cubes made Easy"},
600
                                {"gb", "LGrxmaTiCZM", "How to solve the Mosaic Cube", "Cuber Stu"},
601
                                {"es", "o5_7dezogqM", "Resolver Mosaic Cube 1/4", "TheMaoiSha"},
602
                                {"es", "wT4wwCOfvQc", "Resolver Mosaic Cube 2/4", "TheMaoiSha"},
603
                                {"es", "yLdSbIK0ULU", "Resolver Mosaic Cube 3/4", "TheMaoiSha"},
604
                                {"es", "l_wl0AgP48k", "Resolver Mosaic Cube 4/4", "TheMaoiSha"},
605
                                {"ru", "wbbP45jHsU4", "Как собрать Мозаичный Куб", "SOLPUZ-Димон"},
606
                                {"pl", "Iu5vd_4h3Uc", "Mosaic cube Tutorial PL", "MrUK"},
607
                                {"br", "a-WiaZdlfjQ", "Mosaic Cube Walkthrough Solve", "Cubo vício"},
608
                                {"tw", "m0vG-cRB8fo", "Mosaic Cube Solution 1/2", "Arwin Hsu"},
609
                                {"tw", "qUDC4TF_1cw", "Mosaic Cube Solution 2/2", "Arwin Hsu"},
610
                               };
611
      }
612
    return null;
613
    }
614
}
(38-38/50)