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