Project

General

Profile

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

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

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 c9c71c3f Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_TETRAHEDRON;
23
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
24 29b82486 Leszek Koltunski
25 82eb152a Leszek Koltunski
import java.io.InputStream;
26 29b82486 Leszek Koltunski
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29
30 c9c71c3f Leszek Koltunski
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
31 8592461c Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
32 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
33 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
34
import org.distorted.objectlib.helpers.ObjectSticker;
35
import org.distorted.objectlib.helpers.ScrambleState;
36 386af988 Leszek Koltunski
import org.distorted.objectlib.main.ShapeTetrahedron;
37 29b82486 Leszek Koltunski
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39
40 386af988 Leszek Koltunski
public class TwistyPyraminx extends ShapeTetrahedron
41 29b82486 Leszek Koltunski
{
42
  static final Static3D[] ROT_AXIS = new Static3D[]
43
         {
44
           new Static3D(     0,-SQ3/3,-SQ6/3),
45
           new Static3D(     0,-SQ3/3,+SQ6/3),
46
           new Static3D(+SQ6/3,+SQ3/3,     0),
47
           new Static3D(-SQ6/3,+SQ3/3,     0),
48
         };
49
50
  private ScrambleState[] mStates;
51
  private int[] mBasicAngle;
52
  private Static4D[] mQuats;
53
  private float[][] mCuts;
54
  private ObjectSticker[] mStickers;
55
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58 64c209f5 Leszek Koltunski
  public TwistyPyraminx(int[] numL, Static4D quat, Static3D move, float scale, InputStream stream)
59 29b82486 Leszek Koltunski
    {
60 64c209f5 Leszek Koltunski
    super(numL, numL[0], quat, move, scale, stream);
61 29b82486 Leszek Koltunski
    }
62
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
65 f9a81f52 Leszek Koltunski
  public ScrambleState[] getScrambleStates()
66 29b82486 Leszek Koltunski
    {
67
    if( mStates==null )
68
      {
69 a57e6870 Leszek Koltunski
      int[] numLayers = getNumLayers();
70
      initializeScrambleStates(numLayers[0]);
71 29b82486 Leszek Koltunski
      }
72
73
    return mStates;
74
    }
75
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
78
  private void initializeQuats()
79
    {
80
    mQuats = new Static4D[]
81
         {
82
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
83
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
84
         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
85
         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
86
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
87
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
88
         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
89
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
90
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
91
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
92
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
93
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
94
         };
95
    }
96
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99
  private int[][] generateState(int start, int end)
100
    {
101
    int len = end-start+1;
102
    int[] tmp = new int[6*len];
103
104
    for(int i=0; i<len; i++)
105
      {
106
      tmp[6*i  ] = start;
107
      tmp[6*i+1] = -1;
108
      tmp[6*i+2] = start;
109
      tmp[6*i+3] = start;
110
      tmp[6*i+4] = +1;
111
      tmp[6*i+5] = start;
112
113
      start++;
114
      }
115
116
    return new int[][] {tmp,tmp,tmp,tmp};
117
    }
118
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120
121
  private void initializeScrambleStates(int numLayers)
122
    {
123
    mStates = new ScrambleState[numLayers];
124
125
    for(int i=0; i<numLayers-1; i++)
126
      {
127
      mStates[i] = new ScrambleState( generateState(0,numLayers-1-i) );
128
      }
129
130
    mStates[numLayers-1] = new ScrambleState( generateState(1,numLayers-2) );
131
    }
132
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134
135 7b832206 Leszek Koltunski
  public int[] getSolvedQuats(int cubit, int[] numLayers)
136 29b82486 Leszek Koltunski
    {
137
    if( mQuats==null ) initializeQuats();
138
    int status = retCubitSolvedStatus(cubit,numLayers);
139 c9c71c3f Leszek Koltunski
    return status<0 ? null : buildSolvedQuats(TouchControlTetrahedron.FACE_AXIS[status],mQuats);
140 29b82486 Leszek Koltunski
    }
141
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
144
  private void addTetrahedralLattice(int size, int index, float[][] pos)
145
    {
146
    final float DX = 1.0f;
147
    final float DY = SQ2/2;
148
    final float DZ = 1.0f;
149
150
    float startX = 0.0f;
151
    float startY =-DY*(size-1)/2;
152
    float startZ = DZ*(size-1)/2;
153
154
    for(int layer=0; layer<size; layer++)
155
      {
156
      float currX = startX;
157
      float currY = startY;
158
159
      for(int x=0; x<layer+1; x++)
160
        {
161
        float currZ = startZ;
162
163
        for(int z=0; z<size-layer; z++)
164
          {
165
          pos[index] = new float[] {currX,currY,currZ};
166
          index++;
167
          currZ -= DZ;
168
          }
169
170
        currX += DX;
171
        }
172
173
      startX-=DX/2;
174
      startY+=DY;
175
      startZ-=DZ/2;
176
      }
177
    }
178
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180
// there are (n^3-n)/6 octahedrons and ((n+1)^3 - (n+1))/6 tetrahedrons
181
182 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
183 29b82486 Leszek Koltunski
    {
184 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
185
    int numOcta = (numL-1)*numL*(numL+1)/6;
186
    int numTetra= numL*(numL+1)*(numL+2)/6;
187 29b82486 Leszek Koltunski
    float[][] ret = new float[numOcta+numTetra][];
188
189 a57e6870 Leszek Koltunski
    addTetrahedralLattice(numL-1,      0,ret);
190
    addTetrahedralLattice(numL  ,numOcta,ret);
191 29b82486 Leszek Koltunski
192
    return ret;
193
    }
194
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196
197 1bb09f88 Leszek Koltunski
  public Static4D[] getQuats()
198 29b82486 Leszek Koltunski
    {
199
    if( mQuats==null ) initializeQuats();
200
    return mQuats;
201
    }
202
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204
205 59c20632 Leszek Koltunski
  public int getSolvedFunctionIndex()
206 29b82486 Leszek Koltunski
    {
207
    return 0;
208
    }
209
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211
212 1bb09f88 Leszek Koltunski
  public int getNumStickerTypes(int[] numLayers)
213 29b82486 Leszek Koltunski
    {
214
    return 1;
215
    }
216
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218
219 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
220 29b82486 Leszek Koltunski
    {
221
    if( mCuts==null )
222
      {
223 a57e6870 Leszek Koltunski
      int numL = numLayers[0];
224
      mCuts = new float[4][numL-1];
225 29b82486 Leszek Koltunski
226 a57e6870 Leszek Koltunski
      for(int i=0; i<numL-1; i++)
227 29b82486 Leszek Koltunski
        {
228 a57e6870 Leszek Koltunski
        float cut = (1.0f+i-numL/4.0f)*(SQ6/3);
229 29b82486 Leszek Koltunski
        mCuts[0][i] = cut;
230
        mCuts[1][i] = cut;
231
        mCuts[2][i] = cut;
232
        mCuts[3][i] = cut;
233
        }
234
      }
235
236
    return mCuts;
237
    }
238
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240
241 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
242 29b82486 Leszek Koltunski
    {
243 59c20632 Leszek Koltunski
    int numAxis = ROT_AXIS.length;
244
    boolean[][] layerRotatable = new boolean[numAxis][];
245 a57e6870 Leszek Koltunski
246 59c20632 Leszek Koltunski
    for(int i=0; i<numAxis; i++)
247
      {
248
      layerRotatable[i] = new boolean[numLayers[i]];
249
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
250 29b82486 Leszek Koltunski
      }
251 59c20632 Leszek Koltunski
252
    return layerRotatable;
253
    }
254
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256
257
  public int getMovementType()
258
    {
259 c9c71c3f Leszek Koltunski
    return TC_TETRAHEDRON;
260 59c20632 Leszek Koltunski
    }
261
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263
264
  public int getMovementSplit()
265
    {
266
    return TYPE_NOT_SPLIT;
267
    }
268
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270
271
  public int[][][] getEnabled()
272
    {
273
    return new int[][][] { {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}} };
274
    }
275
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277
278
  public float[] getDist3D(int[] numLayers)
279
    {
280
    return null;
281 29b82486 Leszek Koltunski
    }
282
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284
285 a75ae1ee Leszek Koltunski
  public int getNumCubitFaces()
286 29b82486 Leszek Koltunski
    {
287
    return 8;
288
    }
289
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291
292
  private int getNumOctahedrons(int numLayers)
293
    {
294
    return (numLayers-1)*numLayers*(numLayers+1)/6;
295
    }
296
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298
299 a75ae1ee Leszek Koltunski
  private int faceColor(int cubit, int face)
300 29b82486 Leszek Koltunski
    {
301 a75ae1ee Leszek Koltunski
    return CUBITS[cubit].getRotRow(face) == 1 ? face : -1;
302 29b82486 Leszek Koltunski
    }
303
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305
306 a75ae1ee Leszek Koltunski
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
307 29b82486 Leszek Koltunski
    {
308 a75ae1ee Leszek Koltunski
    return 0;
309
    }
310 a57e6870 Leszek Koltunski
311 a75ae1ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
312
313
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
314
    {
315
    if( cubit < getNumOctahedrons(numLayers[0]) )
316 29b82486 Leszek Koltunski
      {
317 a75ae1ee Leszek Koltunski
      switch( face )
318 29b82486 Leszek Koltunski
        {
319
        case 0: return faceColor(cubit,0);
320
        case 2: return faceColor(cubit,1);
321
        case 5: return faceColor(cubit,3);
322
        case 7: return faceColor(cubit,2);
323 a75ae1ee Leszek Koltunski
        default:return -1;
324 29b82486 Leszek Koltunski
        }
325
      }
326
    else
327
      {
328 a75ae1ee Leszek Koltunski
      return face<NUM_FACE_COLORS ? faceColor(cubit,face) : -1;
329 29b82486 Leszek Koltunski
      }
330
    }
331
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333
334 e30c522a Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
335 29b82486 Leszek Koltunski
    {
336 e30c522a Leszek Koltunski
    int numL = getNumLayers()[0];
337 29b82486 Leszek Koltunski
338
    if( variant==0 )
339
      {
340
      double[][] vertices = new double[][] { { 0.5,0.0,0.5},{ 0.5,0.0,-0.5},{-0.5,0.0,-0.5},{-0.5,0.0,0.5},{ 0.0,SQ2/2,0.0},{ 0.0,-SQ2/2,0.0} };
341
      int[][] vert_indices = new int[][] { {3,0,4},{0,1,4},{1,2,4},{2,3,4},{5,0,3},{5,1,0},{5,2,1},{5,3,2} };
342 a57e6870 Leszek Koltunski
      int N = numL==3? 6 : 5;
343
      int E = numL==3? 2 : 1;
344 29b82486 Leszek Koltunski
      float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
345
      int[] bandIndices   = new int[] { 0,0,0,0,0,0,0,0 };
346
      float[][] corners   = new float[][] { {0.04f,0.20f} };
347
      int[] cornerIndices = new int[] { 0,0,0,0,0,0 };
348
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
349
      int[] centerIndices = new int[] { 0,0,0,0,0,0 };
350
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
351
      }
352
    else
353
      {
354
      double[][] vertices = new double[][] { {-0.5, SQ2/4, 0.0},{ 0.5, SQ2/4, 0.0},{ 0.0,-SQ2/4, 0.5},{ 0.0,-SQ2/4,-0.5} };
355
      int[][] vert_indices = new int[][] { {2,1,0},{3,0,1},{3,2,0},{2,3,1} };
356 a57e6870 Leszek Koltunski
      int N = numL==3? 6 : 5;
357
      int E = numL==3? 2 : 1;
358 29b82486 Leszek Koltunski
      float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
359
      int[] bandIndices   = new int[] { 0,0,0,0 };
360
      float[][] corners   = new float[][] { {0.06f,0.15f} };
361
      int[] cornerIndices = new int[] { 0,0,0,0 };
362
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
363
      int[] centerIndices = new int[] { 0,0,0,0 };
364
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
365
      }
366
    }
367
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369
370 7b832206 Leszek Koltunski
  public Static4D getQuat(int cubit, int[] numLayers)
371 29b82486 Leszek Koltunski
    {
372
    if( mQuats==null ) initializeQuats();
373
    return mQuats[0];
374
    }
375
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377
378 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
379 29b82486 Leszek Koltunski
    {
380
    return 2;
381
    }
382
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384
385 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
386 29b82486 Leszek Koltunski
    {
387 a57e6870 Leszek Koltunski
    return cubit<getNumOctahedrons(numLayers[0]) ? 0:1;
388 29b82486 Leszek Koltunski
    }
389
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391
392 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
393 29b82486 Leszek Koltunski
    {
394
    if( mStickers==null )
395
      {
396
      float[][] STICKERS = new float[][] { { -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f } };
397
      final float radius = 0.06f;
398
      final float[] radii= {radius,radius,radius};
399
      mStickers = new ObjectSticker[STICKERS.length];
400 8592461c Leszek Koltunski
401
      float stroke = 0.08f;
402
403
      if( ObjectControl.isInIconMode() )
404
        {
405 a57e6870 Leszek Koltunski
        int[] numLayers = getNumLayers();
406
407
        switch(numLayers[0])
408 8592461c Leszek Koltunski
          {
409
          case 2: stroke*=1.0f; break;
410
          case 3: stroke*=1.4f; break;
411
          case 4: stroke*=1.7f; break;
412
          default:stroke*=1.9f; break;
413
          }
414
        }
415
416 29b82486 Leszek Koltunski
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
417
      }
418
419 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
420
    }
421
422 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
423
// public API
424
425
  public Static3D[] getRotationAxis()
426
    {
427
    return ROT_AXIS;
428
    }
429
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431
432
  public int[] getBasicAngle()
433
    {
434
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
435
    return mBasicAngle;
436
    }
437
438 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
439
440 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
441 61aa85e4 Leszek Koltunski
    {
442 a57e6870 Leszek Koltunski
    switch(numLayers[0])
443 61aa85e4 Leszek Koltunski
      {
444 8005e762 Leszek Koltunski
      case 3: return ObjectType.PYRA_3;
445
      case 4: return ObjectType.PYRA_4;
446
      case 5: return ObjectType.PYRA_5;
447 61aa85e4 Leszek Koltunski
      }
448
449 8005e762 Leszek Koltunski
    return ObjectType.PYRA_3;
450 61aa85e4 Leszek Koltunski
    }
451
452 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
453
454 e26eb4e7 Leszek Koltunski
  public String getObjectName()
455 29b82486 Leszek Koltunski
    {
456 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
457 29b82486 Leszek Koltunski
      {
458 e26eb4e7 Leszek Koltunski
      case 3: return "Pyraminx";
459
      case 4: return "Master Pyraminx";
460
      case 5: return "Professor's Pyraminx";
461 29b82486 Leszek Koltunski
      }
462 e26eb4e7 Leszek Koltunski
    return "Pyraminx";
463 29b82486 Leszek Koltunski
    }
464
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466
467 e26eb4e7 Leszek Koltunski
  public String getInventor()
468 29b82486 Leszek Koltunski
    {
469 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
470 29b82486 Leszek Koltunski
      {
471 e26eb4e7 Leszek Koltunski
      case 3: return "Uwe Meffert";
472
      case 4: return "Katsuhiko Okamoto";
473
      case 5: return "Timur Evbatyrov";
474 29b82486 Leszek Koltunski
      }
475 e26eb4e7 Leszek Koltunski
    return "Uwe Meffert";
476 29b82486 Leszek Koltunski
    }
477
478 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
479
480 e26eb4e7 Leszek Koltunski
  public int getYearOfInvention()
481 59c20632 Leszek Koltunski
    {
482 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
483 59c20632 Leszek Koltunski
      {
484
      case 3: return 1970;
485
      case 4: return 2002;
486
      case 5: return 2011;
487
      }
488
    return 1970;
489
    }
490
491 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
492
493 e26eb4e7 Leszek Koltunski
  public int getComplexity()
494 29b82486 Leszek Koltunski
    {
495 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
496 29b82486 Leszek Koltunski
      {
497
      case 3: return 4;
498
      case 4: return 6;
499
      case 5: return 8;
500
      }
501
    return 4;
502
    }
503
}