Project

General

Profile

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

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

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
  private float[][] mPosition;
55

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

    
58
  public TwistyDiamond(int[] numL, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
59
    {
60
    super(numL, meshState, iconMode, 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
    if( mPosition==null )
280
      {
281
      int layers = numLayers[0];
282
      int numO = getNumOctahedrons(layers);
283
      int numT = getNumTetrahedrons(layers);
284
      int index = 0;
285
      float height = 0.0f;
286

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

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

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

    
298
      height = SQ2/4;
299

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

    
308
    return mPosition;
309
    }
310

    
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312

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

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

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

    
332
    return null;
333
    }
334

    
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336

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

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

    
347
    return -1;
348
    }
349

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351

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

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

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

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

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

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

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

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

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

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

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

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

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

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

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

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

    
459
    return stroke;
460
    }
461

    
462
///////////////////////////////////////////////////////////////////////////////////////////////////
463

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

    
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470
// PUBLIC API
471

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

    
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478

    
479
  public int[] getBasicAngles()
480
    {
481
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
482
    return mBasicAngle;
483
    }
484

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486

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

    
496
    return ObjectType.DIAM_2.name();
497
    }
498

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

    
501
  public long getSignature()
502
    {
503
    switch(getNumLayers()[0])
504
      {
505
      case 2: return ObjectType.DIAM_2.ordinal();
506
      case 3: return ObjectType.DIAM_3.ordinal();
507
      case 4: return ObjectType.DIAM_4.ordinal();
508
      }
509

    
510
    return ObjectType.DIAM_2.ordinal();
511
    }
512

    
513
///////////////////////////////////////////////////////////////////////////////////////////////////
514

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

    
524
    return "Skewb Diamond";
525
    }
526

    
527
///////////////////////////////////////////////////////////////////////////////////////////////////
528

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

    
538
    return "Uwe Meffert";
539
    }
540

    
541
///////////////////////////////////////////////////////////////////////////////////////////////////
542

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

    
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555

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

    
565
    return 0;
566
    }
567

    
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569

    
570
  public String[][] getTutorials()
571
    {
572
    int[] numLayers = getNumLayers();
573

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