Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyDiamond.java @ a70b1e96

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_OCTAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
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.ObjectSignatures;
24
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
25
import org.distorted.objectlib.main.InitData;
26
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
27
import org.distorted.objectlib.main.ObjectType;
28
import org.distorted.objectlib.helpers.ObjectShape;
29
import org.distorted.objectlib.shape.ShapeOctahedron;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class TwistyDiamond extends ShapeOctahedron
34
{
35
  // the four rotation axis of a Diamond. Must be normalized.
36
  static final Static3D[] ROT_AXIS = new Static3D[]
37
         {
38
           new Static3D( SQ6/3, SQ3/3,     0),
39
           new Static3D(-SQ6/3, SQ3/3,     0),
40
           new Static3D(     0,-SQ3/3,-SQ6/3),
41
           new Static3D(     0,-SQ3/3, SQ6/3)
42
         };
43

    
44
  private int[][] mEdges;
45
  private int[][] mBasicAngle;
46
  private float[][] mCuts;
47
  private int[] mTetraToFaceMap;
48
  private float[][] mPosition;
49

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

    
52
  public TwistyDiamond(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
53
    {
54
    super(meshState, iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
55
    }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

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

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
  public int[][] getScrambleEdges()
71
    {
72
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
73
    return mEdges;
74
    }
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
  public float[][] getCuts(int[] numLayers)
79
    {
80
    int numL = numLayers[0];
81
    if( numL<2 ) return null;
82

    
83
    if( mCuts==null )
84
      {
85
      mCuts = new float[4][numL-1];
86
      float cut = (SQ6/6)*(2-numL);
87

    
88
      for(int i=0; i<numL-1; i++)
89
        {
90
        mCuts[0][i] = cut;
91
        mCuts[1][i] = cut;
92
        mCuts[2][i] = cut;
93
        mCuts[3][i] = cut;
94
        cut += SQ6/3;
95
        }
96
      }
97

    
98
    return mCuts;
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  public boolean[][] getLayerRotatable(int[] numLayers)
104
    {
105
    int numAxis = ROT_AXIS.length;
106
    boolean[][] layerRotatable = new boolean[numAxis][];
107

    
108
    for(int i=0; i<numAxis; i++)
109
      {
110
      layerRotatable[i] = new boolean[numLayers[i]];
111
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
112
      }
113

    
114
    return layerRotatable;
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  public int getTouchControlType()
120
    {
121
    return TC_OCTAHEDRON;
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  public int getTouchControlSplit()
127
    {
128
    return TYPE_NOT_SPLIT;
129
    }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
  public int[][][] getEnabled()
134
    {
135
    return new int[][][]
136
      {
137
          {{1,2,3}},{{1,2,3}},{{0,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,3}},{{0,1,2}},{{0,1,2}}
138
      };
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
  public float[] getDist3D(int[] numLayers)
144
    {
145
    return TouchControlOctahedron.D3D;
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  public Static3D[] getFaceAxis()
151
    {
152
    return TouchControlOctahedron.FACE_AXIS;
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  private int getNumOctahedrons(int layers)
158
    {
159
    return layers==1 ? 1 : 4*(layers-1)*(layers-1) + 2;
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  private int getNumTetrahedrons(int layers)
165
    {
166
    return 4*layers*(layers-1);
167
    }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

    
171
  private int createOctaPositions(float[][] centers, int index, int layers, float height)
172
    {
173
    float x = (layers-1)*0.5f;
174
    float z = (layers+1)*0.5f;
175

    
176
    for(int i=0; i<layers; i++, index++)
177
      {
178
      z -= 1;
179
      centers[index][0] = x;
180
      centers[index][1] = height;
181
      centers[index][2] = z;
182
      }
183

    
184
    for(int i=0; i<layers-1; i++, index++)
185
      {
186
      x -= 1;
187
      centers[index][0] = x;
188
      centers[index][1] = height;
189
      centers[index][2] = z;
190
      }
191

    
192
    for(int i=0; i<layers-1; i++, index++)
193
      {
194
      z += 1;
195
      centers[index][0] = x;
196
      centers[index][1] = height;
197
      centers[index][2] = z;
198
      }
199

    
200
    for(int i=0; i<layers-2; i++, index++)
201
      {
202
      x += 1;
203
      centers[index][0] = x;
204
      centers[index][1] = height;
205
      centers[index][2] = z;
206
      }
207

    
208
    return index;
209
    }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

    
213
  private int createTetraPositions(float[][] centers, int index, int layers, float height)
214
    {
215
    float x = (layers-1)*0.5f;
216
    float z =  layers*0.5f;
217

    
218
    for(int i=0; i<layers-1; i++, index++)
219
      {
220
      z -= 1;
221
      centers[index][0] = x;
222
      centers[index][1] = height;
223
      centers[index][2] = z;
224
      }
225

    
226
    x += 0.5f;
227
    z -= 0.5f;
228

    
229
    for(int i=0; i<layers-1; i++, index++)
230
      {
231
      x -= 1;
232
      centers[index][0] = x;
233
      centers[index][1] = height;
234
      centers[index][2] = z;
235
      }
236

    
237
    x -= 0.5f;
238
    z -= 0.5f;
239

    
240
    for(int i=0; i<layers-1; i++, index++)
241
      {
242
      z += 1;
243
      centers[index][0] = x;
244
      centers[index][1] = height;
245
      centers[index][2] = z;
246
      }
247

    
248
    x -= 0.5f;
249
    z += 0.5f;
250

    
251
    for(int i=0; i<layers-1; i++, index++)
252
      {
253
      x += 1;
254
      centers[index][0] = x;
255
      centers[index][1] = height;
256
      centers[index][2] = z;
257
      }
258

    
259
    return index;
260
    }
261

    
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

    
264
  public float[][] getCubitPositions(int[] numLayers)
265
    {
266
    if( mPosition==null )
267
      {
268
      int layers = numLayers[0];
269
      int numO = getNumOctahedrons(layers);
270
      int numT = getNumTetrahedrons(layers);
271
      int index = 0;
272
      float height = 0.0f;
273

    
274
      mPosition = new float[numO+numT][3];
275

    
276
      index = createOctaPositions(mPosition,index,layers,height);
277

    
278
      for(int i=layers-1; i>0; i--)
279
        {
280
        height += SQ2/2;
281
        index = createOctaPositions(mPosition,index,i,+height);
282
        index = createOctaPositions(mPosition,index,i,-height);
283
        }
284

    
285
      height = SQ2/4;
286

    
287
      for(int i=layers; i>1; i--)
288
        {
289
        index = createTetraPositions(mPosition,index,i,+height);
290
        index = createTetraPositions(mPosition,index,i,-height);
291
        height += SQ2/2;
292
        }
293
      }
294

    
295
    return mPosition;
296
    }
297

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

    
300
  public Static4D getCubitQuats(int cubit, int[] numLayers)
301
    {
302
    int numL = numLayers[0];
303
    int numO = getNumOctahedrons(numL);
304

    
305
    if( cubit<numO ) return mObjectQuats[0];
306

    
307
    switch( retFaceTetraBelongsTo(cubit-numO, numL) )
308
      {
309
      case 0: return mObjectQuats[0];                   // unit quat
310
      case 1: return new Static4D(0,-SQ2/2,0,SQ2/2);    //  90 along Y
311
      case 2: return mObjectQuats[10];                  // 180 along Y
312
      case 3: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along
313
      case 4: return new Static4D(0,     0,1,    0);    // 180 along Z
314
      case 5: return mObjectQuats[4];
315
      case 6: return new Static4D(     1,0,0,    0);    // 180 along X
316
      case 7: return mObjectQuats[3];
317
      }
318

    
319
    return null;
320
    }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
  private int retFaceTetraBelongsTo(int tetra, int numLayers)
325
    {
326
    if( mTetraToFaceMap==null ) mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4};
327

    
328
    for(int i=numLayers-1; i>0; i--)
329
      {
330
      if( tetra < 8*i ) return mTetraToFaceMap[tetra/i];
331
      tetra -= 8*i;
332
      }
333

    
334
    return -1;
335
    }
336

    
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

    
339
  private float[][] getVertices(int variant)
340
    {
341
    if( variant==0 )
342
      {
343
      return new float[][]
344
          {
345
             { 0.5f,  0.0f, 0.5f},
346
             { 0.5f,  0.0f,-0.5f},
347
             {-0.5f,  0.0f,-0.5f},
348
             {-0.5f,  0.0f, 0.5f},
349
             { 0.0f, SQ2/2, 0.0f},
350
             { 0.0f,-SQ2/2, 0.0f}
351
          };
352
      }
353
    else
354
      {
355
      return new float[][]
356
          {
357
             {-0.5f, SQ2/4, 0.0f},
358
             { 0.5f, SQ2/4, 0.0f},
359
             { 0.0f,-SQ2/4, 0.5f},
360
             { 0.0f,-SQ2/4,-0.5f}
361
          };
362
      }
363
    }
364

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

    
367
  public ObjectShape getObjectShape(int variant)
368
    {
369
    if( variant==0 )
370
      {
371
      int[][] indices =
372
          {
373
             {3,0,4},
374
             {0,1,4},
375
             {1,2,4},
376
             {2,3,4},
377
             {5,0,3},
378
             {5,1,0},
379
             {5,2,1},
380
             {5,3,2}
381
          };
382

    
383
      return new ObjectShape(getVertices(variant), indices);
384
      }
385
    else
386
      {
387
      int[][] indices = { {2,1,0}, {2,3,1}, {3,2,0}, {3,0,1} };
388
      return new ObjectShape(getVertices(variant), indices);
389
      }
390
    }
391

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

    
394
  public ObjectFaceShape getObjectFaceShape(int variant)
395
    {
396
    int numL = getNumLayers()[0];
397
    int N = numL>3 ? 5:6;
398
    int E = numL>2 ? (numL>3 ? 0:1) : 2;
399
    float height = isInIconMode() ? 0.001f : 0.05f;
400

    
401
    if( variant==0 )
402
      {
403
      float[][] bands  = { {height,20,0.5f,0.8f,N,E,E} };
404
      int[] bandIndices= { 0,0,0,0,0,0,0,0 };
405
      return new ObjectFaceShape(bands,bandIndices,null);
406
      }
407
    else
408
      {
409
      float[][] bands  = { {height,35,0.5f,0.8f,N,E,E} };
410
      int[] bandIndices= { 0,0,0,0 };
411
      return new ObjectFaceShape(bands,bandIndices,null);
412
      }
413
    }
414

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

    
417
  public ObjectVertexEffects getVertexEffects(int variant)
418
    {
419
    if( variant==0 )
420
      {
421
      float[][] corners= { {0.06f,0.15f} };
422
      int[] indices    = { 0,0,0,0,0,0 };
423
      float[][] centers= { {0.0f, 0.0f, 0.0f} };
424
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
425
      }
426
    else
427
      {
428
      float[][] corners= { {0.08f,0.15f} };
429
      int[] indices    = { 0,0,0,0 };
430
      float[][] centers= { {0.0f, 0.0f, 0.0f} };
431
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
432
      }
433
    }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

    
437
  public int getNumCubitVariants(int[] numLayers)
438
    {
439
    return 2;
440
    }
441

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

    
444
  public int getCubitVariant(int cubit, int[] numLayers)
445
    {
446
    return cubit<getNumOctahedrons(numLayers[0]) ? 0 : 1;
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450

    
451
  public float getStickerRadius()
452
    {
453
    return 0.08f;
454
    }
455

    
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457

    
458
  public float getStickerStroke()
459
    {
460
    float stroke = 0.08f;
461

    
462
    if( isInIconMode() )
463
      {
464
      int[] numLayers = getNumLayers();
465

    
466
      switch(numLayers[0])
467
        {
468
        case 2: stroke*=1.4f; break;
469
        case 3: stroke*=2.0f; break;
470
        case 4: stroke*=2.1f; break;
471
        default:stroke*=2.2f; break;
472
        }
473
      }
474

    
475
    return stroke;
476
    }
477

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

    
480
  public float[][] getStickerAngles()
481
    {
482
    return null;
483
    }
484

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486
// PUBLIC API
487

    
488
  public Static3D[] getRotationAxis()
489
    {
490
    return ROT_AXIS;
491
    }
492

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494

    
495
  public int[][] getBasicAngles()
496
    {
497
    if( mBasicAngle ==null )
498
      {
499
      int num = getNumLayers()[0];
500
      int[] tmp = new int[num];
501
      for(int i=0; i<num; i++) tmp[i] = 3;
502
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
503
      }
504
    return mBasicAngle;
505
    }
506

    
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508

    
509
  public String getShortName()
510
    {
511
    switch(getNumLayers()[0])
512
      {
513
      case 2: return ObjectType.DIAM_2.name();
514
      case 3: return ObjectType.DIAM_3.name();
515
      case 4: return ObjectType.DIAM_4.name();
516
      }
517

    
518
    return ObjectType.DIAM_2.name();
519
    }
520

    
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522

    
523
  public ObjectSignature getSignature()
524
    {
525
    switch(getNumLayers()[0])
526
      {
527
      case 2: return new ObjectSignature(ObjectSignatures.DIAM_2);
528
      case 3: return new ObjectSignature(ObjectSignatures.DIAM_3);
529
      case 4: return new ObjectSignature(ObjectSignatures.DIAM_4);
530
      }
531

    
532
    return null;
533
    }
534

    
535
///////////////////////////////////////////////////////////////////////////////////////////////////
536

    
537
  public String getObjectName()
538
    {
539
    switch(getNumLayers()[0])
540
      {
541
      case 2: return "Skewb Diamond";
542
      case 3: return "Face Turning Octahedron";
543
      case 4: return "Master Face Turning Octahedron";
544
      }
545

    
546
    return "Skewb Diamond";
547
    }
548

    
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550

    
551
  public String getInventor()
552
    {
553
    switch(getNumLayers()[0])
554
      {
555
      case 2: return "Uwe Meffert";
556
      case 3: return "David Pitcher";
557
      case 4: return "Timur Evbatyrov";
558
      }
559

    
560
    return "Uwe Meffert";
561
    }
562

    
563
///////////////////////////////////////////////////////////////////////////////////////////////////
564

    
565
  public int getYearOfInvention()
566
    {
567
    switch(getNumLayers()[0])
568
      {
569
      case 2: return 1984;
570
      case 3: return 2003;
571
      case 4: return 2011;
572
      }
573
    return 1984;
574
    }
575

    
576
///////////////////////////////////////////////////////////////////////////////////////////////////
577

    
578
  public int getComplexity()
579
    {
580
    switch(getNumLayers()[0])
581
      {
582
      case 2: return 1;
583
      case 3: return 3;
584
      case 4: return 4;
585
      }
586

    
587
    return 0;
588
    }
589

    
590
///////////////////////////////////////////////////////////////////////////////////////////////////
591

    
592
  public String[][] getTutorials()
593
    {
594
    int[] numLayers = getNumLayers();
595

    
596
    switch(numLayers[0])
597
      {
598
      case 2: return new String[][] {
599
                          {"gb","R2wrbJJ3izM","How to Solve a Skewb Diamond","Dr. Penguin^3"},
600
                          {"es","2RCusYQdYYE","Como resolver Skewb Diamond","Tutoriales Rubik"},
601
                          {"ru","k8B6RFcNoGw","Как собрать Skewb Diamond","Алексей Ярыгин"},
602
                          {"fr","tqbkgwNcZCE","Comment résoudre le Skewb Diamond","Valentino Cube"},
603
                          {"de","6ewzrCOnZfg","Octagon lösen","JamesKnopf"},
604
                          {"pl","61_Z4TpLMBc","Diamond Skewb TUTORIAL PL","MrUk"},
605
                          {"br","UapwpXMYtH4","Como resolver o Octaedro Diamond","Rafael Cinoto"},
606
                          {"kr","hVBSlfHVTME","공식 하나만 사용 - 다이아몬드 스큐브","Denzel Washington"},
607
                         };
608
      case 3: return new String[][] {
609
                          {"gb","n_mBSUDLUZw","Face Turning Octahedron Tutorial","SuperAntoniovivaldi"},
610
                          {"es","ogf0t6fGxZI","FTO - Tutorial en español","Gadi Rubik"},
611
                          {"ru","VXCjk0bVRoA","Как собрать Face Turning Octahedron","Алексей Ярыгин"},
612
                          {"de","6bO0AcwY5K8","Face Turning Octahedron - Tutorial","GerCubing"},
613
                          {"pl","huWg-ZfP-KY","Octahedron cube TUTORIAL PL","MrUk"},
614
                          {"br","WN3BoP4EbvM","Como resolver o octaedro 3x3 1/3","Rafael Cinoto"},
615
                          {"br","4zFlfANOliE","Como resolver o octaedro 3x3 2/3","Rafael Cinoto"},
616
                          {"br","6OvNzoHk7RU","Como resolver o octaedro 3x3 3/3","Rafael Cinoto"},
617
                          {"vn","KzGQ-mVRsss","Tutorial N.43 - FTO","Duy Thích Rubik"},
618
                         };
619
      case 4: return new String[][] {
620
                          {"gb","3GJkySk5zeQ","Master Face Turning Octahedron","SuperAntoniovivaldi"},
621
                          {"gb","zW_1htxy52k","Master FTO Tutorial","Michele Regano"},
622
                          {"es","3K8XL9SBSvs","Tutorial Master FTO de Mf8","Robert Cubes"},
623
                          {"ru","0CRwhZ2JNJA","Как собрать Master FTO","Алексей Ярыгин"},
624
                          {"vn","4XdeuGYDCJo","Tutorial N.141 - Master FTO","Duy Thích Rubik"},
625
                         };
626
      }
627
    return null;
628
    }
629
}
(13-13/47)