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.objects;
|
21
|
|
22
|
import android.content.res.Resources;
|
23
|
|
24
|
import org.distorted.helpers.ObjectShape;
|
25
|
import org.distorted.helpers.ObjectSticker;
|
26
|
import org.distorted.helpers.ScrambleState;
|
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
|
import org.distorted.main.R;
|
33
|
|
34
|
import java.util.Random;
|
35
|
|
36
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37
|
|
38
|
public class TwistyPyraminx extends TwistyObject
|
39
|
{
|
40
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
41
|
{
|
42
|
new Static3D( 0,-SQ3/3,-SQ6/3),
|
43
|
new Static3D( 0,-SQ3/3,+SQ6/3),
|
44
|
new Static3D(+SQ6/3,+SQ3/3, 0),
|
45
|
new Static3D(-SQ6/3,+SQ3/3, 0),
|
46
|
};
|
47
|
|
48
|
private static final int[] FACE_COLORS = new int[]
|
49
|
{
|
50
|
COLOR_GREEN , COLOR_YELLOW,
|
51
|
COLOR_BLUE , COLOR_RED
|
52
|
};
|
53
|
|
54
|
private int mCurrState;
|
55
|
private int mIndexExcluded;
|
56
|
private ScrambleState[] mStates;
|
57
|
private int[][] mScrambleTable;
|
58
|
private int[] mNumOccurences;
|
59
|
private int[] mBasicAngle;
|
60
|
private Static4D[] mQuats;
|
61
|
private ObjectSticker[] mStickers;
|
62
|
|
63
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64
|
|
65
|
TwistyPyraminx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
66
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
67
|
{
|
68
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.PYRA, res, scrWidth);
|
69
|
|
70
|
initializeScrambleStates(size);
|
71
|
}
|
72
|
|
73
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74
|
|
75
|
private void initializeQuats()
|
76
|
{
|
77
|
mQuats = new Static4D[]
|
78
|
{
|
79
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f),
|
80
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f),
|
81
|
new Static4D( SQ2/2, 0.5f, 0.0f, 0.5f),
|
82
|
new Static4D(-SQ2/2, 0.5f, 0.0f, 0.5f),
|
83
|
new Static4D( 0.0f, -0.5f, -SQ2/2, 0.5f),
|
84
|
new Static4D( 0.0f, -0.5f, SQ2/2, 0.5f),
|
85
|
new Static4D( SQ2/2, 0.5f, 0.0f, -0.5f),
|
86
|
new Static4D(-SQ2/2, 0.5f, 0.0f, -0.5f),
|
87
|
new Static4D( 0.0f, -0.5f, -SQ2/2, -0.5f),
|
88
|
new Static4D( 0.0f, -0.5f, SQ2/2, -0.5f),
|
89
|
new Static4D( SQ2/2, 0.0f, SQ2/2, 0.0f),
|
90
|
new Static4D(-SQ2/2, 0.0f, SQ2/2, 0.0f)
|
91
|
};
|
92
|
}
|
93
|
|
94
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95
|
|
96
|
private int[][] generateState(int start, int end)
|
97
|
{
|
98
|
int len = end-start+1;
|
99
|
int[] tmp = new int[6*len];
|
100
|
|
101
|
for(int i=0; i<len; i++)
|
102
|
{
|
103
|
tmp[6*i ] = start;
|
104
|
tmp[6*i+1] = -1;
|
105
|
tmp[6*i+2] = start;
|
106
|
tmp[6*i+3] = start;
|
107
|
tmp[6*i+4] = +1;
|
108
|
tmp[6*i+5] = start;
|
109
|
|
110
|
start++;
|
111
|
}
|
112
|
|
113
|
return new int[][] {tmp,tmp,tmp,tmp};
|
114
|
}
|
115
|
|
116
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117
|
|
118
|
private void initializeScrambleStates(int numLayers)
|
119
|
{
|
120
|
mStates = new ScrambleState[numLayers];
|
121
|
|
122
|
for(int i=0; i<numLayers-1; i++)
|
123
|
{
|
124
|
mStates[i] = new ScrambleState( generateState(0,numLayers-1-i) );
|
125
|
}
|
126
|
|
127
|
mStates[numLayers-1] = new ScrambleState( generateState(1,numLayers-2) );
|
128
|
}
|
129
|
|
130
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131
|
|
132
|
int[] getSolvedQuats(int cubit, int numLayers)
|
133
|
{
|
134
|
if( mQuats==null ) initializeQuats();
|
135
|
int status = retCubitSolvedStatus(cubit,numLayers);
|
136
|
return status<0 ? null : buildSolvedQuats(MovementPyraminx.FACE_AXIS[status],mQuats);
|
137
|
}
|
138
|
|
139
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140
|
|
141
|
private void addTetrahedralLattice(int size, int index, float[][] pos)
|
142
|
{
|
143
|
final float DX = 1.0f;
|
144
|
final float DY = SQ2/2;
|
145
|
final float DZ = 1.0f;
|
146
|
|
147
|
float startX = 0.0f;
|
148
|
float startY =-DY*(size-1)/2;
|
149
|
float startZ = DZ*(size-1)/2;
|
150
|
|
151
|
for(int layer=0; layer<size; layer++)
|
152
|
{
|
153
|
float currX = startX;
|
154
|
float currY = startY;
|
155
|
|
156
|
for(int x=0; x<layer+1; x++)
|
157
|
{
|
158
|
float currZ = startZ;
|
159
|
|
160
|
for(int z=0; z<size-layer; z++)
|
161
|
{
|
162
|
pos[index] = new float[] {currX,currY,currZ};
|
163
|
index++;
|
164
|
currZ -= DZ;
|
165
|
}
|
166
|
|
167
|
currX += DX;
|
168
|
}
|
169
|
|
170
|
startX-=DX/2;
|
171
|
startY+=DY;
|
172
|
startZ-=DZ/2;
|
173
|
}
|
174
|
}
|
175
|
|
176
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
177
|
// there are (n^3-n)/6 octahedrons and ((n+1)^3 - (n+1))/6 tetrahedrons
|
178
|
|
179
|
float[][] getCubitPositions(int size)
|
180
|
{
|
181
|
int numOcta = (size-1)*size*(size+1)/6;
|
182
|
int numTetra= size*(size+1)*(size+2)/6;
|
183
|
float[][] ret = new float[numOcta+numTetra][];
|
184
|
|
185
|
addTetrahedralLattice(size-1, 0,ret);
|
186
|
addTetrahedralLattice(size ,numOcta,ret);
|
187
|
|
188
|
return ret;
|
189
|
}
|
190
|
|
191
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192
|
|
193
|
Static4D[] getQuats()
|
194
|
{
|
195
|
if( mQuats==null ) initializeQuats();
|
196
|
return mQuats;
|
197
|
}
|
198
|
|
199
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
200
|
|
201
|
int getNumFaces()
|
202
|
{
|
203
|
return FACE_COLORS.length;
|
204
|
}
|
205
|
|
206
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
207
|
|
208
|
int getSolvedFunctionIndex()
|
209
|
{
|
210
|
return 0;
|
211
|
}
|
212
|
|
213
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
214
|
|
215
|
int getNumStickerTypes(int numLayers)
|
216
|
{
|
217
|
return 1;
|
218
|
}
|
219
|
|
220
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221
|
|
222
|
float[][] getCuts(int size)
|
223
|
{
|
224
|
float[][] cuts = new float[4][size-1];
|
225
|
|
226
|
for(int i=0; i<size-1; i++)
|
227
|
{
|
228
|
float cut = (1.0f-0.25f*size+i)*(SQ6/3);
|
229
|
cuts[0][i] = cut;
|
230
|
cuts[1][i] = cut;
|
231
|
cuts[2][i] = cut;
|
232
|
cuts[3][i] = cut;
|
233
|
}
|
234
|
|
235
|
return cuts;
|
236
|
}
|
237
|
|
238
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
239
|
|
240
|
int getNumCubitFaces()
|
241
|
{
|
242
|
return 8;
|
243
|
}
|
244
|
|
245
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
246
|
|
247
|
float getScreenRatio()
|
248
|
{
|
249
|
return 0.88f;
|
250
|
}
|
251
|
|
252
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
253
|
|
254
|
boolean shouldResetTextureMaps()
|
255
|
{
|
256
|
return false;
|
257
|
}
|
258
|
|
259
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
260
|
|
261
|
private int getNumOctahedrons(int numLayers)
|
262
|
{
|
263
|
return (numLayers-1)*numLayers*(numLayers+1)/6;
|
264
|
}
|
265
|
|
266
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
267
|
|
268
|
private int faceColor(int cubit, int axis)
|
269
|
{
|
270
|
return CUBITS[cubit].mRotationRow[axis] == 1 ? axis : NUM_FACES;
|
271
|
}
|
272
|
|
273
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
274
|
|
275
|
int getFaceColor(int cubit, int cubitface, int size)
|
276
|
{
|
277
|
if( cubit< (size-1)*size*(size+1)/6 )
|
278
|
{
|
279
|
switch( cubitface )
|
280
|
{
|
281
|
case 0: return faceColor(cubit,0);
|
282
|
case 2: return faceColor(cubit,1);
|
283
|
case 5: return faceColor(cubit,3);
|
284
|
case 7: return faceColor(cubit,2);
|
285
|
default:return NUM_FACES;
|
286
|
}
|
287
|
}
|
288
|
else
|
289
|
{
|
290
|
return cubitface<NUM_FACES ? faceColor(cubit,cubitface) : NUM_FACES;
|
291
|
}
|
292
|
}
|
293
|
|
294
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
295
|
|
296
|
ObjectShape getObjectShape(int cubit, int numLayers)
|
297
|
{
|
298
|
int variant = getCubitVariant(cubit,numLayers);
|
299
|
|
300
|
if( variant==0 )
|
301
|
{
|
302
|
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} };
|
303
|
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} };
|
304
|
int N = numLayers==3? 6 : 5;
|
305
|
int E = numLayers==3? 2 : 1;
|
306
|
float[][] bands = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
|
307
|
int[] bandIndices = new int[] { 0,0,0,0,0,0,0,0 };
|
308
|
float[][] corners = new float[][] { {0.04f,0.20f} };
|
309
|
int[] cornerIndices = new int[] { 0,0,0,0,0,0 };
|
310
|
float[][] centers = new float[][] { {0.0f, 0.0f, 0.0f} };
|
311
|
int[] centerIndices = new int[] { 0,0,0,0,0,0 };
|
312
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
313
|
}
|
314
|
else
|
315
|
{
|
316
|
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} };
|
317
|
int[][] vert_indices = new int[][] { {2,1,0},{3,0,1},{3,2,0},{2,3,1} };
|
318
|
int N = numLayers==3? 6 : 5;
|
319
|
int E = numLayers==3? 2 : 1;
|
320
|
float[][] bands = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
|
321
|
int[] bandIndices = new int[] { 0,0,0,0 };
|
322
|
float[][] corners = new float[][] { {0.06f,0.15f} };
|
323
|
int[] cornerIndices = new int[] { 0,0,0,0 };
|
324
|
float[][] centers = new float[][] { {0.0f, 0.0f, 0.0f} };
|
325
|
int[] centerIndices = new int[] { 0,0,0,0 };
|
326
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
327
|
}
|
328
|
}
|
329
|
|
330
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
331
|
|
332
|
Static4D getQuat(int cubit, int numLayers)
|
333
|
{
|
334
|
if( mQuats==null ) initializeQuats();
|
335
|
return mQuats[0];
|
336
|
}
|
337
|
|
338
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
339
|
|
340
|
int getNumCubitVariants(int numLayers)
|
341
|
{
|
342
|
return 2;
|
343
|
}
|
344
|
|
345
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
346
|
|
347
|
int getCubitVariant(int cubit, int numLayers)
|
348
|
{
|
349
|
return cubit<getNumOctahedrons(numLayers) ? 0:1;
|
350
|
}
|
351
|
|
352
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
353
|
|
354
|
int getColor(int face)
|
355
|
{
|
356
|
return FACE_COLORS[face];
|
357
|
}
|
358
|
|
359
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
360
|
|
361
|
ObjectSticker retSticker(int face)
|
362
|
{
|
363
|
if( mStickers==null )
|
364
|
{
|
365
|
float[][] STICKERS = new float[][] { { -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f } };
|
366
|
final float stroke = 0.08f;
|
367
|
final float radius = 0.06f;
|
368
|
final float[] radii= {radius,radius,radius};
|
369
|
mStickers = new ObjectSticker[STICKERS.length];
|
370
|
mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
|
371
|
}
|
372
|
|
373
|
return mStickers[face/NUM_FACES];
|
374
|
}
|
375
|
|
376
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
377
|
// SQ6/3 = height of the tetrahedron
|
378
|
|
379
|
float returnMultiplier()
|
380
|
{
|
381
|
return getNumLayers()/(SQ6/3);
|
382
|
}
|
383
|
|
384
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
385
|
|
386
|
private void initializeScrambling()
|
387
|
{
|
388
|
int numLayers = getNumLayers();
|
389
|
|
390
|
if( mScrambleTable ==null )
|
391
|
{
|
392
|
mScrambleTable = new int[NUM_AXIS][numLayers];
|
393
|
}
|
394
|
if( mNumOccurences ==null )
|
395
|
{
|
396
|
int max=0;
|
397
|
|
398
|
for (ScrambleState mState : mStates)
|
399
|
{
|
400
|
int tmp = mState.getTotal(-1);
|
401
|
if (max < tmp) max = tmp;
|
402
|
}
|
403
|
|
404
|
mNumOccurences = new int[max];
|
405
|
}
|
406
|
|
407
|
for(int i=0; i<NUM_AXIS; i++)
|
408
|
for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
|
409
|
}
|
410
|
|
411
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
412
|
// PUBLIC API
|
413
|
|
414
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
|
415
|
{
|
416
|
if( curr==0 )
|
417
|
{
|
418
|
mCurrState = 0;
|
419
|
mIndexExcluded =-1;
|
420
|
initializeScrambling();
|
421
|
}
|
422
|
|
423
|
int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
|
424
|
|
425
|
scramble[curr][0] = info[0];
|
426
|
scramble[curr][1] = info[1];
|
427
|
scramble[curr][2] = info[2];
|
428
|
|
429
|
mCurrState = info[3];
|
430
|
mIndexExcluded = info[0];
|
431
|
}
|
432
|
|
433
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
434
|
|
435
|
public Static3D[] getRotationAxis()
|
436
|
{
|
437
|
return ROT_AXIS;
|
438
|
}
|
439
|
|
440
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
441
|
|
442
|
public int[] getBasicAngle()
|
443
|
{
|
444
|
if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
|
445
|
return mBasicAngle;
|
446
|
}
|
447
|
|
448
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
449
|
|
450
|
public int getObjectName(int numLayers)
|
451
|
{
|
452
|
switch(numLayers)
|
453
|
{
|
454
|
case 3: return R.string.pyra3;
|
455
|
case 4: return R.string.pyra4;
|
456
|
case 5: return R.string.pyra5;
|
457
|
}
|
458
|
return R.string.pyra3;
|
459
|
}
|
460
|
|
461
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
462
|
|
463
|
public int getInventor(int numLayers)
|
464
|
{
|
465
|
switch(numLayers)
|
466
|
{
|
467
|
case 3: return R.string.pyra3_inventor;
|
468
|
case 4: return R.string.pyra4_inventor;
|
469
|
case 5: return R.string.pyra5_inventor;
|
470
|
}
|
471
|
return R.string.pyra3_inventor;
|
472
|
}
|
473
|
|
474
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
475
|
|
476
|
public int getComplexity(int numLayers)
|
477
|
{
|
478
|
switch(numLayers)
|
479
|
{
|
480
|
case 3: return 4;
|
481
|
case 4: return 6;
|
482
|
case 5: return 8;
|
483
|
}
|
484
|
return 4;
|
485
|
}
|
486
|
}
|