1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.objectlib.objects;
|
11
|
|
12
|
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_OCTAHEDRON;
|
13
|
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
|
14
|
|
15
|
import org.distorted.library.type.Static3D;
|
16
|
import org.distorted.library.type.Static4D;
|
17
|
|
18
|
import org.distorted.objectlib.helpers.FactoryCubit;
|
19
|
import org.distorted.objectlib.helpers.ObjectFaceShape;
|
20
|
import org.distorted.objectlib.metadata.Metadata;
|
21
|
import org.distorted.objectlib.helpers.ObjectVertexEffects;
|
22
|
import org.distorted.objectlib.main.InitAssets;
|
23
|
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
|
24
|
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
|
25
|
import org.distorted.objectlib.metadata.ListObjects;
|
26
|
import org.distorted.objectlib.helpers.ObjectShape;
|
27
|
import org.distorted.objectlib.shape.ShapeOctahedron;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
public class TwistyDiamond extends ShapeOctahedron
|
32
|
{
|
33
|
// the four rotation axis of a Diamond. Must be normalized.
|
34
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
35
|
{
|
36
|
new Static3D( SQ6/3, SQ3/3, 0),
|
37
|
new Static3D(-SQ6/3, SQ3/3, 0),
|
38
|
new Static3D( 0,-SQ3/3,-SQ6/3),
|
39
|
new Static3D( 0,-SQ3/3, SQ6/3)
|
40
|
};
|
41
|
|
42
|
private int[][] mEdges;
|
43
|
private int[][] mBasicAngle;
|
44
|
private float[][] mCuts;
|
45
|
private int[] mTetraToFaceMap;
|
46
|
private float[][] mPosition;
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
|
50
|
public TwistyDiamond(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
|
51
|
{
|
52
|
super(iconMode, meta.getNumLayers()[0], quat, move, scale, meta, asset);
|
53
|
}
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
@Override
|
58
|
public float[][] returnRotationFactor()
|
59
|
{
|
60
|
int numL = getNumLayers()[0];
|
61
|
float[] f = new float[numL];
|
62
|
for(int i=0; i<numL; i++) f[i] = 1.5f;
|
63
|
return new float[][] { f,f,f,f };
|
64
|
}
|
65
|
|
66
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67
|
|
68
|
public int[][] getScrambleEdges()
|
69
|
{
|
70
|
if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
|
71
|
return mEdges;
|
72
|
}
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
|
76
|
public float[][] getCuts(int[] numLayers)
|
77
|
{
|
78
|
int numL = numLayers[0];
|
79
|
if( numL<2 ) return null;
|
80
|
|
81
|
if( mCuts==null )
|
82
|
{
|
83
|
mCuts = new float[4][numL-1];
|
84
|
float cut = (SQ6/6)*(2-numL);
|
85
|
|
86
|
for(int i=0; i<numL-1; i++)
|
87
|
{
|
88
|
mCuts[0][i] = cut;
|
89
|
mCuts[1][i] = cut;
|
90
|
mCuts[2][i] = cut;
|
91
|
mCuts[3][i] = cut;
|
92
|
cut += SQ6/3;
|
93
|
}
|
94
|
}
|
95
|
|
96
|
return mCuts;
|
97
|
}
|
98
|
|
99
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100
|
|
101
|
public boolean[][] getLayerRotatable(int[] numLayers)
|
102
|
{
|
103
|
int numAxis = ROT_AXIS.length;
|
104
|
boolean[][] layerRotatable = new boolean[numAxis][];
|
105
|
|
106
|
for(int i=0; i<numAxis; i++)
|
107
|
{
|
108
|
layerRotatable[i] = new boolean[numLayers[i]];
|
109
|
for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
|
110
|
}
|
111
|
|
112
|
return layerRotatable;
|
113
|
}
|
114
|
|
115
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116
|
|
117
|
public int getTouchControlType()
|
118
|
{
|
119
|
return TC_OCTAHEDRON;
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
|
124
|
public int getTouchControlSplit()
|
125
|
{
|
126
|
return TYPE_NOT_SPLIT;
|
127
|
}
|
128
|
|
129
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130
|
|
131
|
public int[][][] getEnabled()
|
132
|
{
|
133
|
return new int[][][]
|
134
|
{
|
135
|
{{1,2,3}},{{1,2,3}},{{0,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,3}},{{0,1,2}},{{0,1,2}}
|
136
|
};
|
137
|
}
|
138
|
|
139
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140
|
|
141
|
public float[] getDist3D(int[] numLayers)
|
142
|
{
|
143
|
return TouchControlOctahedron.D3D;
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
public Static3D[] getFaceAxis()
|
149
|
{
|
150
|
return TouchControlOctahedron.FACE_AXIS;
|
151
|
}
|
152
|
|
153
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
154
|
|
155
|
private int getNumOctahedrons(int layers)
|
156
|
{
|
157
|
return layers==1 ? 1 : 4*(layers-1)*(layers-1) + 2;
|
158
|
}
|
159
|
|
160
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
161
|
|
162
|
private int getNumTetrahedrons(int layers)
|
163
|
{
|
164
|
return 4*layers*(layers-1);
|
165
|
}
|
166
|
|
167
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
168
|
|
169
|
private int createOctaPositions(float[][] centers, int index, int layers, float height)
|
170
|
{
|
171
|
float x = (layers-1)*0.5f;
|
172
|
float z = (layers+1)*0.5f;
|
173
|
|
174
|
for(int i=0; i<layers; i++, index++)
|
175
|
{
|
176
|
z -= 1;
|
177
|
centers[index][0] = x;
|
178
|
centers[index][1] = height;
|
179
|
centers[index][2] = z;
|
180
|
}
|
181
|
|
182
|
for(int i=0; i<layers-1; i++, index++)
|
183
|
{
|
184
|
x -= 1;
|
185
|
centers[index][0] = x;
|
186
|
centers[index][1] = height;
|
187
|
centers[index][2] = z;
|
188
|
}
|
189
|
|
190
|
for(int i=0; i<layers-1; i++, index++)
|
191
|
{
|
192
|
z += 1;
|
193
|
centers[index][0] = x;
|
194
|
centers[index][1] = height;
|
195
|
centers[index][2] = z;
|
196
|
}
|
197
|
|
198
|
for(int i=0; i<layers-2; i++, index++)
|
199
|
{
|
200
|
x += 1;
|
201
|
centers[index][0] = x;
|
202
|
centers[index][1] = height;
|
203
|
centers[index][2] = z;
|
204
|
}
|
205
|
|
206
|
return index;
|
207
|
}
|
208
|
|
209
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
210
|
|
211
|
private int createTetraPositions(float[][] centers, int index, int layers, float height)
|
212
|
{
|
213
|
float x = (layers-1)*0.5f;
|
214
|
float z = layers*0.5f;
|
215
|
|
216
|
for(int i=0; i<layers-1; i++, index++)
|
217
|
{
|
218
|
z -= 1;
|
219
|
centers[index][0] = x;
|
220
|
centers[index][1] = height;
|
221
|
centers[index][2] = z;
|
222
|
}
|
223
|
|
224
|
x += 0.5f;
|
225
|
z -= 0.5f;
|
226
|
|
227
|
for(int i=0; i<layers-1; i++, index++)
|
228
|
{
|
229
|
x -= 1;
|
230
|
centers[index][0] = x;
|
231
|
centers[index][1] = height;
|
232
|
centers[index][2] = z;
|
233
|
}
|
234
|
|
235
|
x -= 0.5f;
|
236
|
z -= 0.5f;
|
237
|
|
238
|
for(int i=0; i<layers-1; i++, index++)
|
239
|
{
|
240
|
z += 1;
|
241
|
centers[index][0] = x;
|
242
|
centers[index][1] = height;
|
243
|
centers[index][2] = z;
|
244
|
}
|
245
|
|
246
|
x -= 0.5f;
|
247
|
z += 0.5f;
|
248
|
|
249
|
for(int i=0; i<layers-1; i++, index++)
|
250
|
{
|
251
|
x += 1;
|
252
|
centers[index][0] = x;
|
253
|
centers[index][1] = height;
|
254
|
centers[index][2] = z;
|
255
|
}
|
256
|
|
257
|
return index;
|
258
|
}
|
259
|
|
260
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
261
|
|
262
|
public float[][] getCubitPositions(int[] numLayers)
|
263
|
{
|
264
|
if( mPosition==null )
|
265
|
{
|
266
|
int layers = numLayers[0];
|
267
|
int numO = getNumOctahedrons(layers);
|
268
|
int numT = getNumTetrahedrons(layers);
|
269
|
int index = 0;
|
270
|
float height = 0.0f;
|
271
|
|
272
|
mPosition = new float[numO+numT][3];
|
273
|
|
274
|
index = createOctaPositions(mPosition,index,layers,height);
|
275
|
|
276
|
for(int i=layers-1; i>0; i--)
|
277
|
{
|
278
|
height += SQ2/2;
|
279
|
index = createOctaPositions(mPosition,index,i,+height);
|
280
|
index = createOctaPositions(mPosition,index,i,-height);
|
281
|
}
|
282
|
|
283
|
height = SQ2/4;
|
284
|
|
285
|
for(int i=layers; i>1; i--)
|
286
|
{
|
287
|
index = createTetraPositions(mPosition,index,i,+height);
|
288
|
index = createTetraPositions(mPosition,index,i,-height);
|
289
|
height += SQ2/2;
|
290
|
}
|
291
|
}
|
292
|
|
293
|
return mPosition;
|
294
|
}
|
295
|
|
296
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
297
|
|
298
|
public Static4D getCubitQuats(int cubit, int[] numLayers)
|
299
|
{
|
300
|
int numL = numLayers[0];
|
301
|
int numO = getNumOctahedrons(numL);
|
302
|
|
303
|
if( cubit<numO ) return mObjectQuats[0];
|
304
|
|
305
|
switch( retFaceTetraBelongsTo(cubit-numO, numL) )
|
306
|
{
|
307
|
case 0: return mObjectQuats[0]; // unit quat
|
308
|
case 1: return new Static4D(0,-SQ2/2,0,SQ2/2); // 90 along Y
|
309
|
case 2: return mObjectQuats[10]; // 180 along Y
|
310
|
case 3: return new Static4D(0, SQ2/2,0,SQ2/2); // 90 along
|
311
|
case 4: return new Static4D(0, 0,1, 0); // 180 along Z
|
312
|
case 5: return mObjectQuats[4];
|
313
|
case 6: return new Static4D( 1,0,0, 0); // 180 along X
|
314
|
case 7: return mObjectQuats[3];
|
315
|
}
|
316
|
|
317
|
return null;
|
318
|
}
|
319
|
|
320
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
321
|
|
322
|
private int retFaceTetraBelongsTo(int tetra, int numLayers)
|
323
|
{
|
324
|
if( mTetraToFaceMap==null ) mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4};
|
325
|
|
326
|
for(int i=numLayers-1; i>0; i--)
|
327
|
{
|
328
|
if( tetra < 8*i ) return mTetraToFaceMap[tetra/i];
|
329
|
tetra -= 8*i;
|
330
|
}
|
331
|
|
332
|
return -1;
|
333
|
}
|
334
|
|
335
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
336
|
|
337
|
private float[][] getVertices(int variant)
|
338
|
{
|
339
|
if( variant==0 )
|
340
|
{
|
341
|
return new float[][]
|
342
|
{
|
343
|
{ 0.5f, 0.0f, 0.5f},
|
344
|
{ 0.5f, 0.0f,-0.5f},
|
345
|
{-0.5f, 0.0f,-0.5f},
|
346
|
{-0.5f, 0.0f, 0.5f},
|
347
|
{ 0.0f, SQ2/2, 0.0f},
|
348
|
{ 0.0f,-SQ2/2, 0.0f}
|
349
|
};
|
350
|
}
|
351
|
else
|
352
|
{
|
353
|
return new float[][]
|
354
|
{
|
355
|
{-0.5f, SQ2/4, 0.0f},
|
356
|
{ 0.5f, SQ2/4, 0.0f},
|
357
|
{ 0.0f,-SQ2/4, 0.5f},
|
358
|
{ 0.0f,-SQ2/4,-0.5f}
|
359
|
};
|
360
|
}
|
361
|
}
|
362
|
|
363
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
364
|
|
365
|
public ObjectShape getObjectShape(int variant)
|
366
|
{
|
367
|
if( variant==0 )
|
368
|
{
|
369
|
int[][] indices =
|
370
|
{
|
371
|
{3,0,4},
|
372
|
{0,1,4},
|
373
|
{1,2,4},
|
374
|
{2,3,4},
|
375
|
{5,0,3},
|
376
|
{5,1,0},
|
377
|
{5,2,1},
|
378
|
{5,3,2}
|
379
|
};
|
380
|
|
381
|
return new ObjectShape(getVertices(variant), indices);
|
382
|
}
|
383
|
else
|
384
|
{
|
385
|
int[][] indices = { {2,1,0}, {2,3,1}, {3,2,0}, {3,0,1} };
|
386
|
return new ObjectShape(getVertices(variant), indices);
|
387
|
}
|
388
|
}
|
389
|
|
390
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
391
|
|
392
|
public ObjectFaceShape getObjectFaceShape(int variant)
|
393
|
{
|
394
|
int numL = getNumLayers()[0];
|
395
|
int N = numL>3 ? 5:6;
|
396
|
int E = numL>2 ? (numL>3 ? 0:1) : 2;
|
397
|
float height = isInIconMode() ? 0.001f : 0.05f;
|
398
|
int angle = 25;
|
399
|
float R = 0.7f;
|
400
|
float S = 0.5f;
|
401
|
|
402
|
if( variant==0 )
|
403
|
{
|
404
|
float[][] bands = { {height,angle,R,S,N,E,E} };
|
405
|
int[] bandIndices= { 0,0,0,0,0,0,0,0 };
|
406
|
return new ObjectFaceShape(bands,bandIndices,null);
|
407
|
}
|
408
|
else
|
409
|
{
|
410
|
float[][] bands = { {height,angle,R,S,N,E,E} };
|
411
|
int[] bandIndices= { 0,0,0,0 };
|
412
|
return new ObjectFaceShape(bands,bandIndices,null);
|
413
|
}
|
414
|
}
|
415
|
|
416
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
417
|
|
418
|
public ObjectVertexEffects getVertexEffects(int variant)
|
419
|
{
|
420
|
if( variant==0 )
|
421
|
{
|
422
|
float[][] corners= { {0.06f,0.15f} };
|
423
|
int[] indices = { 0,0,0,0,0,0 };
|
424
|
float[][] centers= { {0.0f, 0.0f, 0.0f} };
|
425
|
return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
|
426
|
}
|
427
|
else
|
428
|
{
|
429
|
float[][] corners= { {0.08f,0.15f} };
|
430
|
int[] indices = { 0,0,0,0 };
|
431
|
float[][] centers= { {0.0f, 0.0f, 0.0f} };
|
432
|
return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
|
433
|
}
|
434
|
}
|
435
|
|
436
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
437
|
|
438
|
public int getNumCubitVariants(int[] numLayers)
|
439
|
{
|
440
|
return 2;
|
441
|
}
|
442
|
|
443
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
444
|
|
445
|
public int getCubitVariant(int cubit, int[] numLayers)
|
446
|
{
|
447
|
return cubit<getNumOctahedrons(numLayers[0]) ? 0 : 1;
|
448
|
}
|
449
|
|
450
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
451
|
|
452
|
public float getStickerRadius()
|
453
|
{
|
454
|
return 0.08f;
|
455
|
}
|
456
|
|
457
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
458
|
|
459
|
public float getStickerStroke()
|
460
|
{
|
461
|
float stroke = 0.08f;
|
462
|
|
463
|
if( isInIconMode() )
|
464
|
{
|
465
|
int[] numLayers = getNumLayers();
|
466
|
|
467
|
switch(numLayers[0])
|
468
|
{
|
469
|
case 2: stroke*=1.4f; break;
|
470
|
case 3: stroke*=2.0f; break;
|
471
|
case 4: stroke*=2.1f; break;
|
472
|
default:stroke*=2.2f; break;
|
473
|
}
|
474
|
}
|
475
|
|
476
|
return stroke;
|
477
|
}
|
478
|
|
479
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
480
|
|
481
|
public float[][][] getStickerAngles()
|
482
|
{
|
483
|
return null;
|
484
|
}
|
485
|
|
486
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
487
|
// PUBLIC API
|
488
|
|
489
|
public Static3D[] getRotationAxis()
|
490
|
{
|
491
|
return ROT_AXIS;
|
492
|
}
|
493
|
|
494
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
495
|
|
496
|
public int[][] getBasicAngles()
|
497
|
{
|
498
|
if( mBasicAngle ==null )
|
499
|
{
|
500
|
int num = getNumLayers()[0];
|
501
|
int[] tmp = new int[num];
|
502
|
for(int i=0; i<num; i++) tmp[i] = 3;
|
503
|
mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
|
504
|
}
|
505
|
return mBasicAngle;
|
506
|
}
|
507
|
|
508
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
509
|
|
510
|
public String getShortName()
|
511
|
{
|
512
|
switch(getNumLayers()[0])
|
513
|
{
|
514
|
case 2: return ListObjects.DIAM_2.name();
|
515
|
case 3: return ListObjects.DIAM_3.name();
|
516
|
case 4: return ListObjects.DIAM_4.name();
|
517
|
}
|
518
|
|
519
|
return ListObjects.DIAM_2.name();
|
520
|
}
|
521
|
|
522
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
523
|
|
524
|
public String[][] getTutorials()
|
525
|
{
|
526
|
int[] numLayers = getNumLayers();
|
527
|
|
528
|
switch(numLayers[0])
|
529
|
{
|
530
|
case 2: return new String[][] {
|
531
|
{"gb","R2wrbJJ3izM","How to Solve a Skewb Diamond","Dr. Penguin^3"},
|
532
|
{"es","2RCusYQdYYE","Como resolver Skewb Diamond","Tutoriales Rubik"},
|
533
|
{"ru","k8B6RFcNoGw","Как собрать Skewb Diamond","Алексей Ярыгин"},
|
534
|
{"fr","tqbkgwNcZCE","Comment résoudre le Skewb Diamond","Valentino Cube"},
|
535
|
{"de","6ewzrCOnZfg","Octagon lösen","JamesKnopf"},
|
536
|
{"pl","61_Z4TpLMBc","Diamond Skewb TUTORIAL PL","MrUk"},
|
537
|
{"br","UapwpXMYtH4","Como resolver o Octaedro Diamond","Rafael Cinoto"},
|
538
|
{"kr","hVBSlfHVTME","공식 하나만 사용 - 다이아몬드 스큐브","Denzel Washington"},
|
539
|
{"tw","tu9KzT4G4rQ","四軸八面體魔術方塊","1hrBLD"},
|
540
|
};
|
541
|
case 3: return new String[][] {
|
542
|
{"gb","n_mBSUDLUZw","Face Turning Octahedron Tutorial","SuperAntoniovivaldi"},
|
543
|
{"es","ogf0t6fGxZI","FTO - Tutorial en español","Gadi Rubik"},
|
544
|
{"ru","VXCjk0bVRoA","Как собрать Face Turning Octahedron","Алексей Ярыгин"},
|
545
|
{"de","6bO0AcwY5K8","Face Turning Octahedron - Tutorial","GerCubing"},
|
546
|
{"pl","huWg-ZfP-KY","Octahedron cube TUTORIAL PL","MrUk"},
|
547
|
{"br","WN3BoP4EbvM","Como resolver o octaedro 3x3 1/3","Rafael Cinoto"},
|
548
|
{"br","4zFlfANOliE","Como resolver o octaedro 3x3 2/3","Rafael Cinoto"},
|
549
|
{"br","6OvNzoHk7RU","Como resolver o octaedro 3x3 3/3","Rafael Cinoto"},
|
550
|
{"vn","KzGQ-mVRsss","Tutorial N.43 - FTO","Duy Thích Rubik"},
|
551
|
};
|
552
|
case 4: return new String[][] {
|
553
|
{"gb","3GJkySk5zeQ","Master Face Turning Octahedron","SuperAntoniovivaldi"},
|
554
|
{"gb","zW_1htxy52k","Master FTO Tutorial","Michele Regano"},
|
555
|
{"es","3K8XL9SBSvs","Tutorial Master FTO de Mf8","Robert Cubes"},
|
556
|
{"ru","0CRwhZ2JNJA","Как собрать Master FTO","Алексей Ярыгин"},
|
557
|
{"vn","4XdeuGYDCJo","Tutorial N.141 - Master FTO","Duy Thích Rubik"},
|
558
|
};
|
559
|
}
|
560
|
return null;
|
561
|
}
|
562
|
}
|