Project

General

Profile

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

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

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.helpers.ObjectSignature;
32
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
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
  private float[][] mPosition;
56

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

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

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

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

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

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

    
87
    return mStates;
88
    }
89

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

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

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

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

    
112
    return mCuts;
113
    }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

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

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

    
128
    return layerRotatable;
129
    }
130

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

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

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

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

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

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

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

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

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

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

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

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

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

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

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

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

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

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

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

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

    
222
    return index;
223
    }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

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

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

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

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

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

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

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

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

    
273
    return index;
274
    }
275

    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

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

    
288
      mPosition = new float[numO+numT][3];
289

    
290
      index = createOctaPositions(mPosition,index,layers,height);
291

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

    
299
      height = SQ2/4;
300

    
301
      for(int i=layers; i>1; i--)
302
        {
303
        index = createTetraPositions(mPosition,index,i,+height);
304
        index = createTetraPositions(mPosition,index,i,-height);
305
        height += SQ2/2;
306
        }
307
      }
308

    
309
    return mPosition;
310
    }
311

    
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

    
314
  public Static4D getCubitQuats(int cubit, int[] numLayers)
315
    {
316
    int numL = numLayers[0];
317
    int numO = getNumOctahedrons(numL);
318

    
319
    if( cubit<numO ) return mObjectQuats[0];
320

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

    
333
    return null;
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  private int retFaceTetraBelongsTo(int tetra, int numLayers)
339
    {
340
    if( mTetraToFaceMap==null ) mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4};
341

    
342
    for(int i=numLayers-1; i>0; i--)
343
      {
344
      if( tetra < 8*i ) return mTetraToFaceMap[tetra/i];
345
      tetra -= 8*i;
346
      }
347

    
348
    return -1;
349
    }
350

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

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

    
367
      int[][] indices =
368
          {
369
             {3,0,4},
370
             {0,1,4},
371
             {1,2,4},
372
             {2,3,4},
373
             {5,0,3},
374
             {5,1,0},
375
             {5,2,1},
376
             {5,3,2}
377
          };
378

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

    
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390

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

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

    
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421

    
422
  public int getNumCubitVariants(int[] numLayers)
423
    {
424
    return 2;
425
    }
426

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

    
429
  public int getCubitVariant(int cubit, int[] numLayers)
430
    {
431
    return cubit<getNumOctahedrons(numLayers[0]) ? 0 : 1;
432
    }
433

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

    
436
  public float getStickerRadius()
437
    {
438
    return 0.08f;
439
    }
440

    
441
///////////////////////////////////////////////////////////////////////////////////////////////////
442

    
443
  public float getStickerStroke()
444
    {
445
    float stroke = 0.08f;
446

    
447
    if( isInIconMode() )
448
      {
449
      int[] numLayers = getNumLayers();
450

    
451
      switch(numLayers[0])
452
        {
453
        case 2: stroke*=1.4f; break;
454
        case 3: stroke*=2.0f; break;
455
        case 4: stroke*=2.1f; break;
456
        default:stroke*=2.2f; break;
457
        }
458
      }
459

    
460
    return stroke;
461
    }
462

    
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464

    
465
  public float[][] getStickerAngles()
466
    {
467
    return null;
468
    }
469

    
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471
// PUBLIC API
472

    
473
  public Static3D[] getRotationAxis()
474
    {
475
    return ROT_AXIS;
476
    }
477

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

    
480
  public int[][] getBasicAngles()
481
    {
482
    if( mBasicAngle ==null )
483
      {
484
      int num = getNumLayers()[0];
485
      int[] tmp = new int[num];
486
      for(int i=0; i<num; i++) tmp[i] = 3;
487
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
488
      }
489
    return mBasicAngle;
490
    }
491

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493

    
494
  public String getShortName()
495
    {
496
    switch(getNumLayers()[0])
497
      {
498
      case 2: return ObjectType.DIAM_2.name();
499
      case 3: return ObjectType.DIAM_3.name();
500
      case 4: return ObjectType.DIAM_4.name();
501
      }
502

    
503
    return ObjectType.DIAM_2.name();
504
    }
505

    
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507

    
508
  public ObjectSignature getSignature()
509
    {
510
    switch(getNumLayers()[0])
511
      {
512
      case 2: return new ObjectSignature(ObjectType.DIAM_2);
513
      case 3: return new ObjectSignature(ObjectType.DIAM_3);
514
      case 4: return new ObjectSignature(ObjectType.DIAM_4);
515
      }
516

    
517
    return null;
518
    }
519

    
520
///////////////////////////////////////////////////////////////////////////////////////////////////
521

    
522
  public String getObjectName()
523
    {
524
    switch(getNumLayers()[0])
525
      {
526
      case 2: return "Skewb Diamond";
527
      case 3: return "Face Turning Octahedron";
528
      case 4: return "Master Face Turning Octahedron";
529
      }
530

    
531
    return "Skewb Diamond";
532
    }
533

    
534
///////////////////////////////////////////////////////////////////////////////////////////////////
535

    
536
  public String getInventor()
537
    {
538
    switch(getNumLayers()[0])
539
      {
540
      case 2: return "Uwe Meffert";
541
      case 3: return "David Pitcher";
542
      case 4: return "Timur Evbatyrov";
543
      }
544

    
545
    return "Uwe Meffert";
546
    }
547

    
548
///////////////////////////////////////////////////////////////////////////////////////////////////
549

    
550
  public int getYearOfInvention()
551
    {
552
    switch(getNumLayers()[0])
553
      {
554
      case 2: return 1984;
555
      case 3: return 2003;
556
      case 4: return 2011;
557
      }
558
    return 1984;
559
    }
560

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

    
563
  public int getComplexity()
564
    {
565
    switch(getNumLayers()[0])
566
      {
567
      case 2: return 1;
568
      case 3: return 3;
569
      case 4: return 4;
570
      }
571

    
572
    return 0;
573
    }
574

    
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576

    
577
  public String[][] getTutorials()
578
    {
579
    int[] numLayers = getNumLayers();
580

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