Project

General

Profile

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

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

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.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32

    
33
import org.distorted.objectlib.R;
34
import org.distorted.objectlib.main.Movement4;
35
import org.distorted.objectlib.main.ObjectControl;
36
import org.distorted.objectlib.main.ObjectType;
37
import org.distorted.objectlib.helpers.ObjectShape;
38
import org.distorted.objectlib.helpers.ObjectSticker;
39
import org.distorted.objectlib.helpers.ScrambleState;
40
import org.distorted.objectlib.main.Twisty4;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

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

    
54
  private ScrambleState[] mStates;
55
  private int[] mBasicAngle;
56
  private Static4D[] mQuats;
57
  private float[][] mCuts;
58
  private ObjectSticker[] mStickers;
59

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

    
62
  public TwistyPyraminx(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
63
                        MeshSquare mesh, DistortedEffects effects, Resources res, int surfaceW, int surfaceH)
64
    {
65
    super(numL, numL[0], quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
66
    }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
  public ScrambleState[] getScrambleStates()
71
    {
72
    if( mStates==null )
73
      {
74
      int[] numLayers = getNumLayers();
75
      initializeScrambleStates(numLayers[0]);
76
      }
77

    
78
    return mStates;
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
  protected int getResource(int[] numLayers)
84
    {
85
    switch(numLayers[0])
86
      {
87
      case 3: return R.raw.pyra_3;
88
      case 4: return R.raw.pyra_4;
89
      case 5: return R.raw.pyra_5;
90
      }
91

    
92
    return 0;
93
    }
94

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

    
97
  private void initializeQuats()
98
    {
99
    mQuats = new Static4D[]
100
         {
101
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
102
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
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.5f,   0.0f, -0.5f),
108
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
109
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
110
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
111
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
112
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
113
         };
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  private int[][] generateState(int start, int end)
119
    {
120
    int len = end-start+1;
121
    int[] tmp = new int[6*len];
122

    
123
    for(int i=0; i<len; i++)
124
      {
125
      tmp[6*i  ] = start;
126
      tmp[6*i+1] = -1;
127
      tmp[6*i+2] = start;
128
      tmp[6*i+3] = start;
129
      tmp[6*i+4] = +1;
130
      tmp[6*i+5] = start;
131

    
132
      start++;
133
      }
134

    
135
    return new int[][] {tmp,tmp,tmp,tmp};
136
    }
137

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

    
140
  private void initializeScrambleStates(int numLayers)
141
    {
142
    mStates = new ScrambleState[numLayers];
143

    
144
    for(int i=0; i<numLayers-1; i++)
145
      {
146
      mStates[i] = new ScrambleState( generateState(0,numLayers-1-i) );
147
      }
148

    
149
    mStates[numLayers-1] = new ScrambleState( generateState(1,numLayers-2) );
150
    }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

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

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
  private void addTetrahedralLattice(int size, int index, float[][] pos)
164
    {
165
    final float DX = 1.0f;
166
    final float DY = SQ2/2;
167
    final float DZ = 1.0f;
168

    
169
    float startX = 0.0f;
170
    float startY =-DY*(size-1)/2;
171
    float startZ = DZ*(size-1)/2;
172

    
173
    for(int layer=0; layer<size; layer++)
174
      {
175
      float currX = startX;
176
      float currY = startY;
177

    
178
      for(int x=0; x<layer+1; x++)
179
        {
180
        float currZ = startZ;
181

    
182
        for(int z=0; z<size-layer; z++)
183
          {
184
          pos[index] = new float[] {currX,currY,currZ};
185
          index++;
186
          currZ -= DZ;
187
          }
188

    
189
        currX += DX;
190
        }
191

    
192
      startX-=DX/2;
193
      startY+=DY;
194
      startZ-=DZ/2;
195
      }
196
    }
197

    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199
// there are (n^3-n)/6 octahedrons and ((n+1)^3 - (n+1))/6 tetrahedrons
200

    
201
  public float[][] getCubitPositions(int[] numLayers)
202
    {
203
    int numL = numLayers[0];
204
    int numOcta = (numL-1)*numL*(numL+1)/6;
205
    int numTetra= numL*(numL+1)*(numL+2)/6;
206
    float[][] ret = new float[numOcta+numTetra][];
207

    
208
    addTetrahedralLattice(numL-1,      0,ret);
209
    addTetrahedralLattice(numL  ,numOcta,ret);
210

    
211
    return ret;
212
    }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

    
216
  public Static4D[] getQuats()
217
    {
218
    if( mQuats==null ) initializeQuats();
219
    return mQuats;
220
    }
221

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

    
224
  public int getSolvedFunctionIndex()
225
    {
226
    return 0;
227
    }
228

    
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

    
231
  public int getNumStickerTypes(int[] numLayers)
232
    {
233
    return 1;
234
    }
235

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

    
238
  public float[][] getCuts(int[] numLayers)
239
    {
240
    if( mCuts==null )
241
      {
242
      int numL = numLayers[0];
243
      mCuts = new float[4][numL-1];
244

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

    
255
    return mCuts;
256
    }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

    
260
  public boolean[][] getLayerRotatable(int[] numLayers)
261
    {
262
    int numAxis = ROT_AXIS.length;
263
    boolean[][] layerRotatable = new boolean[numAxis][];
264

    
265
    for(int i=0; i<numAxis; i++)
266
      {
267
      layerRotatable[i] = new boolean[numLayers[i]];
268
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
269
      }
270

    
271
    return layerRotatable;
272
    }
273

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

    
276
  public int getMovementType()
277
    {
278
    return MOVEMENT_TETRAHEDRON;
279
    }
280

    
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

    
283
  public int getMovementSplit()
284
    {
285
    return TYPE_NOT_SPLIT;
286
    }
287

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

    
290
  public int[][][] getEnabled()
291
    {
292
    return new int[][][] { {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}} };
293
    }
294

    
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296

    
297
  public float[] getDist3D(int[] numLayers)
298
    {
299
    return null;
300
    }
301

    
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303

    
304
  public int getNumCubitFaces()
305
    {
306
    return 8;
307
    }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

    
311
  private int getNumOctahedrons(int numLayers)
312
    {
313
    return (numLayers-1)*numLayers*(numLayers+1)/6;
314
    }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

    
318
  private int faceColor(int cubit, int face)
319
    {
320
    return CUBITS[cubit].getRotRow(face) == 1 ? face : -1;
321
    }
322

    
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324

    
325
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
326
    {
327
    return 0;
328
    }
329

    
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331

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

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

    
353
  public ObjectShape getObjectShape(int variant)
354
    {
355
    int numL = getNumLayers()[0];
356

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

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

    
389
  public Static4D getQuat(int cubit, int[] numLayers)
390
    {
391
    if( mQuats==null ) initializeQuats();
392
    return mQuats[0];
393
    }
394

    
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396

    
397
  public int getNumCubitVariants(int[] numLayers)
398
    {
399
    return 2;
400
    }
401

    
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403

    
404
  public int getCubitVariant(int cubit, int[] numLayers)
405
    {
406
    return cubit<getNumOctahedrons(numLayers[0]) ? 0:1;
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410

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

    
420
      float stroke = 0.08f;
421

    
422
      if( ObjectControl.isInIconMode() )
423
        {
424
        int[] numLayers = getNumLayers();
425

    
426
        switch(numLayers[0])
427
          {
428
          case 2: stroke*=1.0f; break;
429
          case 3: stroke*=1.4f; break;
430
          case 4: stroke*=1.7f; break;
431
          default:stroke*=1.9f; break;
432
          }
433
        }
434

    
435
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
436
      }
437

    
438
    return mStickers[sticker];
439
    }
440

    
441
///////////////////////////////////////////////////////////////////////////////////////////////////
442
// public API
443

    
444
  public Static3D[] getRotationAxis()
445
    {
446
    return ROT_AXIS;
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450

    
451
  public int[] getBasicAngle()
452
    {
453
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
454
    return mBasicAngle;
455
    }
456

    
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458

    
459
  public ObjectType intGetObjectType(int[] numLayers)
460
    {
461
    switch(numLayers[0])
462
      {
463
      case 3: return ObjectType.PYRA_3;
464
      case 4: return ObjectType.PYRA_4;
465
      case 5: return ObjectType.PYRA_5;
466
      }
467

    
468
    return ObjectType.PYRA_3;
469
    }
470

    
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472

    
473
  public int getObjectName(int[] numLayers)
474
    {
475
    switch(numLayers[0])
476
      {
477
      case 3: return R.string.pyra3;
478
      case 4: return R.string.pyra4;
479
      case 5: return R.string.pyra5;
480
      }
481
    return R.string.pyra3;
482
    }
483

    
484
///////////////////////////////////////////////////////////////////////////////////////////////////
485

    
486
  public int getInventor(int[] numLayers)
487
    {
488
    switch(numLayers[0])
489
      {
490
      case 3: return R.string.pyra3_inventor;
491
      case 4: return R.string.pyra4_inventor;
492
      case 5: return R.string.pyra5_inventor;
493
      }
494
    return R.string.pyra3_inventor;
495
    }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498

    
499
  public int getYearOfInvention(int[] numLayers)
500
    {
501
    switch(numLayers[0])
502
      {
503
      case 3: return 1970;
504
      case 4: return 2002;
505
      case 5: return 2011;
506
      }
507
    return 1970;
508
    }
509

    
510
///////////////////////////////////////////////////////////////////////////////////////////////////
511

    
512
  public int getComplexity(int[] numLayers)
513
    {
514
    switch(numLayers[0])
515
      {
516
      case 3: return 4;
517
      case 4: return 6;
518
      case 5: return 8;
519
      }
520
    return 4;
521
    }
522
}
(18-18/25)