Project

General

Profile

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

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

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.ObjectControl;
33
import org.distorted.objectlib.main.ObjectType;
34
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ScrambleState;
36
import org.distorted.objectlib.main.ShapeTetrahedron;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class TwistyPyraminx extends ShapeTetrahedron
41
{
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 float[][] mCuts;
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

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

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

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

    
71
    return mStates;
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

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

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

    
90
      start++;
91
      }
92

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

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

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

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

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

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

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

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

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

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

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

    
138
        currX += DX;
139
        }
140

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

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

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

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
  public int[] getSolvedQuats(int cubit, int[] numLayers)
157
    {
158
    int status = retCubitSolvedStatus(cubit,numLayers);
159
    return status<0 ? null : buildSolvedQuats(TouchControlTetrahedron.FACE_AXIS[status],mObjectQuats);
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  public int getSolvedFunctionIndex()
165
    {
166
    return 0;
167
    }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

    
171
  public float[][] getCuts(int[] numLayers)
172
    {
173
    if( mCuts==null )
174
      {
175
      int numL = numLayers[0];
176
      mCuts = new float[4][numL-1];
177

    
178
      for(int i=0; i<numL-1; i++)
179
        {
180
        float cut = (1.0f+i-numL/4.0f)*(SQ6/3);
181
        mCuts[0][i] = cut;
182
        mCuts[1][i] = cut;
183
        mCuts[2][i] = cut;
184
        mCuts[3][i] = cut;
185
        }
186
      }
187

    
188
    return mCuts;
189
    }
190

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

    
193
  public boolean[][] getLayerRotatable(int[] numLayers)
194
    {
195
    int numAxis = ROT_AXIS.length;
196
    boolean[][] layerRotatable = new boolean[numAxis][];
197

    
198
    for(int i=0; i<numAxis; i++)
199
      {
200
      layerRotatable[i] = new boolean[numLayers[i]];
201
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
202
      }
203

    
204
    return layerRotatable;
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

    
209
  public int getTouchControlType()
210
    {
211
    return TC_TETRAHEDRON;
212
    }
213

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

    
216
  public int getTouchControlSplit()
217
    {
218
    return TYPE_NOT_SPLIT;
219
    }
220

    
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

    
223
  public int[][][] getEnabled()
224
    {
225
    return new int[][][] { {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}} };
226
    }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

    
230
  public float[] getDist3D(int[] numLayers)
231
    {
232
    return TouchControlTetrahedron.D3D;
233
    }
234

    
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

    
237
  public Static3D[] getFaceAxis()
238
    {
239
    return TouchControlTetrahedron.FACE_AXIS;
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243
// there are (n^3-n)/6 octahedrons and ((n+1)^3 - (n+1))/6 tetrahedrons
244

    
245
  public float[][] getCubitPositions(int[] numLayers)
246
    {
247
    int numL = numLayers[0];
248
    int numOcta = (numL-1)*numL*(numL+1)/6;
249
    int numTetra= numL*(numL+1)*(numL+2)/6;
250
    float[][] ret = new float[numOcta+numTetra][];
251

    
252
    addTetrahedralLattice(numL-1,      0,ret);
253
    addTetrahedralLattice(numL  ,numOcta,ret);
254

    
255
    return ret;
256
    }
257

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

    
260
  public Static4D getCubitQuats(int cubit, int[] numLayers)
261
    {
262
    return mObjectQuats[0];
263
    }
264

    
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

    
267
  public ObjectShape getObjectShape(int variant)
268
    {
269
    if( variant==0 )
270
      {
271
      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} };
272
      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} };
273
      return new ObjectShape(vertices, indices);
274
      }
275
    else
276
      {
277
      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} };
278
      int[][] indices   = { {2,1,0},{3,0,1},{3,2,0},{2,3,1} };
279
      return new ObjectShape(vertices, indices);
280
      }
281
    }
282

    
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

    
285
  public ObjectFaceShape getObjectFaceShape(int variant)
286
    {
287
    int numL = getNumLayers()[0];
288

    
289
    if( variant==0 )
290
      {
291
      int N = numL==3? 6 : 5;
292
      int E = numL==3? 2 : 1;
293
      float[][] bands     = { {0.05f,35,0.5f,0.8f,N,E,E} };
294
      int[] bandIndices   = { 0,0,0,0,0,0,0,0 };
295
      float[][] corners   = { {0.04f,0.20f} };
296
      int[] cornerIndices = { 0,0,0,0,0,0 };
297
      float[][] centers   = { {0.0f, 0.0f, 0.0f} };
298
      int[] centerIndices = { 0,0,0,0,0,0 };
299
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
300
      }
301
    else
302
      {
303
      int N = numL==3? 6 : 5;
304
      int E = numL==3? 2 : 1;
305
      float[][] bands     = { {0.05f,35,0.5f,0.8f,N,E,E} };
306
      int[] bandIndices   = { 0,0,0,0 };
307
      float[][] corners   = { {0.06f,0.15f} };
308
      int[] cornerIndices = { 0,0,0,0 };
309
      float[][] centers   = { {0.0f, 0.0f, 0.0f} };
310
      int[] centerIndices = { 0,0,0,0 };
311
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
312
      }
313
    }
314

    
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

    
317
  public int getNumCubitVariants(int[] numLayers)
318
    {
319
    return 2;
320
    }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
  public int getCubitVariant(int cubit, int[] numLayers)
325
    {
326
    return cubit<getNumOctahedrons(numLayers[0]) ? 0:1;
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

    
331
  public float getStickerRadius()
332
    {
333
    return 0.08f;
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  public float getStickerStroke()
339
    {
340
    float stroke = 0.08f;
341

    
342
    if( ObjectControl.isInIconMode() )
343
      {
344
      int[] numLayers = getNumLayers();
345

    
346
      switch(numLayers[0])
347
        {
348
        case 2: stroke*=1.0f; break;
349
        case 3: stroke*=1.4f; break;
350
        case 4: stroke*=1.7f; break;
351
        default:stroke*=1.9f; break;
352
        }
353
      }
354

    
355
    return stroke;
356
    }
357

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

    
360
  public float[][] getStickerAngles()
361
    {
362
    return null;
363
    }
364

    
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366
// public API
367

    
368
  public Static3D[] getRotationAxis()
369
    {
370
    return ROT_AXIS;
371
    }
372

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

    
375
  public int[] getBasicAngles()
376
    {
377
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
378
    return mBasicAngle;
379
    }
380

    
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382

    
383
  public ObjectType intGetObjectType(int[] numLayers)
384
    {
385
    switch(numLayers[0])
386
      {
387
      case 3: return ObjectType.PYRA_3;
388
      case 4: return ObjectType.PYRA_4;
389
      case 5: return ObjectType.PYRA_5;
390
      }
391

    
392
    return ObjectType.PYRA_3;
393
    }
394

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

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

    
408
///////////////////////////////////////////////////////////////////////////////////////////////////
409

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

    
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422

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

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
  public int getComplexity()
437
    {
438
    switch(getNumLayers()[0])
439
      {
440
      case 3: return 1;
441
      case 4: return 2;
442
      case 5: return 3;
443
      }
444
    return 4;
445
    }
446
}
(18-18/26)