Project

General

Profile

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

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

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.main.InitData;
33
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
34
import org.distorted.objectlib.main.ObjectType;
35
import org.distorted.objectlib.helpers.ObjectShape;
36
import org.distorted.objectlib.scrambling.ScrambleState;
37
import org.distorted.objectlib.main.ShapeOctahedron;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

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

    
52
  private ScrambleState[] mStates;
53
  private int[][] mBasicAngle;
54
  private float[][] mCuts;
55
  private int[] mTetraToFaceMap;
56
  private float[][] mPosition;
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
  public TwistyDiamond(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
61
    {
62
    super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

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

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

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

    
88
    return mStates;
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

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

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

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

    
113
    return mCuts;
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

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

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

    
129
    return layerRotatable;
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

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

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

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

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

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

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

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

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

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

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

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

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

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

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

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

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

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

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

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

    
223
    return index;
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

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

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

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

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

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

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

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

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

    
274
    return index;
275
    }
276

    
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

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

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

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

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

    
300
      height = SQ2/4;
301

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

    
310
    return mPosition;
311
    }
312

    
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314

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

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

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

    
334
    return null;
335
    }
336

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

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

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

    
349
    return -1;
350
    }
351

    
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

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

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

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

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

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

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

    
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422

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

    
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429

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

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

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

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

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

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

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

    
461
    return stroke;
462
    }
463

    
464
///////////////////////////////////////////////////////////////////////////////////////////////////
465

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

    
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472
// PUBLIC API
473

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

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

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

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

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

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

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

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

    
518
    return null;
519
    }
520

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

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

    
532
    return "Skewb Diamond";
533
    }
534

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

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

    
546
    return "Uwe Meffert";
547
    }
548

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

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

    
562
///////////////////////////////////////////////////////////////////////////////////////////////////
563

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

    
573
    return 0;
574
    }
575

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

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

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