Project

General

Profile

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

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

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

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

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

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

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

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

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

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

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

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

    
85
    return mStates;
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

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

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

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

    
110
    return mCuts;
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

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

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

    
126
    return layerRotatable;
127
    }
128

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

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

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

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

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

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

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

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

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

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

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

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

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

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

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

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

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

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

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

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

    
220
    return index;
221
    }
222

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

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

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

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

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

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

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

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

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

    
271
    return index;
272
    }
273

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

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

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

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

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

    
295
    height = SQ2/4;
296

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

    
304
    return CENTERS;
305
    }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

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

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

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

    
328
    return null;
329
    }
330

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

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

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

    
343
    return -1;
344
    }
345

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

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

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

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

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

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

    
393
    if( variant==0 )
394
      {
395
      float[][] bands     = { {height,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     = { {height,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( 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
                          {"vn","KzGQ-mVRsss","Tutorial N.43 - FTO","Duy Thích Rubik"},
592
                         };
593
      case 4: return new String[][] {
594
                          {"gb","3GJkySk5zeQ","Master Face Turning Octahedron","SuperAntoniovivaldi"},
595
                          {"gb","zW_1htxy52k","Master FTO Tutorial","Michele Regano"},
596
                          {"es","3K8XL9SBSvs","Tutorial Master FTO de Mf8","Robert Cubes"},
597
                          {"ru","0CRwhZ2JNJA","Как собрать Master FTO","Алексей Ярыгин"},
598
                          {"vn","4XdeuGYDCJo","Tutorial N.141 - Master FTO","Duy Thích Rubik"},
599
                         };
600
      }
601
    return null;
602
    }
603
}
(11-11/34)