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