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 static org.distorted.objects.Movement.TYPE_NOT_SPLIT;
|
23
|
|
24
|
import android.content.res.Resources;
|
25
|
|
26
|
import org.distorted.helpers.ObjectShape;
|
27
|
import org.distorted.helpers.ObjectSticker;
|
28
|
import org.distorted.helpers.ScrambleState;
|
29
|
import org.distorted.library.main.DistortedEffects;
|
30
|
import org.distorted.library.main.DistortedTexture;
|
31
|
import org.distorted.library.mesh.MeshSquare;
|
32
|
import org.distorted.library.type.Static3D;
|
33
|
import org.distorted.library.type.Static4D;
|
34
|
import org.distorted.main.R;
|
35
|
|
36
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37
|
|
38
|
class TwistyUltimate extends Twisty12
|
39
|
{
|
40
|
private static final float A = (float)Math.sqrt(21*SQ5+47);
|
41
|
private static final float B = SQ6*(5*SQ5+11)/(6*A);
|
42
|
private static final float C = SQ6*( SQ5+ 2)/(3*A);
|
43
|
private static final float D = SQ3/3;
|
44
|
private static final float E = (SQ5+1)/4;
|
45
|
private static final float F = (SQ5-1)/4;
|
46
|
private static final float G = (SQ5+3)/4;
|
47
|
|
48
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
49
|
{
|
50
|
new Static3D( B,0,C ),
|
51
|
new Static3D( C,B,0 ),
|
52
|
new Static3D(-D,D,D ),
|
53
|
new Static3D( 0,C,-B)
|
54
|
};
|
55
|
|
56
|
private static final int[][][] ENABLED = new int[][][]
|
57
|
{
|
58
|
{{2,3}},{{1,3}},{{1,3}},{{2,3}},{{0,3}},{{0,2}},{{0,2}},{{0,3}},{{1,2}},{{0,1}},{{0,1}},{{1,2}}
|
59
|
};
|
60
|
|
61
|
private ScrambleState[] mStates;
|
62
|
private int[] mBasicAngle;
|
63
|
private Static4D[] mQuats;
|
64
|
private float[][] mCuts;
|
65
|
private boolean[][] mLayerRotatable;
|
66
|
private int[][] mFaceMap;
|
67
|
private float[][] mCenters;
|
68
|
private int[] mQuatIndex;
|
69
|
private ObjectSticker[] mStickers;
|
70
|
private Movement mMovement;
|
71
|
|
72
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73
|
|
74
|
TwistyUltimate(int size, Static4D quat, DistortedTexture texture,
|
75
|
MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
76
|
{
|
77
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.ULTI, res, scrWidth);
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
|
82
|
ScrambleState[] getScrambleStates()
|
83
|
{
|
84
|
if( mStates==null )
|
85
|
{
|
86
|
int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
|
87
|
|
88
|
mStates = new ScrambleState[]
|
89
|
{
|
90
|
new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
|
91
|
};
|
92
|
}
|
93
|
|
94
|
return mStates;
|
95
|
}
|
96
|
|
97
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98
|
|
99
|
private void initializeQuats()
|
100
|
{
|
101
|
mQuats = new Static4D[]
|
102
|
{
|
103
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
104
|
new Static4D(-0.5f, 0.5f, 0.5f, 0.5f ),
|
105
|
new Static4D( 0.5f,-0.5f,-0.5f, 0.5f ),
|
106
|
new Static4D( 0.0f, F, -E, 0.5f ),
|
107
|
new Static4D( 0.0f, -F, E, 0.5f ),
|
108
|
new Static4D( E, 0.0f, F, 0.5f ),
|
109
|
new Static4D( -E, 0.0f, -F, 0.5f ),
|
110
|
new Static4D( F, E, 0.0f, 0.5f ),
|
111
|
new Static4D( -F, -E, 0.0f, 0.5f ),
|
112
|
new Static4D( E, F,-0.5f, 0.0f ),
|
113
|
new Static4D( 0.5f, -E, F, 0.0f ),
|
114
|
new Static4D( F, 0.5f, E, 0.0f )
|
115
|
};
|
116
|
}
|
117
|
|
118
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119
|
|
120
|
int[] getSolvedQuats(int cubit, int numLayers)
|
121
|
{
|
122
|
if( mQuats==null ) initializeQuats();
|
123
|
int status = retCubitSolvedStatus(cubit,numLayers);
|
124
|
return status<0 ? null : buildSolvedQuats(Movement12.FACE_AXIS[status],mQuats);
|
125
|
}
|
126
|
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
|
129
|
ObjectShape getObjectShape(int cubit, int numLayers)
|
130
|
{
|
131
|
int variant = getCubitVariant(cubit,numLayers);
|
132
|
|
133
|
if( variant==0 )
|
134
|
{
|
135
|
double[][] vertices = new double[][]
|
136
|
{
|
137
|
{ 0.0 , 0.0 , 0.0 },
|
138
|
{ -E , E+0.5, -0.5 },
|
139
|
{-0.5 , -E , -E-0.5},
|
140
|
{ E+0.5, 0.5 , -E },
|
141
|
{ 0.0 , 1 , -2*E-1},
|
142
|
{ 0.0 , 1 , 0.0 },
|
143
|
{ -E ,-E+0.5, -0.5 },
|
144
|
{ E ,-E+0.5, -0.5 }
|
145
|
};
|
146
|
int[][] vert_indices = new int[][]
|
147
|
{
|
148
|
{6,0,5,1},
|
149
|
{0,7,3,5},
|
150
|
{0,6,2,7},
|
151
|
{4,3,5,1},
|
152
|
{4,2,7,3},
|
153
|
{4,1,6,2},
|
154
|
};
|
155
|
|
156
|
float[][] bands = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
|
157
|
int[] bandIndices = new int[] { 0,0,0,1,1,1 };
|
158
|
float[][] corners = new float[][] { { 0.013f, 0.16f } };
|
159
|
int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
|
160
|
float[][] centers = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
|
161
|
int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
|
162
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
163
|
}
|
164
|
else if( variant==1 )
|
165
|
{
|
166
|
double[][] vertices = new double[][]
|
167
|
{
|
168
|
{ 0.00, 0.00, 0.00},
|
169
|
{ - 0.50,-SQ5/4 - 0.25,-SQ5/4 - 0.75},
|
170
|
{ SQ5/4 + 0.25,-SQ5/4 - 0.75, + 0.50},
|
171
|
{ SQ5/4 + 0.75, + 0.50,-SQ5/4 - 0.25},
|
172
|
{ SQ5/2 + 0.50,-SQ5/2 - 0.50,-SQ5/2 - 0.50},
|
173
|
{ SQ5/4 - 0.25, + 0.50,-SQ5/4 - 0.25},
|
174
|
{ - 0.50,-SQ5/4 - 0.25,-SQ5/4 + 0.25},
|
175
|
{ SQ5/4 + 0.25,-SQ5/4 + 0.25, + 0.50}
|
176
|
};
|
177
|
int[][] vert_indices = new int[][]
|
178
|
{
|
179
|
{6,0,5,1},
|
180
|
{0,7,3,5},
|
181
|
{0,6,2,7},
|
182
|
{1,5,3,4},
|
183
|
{3,7,2,4},
|
184
|
{2,6,1,4},
|
185
|
};
|
186
|
|
187
|
float[][] bands = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
|
188
|
int[] bandIndices = new int[] { 0,0,0,1,1,1 };
|
189
|
float[][] corners = new float[][] { { 0.013f, 0.16f } };
|
190
|
int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
|
191
|
float[][] centers = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
|
192
|
int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
|
193
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
194
|
}
|
195
|
else
|
196
|
{
|
197
|
double[][] vertices = new double[][]
|
198
|
{
|
199
|
{ -E ,-E+0.5, 0.5},
|
200
|
{ E , E-0.5, -0.5},
|
201
|
{-2*E , 0.0, 0.0},
|
202
|
{ 0.5, E , -E-0.5},
|
203
|
{ -E ,-E-0.5, 0.5},
|
204
|
{ E+0.5, -0.5, -E },
|
205
|
{-2*E , -1.0, 0.0},
|
206
|
{ 1.0, 0.0,-2*E },
|
207
|
{-2*E+0.5, E , -E-0.5},
|
208
|
{ 0.5,-E-1.0, -E+0.5},
|
209
|
{ -E ,-E-0.5,-2*E-0.5}
|
210
|
};
|
211
|
int[][] vert_indices = new int[][]
|
212
|
{
|
213
|
{0,1,3,8,2}, // counterclockwise!
|
214
|
{0,4,9,5,1},
|
215
|
{ 0,2,6,4},
|
216
|
{ 1,5,7,3},
|
217
|
{10,9,4,6},
|
218
|
{10,9,5,7},
|
219
|
{10,8,3,7},
|
220
|
{10,8,2,6}
|
221
|
};
|
222
|
|
223
|
float[][] bands = new float[][] { {0.04f,17,0.5f,0.2f,5,2,2}, {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
|
224
|
int[] bandIndices = new int[] { 0,0,1,1,2,2,2,2 };
|
225
|
float[][] corners = new float[][] { { 0.013f, 0.16f } };
|
226
|
int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
|
227
|
float[][] centers = new float[][] { { -(SQ5+1)/4, 0.5f, -(SQ5+5)/4 } };
|
228
|
int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
|
229
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
230
|
}
|
231
|
}
|
232
|
|
233
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
234
|
|
235
|
Static4D getQuat(int cubit, int numLayers)
|
236
|
{
|
237
|
if( mQuats ==null ) initializeQuats();
|
238
|
if( mQuatIndex ==null ) mQuatIndex = new int[] { 0,6,1,2,0,4,6,5,0,1,4,9,5,2 };
|
239
|
return mQuats[mQuatIndex[cubit]];
|
240
|
}
|
241
|
|
242
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
243
|
|
244
|
int getNumCubitVariants(int numLayers)
|
245
|
{
|
246
|
return 3;
|
247
|
}
|
248
|
|
249
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
250
|
|
251
|
int getCubitVariant(int cubit, int numLayers)
|
252
|
{
|
253
|
return cubit<4 ? 0 : (cubit<8 ? 1:2);
|
254
|
}
|
255
|
|
256
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
257
|
|
258
|
float[][] getCubitPositions(int numLayers)
|
259
|
{
|
260
|
if( mCenters==null )
|
261
|
{
|
262
|
mCenters = new float[][]
|
263
|
{
|
264
|
{ 0, -1, 2*G },
|
265
|
{ 2*E,-2*E,-2*E },
|
266
|
{-2*G, 0, -1 },
|
267
|
{ 1, 2*G, 0 },
|
268
|
|
269
|
{-2*E, 2*E, 2*E },
|
270
|
{ 2*G, 0, 1 },
|
271
|
{ -1, -2*G, 0 },
|
272
|
{ 0, 1,-2*G },
|
273
|
|
274
|
{ E, (E+0.5f), (E+G) },
|
275
|
{ -(E+G), -E, (E+0.5f) },
|
276
|
{ (E+0.5f), -(E+G), E },
|
277
|
{ -E,-(E+0.5f), -(E+G) },
|
278
|
{ (E+G), E,-(E+0.5f) },
|
279
|
{-(E+0.5f), (E+G), -E }
|
280
|
};
|
281
|
}
|
282
|
|
283
|
return mCenters;
|
284
|
}
|
285
|
|
286
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
287
|
|
288
|
int getFaceColor(int cubit, int cubitface, int size)
|
289
|
{
|
290
|
if( mFaceMap==null )
|
291
|
{
|
292
|
mFaceMap = new int[][]
|
293
|
{
|
294
|
{ 25,24,35, 36,36,36,36,36 },
|
295
|
{ 27,28,29, 36,36,36,36,36 },
|
296
|
{ 31,26,30, 36,36,36,36,36 },
|
297
|
{ 32,34,33, 36,36,36,36,36 },
|
298
|
|
299
|
{ 31,32,25, 36,36,36,36,36 },
|
300
|
{ 33,28,24, 36,36,36,36,36 },
|
301
|
{ 26,35,27, 36,36,36,36,36 },
|
302
|
{ 30,29,34, 36,36,36,36,36 },
|
303
|
|
304
|
{ 8, 0,13,21, 36,36,36,36 },
|
305
|
{ 1, 2,19,23, 36,36,36,36 },
|
306
|
{ 4,11,12,15, 36,36,36,36 },
|
307
|
{ 3, 6,14,17, 36,36,36,36 },
|
308
|
{ 5, 9,22,16, 36,36,36,36 },
|
309
|
{ 7,10,20,18, 36,36,36,36 }
|
310
|
};
|
311
|
}
|
312
|
|
313
|
return mFaceMap[cubit][cubitface];
|
314
|
}
|
315
|
|
316
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
317
|
|
318
|
ObjectSticker retSticker(int face)
|
319
|
{
|
320
|
if( mStickers==null )
|
321
|
{
|
322
|
float[][] STICKERS = new float[][]
|
323
|
{
|
324
|
{ -0.14400357f, -0.47894150f, 0.50000000f,-0.011045523f, 0.37700626f, 0.36749030f,-0.26699730f, 0.36749026f, -0.46600536f, -0.24499352f }, // Big cubit 1st
|
325
|
{ 0.36327127f, 0.26393202f,-0.36327127f, 0.500000000f,-0.36327127f,-0.26393202f, 0.36327127f,-0.50000000f }, // Big cubit 2nd
|
326
|
{ -0.29389262f, -0.50000000f, 0.29389262f,-0.309017000f, 0.29389262f, 0.30901700f,-0.29389262f, 0.50000000f }, // Small cubit 1st
|
327
|
};
|
328
|
|
329
|
final float R1 = 0.08f;
|
330
|
final float R2 = 0.13f;
|
331
|
final float R3 = 0.11f;
|
332
|
final float[][] radii = { {R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
|
333
|
final float[] strokes = { 0.07f, 0.09f, 0.08f };
|
334
|
|
335
|
mStickers = new ObjectSticker[STICKERS.length];
|
336
|
|
337
|
for(int s=0; s<STICKERS.length; s++)
|
338
|
{
|
339
|
mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
|
340
|
}
|
341
|
}
|
342
|
|
343
|
return mStickers[face/NUM_FACE_COLORS];
|
344
|
}
|
345
|
|
346
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
347
|
|
348
|
Static4D[] getQuats()
|
349
|
{
|
350
|
if( mQuats==null ) initializeQuats();
|
351
|
return mQuats;
|
352
|
}
|
353
|
|
354
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
355
|
|
356
|
int getSolvedFunctionIndex()
|
357
|
{
|
358
|
return 0;
|
359
|
}
|
360
|
|
361
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
362
|
|
363
|
float[][] getCuts(int numLayers)
|
364
|
{
|
365
|
if( mCuts==null )
|
366
|
{
|
367
|
float[] cut = new float[] {0.0f};
|
368
|
mCuts = new float[][] { cut,cut,cut,cut };
|
369
|
}
|
370
|
|
371
|
return mCuts;
|
372
|
}
|
373
|
|
374
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
375
|
|
376
|
private void getLayerRotatable(int numLayers)
|
377
|
{
|
378
|
if( mLayerRotatable==null )
|
379
|
{
|
380
|
int numAxis = ROT_AXIS.length;
|
381
|
boolean[] tmp = new boolean[numLayers];
|
382
|
for(int i=0; i<numLayers; i++) tmp[i] = true;
|
383
|
mLayerRotatable = new boolean[numAxis][];
|
384
|
for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
|
385
|
}
|
386
|
}
|
387
|
|
388
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
389
|
|
390
|
int getNumStickerTypes(int numLayers)
|
391
|
{
|
392
|
return 3;
|
393
|
}
|
394
|
|
395
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
396
|
|
397
|
int getNumCubitFaces()
|
398
|
{
|
399
|
return 8;
|
400
|
}
|
401
|
|
402
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
403
|
// PUBLIC API
|
404
|
|
405
|
public Static3D[] getRotationAxis()
|
406
|
{
|
407
|
return ROT_AXIS;
|
408
|
}
|
409
|
|
410
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
411
|
|
412
|
public Movement getMovement()
|
413
|
{
|
414
|
if( mMovement==null )
|
415
|
{
|
416
|
int numLayers = getNumLayers();
|
417
|
if( mCuts==null ) getCuts(numLayers);
|
418
|
getLayerRotatable(numLayers);
|
419
|
mMovement = new Movement12(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_NOT_SPLIT,ENABLED);
|
420
|
}
|
421
|
return mMovement;
|
422
|
}
|
423
|
|
424
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
425
|
|
426
|
public int[] getBasicAngle()
|
427
|
{
|
428
|
if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
|
429
|
return mBasicAngle;
|
430
|
}
|
431
|
|
432
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
433
|
|
434
|
public int getObjectName(int numLayers)
|
435
|
{
|
436
|
return R.string.ulti2;
|
437
|
}
|
438
|
|
439
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
440
|
|
441
|
public int getInventor(int numLayers)
|
442
|
{
|
443
|
return R.string.ulti2_inventor;
|
444
|
}
|
445
|
|
446
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
447
|
|
448
|
public int getComplexity(int numLayers)
|
449
|
{
|
450
|
return 6;
|
451
|
}
|
452
|
}
|