Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyPyraminx.java @ 5d09301e

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.objects;
11

    
12
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_TETRAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
14

    
15
import java.io.InputStream;
16

    
17
import org.distorted.library.type.Static3D;
18
import org.distorted.library.type.Static4D;
19

    
20
import org.distorted.objectlib.helpers.ObjectFaceShape;
21
import org.distorted.objectlib.helpers.ObjectSignature;
22
import org.distorted.objectlib.main.InitData;
23
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
24
import org.distorted.objectlib.main.ObjectType;
25
import org.distorted.objectlib.helpers.ObjectShape;
26
import org.distorted.objectlib.scrambling.ScrambleState;
27
import org.distorted.objectlib.main.ShapeTetrahedron;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class TwistyPyraminx extends ShapeTetrahedron
32
{
33
  static final Static3D[] ROT_AXIS = new Static3D[]
34
         {
35
           new Static3D(     0,-SQ3/3,-SQ6/3),
36
           new Static3D(     0,-SQ3/3,+SQ6/3),
37
           new Static3D(+SQ6/3,+SQ3/3,     0),
38
           new Static3D(-SQ6/3,+SQ3/3,     0),
39
         };
40

    
41
  private ScrambleState[] mStates;
42
  private int[][] mBasicAngle;
43
  private float[][] mCuts;
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
  public TwistyPyraminx(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
48
    {
49
    super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
50
    }
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  public ScrambleState[] getScrambleStates()
55
    {
56
    if( mStates==null )
57
      {
58
      int[] numLayers = getNumLayers();
59
      initializeScrambleStates(numLayers[0]);
60
      }
61

    
62
    return mStates;
63
    }
64

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

    
67
  private int[][] generateState(int start, int end)
68
    {
69
    int len = end-start+1;
70
    int[] tmp = new int[6*len];
71

    
72
    for(int i=0; i<len; i++)
73
      {
74
      tmp[6*i  ] = start;
75
      tmp[6*i+1] = -1;
76
      tmp[6*i+2] = start;
77
      tmp[6*i+3] = start;
78
      tmp[6*i+4] = +1;
79
      tmp[6*i+5] = start;
80

    
81
      start++;
82
      }
83

    
84
    return new int[][] {tmp,tmp,tmp,tmp};
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  private void initializeScrambleStates(int numLayers)
90
    {
91
    mStates = new ScrambleState[numLayers];
92

    
93
    for(int i=0; i<numLayers-1; i++)
94
      {
95
      mStates[i] = new ScrambleState( generateState(0,numLayers-1-i) );
96
      }
97

    
98
    mStates[numLayers-1] = new ScrambleState( generateState(1,numLayers-2) );
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  private void addTetrahedralLattice(int size, int index, float[][] pos)
104
    {
105
    final float DX = 1.0f;
106
    final float DY = SQ2/2;
107
    final float DZ = 1.0f;
108

    
109
    float startX = 0.0f;
110
    float startY =-DY*(size-1)/2;
111
    float startZ = DZ*(size-1)/2;
112

    
113
    for(int layer=0; layer<size; layer++)
114
      {
115
      float currX = startX;
116
      float currY = startY;
117

    
118
      for(int x=0; x<layer+1; x++)
119
        {
120
        float currZ = startZ;
121

    
122
        for(int z=0; z<size-layer; z++)
123
          {
124
          pos[index] = new float[] {currX,currY,currZ};
125
          index++;
126
          currZ -= DZ;
127
          }
128

    
129
        currX += DX;
130
        }
131

    
132
      startX-=DX/2;
133
      startY+=DY;
134
      startZ-=DZ/2;
135
      }
136
    }
137

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

    
140
  private int getNumOctahedrons(int numLayers)
141
    {
142
    return (numLayers-1)*numLayers*(numLayers+1)/6;
143
    }
144

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

    
147
  public float[][] getCuts(int[] numLayers)
148
    {
149
    if( mCuts==null )
150
      {
151
      int numL = numLayers[0];
152
      mCuts = new float[4][numL-1];
153

    
154
      for(int i=0; i<numL-1; i++)
155
        {
156
        float cut = (1.0f+i-numL/4.0f)*(SQ6/3);
157
        mCuts[0][i] = cut;
158
        mCuts[1][i] = cut;
159
        mCuts[2][i] = cut;
160
        mCuts[3][i] = cut;
161
        }
162
      }
163

    
164
    return mCuts;
165
    }
166

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

    
169
  public boolean[][] getLayerRotatable(int[] numLayers)
170
    {
171
    int numAxis = ROT_AXIS.length;
172
    boolean[][] layerRotatable = new boolean[numAxis][];
173

    
174
    for(int i=0; i<numAxis; i++)
175
      {
176
      layerRotatable[i] = new boolean[numLayers[i]];
177
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
178
      }
179

    
180
    return layerRotatable;
181
    }
182

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

    
185
  public int getTouchControlType()
186
    {
187
    return TC_TETRAHEDRON;
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  public int getTouchControlSplit()
193
    {
194
    return TYPE_NOT_SPLIT;
195
    }
196

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

    
199
  public int[][][] getEnabled()
200
    {
201
    return new int[][][] { {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}} };
202
    }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
  public float[] getDist3D(int[] numLayers)
207
    {
208
    return TouchControlTetrahedron.D3D;
209
    }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

    
213
  public Static3D[] getFaceAxis()
214
    {
215
    return TouchControlTetrahedron.FACE_AXIS;
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
// there are (n^3-n)/6 octahedrons and ((n+1)^3 - (n+1))/6 tetrahedrons
220

    
221
  public float[][] getCubitPositions(int[] numLayers)
222
    {
223
    int numL = numLayers[0];
224
    int numOcta = (numL-1)*numL*(numL+1)/6;
225
    int numTetra= numL*(numL+1)*(numL+2)/6;
226
    float[][] ret = new float[numOcta+numTetra][];
227

    
228
    addTetrahedralLattice(numL-1,      0,ret);
229
    addTetrahedralLattice(numL  ,numOcta,ret);
230

    
231
    return ret;
232
    }
233

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

    
236
  public Static4D getCubitQuats(int cubit, int[] numLayers)
237
    {
238
    return mObjectQuats[0];
239
    }
240

    
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

    
243
  public ObjectShape getObjectShape(int variant)
244
    {
245
    if( variant==0 )
246
      {
247
      float[][] vertices= { { 0.5f,0.0f,0.5f},{ 0.5f,0.0f,-0.5f},{-0.5f,0.0f,-0.5f},{-0.5f,0.0f,0.5f},{ 0.0f,SQ2/2,0.0f},{ 0.0f,-SQ2/2,0.0f} };
248
      int[][] indices   = { {3,0,4},{0,1,4},{1,2,4},{2,3,4},{5,0,3},{5,1,0},{5,2,1},{5,3,2} };
249
      return new ObjectShape(vertices, indices);
250
      }
251
    else
252
      {
253
      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} };
254
      int[][] indices   = { {2,1,0},{3,0,1},{3,2,0},{2,3,1} };
255
      return new ObjectShape(vertices, indices);
256
      }
257
    }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

    
261
  public ObjectFaceShape getObjectFaceShape(int variant)
262
    {
263
    int numL = getNumLayers()[0];
264
    float height = isInIconMode() ? 0.001f : 0.05f;
265

    
266
    if( variant==0 )
267
      {
268
      int N = numL==3? 6 : 5;
269
      int E = numL==3? 2 : 1;
270
      float[][] bands     = { {height,20,0.5f,0.8f,N,E,E} };
271
      int[] bandIndices   = { 0,0,0,0,0,0,0,0 };
272
      float[][] corners   = { {0.04f,0.20f} };
273
      int[] cornerIndices = { 0,0,0,0,0,0 };
274
      float[][] centers   = { {0.0f, 0.0f, 0.0f} };
275
      int[] centerIndices = { 0,0,0,0,0,0 };
276
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
277
      }
278
    else
279
      {
280
      int N = numL==3? 6 : 5;
281
      int E = numL==3? 2 : 1;
282
      float[][] bands     = { {height,35,0.5f,0.8f,N,E,E} };
283
      int[] bandIndices   = { 0,0,0,0 };
284
      float[][] corners   = { {0.06f,0.15f} };
285
      int[] cornerIndices = { 0,0,0,0 };
286
      float[][] centers   = { {0.0f, 0.0f, 0.0f} };
287
      int[] centerIndices = { 0,0,0,0 };
288
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
289
      }
290
    }
291

    
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

    
294
  public int getNumCubitVariants(int[] numLayers)
295
    {
296
    return 2;
297
    }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

    
301
  public int getCubitVariant(int cubit, int[] numLayers)
302
    {
303
    return cubit<getNumOctahedrons(numLayers[0]) ? 0:1;
304
    }
305

    
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307

    
308
  public float getStickerRadius()
309
    {
310
    return 0.08f;
311
    }
312

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

    
315
  public float getStickerStroke()
316
    {
317
    float stroke = 0.08f;
318

    
319
    if( isInIconMode() )
320
      {
321
      int[] numLayers = getNumLayers();
322

    
323
      switch(numLayers[0])
324
        {
325
        case 2: stroke*=1.0f; break;
326
        case 3: stroke*=1.4f; break;
327
        case 4: stroke*=1.7f; break;
328
        default:stroke*=1.9f; break;
329
        }
330
      }
331

    
332
    return stroke;
333
    }
334

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

    
337
  public float[][] getStickerAngles()
338
    {
339
    return null;
340
    }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343
// public API
344

    
345
  public Static3D[] getRotationAxis()
346
    {
347
    return ROT_AXIS;
348
    }
349

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

    
352
  public int[][] getBasicAngles()
353
    {
354
    if( mBasicAngle ==null )
355
      {
356
      int num = getNumLayers()[0];
357
      int[] tmp = new int[num];
358
      for(int i=0; i<num; i++) tmp[i] = 3;
359
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
360
      }
361

    
362
    return mBasicAngle;
363
    }
364

    
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366

    
367
  public String getShortName()
368
    {
369
    switch(getNumLayers()[0])
370
      {
371
      case 3: return ObjectType.PYRA_3.name();
372
      case 4: return ObjectType.PYRA_4.name();
373
      case 5: return ObjectType.PYRA_5.name();
374
      }
375

    
376
    return ObjectType.PYRA_3.name();
377
    }
378

    
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

    
381
  public ObjectSignature getSignature()
382
    {
383
    switch(getNumLayers()[0])
384
      {
385
      case 3: return new ObjectSignature(ObjectType.PYRA_3);
386
      case 4: return new ObjectSignature(ObjectType.PYRA_4);
387
      case 5: return new ObjectSignature(ObjectType.PYRA_5);
388
      }
389

    
390
    return null;
391
    }
392

    
393
///////////////////////////////////////////////////////////////////////////////////////////////////
394

    
395
  public String getObjectName()
396
    {
397
    switch(getNumLayers()[0])
398
      {
399
      case 3: return "Pyraminx";
400
      case 4: return "Master Pyraminx";
401
      case 5: return "Professor's Pyraminx";
402
      }
403
    return null;
404
    }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
  public String getInventor()
409
    {
410
    switch(getNumLayers()[0])
411
      {
412
      case 3: return "Uwe Meffert";
413
      case 4: return "Katsuhiko Okamoto";
414
      case 5: return "Timur Evbatyrov";
415
      }
416
    return null;
417
    }
418

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

    
421
  public int getYearOfInvention()
422
    {
423
    switch(getNumLayers()[0])
424
      {
425
      case 3: return 1970;
426
      case 4: return 2002;
427
      case 5: return 2011;
428
      }
429
    return 1970;
430
    }
431

    
432
///////////////////////////////////////////////////////////////////////////////////////////////////
433

    
434
  public int getComplexity()
435
    {
436
    switch(getNumLayers()[0])
437
      {
438
      case 3: return 1;
439
      case 4: return 2;
440
      case 5: return 3;
441
      }
442
    return 4;
443
    }
444

    
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446

    
447
  public String[][] getTutorials()
448
    {
449
    int[] numLayers = getNumLayers();
450

    
451
    switch(numLayers[0])
452
      {
453
      case 3: return new String[][] {
454
                          {"gb","xIQtn2qazvg","Pyraminx Layer By Layer","Z3"},
455
                          {"es","4cJJe9RAzAU","Resolver Pyraminx","Cuby"},
456
                          {"ru","F4_bhfWyVRQ","Как собрать ПИРАМИДКУ","Е Бондаренко"},
457
                          {"fr","Z2h1YI6jPes","Comment résoudre le Pyraminx","ValentinoCube"},
458
                          {"de","x_DMA8htJpY","Pyraminx lösen","Pezcraft"},
459
                          {"pl","uNpKpJfAa5I","Jak ułożyć: Pyraminx","DżoDżo"},
460
                          {"br","dtC0GNGyXqw","Como resolver o Pyraminx","Pedro Filho"},
461
                          {"kr","mO3excjvvoA","피라밍크스 맞추는 방법","iamzoone"},
462
                          {"vn","p9LUWUW5iYg","Tutorial N.4 - Pyraminx","Duy Thích Rubik"},
463
                    //    {"tw","YS3cDcP6Aro","金字塔方塊解法","1hrBLD"},
464
                         };
465
      case 4: return new String[][] {
466
                          {"gb","tGQDqDcSa6U","How to Solve the Master Pyraminx","Z3"},
467
                          {"es","74PIPm9-uPg","Resolver Master Pyraminx 4x4","Cuby"},
468
                          {"ru","-F_xJAwkobU","Как собрать Мастер Пираминкс"," Алексей Ярыгин"},
469
                          {"fr","F3gzBs7uvmw","Tuto: résoudre le Master Pyraminx","Spaghetti Cubing"},
470
                          {"de","3Q_bO7_FfAI","Master Pyraminx lösen","CubaroCubing"},
471
                          {"pl","EamwvhmHC7Q","4x4 (Master) Pyraminx PL","MrUk"},
472
                          {"br","cKql6YZ7yAg","Como resolver o Pyraminx 4x4 1/3","Rafael Cinoto"},
473
                          {"br","gtNQDPsN2Dg","Como resolver o Pyraminx 4x4 2/3","Rafael Cinoto"},
474
                          {"br","j8_-s4rd8mw","Como resolver o Pyraminx 4x4 3/3","Rafael Cinoto"},
475
                          {"kr","JlmBKaHESyY","마스터 피라밍크스 해법","주누후누"},
476
                          {"vn","AMCll82WcJY","Tutorial N.13 - Master Pyraminx","Duy Thích Rubik"},
477
                         };
478
      case 5: return new String[][] {
479
                          {"gb","2nsPEECDdN0","Professor Pyraminx Solve","RedKB"},
480
                          {"es","cSDj8OQK3TU","Tutorial del Professor Pyraminx","QBAndo"},
481
                          {"ru","gMp1tbDyDWg","Как собрать Professor Pyraminx","RBcuber"},
482
                          {"de","pCHx9bVMSgI","Professor Pyraminx Teil 1","Arvid Bollmann"},
483
                          {"de","iiNXJMVNmCM","Professor Pyraminx Teil 2","Arvid Bollmann"},
484
                          {"br","t2QJSSjNxPw","Resolver o Professor Pyraminx 1/4","Rafael Cinoto"},
485
                          {"br","mI6W6IFyVv0","Resolver o Professor Pyraminx 2/4","Rafael Cinoto"},
486
                          {"br","0HoOp6JlLSs","Resolver o Professor Pyraminx 3/4","Rafael Cinoto"},
487
                          {"br","Xg1jnCRsw_I","Resolver o Professor Pyraminx 4/4","Rafael Cinoto"},
488
                          {"vn","OHwPqp3kQdE","Professor Pyraminx làm chậm","TRẦN QUANG HÙNG"},
489
                         };
490
      }
491
    return null;
492
    }
493
}
(25-25/36)