Project

General

Profile

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

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

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 java.io.InputStream;
16

    
17
import org.distorted.library.type.Static3D;
18
import org.distorted.library.type.Static4D;
19

    
20
import org.distorted.objectlib.helpers.ObjectFaceShape;
21
import org.distorted.objectlib.helpers.ObjectSignature;
22
import org.distorted.objectlib.main.InitData;
23
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
24
import org.distorted.objectlib.main.ObjectType;
25
import org.distorted.objectlib.helpers.ObjectShape;
26
import org.distorted.objectlib.scrambling.ScrambleState;
27
import org.distorted.objectlib.main.ShapeOctahedron;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

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

    
42
  private ScrambleState[] mStates;
43
  private int[][] mBasicAngle;
44
  private float[][] mCuts;
45
  private int[] mTetraToFaceMap;
46
  private float[][] mPosition;
47

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

    
50
  public TwistyDiamond(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
51
    {
52
    super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
53
    }
54

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

    
57
  public ScrambleState[] getScrambleStates()
58
    {
59
    if( mStates==null )
60
      {
61
      int[] numLayers = getNumLayers();
62
      int numL = numLayers[0];
63
      int[] tmp = new int[3*2*numL];
64

    
65
      for(int i=0; i<2*numL; i++)
66
        {
67
        tmp[3*i  ] = (i<numL) ?  i:i-numL;
68
        tmp[3*i+1] = (i%2==0) ? -1:1;
69
        tmp[3*i+2] = 0;
70
        }
71

    
72
      mStates = new ScrambleState[]
73
        {
74
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
75
        };
76
      }
77

    
78
    return mStates;
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
  public float[][] getCuts(int[] numLayers)
84
    {
85
    int numL = numLayers[0];
86
    if( numL<2 ) return null;
87

    
88
    if( mCuts==null )
89
      {
90
      mCuts = new float[4][numL-1];
91
      float cut = (SQ6/6)*(2-numL);
92

    
93
      for(int i=0; i<numL-1; i++)
94
        {
95
        mCuts[0][i] = cut;
96
        mCuts[1][i] = cut;
97
        mCuts[2][i] = cut;
98
        mCuts[3][i] = cut;
99
        cut += SQ6/3;
100
        }
101
      }
102

    
103
    return mCuts;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public boolean[][] getLayerRotatable(int[] numLayers)
109
    {
110
    int numAxis = ROT_AXIS.length;
111
    boolean[][] layerRotatable = new boolean[numAxis][];
112

    
113
    for(int i=0; i<numAxis; i++)
114
      {
115
      layerRotatable[i] = new boolean[numLayers[i]];
116
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
117
      }
118

    
119
    return layerRotatable;
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
  public int getTouchControlType()
125
    {
126
    return TC_OCTAHEDRON;
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public int getTouchControlSplit()
132
    {
133
    return TYPE_NOT_SPLIT;
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  public int[][][] getEnabled()
139
    {
140
    return new int[][][]
141
      {
142
          {{1,2,3}},{{1,2,3}},{{0,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,3}},{{0,1,2}},{{0,1,2}}
143
      };
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  public float[] getDist3D(int[] numLayers)
149
    {
150
    return TouchControlOctahedron.D3D;
151
    }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

    
155
  public Static3D[] getFaceAxis()
156
    {
157
    return TouchControlOctahedron.FACE_AXIS;
158
    }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

    
162
  private int getNumOctahedrons(int layers)
163
    {
164
    return layers==1 ? 1 : 4*(layers-1)*(layers-1) + 2;
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  private int getNumTetrahedrons(int layers)
170
    {
171
    return 4*layers*(layers-1);
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  private int createOctaPositions(float[][] centers, int index, int layers, float height)
177
    {
178
    float x = (layers-1)*0.5f;
179
    float z = (layers+1)*0.5f;
180

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

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

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

    
205
    for(int i=0; i<layers-2; i++, index++)
206
      {
207
      x += 1;
208
      centers[index][0] = x;
209
      centers[index][1] = height;
210
      centers[index][2] = z;
211
      }
212

    
213
    return index;
214
    }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
  private int createTetraPositions(float[][] centers, int index, int layers, float height)
219
    {
220
    float x = (layers-1)*0.5f;
221
    float z =  layers*0.5f;
222

    
223
    for(int i=0; i<layers-1; i++, index++)
224
      {
225
      z -= 1;
226
      centers[index][0] = x;
227
      centers[index][1] = height;
228
      centers[index][2] = z;
229
      }
230

    
231
    x += 0.5f;
232
    z -= 0.5f;
233

    
234
    for(int i=0; i<layers-1; i++, index++)
235
      {
236
      x -= 1;
237
      centers[index][0] = x;
238
      centers[index][1] = height;
239
      centers[index][2] = z;
240
      }
241

    
242
    x -= 0.5f;
243
    z -= 0.5f;
244

    
245
    for(int i=0; i<layers-1; i++, index++)
246
      {
247
      z += 1;
248
      centers[index][0] = x;
249
      centers[index][1] = height;
250
      centers[index][2] = z;
251
      }
252

    
253
    x -= 0.5f;
254
    z += 0.5f;
255

    
256
    for(int i=0; i<layers-1; i++, index++)
257
      {
258
      x += 1;
259
      centers[index][0] = x;
260
      centers[index][1] = height;
261
      centers[index][2] = z;
262
      }
263

    
264
    return index;
265
    }
266

    
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

    
269
  public float[][] getCubitPositions(int[] numLayers)
270
    {
271
    if( mPosition==null )
272
      {
273
      int layers = numLayers[0];
274
      int numO = getNumOctahedrons(layers);
275
      int numT = getNumTetrahedrons(layers);
276
      int index = 0;
277
      float height = 0.0f;
278

    
279
      mPosition = new float[numO+numT][3];
280

    
281
      index = createOctaPositions(mPosition,index,layers,height);
282

    
283
      for(int i=layers-1; i>0; i--)
284
        {
285
        height += SQ2/2;
286
        index = createOctaPositions(mPosition,index,i,+height);
287
        index = createOctaPositions(mPosition,index,i,-height);
288
        }
289

    
290
      height = SQ2/4;
291

    
292
      for(int i=layers; i>1; i--)
293
        {
294
        index = createTetraPositions(mPosition,index,i,+height);
295
        index = createTetraPositions(mPosition,index,i,-height);
296
        height += SQ2/2;
297
        }
298
      }
299

    
300
    return mPosition;
301
    }
302

    
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

    
305
  public Static4D getCubitQuats(int cubit, int[] numLayers)
306
    {
307
    int numL = numLayers[0];
308
    int numO = getNumOctahedrons(numL);
309

    
310
    if( cubit<numO ) return mObjectQuats[0];
311

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

    
324
    return null;
325
    }
326

    
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328

    
329
  private int retFaceTetraBelongsTo(int tetra, int numLayers)
330
    {
331
    if( mTetraToFaceMap==null ) mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4};
332

    
333
    for(int i=numLayers-1; i>0; i--)
334
      {
335
      if( tetra < 8*i ) return mTetraToFaceMap[tetra/i];
336
      tetra -= 8*i;
337
      }
338

    
339
    return -1;
340
    }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343

    
344
  public ObjectShape getObjectShape(int variant)
345
    {
346
    if( variant==0 )
347
      {
348
      float[][] vertices =
349
          {
350
             { 0.5f,  0.0f, 0.5f},
351
             { 0.5f,  0.0f,-0.5f},
352
             {-0.5f,  0.0f,-0.5f},
353
             {-0.5f,  0.0f, 0.5f},
354
             { 0.0f, SQ2/2, 0.0f},
355
             { 0.0f,-SQ2/2, 0.0f}
356
          };
357

    
358
      int[][] indices =
359
          {
360
             {3,0,4},
361
             {0,1,4},
362
             {1,2,4},
363
             {2,3,4},
364
             {5,0,3},
365
             {5,1,0},
366
             {5,2,1},
367
             {5,3,2}
368
          };
369

    
370
      return new ObjectShape(vertices, indices);
371
      }
372
    else
373
      {
374
      float[][] vertices= { {-0.5f, SQ2/4, 0.0f}, { 0.5f, SQ2/4, 0.0f}, { 0.0f,-SQ2/4, 0.5f}, { 0.0f,-SQ2/4,-0.5f} };
375
      int[][] indices   = { {2,1,0}, {2,3,1}, {3,2,0}, {3,0,1} };
376
      return new ObjectShape(vertices, indices);
377
      }
378
    }
379

    
380
///////////////////////////////////////////////////////////////////////////////////////////////////
381

    
382
  public ObjectFaceShape getObjectFaceShape(int variant)
383
    {
384
    int numL = getNumLayers()[0];
385
    int N = numL>3 ? 5:6;
386
    int E = numL>2 ? (numL>3 ? 0:1) : 2;
387
    float height = isInIconMode() ? 0.001f : 0.05f;
388

    
389
    if( variant==0 )
390
      {
391
      float[][] bands     = { {height,20,0.5f,0.8f,N,E,E} };
392
      int[] bandIndices   = { 0,0,0,0,0,0,0,0 };
393
      float[][] corners   = { {0.04f,0.20f} };
394
      int[] cornerIndices = { 0,0,0,0,0,0 };
395
      float[][] centers   = { {0.0f, 0.0f, 0.0f} };
396
      int[] centerIndices = { 0,0,0,0,0,0 };
397
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
398
      }
399
    else
400
      {
401
      float[][] bands     = { {height,35,0.5f,0.8f,N,E,E} };
402
      int[] bandIndices   = { 0,0,0,0 };
403
      float[][] corners   = { {0.08f,0.15f} };
404
      int[] cornerIndices = { 0,0,0,0 };
405
      float[][] centers   = { {0.0f, 0.0f, 0.0f} };
406
      int[] centerIndices = { 0,0,0,0 };
407
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
408
      }
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

    
413
  public int getNumCubitVariants(int[] numLayers)
414
    {
415
    return 2;
416
    }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419

    
420
  public int getCubitVariant(int cubit, int[] numLayers)
421
    {
422
    return cubit<getNumOctahedrons(numLayers[0]) ? 0 : 1;
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

    
427
  public float getStickerRadius()
428
    {
429
    return 0.08f;
430
    }
431

    
432
///////////////////////////////////////////////////////////////////////////////////////////////////
433

    
434
  public float getStickerStroke()
435
    {
436
    float stroke = 0.08f;
437

    
438
    if( isInIconMode() )
439
      {
440
      int[] numLayers = getNumLayers();
441

    
442
      switch(numLayers[0])
443
        {
444
        case 2: stroke*=1.4f; break;
445
        case 3: stroke*=2.0f; break;
446
        case 4: stroke*=2.1f; break;
447
        default:stroke*=2.2f; break;
448
        }
449
      }
450

    
451
    return stroke;
452
    }
453

    
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455

    
456
  public float[][] getStickerAngles()
457
    {
458
    return null;
459
    }
460

    
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462
// PUBLIC API
463

    
464
  public Static3D[] getRotationAxis()
465
    {
466
    return ROT_AXIS;
467
    }
468

    
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470

    
471
  public int[][] getBasicAngles()
472
    {
473
    if( mBasicAngle ==null )
474
      {
475
      int num = getNumLayers()[0];
476
      int[] tmp = new int[num];
477
      for(int i=0; i<num; i++) tmp[i] = 3;
478
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
479
      }
480
    return mBasicAngle;
481
    }
482

    
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484

    
485
  public String getShortName()
486
    {
487
    switch(getNumLayers()[0])
488
      {
489
      case 2: return ObjectType.DIAM_2.name();
490
      case 3: return ObjectType.DIAM_3.name();
491
      case 4: return ObjectType.DIAM_4.name();
492
      }
493

    
494
    return ObjectType.DIAM_2.name();
495
    }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498

    
499
  public ObjectSignature getSignature()
500
    {
501
    switch(getNumLayers()[0])
502
      {
503
      case 2: return new ObjectSignature(ObjectType.DIAM_2);
504
      case 3: return new ObjectSignature(ObjectType.DIAM_3);
505
      case 4: return new ObjectSignature(ObjectType.DIAM_4);
506
      }
507

    
508
    return null;
509
    }
510

    
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512

    
513
  public String getObjectName()
514
    {
515
    switch(getNumLayers()[0])
516
      {
517
      case 2: return "Skewb Diamond";
518
      case 3: return "Face Turning Octahedron";
519
      case 4: return "Master Face Turning Octahedron";
520
      }
521

    
522
    return "Skewb Diamond";
523
    }
524

    
525
///////////////////////////////////////////////////////////////////////////////////////////////////
526

    
527
  public String getInventor()
528
    {
529
    switch(getNumLayers()[0])
530
      {
531
      case 2: return "Uwe Meffert";
532
      case 3: return "David Pitcher";
533
      case 4: return "Timur Evbatyrov";
534
      }
535

    
536
    return "Uwe Meffert";
537
    }
538

    
539
///////////////////////////////////////////////////////////////////////////////////////////////////
540

    
541
  public int getYearOfInvention()
542
    {
543
    switch(getNumLayers()[0])
544
      {
545
      case 2: return 1984;
546
      case 3: return 2003;
547
      case 4: return 2011;
548
      }
549
    return 1984;
550
    }
551

    
552
///////////////////////////////////////////////////////////////////////////////////////////////////
553

    
554
  public int getComplexity()
555
    {
556
    switch(getNumLayers()[0])
557
      {
558
      case 2: return 1;
559
      case 3: return 3;
560
      case 4: return 4;
561
      }
562

    
563
    return 0;
564
    }
565

    
566
///////////////////////////////////////////////////////////////////////////////////////////////////
567

    
568
  public String[][] getTutorials()
569
    {
570
    int[] numLayers = getNumLayers();
571

    
572
    switch(numLayers[0])
573
      {
574
      case 2: return new String[][] {
575
                          {"gb","R2wrbJJ3izM","How to Solve a Skewb Diamond","Dr. Penguin^3"},
576
                          {"es","2RCusYQdYYE","Como resolver Skewb Diamond","Tutoriales Rubik"},
577
                          {"ru","k8B6RFcNoGw","Как собрать Skewb Diamond","Алексей Ярыгин"},
578
                          {"fr","tqbkgwNcZCE","Comment résoudre le Skewb Diamond","Valentino Cube"},
579
                          {"de","6ewzrCOnZfg","Octagon lösen","JamesKnopf"},
580
                          {"pl","61_Z4TpLMBc","Diamond Skewb TUTORIAL PL","MrUk"},
581
                          {"br","UapwpXMYtH4","Como resolver o Octaedro Diamond","Rafael Cinoto"},
582
                          {"kr","hVBSlfHVTME","공식 하나만 사용 - 다이아몬드 스큐브","Denzel Washington"},
583
                         };
584
      case 3: return new String[][] {
585
                          {"gb","n_mBSUDLUZw","Face Turning Octahedron Tutorial","SuperAntoniovivaldi"},
586
                          {"es","ogf0t6fGxZI","FTO - Tutorial en español","Gadi Rubik"},
587
                          {"ru","VXCjk0bVRoA","Как собрать Face Turning Octahedron","Алексей Ярыгин"},
588
                          {"de","6bO0AcwY5K8","Face Turning Octahedron - Tutorial","GerCubing"},
589
                          {"pl","huWg-ZfP-KY","Octahedron cube TUTORIAL PL","MrUk"},
590
                          {"br","WN3BoP4EbvM","Como resolver o octaedro 3x3 1/3","Rafael Cinoto"},
591
                          {"br","4zFlfANOliE","Como resolver o octaedro 3x3 2/3","Rafael Cinoto"},
592
                          {"br","6OvNzoHk7RU","Como resolver o octaedro 3x3 3/3","Rafael Cinoto"},
593
                          {"vn","KzGQ-mVRsss","Tutorial N.43 - FTO","Duy Thích Rubik"},
594
                         };
595
      case 4: return new String[][] {
596
                          {"gb","3GJkySk5zeQ","Master Face Turning Octahedron","SuperAntoniovivaldi"},
597
                          {"gb","zW_1htxy52k","Master FTO Tutorial","Michele Regano"},
598
                          {"es","3K8XL9SBSvs","Tutorial Master FTO de Mf8","Robert Cubes"},
599
                          {"ru","0CRwhZ2JNJA","Как собрать Master FTO","Алексей Ярыгин"},
600
                          {"vn","4XdeuGYDCJo","Tutorial N.141 - Master FTO","Duy Thích Rubik"},
601
                         };
602
      }
603
    return null;
604
    }
605
}
(8-8/36)