1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 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 TwistyJing extends TwistyObject
|
39
|
{
|
40
|
static final float F = 0.24f; // length of the edge of the corner cubit divided by
|
41
|
// the length of the edge of the whole tetrahedron.
|
42
|
// keep < 0.25.
|
43
|
|
44
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
45
|
{
|
46
|
new Static3D( 0,-SQ3/3,-SQ6/3),
|
47
|
new Static3D( 0,-SQ3/3,+SQ6/3),
|
48
|
new Static3D(+SQ6/3,+SQ3/3, 0),
|
49
|
new Static3D(-SQ6/3,+SQ3/3, 0),
|
50
|
};
|
51
|
|
52
|
private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
|
53
|
|
54
|
private static final int[] FACE_COLORS = new int[]
|
55
|
{
|
56
|
COLOR_GREEN , COLOR_YELLOW,
|
57
|
COLOR_BLUE , COLOR_RED
|
58
|
};
|
59
|
|
60
|
private static final int[] ROT_QUAT = {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
|
61
|
|
62
|
// computed with res/raw/compute_quats.c
|
63
|
private static final Static4D[] QUATS = new Static4D[]
|
64
|
{
|
65
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f),
|
66
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f),
|
67
|
new Static4D( SQ2/2, 0.5f, 0.0f, 0.5f),
|
68
|
new Static4D(-SQ2/2, 0.5f, 0.0f, 0.5f),
|
69
|
new Static4D( 0.0f, -0.5f, -SQ2/2, 0.5f),
|
70
|
new Static4D( 0.0f, -0.5f, SQ2/2, 0.5f),
|
71
|
new Static4D( SQ2/2, 0.5f, 0.0f, -0.5f),
|
72
|
new Static4D(-SQ2/2, 0.5f, 0.0f, -0.5f),
|
73
|
new Static4D( 0.0f, -0.5f, -SQ2/2, -0.5f),
|
74
|
new Static4D( 0.0f, -0.5f, SQ2/2, -0.5f),
|
75
|
new Static4D( SQ2/2, 0.0f, SQ2/2, 0.0f),
|
76
|
new Static4D(-SQ2/2, 0.0f, SQ2/2, 0.0f)
|
77
|
};
|
78
|
|
79
|
static final float[][] CENTERS = new float[][]
|
80
|
{
|
81
|
{ 0.000f, -SQ2/4, 0.500f },
|
82
|
{ 0.000f, -SQ2/4,-0.500f },
|
83
|
{-0.500f, SQ2/4, 0.000f },
|
84
|
{ 0.500f, SQ2/4, 0.000f },
|
85
|
|
86
|
{ 0.000f, -SQ2/4, 0.000f },
|
87
|
{-0.250f, 0.000f, 0.250f },
|
88
|
{ 0.250f, 0.000f, 0.250f },
|
89
|
{-0.250f, 0.000f,-0.250f },
|
90
|
{ 0.250f, 0.000f,-0.250f },
|
91
|
{ 0.000f, SQ2/4, 0.000f },
|
92
|
|
93
|
{ 0.000f, SQ2/12, 1.0f/6 },
|
94
|
{ 0.000f, SQ2/12,-1.0f/6 },
|
95
|
{-1.0f/6,-SQ2/12, 0.000f },
|
96
|
{ 1.0f/6,-SQ2/12, 0.000f },
|
97
|
};
|
98
|
|
99
|
// Colors of the faces of cubits.
|
100
|
// GREEN 0 YELLOW 1 BLUE 2 RED 3
|
101
|
// GREEN 4 YELLOW 5 BLUE 6 RED 7
|
102
|
// GREEN 8 YELLOW 9 BLUE 10 RED 11
|
103
|
private static final int[][] mFaceMap = new int[][]
|
104
|
{
|
105
|
{ 0, 3, 2, 12, 12, 12 },
|
106
|
{ 1, 2, 3, 12, 12, 12 },
|
107
|
{ 1, 0, 2, 12, 12, 12 },
|
108
|
{ 1, 3, 0, 12, 12, 12 },
|
109
|
|
110
|
{ 7, 6, 12, 12, 12, 12 },
|
111
|
{ 4, 6, 12, 12, 12, 12 },
|
112
|
{ 7, 4, 12, 12, 12, 12 },
|
113
|
{ 5, 6, 12, 12, 12, 12 },
|
114
|
{ 7, 5, 12, 12, 12, 12 },
|
115
|
{ 4, 5, 12, 12, 12, 12 },
|
116
|
|
117
|
{ 8, 12, 12, 12, 12, 12 },
|
118
|
{ 9, 12, 12, 12, 12, 12 },
|
119
|
{ 10, 12, 12, 12, 12, 12 },
|
120
|
{ 11, 12, 12, 12, 12, 12 },
|
121
|
};
|
122
|
|
123
|
private static final float X = F/2;
|
124
|
private static final float Y = F*SQ2/2;
|
125
|
private static final float Z =-F/2;
|
126
|
private static final float L = (1-3*F);
|
127
|
private static final float X2= L/2;
|
128
|
private static final float Y2= L*SQ2/2;
|
129
|
private static final float Z2=-L/2;
|
130
|
private static final float D = F/L;
|
131
|
|
132
|
private static final double[][] VERTICES_CORNER = new double[][]
|
133
|
{
|
134
|
{ 0.0, 0.0, 0.0 },
|
135
|
{ X, Y, Z },
|
136
|
{ 0.0, 2*Y, 2*Z },
|
137
|
{ -X, Y, Z },
|
138
|
{ 0.0, 0.0, -F },
|
139
|
{ X, Y, Z-F },
|
140
|
{ 0.0, 2*Y, 2*Z-F },
|
141
|
{ -X, Y, Z-F },
|
142
|
};
|
143
|
|
144
|
private static final int[][] VERT_INDEXES_CORNER = new int[][]
|
145
|
{
|
146
|
{0,1,2,3},
|
147
|
{1,0,4,5},
|
148
|
{7,4,0,3},
|
149
|
{1,5,6,2},
|
150
|
{7,3,2,6},
|
151
|
{4,7,6,5}
|
152
|
};
|
153
|
|
154
|
private static final double[][] VERTICES_EDGE = new double[][]
|
155
|
{
|
156
|
{ 0.0, 0.0, 0.5-F },
|
157
|
{ X, Y, Z+0.5-F },
|
158
|
{ 0.0, 2*Y, 2*Z+0.5-F },
|
159
|
{ -X, Y, Z+0.5-F },
|
160
|
{ 0.0, 0.0, -0.5+F },
|
161
|
{ X, Y, -Z-0.5+F },
|
162
|
{ 0.0, 2*Y,-2*Z-0.5+F },
|
163
|
{ -X, Y, -Z-0.5+F },
|
164
|
};
|
165
|
|
166
|
private static final int[][] VERT_INDEXES_EDGE = new int[][]
|
167
|
{
|
168
|
{0,4,5,1},
|
169
|
{3,7,4,0},
|
170
|
{0,1,2,3},
|
171
|
{4,7,6,5},
|
172
|
{1,5,6,2},
|
173
|
{2,6,7,3}
|
174
|
};
|
175
|
|
176
|
private static final double[][] VERTICES_FACE = new double[][]
|
177
|
{
|
178
|
{ 0.0, -2*Y2/3, -2*Z2/3 },
|
179
|
{ X2, Y2/3, Z2/3 },
|
180
|
{ -X2, Y2/3, Z2/3 },
|
181
|
{ 0.0, -2*Y2/3,-2*Z2/3+2*D*Z2 },
|
182
|
{ X2-D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
|
183
|
{ -X2+D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
|
184
|
};
|
185
|
|
186
|
private static final int[][] VERT_INDEXES_FACE = new int[][]
|
187
|
{
|
188
|
{0,1,2},
|
189
|
{3,5,4},
|
190
|
{0,3,4,1},
|
191
|
{5,3,0,2},
|
192
|
{4,5,2,1}
|
193
|
};
|
194
|
|
195
|
private static final float[][] STICKERS = new float[][]
|
196
|
{
|
197
|
{ 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
|
198
|
{ -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
|
199
|
{ 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
|
200
|
};
|
201
|
|
202
|
private static final ObjectSticker[] mStickers;
|
203
|
|
204
|
static
|
205
|
{
|
206
|
mStickers = new ObjectSticker[STICKERS.length];
|
207
|
final float R1 = 0.05f;
|
208
|
final float R2 = 0.10f;
|
209
|
final float R3 = 0.03f;
|
210
|
final float[][] radii = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
|
211
|
final float[] strokes = { 0.06f, 0.03f, 0.05f };
|
212
|
|
213
|
for(int s=0; s<STICKERS.length; s++)
|
214
|
{
|
215
|
mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
|
216
|
}
|
217
|
}
|
218
|
|
219
|
private int mCurrState;
|
220
|
private int mIndexExcluded;
|
221
|
private final ScrambleState[] mStates;
|
222
|
private int[][] mScrambleTable;
|
223
|
private int[] mNumOccurences;
|
224
|
|
225
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226
|
|
227
|
TwistyJing(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
228
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
229
|
{
|
230
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.JING, res, scrWidth);
|
231
|
|
232
|
int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
|
233
|
|
234
|
mStates = new ScrambleState[]
|
235
|
{
|
236
|
new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
|
237
|
};
|
238
|
}
|
239
|
|
240
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
241
|
|
242
|
int[] getSolvedQuats(int cubit, int numLayers)
|
243
|
{
|
244
|
int status = retCubitSolvedStatus(cubit,numLayers);
|
245
|
return status<0 ? null : buildSolvedQuats(MovementJing.FACE_AXIS[status],QUATS);
|
246
|
}
|
247
|
|
248
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
249
|
|
250
|
float[][] getCubitPositions(int size)
|
251
|
{
|
252
|
return CENTERS;
|
253
|
}
|
254
|
|
255
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256
|
|
257
|
Static4D[] getQuats()
|
258
|
{
|
259
|
return QUATS;
|
260
|
}
|
261
|
|
262
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
263
|
|
264
|
int getNumFaces()
|
265
|
{
|
266
|
return FACE_COLORS.length;
|
267
|
}
|
268
|
|
269
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
270
|
|
271
|
int getSolvedFunctionIndex()
|
272
|
{
|
273
|
return 0;
|
274
|
}
|
275
|
|
276
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
277
|
|
278
|
int getNumStickerTypes(int numLayers)
|
279
|
{
|
280
|
return STICKERS.length;
|
281
|
}
|
282
|
|
283
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
284
|
|
285
|
float[][] getCuts(int size)
|
286
|
{
|
287
|
float[] cut = { (F-0.25f)*(SQ6/3) };
|
288
|
return new float[][] { cut,cut,cut,cut };
|
289
|
}
|
290
|
|
291
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
292
|
|
293
|
int getNumCubitFaces()
|
294
|
{
|
295
|
return 6;
|
296
|
}
|
297
|
|
298
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
299
|
|
300
|
float getScreenRatio()
|
301
|
{
|
302
|
return 2*TwistyPyraminx.SCREEN_RATIO;
|
303
|
}
|
304
|
|
305
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
306
|
|
307
|
boolean shouldResetTextureMaps()
|
308
|
{
|
309
|
return false;
|
310
|
}
|
311
|
|
312
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
313
|
|
314
|
int getFaceColor(int cubit, int cubitface, int size)
|
315
|
{
|
316
|
return mFaceMap[cubit][cubitface];
|
317
|
}
|
318
|
|
319
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
320
|
|
321
|
ObjectShape getObjectShape(int cubit, int numLayers)
|
322
|
{
|
323
|
int variant = getCubitVariant(cubit,numLayers);
|
324
|
|
325
|
if( variant==0 )
|
326
|
{
|
327
|
float[][] bands = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
|
328
|
int[] bandIndices = new int[] { 0,0,0,1,1,1 };
|
329
|
float[][] corners = new float[][] { {0.08f,0.20f*F},{0.07f,0.20f*F} };
|
330
|
int[] cornerIndices = new int[] { 0,1,1,-1,1,-1,-1,-1 };
|
331
|
float[][] centers = new float[][] { { 0.0f, F*SQ2/2, -F} };
|
332
|
int[] centerIndices = new int[] { 0,0,0,-1,0,-1,-1,-1 };
|
333
|
return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
334
|
}
|
335
|
else if( variant==1 )
|
336
|
{
|
337
|
float[][] bands = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
|
338
|
int[] bandIndices = new int[] { 0,0,1,1,1,1 };
|
339
|
float[][] corners = new float[][] { {0.07f,0.20f*F} };
|
340
|
int[] cornerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
|
341
|
float[][] centers = new float[][] { { 0, F*SQ2/2, 0 } };
|
342
|
int[] centerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
|
343
|
return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
344
|
}
|
345
|
else
|
346
|
{
|
347
|
float[][] bands = new float[][] { {0.020f,35,0.20f*(1-3*F),0.6f*(1-3*F),5,1,1}, {0.001f,35,0.05f*(1-3*F),0.1f*(1-3*F),5,1,1} };
|
348
|
int[] bandIndices = new int[] { 0,1,1,1,1,1 };
|
349
|
float[][] corners = new float[][] { {0.04f,0.15f} };
|
350
|
int[] cornerIndices = new int[] { 0,0,0,-1,-1,-1 };
|
351
|
float[][] centers = new float[][] { { 0, -2*Y/3, 4*Z/3 } };
|
352
|
int[] centerIndices = new int[] { 0,0,0,-1,-1,-1 };
|
353
|
return new ObjectShape(VERTICES_FACE,VERT_INDEXES_FACE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
354
|
}
|
355
|
}
|
356
|
|
357
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
358
|
|
359
|
Static4D getQuat(int cubit, int numLayers)
|
360
|
{
|
361
|
return QUATS[ROT_QUAT[cubit]];
|
362
|
}
|
363
|
|
364
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
365
|
|
366
|
int getNumCubitVariants(int numLayers)
|
367
|
{
|
368
|
return 3;
|
369
|
}
|
370
|
|
371
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
372
|
|
373
|
int getCubitVariant(int cubit, int numLayers)
|
374
|
{
|
375
|
return cubit<4 ? 0 : (cubit<10?1:2);
|
376
|
}
|
377
|
|
378
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
379
|
|
380
|
int getColor(int face)
|
381
|
{
|
382
|
return FACE_COLORS[face];
|
383
|
}
|
384
|
|
385
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
386
|
|
387
|
ObjectSticker retSticker(int face)
|
388
|
{
|
389
|
return mStickers[face/NUM_FACES];
|
390
|
}
|
391
|
|
392
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
393
|
// SQ6/3 = height of the tetrahedron
|
394
|
|
395
|
float returnMultiplier()
|
396
|
{
|
397
|
return getNumLayers()/(SQ6/3);
|
398
|
}
|
399
|
|
400
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
401
|
|
402
|
private void initializeScrambling()
|
403
|
{
|
404
|
int numLayers = getNumLayers();
|
405
|
|
406
|
if( mScrambleTable ==null )
|
407
|
{
|
408
|
mScrambleTable = new int[NUM_AXIS][numLayers];
|
409
|
}
|
410
|
if( mNumOccurences ==null )
|
411
|
{
|
412
|
int max=0;
|
413
|
|
414
|
for (ScrambleState mState : mStates)
|
415
|
{
|
416
|
int tmp = mState.getTotal(-1);
|
417
|
if (max < tmp) max = tmp;
|
418
|
}
|
419
|
|
420
|
mNumOccurences = new int[max];
|
421
|
}
|
422
|
|
423
|
for(int i=0; i<NUM_AXIS; i++)
|
424
|
for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
|
425
|
}
|
426
|
|
427
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
428
|
// PUBLIC API
|
429
|
|
430
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
|
431
|
{
|
432
|
if( curr==0 )
|
433
|
{
|
434
|
mCurrState = 0;
|
435
|
mIndexExcluded =-1;
|
436
|
initializeScrambling();
|
437
|
}
|
438
|
|
439
|
int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
|
440
|
|
441
|
scramble[curr][0] = info[0];
|
442
|
scramble[curr][1] = info[1];
|
443
|
scramble[curr][2] = info[2];
|
444
|
|
445
|
mCurrState = info[3];
|
446
|
mIndexExcluded = info[0];
|
447
|
}
|
448
|
|
449
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
450
|
|
451
|
public Static3D[] getRotationAxis()
|
452
|
{
|
453
|
return ROT_AXIS;
|
454
|
}
|
455
|
|
456
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
457
|
|
458
|
public int[] getBasicAngle()
|
459
|
{
|
460
|
return BASIC_ANGLE;
|
461
|
}
|
462
|
|
463
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
464
|
|
465
|
public int getObjectName(int numLayers)
|
466
|
{
|
467
|
return R.string.jing;
|
468
|
}
|
469
|
|
470
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
471
|
|
472
|
public int getInventor(int numLayers)
|
473
|
{
|
474
|
return R.string.jing_inventor;
|
475
|
}
|
476
|
|
477
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
478
|
|
479
|
public int getComplexity(int numLayers)
|
480
|
{
|
481
|
return 4;
|
482
|
}
|
483
|
}
|