Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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_TETRAHEDRON;
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.TouchControlTetrahedron;
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.ShapeTetrahedron;
36

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

    
39
public class TwistyPyraminx extends ShapeTetrahedron
40
{
41
  static final Static3D[] ROT_AXIS = new Static3D[]
42
         {
43
           new Static3D(     0,-SQ3/3,-SQ6/3),
44
           new Static3D(     0,-SQ3/3,+SQ6/3),
45
           new Static3D(+SQ6/3,+SQ3/3,     0),
46
           new Static3D(-SQ6/3,+SQ3/3,     0),
47
         };
48

    
49
  private ScrambleState[] mStates;
50
  private int[][] mBasicAngle;
51
  private float[][] mCuts;
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

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

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
  public ScrambleState[] getScrambleStates()
63
    {
64
    if( mStates==null )
65
      {
66
      int[] numLayers = getNumLayers();
67
      initializeScrambleStates(numLayers[0]);
68
      }
69

    
70
    return mStates;
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  private int[][] generateState(int start, int end)
76
    {
77
    int len = end-start+1;
78
    int[] tmp = new int[6*len];
79

    
80
    for(int i=0; i<len; i++)
81
      {
82
      tmp[6*i  ] = start;
83
      tmp[6*i+1] = -1;
84
      tmp[6*i+2] = start;
85
      tmp[6*i+3] = start;
86
      tmp[6*i+4] = +1;
87
      tmp[6*i+5] = start;
88

    
89
      start++;
90
      }
91

    
92
    return new int[][] {tmp,tmp,tmp,tmp};
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  private void initializeScrambleStates(int numLayers)
98
    {
99
    mStates = new ScrambleState[numLayers];
100

    
101
    for(int i=0; i<numLayers-1; i++)
102
      {
103
      mStates[i] = new ScrambleState( generateState(0,numLayers-1-i) );
104
      }
105

    
106
    mStates[numLayers-1] = new ScrambleState( generateState(1,numLayers-2) );
107
    }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
  private void addTetrahedralLattice(int size, int index, float[][] pos)
112
    {
113
    final float DX = 1.0f;
114
    final float DY = SQ2/2;
115
    final float DZ = 1.0f;
116

    
117
    float startX = 0.0f;
118
    float startY =-DY*(size-1)/2;
119
    float startZ = DZ*(size-1)/2;
120

    
121
    for(int layer=0; layer<size; layer++)
122
      {
123
      float currX = startX;
124
      float currY = startY;
125

    
126
      for(int x=0; x<layer+1; x++)
127
        {
128
        float currZ = startZ;
129

    
130
        for(int z=0; z<size-layer; z++)
131
          {
132
          pos[index] = new float[] {currX,currY,currZ};
133
          index++;
134
          currZ -= DZ;
135
          }
136

    
137
        currX += DX;
138
        }
139

    
140
      startX-=DX/2;
141
      startY+=DY;
142
      startZ-=DZ/2;
143
      }
144
    }
145

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

    
148
  private int getNumOctahedrons(int numLayers)
149
    {
150
    return (numLayers-1)*numLayers*(numLayers+1)/6;
151
    }
152

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

    
155
  public float[][] getCuts(int[] numLayers)
156
    {
157
    if( mCuts==null )
158
      {
159
      int numL = numLayers[0];
160
      mCuts = new float[4][numL-1];
161

    
162
      for(int i=0; i<numL-1; i++)
163
        {
164
        float cut = (1.0f+i-numL/4.0f)*(SQ6/3);
165
        mCuts[0][i] = cut;
166
        mCuts[1][i] = cut;
167
        mCuts[2][i] = cut;
168
        mCuts[3][i] = cut;
169
        }
170
      }
171

    
172
    return mCuts;
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

    
177
  public boolean[][] getLayerRotatable(int[] numLayers)
178
    {
179
    int numAxis = ROT_AXIS.length;
180
    boolean[][] layerRotatable = new boolean[numAxis][];
181

    
182
    for(int i=0; i<numAxis; i++)
183
      {
184
      layerRotatable[i] = new boolean[numLayers[i]];
185
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
186
      }
187

    
188
    return layerRotatable;
189
    }
190

    
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

    
193
  public int getTouchControlType()
194
    {
195
    return TC_TETRAHEDRON;
196
    }
197

    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

    
200
  public int getTouchControlSplit()
201
    {
202
    return TYPE_NOT_SPLIT;
203
    }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

    
207
  public int[][][] getEnabled()
208
    {
209
    return new int[][][] { {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}} };
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  public float[] getDist3D(int[] numLayers)
215
    {
216
    return TouchControlTetrahedron.D3D;
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
  public Static3D[] getFaceAxis()
222
    {
223
    return TouchControlTetrahedron.FACE_AXIS;
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227
// there are (n^3-n)/6 octahedrons and ((n+1)^3 - (n+1))/6 tetrahedrons
228

    
229
  public float[][] getCubitPositions(int[] numLayers)
230
    {
231
    int numL = numLayers[0];
232
    int numOcta = (numL-1)*numL*(numL+1)/6;
233
    int numTetra= numL*(numL+1)*(numL+2)/6;
234
    float[][] ret = new float[numOcta+numTetra][];
235

    
236
    addTetrahedralLattice(numL-1,      0,ret);
237
    addTetrahedralLattice(numL  ,numOcta,ret);
238

    
239
    return ret;
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
  public Static4D getCubitQuats(int cubit, int[] numLayers)
245
    {
246
    return mObjectQuats[0];
247
    }
248

    
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

    
251
  public ObjectShape getObjectShape(int variant)
252
    {
253
    if( variant==0 )
254
      {
255
      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} };
256
      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} };
257
      return new ObjectShape(vertices, indices);
258
      }
259
    else
260
      {
261
      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} };
262
      int[][] indices   = { {2,1,0},{3,0,1},{3,2,0},{2,3,1} };
263
      return new ObjectShape(vertices, indices);
264
      }
265
    }
266

    
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

    
269
  public ObjectFaceShape getObjectFaceShape(int variant)
270
    {
271
    int numL = getNumLayers()[0];
272
    float height = isInIconMode() ? 0.001f : 0.05f;
273

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

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

    
302
  public int getNumCubitVariants(int[] numLayers)
303
    {
304
    return 2;
305
    }
306

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

    
309
  public int getCubitVariant(int cubit, int[] numLayers)
310
    {
311
    return cubit<getNumOctahedrons(numLayers[0]) ? 0:1;
312
    }
313

    
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315

    
316
  public float getStickerRadius()
317
    {
318
    return 0.08f;
319
    }
320

    
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322

    
323
  public float getStickerStroke()
324
    {
325
    float stroke = 0.08f;
326

    
327
    if( isInIconMode() )
328
      {
329
      int[] numLayers = getNumLayers();
330

    
331
      switch(numLayers[0])
332
        {
333
        case 2: stroke*=1.0f; break;
334
        case 3: stroke*=1.4f; break;
335
        case 4: stroke*=1.7f; break;
336
        default:stroke*=1.9f; break;
337
        }
338
      }
339

    
340
    return stroke;
341
    }
342

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344

    
345
  public float[][] getStickerAngles()
346
    {
347
    return null;
348
    }
349

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351
// public API
352

    
353
  public Static3D[] getRotationAxis()
354
    {
355
    return ROT_AXIS;
356
    }
357

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

    
360
  public int[][] getBasicAngles()
361
    {
362
    if( mBasicAngle ==null )
363
      {
364
      int num = getNumLayers()[0];
365
      int[] tmp = new int[num];
366
      for(int i=0; i<num; i++) tmp[i] = 3;
367
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
368
      }
369

    
370
    return mBasicAngle;
371
    }
372

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

    
375
  public String getShortName()
376
    {
377
    switch(getNumLayers()[0])
378
      {
379
      case 3: return ObjectType.PYRA_3.name();
380
      case 4: return ObjectType.PYRA_4.name();
381
      case 5: return ObjectType.PYRA_5.name();
382
      }
383

    
384
    return ObjectType.PYRA_3.name();
385
    }
386

    
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388

    
389
  public long getSignature()
390
    {
391
    switch(getNumLayers()[0])
392
      {
393
      case 3: return ObjectType.PYRA_3.ordinal();
394
      case 4: return ObjectType.PYRA_4.ordinal();
395
      case 5: return ObjectType.PYRA_5.ordinal();
396
      }
397

    
398
    return ObjectType.PYRA_3.ordinal();
399
    }
400

    
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402

    
403
  public String getObjectName()
404
    {
405
    switch(getNumLayers()[0])
406
      {
407
      case 3: return "Pyraminx";
408
      case 4: return "Master Pyraminx";
409
      case 5: return "Professor's Pyraminx";
410
      }
411
    return "Pyraminx";
412
    }
413

    
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415

    
416
  public String getInventor()
417
    {
418
    switch(getNumLayers()[0])
419
      {
420
      case 3: return "Uwe Meffert";
421
      case 4: return "Katsuhiko Okamoto";
422
      case 5: return "Timur Evbatyrov";
423
      }
424
    return "Uwe Meffert";
425
    }
426

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

    
429
  public int getYearOfInvention()
430
    {
431
    switch(getNumLayers()[0])
432
      {
433
      case 3: return 1970;
434
      case 4: return 2002;
435
      case 5: return 2011;
436
      }
437
    return 1970;
438
    }
439

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

    
442
  public int getComplexity()
443
    {
444
    switch(getNumLayers()[0])
445
      {
446
      case 3: return 1;
447
      case 4: return 2;
448
      case 5: return 3;
449
      }
450
    return 4;
451
    }
452

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

    
455
  public String[][] getTutorials()
456
    {
457
    int[] numLayers = getNumLayers();
458

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