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_HEXAHEDRON;
|
13
|
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
|
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.helpers.ObjectSignature;
|
21
|
import org.distorted.objectlib.helpers.ObjectVertexEffects;
|
22
|
import org.distorted.objectlib.main.InitAssets;
|
23
|
import org.distorted.objectlib.main.InitData;
|
24
|
import org.distorted.objectlib.main.ObjectSignatures;
|
25
|
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
|
26
|
import org.distorted.objectlib.main.ObjectType;
|
27
|
import org.distorted.objectlib.helpers.ObjectShape;
|
28
|
import org.distorted.objectlib.shape.ShapeHexahedron;
|
29
|
|
30
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31
|
|
32
|
public class TwistyRex extends ShapeHexahedron
|
33
|
{
|
34
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
35
|
{
|
36
|
new Static3D( SQ3/3, SQ3/3, SQ3/3),
|
37
|
new Static3D( SQ3/3, SQ3/3,-SQ3/3),
|
38
|
new Static3D( SQ3/3,-SQ3/3, SQ3/3),
|
39
|
new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
|
40
|
};
|
41
|
|
42
|
public static final float REX_D = 0.2f;
|
43
|
|
44
|
private int[][] mEdges;
|
45
|
private int[][] mBasicAngle;
|
46
|
private float[][] mCuts;
|
47
|
private float[][] mPosition;
|
48
|
private int[] mQuatIndex;
|
49
|
|
50
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51
|
|
52
|
public TwistyRex(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
|
53
|
{
|
54
|
super(meshState, iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
|
55
|
}
|
56
|
|
57
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58
|
|
59
|
@Override
|
60
|
public float[][] returnRotationFactor()
|
61
|
{
|
62
|
float C = 1.5f;
|
63
|
float[] f = new float[] { C,C,C };
|
64
|
return new float[][] { f,f,f,f };
|
65
|
}
|
66
|
|
67
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68
|
|
69
|
@Override
|
70
|
public void adjustStickerCoords()
|
71
|
{
|
72
|
mStickerCoords = new float[][]
|
73
|
{
|
74
|
{ 0.35f, -0.35f, -0.1428f, 0.5f, -0.5f, 0.1428f },
|
75
|
{ -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
|
76
|
{ 0.00f, -0.200f, 0.525f, 0.105f, -0.525f, 0.105f }
|
77
|
};
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
// single state; middle layer doesn't move.
|
82
|
|
83
|
public int[][] getScrambleEdges()
|
84
|
{
|
85
|
if( mEdges==null )
|
86
|
{
|
87
|
mEdges = new int[][] { { 0,0,1,0, 4,0,5,0, 6,0,7,0, 10,0,11,0, 12,0,13,0, 16,0,17,0, 18,0,19,0, 22,0,23,0 } };
|
88
|
}
|
89
|
return mEdges;
|
90
|
}
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93
|
|
94
|
public float[][] getCuts(int[] numLayers)
|
95
|
{
|
96
|
if( mCuts==null )
|
97
|
{
|
98
|
float C = SQ3*0.45f; // bit less than 1/2 of the length of the main diagonal
|
99
|
float[] cut = new float[] {-C,+C};
|
100
|
mCuts = new float[][] { cut,cut,cut,cut };
|
101
|
}
|
102
|
|
103
|
return mCuts;
|
104
|
}
|
105
|
|
106
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107
|
|
108
|
public boolean[][] getLayerRotatable(int[] numLayers)
|
109
|
{
|
110
|
boolean[] tmp = new boolean[] {true,false,true};
|
111
|
return new boolean[][] { tmp,tmp,tmp,tmp };
|
112
|
}
|
113
|
|
114
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115
|
|
116
|
public int getTouchControlType()
|
117
|
{
|
118
|
return TC_HEXAHEDRON;
|
119
|
}
|
120
|
|
121
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
122
|
|
123
|
public int getTouchControlSplit()
|
124
|
{
|
125
|
return TYPE_SPLIT_CORNER;
|
126
|
}
|
127
|
|
128
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129
|
|
130
|
public int[][][] getEnabled()
|
131
|
{
|
132
|
return new int[][][]
|
133
|
{
|
134
|
{{0,1},{3,1},{2,3},{0,2}},
|
135
|
{{2,3},{3,1},{0,1},{0,2}},
|
136
|
{{1,2},{0,1},{0,3},{2,3}},
|
137
|
{{1,2},{2,3},{0,3},{0,1}},
|
138
|
{{0,3},{0,2},{1,2},{1,3}},
|
139
|
{{1,2},{0,2},{0,3},{1,3}},
|
140
|
};
|
141
|
}
|
142
|
|
143
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
144
|
|
145
|
public float[] getDist3D(int[] numLayers)
|
146
|
{
|
147
|
return TouchControlHexahedron.D3D;
|
148
|
}
|
149
|
|
150
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151
|
|
152
|
public Static3D[] getFaceAxis()
|
153
|
{
|
154
|
return TouchControlHexahedron.FACE_AXIS;
|
155
|
}
|
156
|
|
157
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158
|
|
159
|
public float[][] getCubitPositions(int[] numLayers)
|
160
|
{
|
161
|
if( mPosition==null )
|
162
|
{
|
163
|
final float DIST1= 1.50f;
|
164
|
final float DIST2= (1+2*REX_D)/2;
|
165
|
final float DIST3= 1.53f;
|
166
|
|
167
|
mPosition = new float[][]
|
168
|
{
|
169
|
{ +DIST2, -DIST2, +DIST3 },
|
170
|
{ -DIST2, +DIST2, +DIST3 },
|
171
|
{ +DIST2, +DIST2, -DIST3 },
|
172
|
{ -DIST2, -DIST2, -DIST3 },
|
173
|
{ +DIST2, +DIST3, -DIST2 },
|
174
|
{ -DIST2, +DIST3, +DIST2 },
|
175
|
{ +DIST2, -DIST3, +DIST2 },
|
176
|
{ -DIST2, -DIST3, -DIST2 },
|
177
|
{ +DIST3, +DIST2, -DIST2 },
|
178
|
{ +DIST3, -DIST2, +DIST2 },
|
179
|
{ -DIST3, +DIST2, +DIST2 },
|
180
|
{ -DIST3, -DIST2, -DIST2 },
|
181
|
|
182
|
{ +DIST2, +DIST2, +DIST3 },
|
183
|
{ -DIST2, -DIST2, +DIST3 },
|
184
|
{ +DIST2, -DIST2, -DIST3 },
|
185
|
{ -DIST2, +DIST2, -DIST3 },
|
186
|
{ -DIST2, +DIST3, -DIST2 },
|
187
|
{ +DIST2, +DIST3, +DIST2 },
|
188
|
{ -DIST2, -DIST3, +DIST2 },
|
189
|
{ +DIST2, -DIST3, -DIST2 },
|
190
|
{ +DIST3, +DIST2, +DIST2 },
|
191
|
{ +DIST3, -DIST2, -DIST2 },
|
192
|
{ -DIST3, +DIST2, -DIST2 },
|
193
|
{ -DIST3, -DIST2, +DIST2 },
|
194
|
|
195
|
{ +0.00f, +0.00f, +DIST3 },
|
196
|
{ +0.00f, +0.00f, -DIST3 },
|
197
|
{ +0.00f, +DIST3, +0.00f },
|
198
|
{ +0.00f, -DIST3, +0.00f },
|
199
|
{ +DIST3, +0.00f, +0.00f },
|
200
|
{ -DIST3, +0.00f, +0.00f },
|
201
|
|
202
|
{ +0.00f, +DIST1, +DIST1 },
|
203
|
{ +DIST1, +0.00f, +DIST1 },
|
204
|
{ +0.00f, -DIST1, +DIST1 },
|
205
|
{ -DIST1, +0.00f, +DIST1 },
|
206
|
{ +DIST1, +DIST1, +0.00f },
|
207
|
{ +DIST1, -DIST1, +0.00f },
|
208
|
{ -DIST1, -DIST1, +0.00f },
|
209
|
{ -DIST1, +DIST1, +0.00f },
|
210
|
{ +0.00f, +DIST1, -DIST1 },
|
211
|
{ +DIST1, +0.00f, -DIST1 },
|
212
|
{ +0.00f, -DIST1, -DIST1 },
|
213
|
{ -DIST1, +0.00f, -DIST1 },
|
214
|
};
|
215
|
}
|
216
|
|
217
|
return mPosition;
|
218
|
}
|
219
|
|
220
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221
|
|
222
|
public Static4D getCubitQuats(int cubit, int[] numLayers)
|
223
|
{
|
224
|
if( mQuatIndex==null )
|
225
|
{
|
226
|
mQuatIndex = new int[] {
|
227
|
0,10, 9,11, 7, 1, 6, 4, 2, 5, 3, 8,
|
228
|
0,10, 9,11, 7, 1, 6, 4, 2, 5, 3, 8,
|
229
|
0, 9, 1, 4, 2, 3,
|
230
|
0, 2,10, 8, 1, 4, 6, 7,11, 5, 9, 3
|
231
|
};
|
232
|
}
|
233
|
return mObjectQuats[mQuatIndex[cubit]];
|
234
|
}
|
235
|
|
236
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
237
|
|
238
|
private float[][] getVertices(int variant)
|
239
|
{
|
240
|
if( variant==0 )
|
241
|
{
|
242
|
return new float[][] { {-0.10f,+0.70f,0},{-0.70f,+0.10f,0},{+0.65f,-0.71f,0},{+0.71f,-0.65f,0},{0,0.05f,-0.2f} };
|
243
|
}
|
244
|
else if( variant==1 )
|
245
|
{
|
246
|
return new float[][] { {-0.10f,-0.70f,0},{-0.70f,-0.10f,0},{+0.65f,+0.71f,0},{+0.71f,+0.65f,0},{0,-0.05f,-0.2f} };
|
247
|
}
|
248
|
else if( variant==2 )
|
249
|
{
|
250
|
float G = 3*REX_D;
|
251
|
return new float[][] { { -G, 0, 0 },{ 0,-G, 0 },{ +G, 0, 0 },{ 0,+G,0 },{ 0, 0,-G} };
|
252
|
}
|
253
|
else
|
254
|
{
|
255
|
float E = 1.5f - 3*REX_D;
|
256
|
float F = 1.5f;
|
257
|
return new float[][] { { -F, 0, 0 },{ 0,-E, 0 },{ +F, 0, 0 },{ 0, 0,-E } };
|
258
|
}
|
259
|
}
|
260
|
|
261
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
262
|
|
263
|
public ObjectShape getObjectShape(int variant)
|
264
|
{
|
265
|
if( variant==0 )
|
266
|
{
|
267
|
int[][] indices = { {0,1,2,3},{0,3,4},{3,2,4},{2,1,4},{1,0,4} };
|
268
|
return new ObjectShape(getVertices(variant), indices);
|
269
|
}
|
270
|
else if( variant==1 )
|
271
|
{
|
272
|
int[][] indices = { {3,2,1,0},{4,3,0},{4,2,3},{4,1,2},{4,0,1} };
|
273
|
return new ObjectShape(getVertices(variant), indices);
|
274
|
}
|
275
|
else if( variant==2 )
|
276
|
{
|
277
|
int[][] indices = { {0,1,2,3},{0,3,4},{3,2,4},{2,1,4},{1,0,4} };
|
278
|
return new ObjectShape(getVertices(variant), indices);
|
279
|
}
|
280
|
else
|
281
|
{
|
282
|
int[][] indices = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
|
283
|
return new ObjectShape(getVertices(variant), indices);
|
284
|
}
|
285
|
}
|
286
|
|
287
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
288
|
|
289
|
public ObjectFaceShape getObjectFaceShape(int variant)
|
290
|
{
|
291
|
if( variant==0 || variant==1 )
|
292
|
{
|
293
|
float height = isInIconMode() ? 0.001f : 0.02f;
|
294
|
float G = (1-REX_D)*SQ2/2;
|
295
|
int[] indices = { 0,1,1,1,1 };
|
296
|
float[][] bands= { { height,10,G/3,0.5f,5,1,1},{ 0.001f,45,0.1f,0.1f,2,0,0} };
|
297
|
return new ObjectFaceShape(bands,indices,null);
|
298
|
}
|
299
|
else if( variant==2 )
|
300
|
{
|
301
|
float height = isInIconMode() ? 0.001f : 0.025f;
|
302
|
float G = 3*REX_D;
|
303
|
int[] indices = { 0,1,1,1,1 };
|
304
|
float[][] bands= { {height,10,G/2,0.5f,5,0,0},{0.001f,45,G/2,0.0f,2,0,0} };
|
305
|
return new ObjectFaceShape(bands,indices,null);
|
306
|
}
|
307
|
else
|
308
|
{
|
309
|
float h1 = isInIconMode() ? 0.001f : 0.03f;
|
310
|
float h2 = isInIconMode() ? 0.001f : 0.01f;
|
311
|
float E = 1.5f - 3*REX_D;
|
312
|
float F = 1.5f;
|
313
|
float G = (float)Math.sqrt(E*E+F*F);
|
314
|
int[] indices = { 0,0,1,1 };
|
315
|
float[][] bands= { {h1,12,F/3,0.8f,5,2,3},{h2,45,G/3,0.2f,5,2,3} };
|
316
|
return new ObjectFaceShape(bands,indices,null);
|
317
|
}
|
318
|
}
|
319
|
|
320
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
321
|
|
322
|
public ObjectVertexEffects getVertexEffects(int variant)
|
323
|
{
|
324
|
if( variant==0 || variant==1 )
|
325
|
{
|
326
|
float[][] centers= { {0.0f,0.0f,(REX_D-1)*SQ2/2} };
|
327
|
float[][] corners= { {0.03f,0.30f} };
|
328
|
int[] indices = {-1,-1,0,0,-1};
|
329
|
return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
|
330
|
}
|
331
|
else if( variant==2 )
|
332
|
{
|
333
|
return null;
|
334
|
}
|
335
|
else
|
336
|
{
|
337
|
float[][] centers= { {0.0f,-1.5f,-1.5f} };
|
338
|
float[][] corners= { {0.06f,0.20f} };
|
339
|
int[] indices = { 0,-1,0,-1 };
|
340
|
return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
|
341
|
}
|
342
|
}
|
343
|
|
344
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
345
|
|
346
|
public int getNumCubitVariants(int[] numLayers)
|
347
|
{
|
348
|
return 4;
|
349
|
}
|
350
|
|
351
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
352
|
|
353
|
public int getCubitVariant(int cubit, int[] numLayers)
|
354
|
{
|
355
|
return cubit<12 ? 0 : (cubit<24 ? 1 : (cubit<30?2:3));
|
356
|
}
|
357
|
|
358
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
359
|
|
360
|
public float getStickerRadius()
|
361
|
{
|
362
|
return 0.09f;
|
363
|
}
|
364
|
|
365
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
366
|
|
367
|
public float getStickerStroke()
|
368
|
{
|
369
|
return isInIconMode() ? 0.25f : 0.12f;
|
370
|
}
|
371
|
|
372
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
373
|
|
374
|
public float[][] getStickerAngles()
|
375
|
{
|
376
|
final float F = (float)(Math.PI/20);
|
377
|
return new float[][] { { F,-F/2,F },{0,0,0,0},{ -F,0,-F } };
|
378
|
}
|
379
|
|
380
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
381
|
// PUBLIC API
|
382
|
|
383
|
public Static3D[] getRotationAxis()
|
384
|
{
|
385
|
return ROT_AXIS;
|
386
|
}
|
387
|
|
388
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
389
|
|
390
|
public int[][] getBasicAngles()
|
391
|
{
|
392
|
if( mBasicAngle==null )
|
393
|
{
|
394
|
int num = getNumLayers()[0];
|
395
|
int[] tmp = new int[num];
|
396
|
for(int i=0; i<num; i++) tmp[i] = 3;
|
397
|
mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
|
398
|
}
|
399
|
|
400
|
return mBasicAngle;
|
401
|
}
|
402
|
|
403
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
404
|
|
405
|
public String getShortName()
|
406
|
{
|
407
|
return ObjectType.REX_3.name();
|
408
|
}
|
409
|
|
410
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
411
|
|
412
|
public ObjectSignature getSignature()
|
413
|
{
|
414
|
return new ObjectSignature(ObjectSignatures.REX_3);
|
415
|
}
|
416
|
|
417
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
418
|
|
419
|
public String getObjectName()
|
420
|
{
|
421
|
return "Rex Cube";
|
422
|
}
|
423
|
|
424
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
425
|
|
426
|
public String getInventor()
|
427
|
{
|
428
|
return "Andrew Cormier";
|
429
|
}
|
430
|
|
431
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
432
|
|
433
|
public int getYearOfInvention()
|
434
|
{
|
435
|
return 2009;
|
436
|
}
|
437
|
|
438
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
439
|
|
440
|
public int getComplexity()
|
441
|
{
|
442
|
return 3;
|
443
|
}
|
444
|
|
445
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
446
|
|
447
|
public String[][] getTutorials()
|
448
|
{
|
449
|
return new String[][]{
|
450
|
{"gb","noAQfWqlMbk","Rex Cube Tutorial","CrazyBadCuber"},
|
451
|
{"es","Q90x9rjLJzw","Resolver Cubo Rex","Cuby"},
|
452
|
{"ru","Dr9CLM6A3fU","Как собрать Рекс Куб","Алексей Ярыгин"},
|
453
|
{"fr","SvK1kf6c43c","Résolution du Rex Cube","Asthalis"},
|
454
|
{"de","AI4vtwpRkEQ","Rex Cube - Tutorial","GerCubing"},
|
455
|
{"pl","ffbFRnHglWY","Rex Cube TUTORIAL PL","MrUk"},
|
456
|
{"kr","B3ftZzHRQyU","렉스 큐브 해법","듀나메스 큐브 해법연구소"},
|
457
|
{"vn","5nE9Q7QmOP4","Tutorial N.87 - Rex Cube","Duy Thích Rubik"},
|
458
|
};
|
459
|
}
|
460
|
}
|