Project

General

Profile

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

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

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.main.Movement.MOVEMENT_TETRAHEDRON;
23
import static org.distorted.objectlib.main.Movement.TYPE_NOT_SPLIT;
24

    
25
import android.content.res.Resources;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.R;
31
import org.distorted.objectlib.main.Movement4;
32
import org.distorted.objectlib.main.ObjectControl;
33
import org.distorted.objectlib.main.ObjectType;
34
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ObjectSticker;
36
import org.distorted.objectlib.helpers.ScrambleState;
37
import org.distorted.objectlib.main.Twisty4;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

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

    
51
  private ScrambleState[] mStates;
52
  private int[] mBasicAngle;
53
  private Static4D[] mQuats;
54
  private float[][] mCuts;
55
  private ObjectSticker[] mStickers;
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  public TwistyPyraminx(int[] numL, Static4D quat, Static3D move, Resources res)
60
    {
61
    super(numL, numL[0], quat, move, res);
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  public ScrambleState[] getScrambleStates()
67
    {
68
    if( mStates==null )
69
      {
70
      int[] numLayers = getNumLayers();
71
      initializeScrambleStates(numLayers[0]);
72
      }
73

    
74
    return mStates;
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
  protected int getResource(int[] numLayers)
80
    {
81
    switch(numLayers[0])
82
      {
83
      case 3: return R.raw.pyra_3;
84
      case 4: return R.raw.pyra_4;
85
      case 5: return R.raw.pyra_5;
86
      }
87

    
88
    return 0;
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  private void initializeQuats()
94
    {
95
    mQuats = new Static4D[]
96
         {
97
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
98
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
99
         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
100
         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
101
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
102
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
103
         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
104
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
105
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
106
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
107
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
108
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
109
         };
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  private int[][] generateState(int start, int end)
115
    {
116
    int len = end-start+1;
117
    int[] tmp = new int[6*len];
118

    
119
    for(int i=0; i<len; i++)
120
      {
121
      tmp[6*i  ] = start;
122
      tmp[6*i+1] = -1;
123
      tmp[6*i+2] = start;
124
      tmp[6*i+3] = start;
125
      tmp[6*i+4] = +1;
126
      tmp[6*i+5] = start;
127

    
128
      start++;
129
      }
130

    
131
    return new int[][] {tmp,tmp,tmp,tmp};
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
  private void initializeScrambleStates(int numLayers)
137
    {
138
    mStates = new ScrambleState[numLayers];
139

    
140
    for(int i=0; i<numLayers-1; i++)
141
      {
142
      mStates[i] = new ScrambleState( generateState(0,numLayers-1-i) );
143
      }
144

    
145
    mStates[numLayers-1] = new ScrambleState( generateState(1,numLayers-2) );
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  public int[] getSolvedQuats(int cubit, int[] numLayers)
151
    {
152
    if( mQuats==null ) initializeQuats();
153
    int status = retCubitSolvedStatus(cubit,numLayers);
154
    return status<0 ? null : buildSolvedQuats(Movement4.FACE_AXIS[status],mQuats);
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  private void addTetrahedralLattice(int size, int index, float[][] pos)
160
    {
161
    final float DX = 1.0f;
162
    final float DY = SQ2/2;
163
    final float DZ = 1.0f;
164

    
165
    float startX = 0.0f;
166
    float startY =-DY*(size-1)/2;
167
    float startZ = DZ*(size-1)/2;
168

    
169
    for(int layer=0; layer<size; layer++)
170
      {
171
      float currX = startX;
172
      float currY = startY;
173

    
174
      for(int x=0; x<layer+1; x++)
175
        {
176
        float currZ = startZ;
177

    
178
        for(int z=0; z<size-layer; z++)
179
          {
180
          pos[index] = new float[] {currX,currY,currZ};
181
          index++;
182
          currZ -= DZ;
183
          }
184

    
185
        currX += DX;
186
        }
187

    
188
      startX-=DX/2;
189
      startY+=DY;
190
      startZ-=DZ/2;
191
      }
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195
// there are (n^3-n)/6 octahedrons and ((n+1)^3 - (n+1))/6 tetrahedrons
196

    
197
  public float[][] getCubitPositions(int[] numLayers)
198
    {
199
    int numL = numLayers[0];
200
    int numOcta = (numL-1)*numL*(numL+1)/6;
201
    int numTetra= numL*(numL+1)*(numL+2)/6;
202
    float[][] ret = new float[numOcta+numTetra][];
203

    
204
    addTetrahedralLattice(numL-1,      0,ret);
205
    addTetrahedralLattice(numL  ,numOcta,ret);
206

    
207
    return ret;
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

    
212
  public Static4D[] getQuats()
213
    {
214
    if( mQuats==null ) initializeQuats();
215
    return mQuats;
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

    
220
  public int getSolvedFunctionIndex()
221
    {
222
    return 0;
223
    }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
  public int getNumStickerTypes(int[] numLayers)
228
    {
229
    return 1;
230
    }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
  public float[][] getCuts(int[] numLayers)
235
    {
236
    if( mCuts==null )
237
      {
238
      int numL = numLayers[0];
239
      mCuts = new float[4][numL-1];
240

    
241
      for(int i=0; i<numL-1; i++)
242
        {
243
        float cut = (1.0f+i-numL/4.0f)*(SQ6/3);
244
        mCuts[0][i] = cut;
245
        mCuts[1][i] = cut;
246
        mCuts[2][i] = cut;
247
        mCuts[3][i] = cut;
248
        }
249
      }
250

    
251
    return mCuts;
252
    }
253

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

    
256
  public boolean[][] getLayerRotatable(int[] numLayers)
257
    {
258
    int numAxis = ROT_AXIS.length;
259
    boolean[][] layerRotatable = new boolean[numAxis][];
260

    
261
    for(int i=0; i<numAxis; i++)
262
      {
263
      layerRotatable[i] = new boolean[numLayers[i]];
264
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
265
      }
266

    
267
    return layerRotatable;
268
    }
269

    
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

    
272
  public int getMovementType()
273
    {
274
    return MOVEMENT_TETRAHEDRON;
275
    }
276

    
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

    
279
  public int getMovementSplit()
280
    {
281
    return TYPE_NOT_SPLIT;
282
    }
283

    
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

    
286
  public int[][][] getEnabled()
287
    {
288
    return new int[][][] { {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}} };
289
    }
290

    
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292

    
293
  public float[] getDist3D(int[] numLayers)
294
    {
295
    return null;
296
    }
297

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

    
300
  public int getNumCubitFaces()
301
    {
302
    return 8;
303
    }
304

    
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306

    
307
  private int getNumOctahedrons(int numLayers)
308
    {
309
    return (numLayers-1)*numLayers*(numLayers+1)/6;
310
    }
311

    
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

    
314
  private int faceColor(int cubit, int face)
315
    {
316
    return CUBITS[cubit].getRotRow(face) == 1 ? face : -1;
317
    }
318

    
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320

    
321
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
322
    {
323
    return 0;
324
    }
325

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327

    
328
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
329
    {
330
    if( cubit < getNumOctahedrons(numLayers[0]) )
331
      {
332
      switch( face )
333
        {
334
        case 0: return faceColor(cubit,0);
335
        case 2: return faceColor(cubit,1);
336
        case 5: return faceColor(cubit,3);
337
        case 7: return faceColor(cubit,2);
338
        default:return -1;
339
        }
340
      }
341
    else
342
      {
343
      return face<NUM_FACE_COLORS ? faceColor(cubit,face) : -1;
344
      }
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
  public ObjectShape getObjectShape(int variant)
350
    {
351
    int numL = getNumLayers()[0];
352

    
353
    if( variant==0 )
354
      {
355
      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} };
356
      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} };
357
      int N = numL==3? 6 : 5;
358
      int E = numL==3? 2 : 1;
359
      float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
360
      int[] bandIndices   = new int[] { 0,0,0,0,0,0,0,0 };
361
      float[][] corners   = new float[][] { {0.04f,0.20f} };
362
      int[] cornerIndices = new int[] { 0,0,0,0,0,0 };
363
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
364
      int[] centerIndices = new int[] { 0,0,0,0,0,0 };
365
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
366
      }
367
    else
368
      {
369
      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} };
370
      int[][] vert_indices = new int[][] { {2,1,0},{3,0,1},{3,2,0},{2,3,1} };
371
      int N = numL==3? 6 : 5;
372
      int E = numL==3? 2 : 1;
373
      float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
374
      int[] bandIndices   = new int[] { 0,0,0,0 };
375
      float[][] corners   = new float[][] { {0.06f,0.15f} };
376
      int[] cornerIndices = new int[] { 0,0,0,0 };
377
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
378
      int[] centerIndices = new int[] { 0,0,0,0 };
379
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
380
      }
381
    }
382

    
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384

    
385
  public Static4D getQuat(int cubit, int[] numLayers)
386
    {
387
    if( mQuats==null ) initializeQuats();
388
    return mQuats[0];
389
    }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

    
393
  public int getNumCubitVariants(int[] numLayers)
394
    {
395
    return 2;
396
    }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

    
400
  public int getCubitVariant(int cubit, int[] numLayers)
401
    {
402
    return cubit<getNumOctahedrons(numLayers[0]) ? 0:1;
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

    
407
  public ObjectSticker retSticker(int sticker)
408
    {
409
    if( mStickers==null )
410
      {
411
      float[][] STICKERS = new float[][] { { -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f } };
412
      final float radius = 0.06f;
413
      final float[] radii= {radius,radius,radius};
414
      mStickers = new ObjectSticker[STICKERS.length];
415

    
416
      float stroke = 0.08f;
417

    
418
      if( ObjectControl.isInIconMode() )
419
        {
420
        int[] numLayers = getNumLayers();
421

    
422
        switch(numLayers[0])
423
          {
424
          case 2: stroke*=1.0f; break;
425
          case 3: stroke*=1.4f; break;
426
          case 4: stroke*=1.7f; break;
427
          default:stroke*=1.9f; break;
428
          }
429
        }
430

    
431
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
432
      }
433

    
434
    return mStickers[sticker];
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438
// public API
439

    
440
  public Static3D[] getRotationAxis()
441
    {
442
    return ROT_AXIS;
443
    }
444

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

    
447
  public int[] getBasicAngle()
448
    {
449
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
450
    return mBasicAngle;
451
    }
452

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

    
455
  public ObjectType intGetObjectType(int[] numLayers)
456
    {
457
    switch(numLayers[0])
458
      {
459
      case 3: return ObjectType.PYRA_3;
460
      case 4: return ObjectType.PYRA_4;
461
      case 5: return ObjectType.PYRA_5;
462
      }
463

    
464
    return ObjectType.PYRA_3;
465
    }
466

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

    
469
  public String getObjectName()
470
    {
471
    switch(getNumLayers()[0])
472
      {
473
      case 3: return "Pyraminx";
474
      case 4: return "Master Pyraminx";
475
      case 5: return "Professor's Pyraminx";
476
      }
477
    return "Pyraminx";
478
    }
479

    
480
///////////////////////////////////////////////////////////////////////////////////////////////////
481

    
482
  public String getInventor()
483
    {
484
    switch(getNumLayers()[0])
485
      {
486
      case 3: return "Uwe Meffert";
487
      case 4: return "Katsuhiko Okamoto";
488
      case 5: return "Timur Evbatyrov";
489
      }
490
    return "Uwe Meffert";
491
    }
492

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494

    
495
  public int getYearOfInvention()
496
    {
497
    switch(getNumLayers()[0])
498
      {
499
      case 3: return 1970;
500
      case 4: return 2002;
501
      case 5: return 2011;
502
      }
503
    return 1970;
504
    }
505

    
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507

    
508
  public int getComplexity()
509
    {
510
    switch(getNumLayers()[0])
511
      {
512
      case 3: return 4;
513
      case 4: return 6;
514
      case 5: return 8;
515
      }
516
    return 4;
517
    }
518
}
(18-18/25)