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 java.io.InputStream;
|
26
|
|
27
|
import org.distorted.library.type.Static3D;
|
28
|
import org.distorted.library.type.Static4D;
|
29
|
|
30
|
import org.distorted.objectlib.main.Movement4;
|
31
|
import org.distorted.objectlib.main.ObjectControl;
|
32
|
import org.distorted.objectlib.main.ObjectType;
|
33
|
import org.distorted.objectlib.helpers.ObjectShape;
|
34
|
import org.distorted.objectlib.helpers.ObjectSticker;
|
35
|
import org.distorted.objectlib.helpers.ScrambleState;
|
36
|
import org.distorted.objectlib.main.Twisty4;
|
37
|
|
38
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39
|
|
40
|
public class TwistyPyraminx extends Twisty4
|
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 Static4D[] mQuats;
|
53
|
private float[][] mCuts;
|
54
|
private ObjectSticker[] mStickers;
|
55
|
|
56
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57
|
|
58
|
public TwistyPyraminx(int[] numL, Static4D quat, Static3D move, InputStream stream)
|
59
|
{
|
60
|
super(numL, numL[0], quat, move, stream);
|
61
|
}
|
62
|
|
63
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64
|
|
65
|
public ScrambleState[] getScrambleStates()
|
66
|
{
|
67
|
if( mStates==null )
|
68
|
{
|
69
|
int[] numLayers = getNumLayers();
|
70
|
initializeScrambleStates(numLayers[0]);
|
71
|
}
|
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
|
public int[] getSolvedQuats(int cubit, int[] numLayers)
|
136
|
{
|
137
|
if( mQuats==null ) initializeQuats();
|
138
|
int status = retCubitSolvedStatus(cubit,numLayers);
|
139
|
return status<0 ? null : buildSolvedQuats(Movement4.FACE_AXIS[status],mQuats);
|
140
|
}
|
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
|
public float[][] getCubitPositions(int[] numLayers)
|
183
|
{
|
184
|
int numL = numLayers[0];
|
185
|
int numOcta = (numL-1)*numL*(numL+1)/6;
|
186
|
int numTetra= numL*(numL+1)*(numL+2)/6;
|
187
|
float[][] ret = new float[numOcta+numTetra][];
|
188
|
|
189
|
addTetrahedralLattice(numL-1, 0,ret);
|
190
|
addTetrahedralLattice(numL ,numOcta,ret);
|
191
|
|
192
|
return ret;
|
193
|
}
|
194
|
|
195
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
196
|
|
197
|
public Static4D[] getQuats()
|
198
|
{
|
199
|
if( mQuats==null ) initializeQuats();
|
200
|
return mQuats;
|
201
|
}
|
202
|
|
203
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
204
|
|
205
|
public int getSolvedFunctionIndex()
|
206
|
{
|
207
|
return 0;
|
208
|
}
|
209
|
|
210
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
211
|
|
212
|
public int getNumStickerTypes(int[] numLayers)
|
213
|
{
|
214
|
return 1;
|
215
|
}
|
216
|
|
217
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
218
|
|
219
|
public float[][] getCuts(int[] numLayers)
|
220
|
{
|
221
|
if( mCuts==null )
|
222
|
{
|
223
|
int numL = numLayers[0];
|
224
|
mCuts = new float[4][numL-1];
|
225
|
|
226
|
for(int i=0; i<numL-1; i++)
|
227
|
{
|
228
|
float cut = (1.0f+i-numL/4.0f)*(SQ6/3);
|
229
|
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
|
public boolean[][] getLayerRotatable(int[] numLayers)
|
242
|
{
|
243
|
int numAxis = ROT_AXIS.length;
|
244
|
boolean[][] layerRotatable = new boolean[numAxis][];
|
245
|
|
246
|
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
|
}
|
251
|
|
252
|
return layerRotatable;
|
253
|
}
|
254
|
|
255
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256
|
|
257
|
public int getMovementType()
|
258
|
{
|
259
|
return MOVEMENT_TETRAHEDRON;
|
260
|
}
|
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
|
}
|
282
|
|
283
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
284
|
|
285
|
public int getNumCubitFaces()
|
286
|
{
|
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
|
private int faceColor(int cubit, int face)
|
300
|
{
|
301
|
return CUBITS[cubit].getRotRow(face) == 1 ? face : -1;
|
302
|
}
|
303
|
|
304
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
305
|
|
306
|
public int getVariantFaceColor(int variant, int face, int[] numLayers)
|
307
|
{
|
308
|
return 0;
|
309
|
}
|
310
|
|
311
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
312
|
|
313
|
public int getCubitFaceColor(int cubit, int face, int[] numLayers)
|
314
|
{
|
315
|
if( cubit < getNumOctahedrons(numLayers[0]) )
|
316
|
{
|
317
|
switch( face )
|
318
|
{
|
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
|
default:return -1;
|
324
|
}
|
325
|
}
|
326
|
else
|
327
|
{
|
328
|
return face<NUM_FACE_COLORS ? faceColor(cubit,face) : -1;
|
329
|
}
|
330
|
}
|
331
|
|
332
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
333
|
|
334
|
public ObjectShape getObjectShape(int variant)
|
335
|
{
|
336
|
int numL = getNumLayers()[0];
|
337
|
|
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
|
int N = numL==3? 6 : 5;
|
343
|
int E = numL==3? 2 : 1;
|
344
|
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
|
int N = numL==3? 6 : 5;
|
357
|
int E = numL==3? 2 : 1;
|
358
|
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
|
public Static4D getQuat(int cubit, int[] numLayers)
|
371
|
{
|
372
|
if( mQuats==null ) initializeQuats();
|
373
|
return mQuats[0];
|
374
|
}
|
375
|
|
376
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
377
|
|
378
|
public int getNumCubitVariants(int[] numLayers)
|
379
|
{
|
380
|
return 2;
|
381
|
}
|
382
|
|
383
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
384
|
|
385
|
public int getCubitVariant(int cubit, int[] numLayers)
|
386
|
{
|
387
|
return cubit<getNumOctahedrons(numLayers[0]) ? 0:1;
|
388
|
}
|
389
|
|
390
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
391
|
|
392
|
public ObjectSticker retSticker(int sticker)
|
393
|
{
|
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
|
|
401
|
float stroke = 0.08f;
|
402
|
|
403
|
if( ObjectControl.isInIconMode() )
|
404
|
{
|
405
|
int[] numLayers = getNumLayers();
|
406
|
|
407
|
switch(numLayers[0])
|
408
|
{
|
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
|
mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
|
417
|
}
|
418
|
|
419
|
return mStickers[sticker];
|
420
|
}
|
421
|
|
422
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
439
|
|
440
|
public ObjectType intGetObjectType(int[] numLayers)
|
441
|
{
|
442
|
switch(numLayers[0])
|
443
|
{
|
444
|
case 3: return ObjectType.PYRA_3;
|
445
|
case 4: return ObjectType.PYRA_4;
|
446
|
case 5: return ObjectType.PYRA_5;
|
447
|
}
|
448
|
|
449
|
return ObjectType.PYRA_3;
|
450
|
}
|
451
|
|
452
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
453
|
|
454
|
public String getObjectName()
|
455
|
{
|
456
|
switch(getNumLayers()[0])
|
457
|
{
|
458
|
case 3: return "Pyraminx";
|
459
|
case 4: return "Master Pyraminx";
|
460
|
case 5: return "Professor's Pyraminx";
|
461
|
}
|
462
|
return "Pyraminx";
|
463
|
}
|
464
|
|
465
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
466
|
|
467
|
public String getInventor()
|
468
|
{
|
469
|
switch(getNumLayers()[0])
|
470
|
{
|
471
|
case 3: return "Uwe Meffert";
|
472
|
case 4: return "Katsuhiko Okamoto";
|
473
|
case 5: return "Timur Evbatyrov";
|
474
|
}
|
475
|
return "Uwe Meffert";
|
476
|
}
|
477
|
|
478
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
479
|
|
480
|
public int getYearOfInvention()
|
481
|
{
|
482
|
switch(getNumLayers()[0])
|
483
|
{
|
484
|
case 3: return 1970;
|
485
|
case 4: return 2002;
|
486
|
case 5: return 2011;
|
487
|
}
|
488
|
return 1970;
|
489
|
}
|
490
|
|
491
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
492
|
|
493
|
public int getComplexity()
|
494
|
{
|
495
|
switch(getNumLayers()[0])
|
496
|
{
|
497
|
case 3: return 4;
|
498
|
case 4: return 6;
|
499
|
case 5: return 8;
|
500
|
}
|
501
|
return 4;
|
502
|
}
|
503
|
}
|