Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.objectlib.objects;
21

    
22
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_OCTAHEDRON;
23
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
24

    
25
import java.io.InputStream;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.helpers.ObjectFaceShape;
31
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
32
import org.distorted.objectlib.main.ObjectControl;
33
import org.distorted.objectlib.main.ObjectType;
34
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.scrambling.ScrambleState;
36
import org.distorted.objectlib.main.ShapeOctahedron;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class TwistyDiamond extends ShapeOctahedron
41
{
42
  // the four rotation axis of a Diamond. Must be normalized.
43
  static final Static3D[] ROT_AXIS = new Static3D[]
44
         {
45
           new Static3D(+SQ6/3,+SQ3/3,     0),
46
           new Static3D(-SQ6/3,+SQ3/3,     0),
47
           new Static3D(     0,-SQ3/3,-SQ6/3),
48
           new Static3D(     0,-SQ3/3,+SQ6/3)
49
         };
50

    
51
  private ScrambleState[] mStates;
52
  private int[] mBasicAngle;
53
  private float[][] mCuts;
54
  private int[] mTetraToFaceMap;
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  public TwistyDiamond(int[] numL, int meshState, Static4D quat, Static3D move, float scale, InputStream stream)
59
    {
60
    super(numL, meshState, numL[0], quat, move, scale, stream);
61
    }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  public ScrambleState[] getScrambleStates()
66
    {
67
    if( mStates==null )
68
      {
69
      int[] numLayers = getNumLayers();
70
      int numL = numLayers[0];
71
      int[] tmp = new int[3*2*numL];
72

    
73
      for(int i=0; i<2*numL; i++)
74
        {
75
        tmp[3*i  ] = (i<numL) ?  i:i-numL;
76
        tmp[3*i+1] = (i%2==0) ? -1:1;
77
        tmp[3*i+2] = 0;
78
        }
79

    
80
      mStates = new ScrambleState[]
81
        {
82
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
83
        };
84
      }
85

    
86
    return mStates;
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

    
91
  public float[][] getCuts(int[] numLayers)
92
    {
93
    int numL = numLayers[0];
94
    if( numL<2 ) return null;
95

    
96
    if( mCuts==null )
97
      {
98
      mCuts = new float[4][numL-1];
99
      float cut = (SQ6/6)*(2-numL);
100

    
101
      for(int i=0; i<numL-1; i++)
102
        {
103
        mCuts[0][i] = cut;
104
        mCuts[1][i] = cut;
105
        mCuts[2][i] = cut;
106
        mCuts[3][i] = cut;
107
        cut += SQ6/3;
108
        }
109
      }
110

    
111
    return mCuts;
112
    }
113

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

    
116
  public boolean[][] getLayerRotatable(int[] numLayers)
117
    {
118
    int numAxis = ROT_AXIS.length;
119
    boolean[][] layerRotatable = new boolean[numAxis][];
120

    
121
    for(int i=0; i<numAxis; i++)
122
      {
123
      layerRotatable[i] = new boolean[numLayers[i]];
124
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
125
      }
126

    
127
    return layerRotatable;
128
    }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
  public int getTouchControlType()
133
    {
134
    return TC_OCTAHEDRON;
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  public int getTouchControlSplit()
140
    {
141
    return TYPE_NOT_SPLIT;
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

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

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
  public float[] getDist3D(int[] numLayers)
157
    {
158
    return TouchControlOctahedron.D3D;
159
    }
160

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
  public Static3D[] getFaceAxis()
164
    {
165
    return TouchControlOctahedron.FACE_AXIS;
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
  private int getNumOctahedrons(int layers)
171
    {
172
    return layers==1 ? 1 : 4*(layers-1)*(layers-1) + 2;
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

    
177
  private int getNumTetrahedrons(int layers)
178
    {
179
    return 4*layers*(layers-1);
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
  private int createOctaPositions(float[][] centers, int index, int layers, float height)
185
    {
186
    float x = (layers-1)*0.5f;
187
    float z = (layers+1)*0.5f;
188

    
189
    for(int i=0; i<layers; i++, index++)
190
      {
191
      z -= 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
      x -= 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-1; i++, index++)
206
      {
207
      z += 1;
208
      centers[index][0] = x;
209
      centers[index][1] = height;
210
      centers[index][2] = z;
211
      }
212

    
213
    for(int i=0; i<layers-2; i++, index++)
214
      {
215
      x += 1;
216
      centers[index][0] = x;
217
      centers[index][1] = height;
218
      centers[index][2] = z;
219
      }
220

    
221
    return index;
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  private int createTetraPositions(float[][] centers, int index, int layers, float height)
227
    {
228
    float x = (layers-1)*0.5f;
229
    float z =  layers*0.5f;
230

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

    
239
    x += 0.5f;
240
    z -= 0.5f;
241

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

    
250
    x -= 0.5f;
251
    z -= 0.5f;
252

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

    
261
    x -= 0.5f;
262
    z += 0.5f;
263

    
264
    for(int i=0; i<layers-1; i++, index++)
265
      {
266
      x += 1;
267
      centers[index][0] = x;
268
      centers[index][1] = height;
269
      centers[index][2] = z;
270
      }
271

    
272
    return index;
273
    }
274

    
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

    
277
  public float[][] getCubitPositions(int[] numLayers)
278
    {
279
    int layers = numLayers[0];
280
    int numO = getNumOctahedrons(layers);
281
    int numT = getNumTetrahedrons(layers);
282
    int index = 0;
283
    float height = 0.0f;
284

    
285
    float[][] CENTERS = new float[numO+numT][3];
286

    
287
    index = createOctaPositions(CENTERS,index,layers,height);
288

    
289
    for(int i=layers-1; i>0; i--)
290
      {
291
      height += SQ2/2;
292
      index = createOctaPositions(CENTERS,index,i,+height);
293
      index = createOctaPositions(CENTERS,index,i,-height);
294
      }
295

    
296
    height = SQ2/4;
297

    
298
    for(int i=layers; i>1; i--)
299
      {
300
      index = createTetraPositions(CENTERS,index,i,+height);
301
      index = createTetraPositions(CENTERS,index,i,-height);
302
      height += SQ2/2;
303
      }
304

    
305
    return CENTERS;
306
    }
307

    
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309

    
310
  public Static4D getCubitQuats(int cubit, int[] numLayers)
311
    {
312
    int numL = numLayers[0];
313
    int numO = getNumOctahedrons(numL);
314

    
315
    if( cubit<numO ) return mObjectQuats[0];
316

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

    
329
    return null;
330
    }
331

    
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

    
334
  private int retFaceTetraBelongsTo(int tetra, int numLayers)
335
    {
336
    if( mTetraToFaceMap==null ) mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4};
337

    
338
    for(int i=numLayers-1; i>0; i--)
339
      {
340
      if( tetra < 8*i ) return mTetraToFaceMap[tetra/i];
341
      tetra -= 8*i;
342
      }
343

    
344
    return -1;
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
  public ObjectShape getObjectShape(int variant)
350
    {
351
    if( variant==0 )
352
      {
353
      float[][] vertices =
354
          {
355
             { 0.5f,  0.0f, 0.5f},
356
             { 0.5f,  0.0f,-0.5f},
357
             {-0.5f,  0.0f,-0.5f},
358
             {-0.5f,  0.0f, 0.5f},
359
             { 0.0f, SQ2/2, 0.0f},
360
             { 0.0f,-SQ2/2, 0.0f}
361
          };
362

    
363
      int[][] indices =
364
          {
365
             {3,0,4},
366
             {0,1,4},
367
             {1,2,4},
368
             {2,3,4},
369
             {5,0,3},
370
             {5,1,0},
371
             {5,2,1},
372
             {5,3,2}
373
          };
374

    
375
      return new ObjectShape(vertices, indices);
376
      }
377
    else
378
      {
379
      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} };
380
      int[][] indices   = { {2,1,0}, {2,3,1}, {3,2,0}, {3,0,1} };
381
      return new ObjectShape(vertices, indices);
382
      }
383
    }
384

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386

    
387
  public ObjectFaceShape getObjectFaceShape(int variant)
388
    {
389
    int numL = getNumLayers()[0];
390
    int N = numL>3 ? 5:6;
391
    int E = numL>2 ? (numL>3 ? 0:1) : 2;
392

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

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

    
417
  public int getNumCubitVariants(int[] numLayers)
418
    {
419
    return 2;
420
    }
421

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

    
424
  public int getCubitVariant(int cubit, int[] numLayers)
425
    {
426
    return cubit<getNumOctahedrons(numLayers[0]) ? 0 : 1;
427
    }
428

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

    
431
  public float getStickerRadius()
432
    {
433
    return 0.08f;
434
    }
435

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

    
438
  public float getStickerStroke()
439
    {
440
    float stroke = 0.08f;
441

    
442
    if( ObjectControl.isInIconMode() )
443
      {
444
      int[] numLayers = getNumLayers();
445

    
446
      switch(numLayers[0])
447
        {
448
        case 2: stroke*=1.4f; break;
449
        case 3: stroke*=2.0f; break;
450
        case 4: stroke*=2.1f; break;
451
        default:stroke*=2.2f; break;
452
        }
453
      }
454

    
455
    return stroke;
456
    }
457

    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

    
460
  public float[][] getStickerAngles()
461
    {
462
    return null;
463
    }
464

    
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466
// PUBLIC API
467

    
468
  public Static3D[] getRotationAxis()
469
    {
470
    return ROT_AXIS;
471
    }
472

    
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474

    
475
  public int[] getBasicAngles()
476
    {
477
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
478
    return mBasicAngle;
479
    }
480

    
481
///////////////////////////////////////////////////////////////////////////////////////////////////
482

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

    
492
    return ObjectType.DIAM_2.name();
493
    }
494

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

    
497
  public long getSignature()
498
    {
499
    switch(getNumLayers()[0])
500
      {
501
      case 2: return ObjectType.DIAM_2.ordinal();
502
      case 3: return ObjectType.DIAM_3.ordinal();
503
      case 4: return ObjectType.DIAM_4.ordinal();
504
      }
505

    
506
    return ObjectType.DIAM_2.ordinal();
507
    }
508

    
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

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

    
520
    return "Skewb Diamond";
521
    }
522

    
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524

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

    
534
    return "Uwe Meffert";
535
    }
536

    
537
///////////////////////////////////////////////////////////////////////////////////////////////////
538

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

    
550
///////////////////////////////////////////////////////////////////////////////////////////////////
551

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

    
561
    return 0;
562
    }
563

    
564
///////////////////////////////////////////////////////////////////////////////////////////////////
565

    
566
  public String[][] getTutorials()
567
    {
568
    int[] numLayers = getNumLayers();
569

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