1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 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.MOVEMENT_HEXAHEDRON;
|
23
|
import static org.distorted.objectlib.main.Movement.TYPE_SPLIT_CORNER;
|
24
|
|
25
|
import java.io.InputStream;
|
26
|
|
27
|
import org.distorted.library.type.Static3D;
|
28
|
import org.distorted.library.type.Static4D;
|
29
|
|
30
|
import org.distorted.objectlib.main.MovementHexahedron;
|
31
|
import org.distorted.objectlib.main.ObjectControl;
|
32
|
import org.distorted.objectlib.main.ObjectType;
|
33
|
import org.distorted.objectlib.helpers.ObjectShape;
|
34
|
import org.distorted.objectlib.helpers.ObjectSticker;
|
35
|
import org.distorted.objectlib.helpers.ScrambleState;
|
36
|
import org.distorted.objectlib.main.TwistyHexahedron;
|
37
|
|
38
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39
|
|
40
|
public class TwistyRedi extends TwistyHexahedron
|
41
|
{
|
42
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
43
|
{
|
44
|
new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
|
45
|
new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
|
46
|
new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
|
47
|
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
|
48
|
};
|
49
|
|
50
|
private ScrambleState[] mStates;
|
51
|
private int[] mBasicAngle;
|
52
|
private Static4D[] mQuats;
|
53
|
private float[][] mCuts;
|
54
|
private float[][] mCenters;
|
55
|
private int[][] mFaceMap;
|
56
|
private ObjectSticker[] mStickers;
|
57
|
|
58
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59
|
|
60
|
public TwistyRedi(int[] numL, Static4D quat, Static3D move, float scale, InputStream stream)
|
61
|
{
|
62
|
super(numL, numL[0], quat, move, scale, stream);
|
63
|
}
|
64
|
|
65
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66
|
|
67
|
public ScrambleState[] getScrambleStates()
|
68
|
{
|
69
|
if( mStates==null )
|
70
|
{
|
71
|
mStates = new ScrambleState[]
|
72
|
{
|
73
|
new ScrambleState( new int[][] { {0,1,1,0,-1,1, 2,1,2,2,-1,2},{0,1,3,0,-1,3, 2,1,4,2,-1,4},{0,1,5,0,-1,5, 2,1,6,2,-1,6},{0,1,7,0,-1,7, 2,1,8,2,-1,8} } ),
|
74
|
new ScrambleState( new int[][] { { },{0,1,3,0,-1,3 },{0,1,5,0,-1,5, },{ 2,1,8,2,-1,8} } ),
|
75
|
new ScrambleState( new int[][] { { },{ 2,1,4,2,-1,4},{ 2,1,6,2,-1,6},{0,1,7,0,-1,7 } } ),
|
76
|
new ScrambleState( new int[][] { {0,1,1,0,-1,1 },{ },{ 2,1,6,2,-1,6},{0,1,7,0,-1,7 } } ),
|
77
|
new ScrambleState( new int[][] { { 2,1,2,2,-1,2},{ },{0,1,5,0,-1,5, },{ 2,1,8,2,-1,8} } ),
|
78
|
new ScrambleState( new int[][] { {0,1,1,0,-1,1 },{ 2,1,4,2,-1,4},{ },{0,1,7,0,-1,7 } } ),
|
79
|
new ScrambleState( new int[][] { { 2,1,2,2,-1,2},{0,1,3,0,-1,3 },{ },{ 2,1,8,2,-1,8} } ),
|
80
|
new ScrambleState( new int[][] { { 2,1,2,2,-1,2},{0,1,3,0,-1,3 },{0,1,5,0,-1,5, },{ } } ),
|
81
|
new ScrambleState( new int[][] { {0,1,1,0,-1,1 },{ 2,1,4,2,-1,4},{ 2,1,6,2,-1,6},{ } } ),
|
82
|
};
|
83
|
}
|
84
|
|
85
|
return mStates;
|
86
|
}
|
87
|
|
88
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89
|
|
90
|
private void initializeQuats()
|
91
|
{
|
92
|
mQuats = new Static4D[]
|
93
|
{
|
94
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
95
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
96
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
97
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
98
|
|
99
|
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ),
|
100
|
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ),
|
101
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f ),
|
102
|
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f ),
|
103
|
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ),
|
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.5f, -0.5f, -0.5f, -0.5f )
|
107
|
};
|
108
|
}
|
109
|
|
110
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111
|
|
112
|
public int[] getSolvedQuats(int cubit, int[] numLayers)
|
113
|
{
|
114
|
if( mQuats==null ) initializeQuats();
|
115
|
int status = retCubitSolvedStatus(cubit,numLayers);
|
116
|
return status<0 ? null : buildSolvedQuats(MovementHexahedron.FACE_AXIS[status],mQuats);
|
117
|
}
|
118
|
|
119
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120
|
|
121
|
public Static4D[] getQuats()
|
122
|
{
|
123
|
if( mQuats==null ) initializeQuats();
|
124
|
return mQuats;
|
125
|
}
|
126
|
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
|
129
|
public int getSolvedFunctionIndex()
|
130
|
{
|
131
|
return 0;
|
132
|
}
|
133
|
|
134
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135
|
|
136
|
public int getNumStickerTypes(int[] numLayers)
|
137
|
{
|
138
|
return 2;
|
139
|
}
|
140
|
|
141
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142
|
|
143
|
public float[][] getCuts(int[] numLayers)
|
144
|
{
|
145
|
if( mCuts==null )
|
146
|
{
|
147
|
float C = +SQ3/3 +0.05f;
|
148
|
float[] cut = new float[] {-C,+C};
|
149
|
mCuts = new float[][] { cut,cut,cut,cut };
|
150
|
}
|
151
|
|
152
|
return mCuts;
|
153
|
}
|
154
|
|
155
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156
|
|
157
|
public boolean[][] getLayerRotatable(int[] numLayers)
|
158
|
{
|
159
|
int numAxis = ROT_AXIS.length;
|
160
|
boolean[] tmp = new boolean[] {true,false,true};
|
161
|
boolean[][] layerRotatable = new boolean[numAxis][];
|
162
|
for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
|
163
|
|
164
|
return layerRotatable;
|
165
|
}
|
166
|
|
167
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
168
|
|
169
|
public int getMovementType()
|
170
|
{
|
171
|
return MOVEMENT_HEXAHEDRON;
|
172
|
}
|
173
|
|
174
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175
|
|
176
|
public int getMovementSplit()
|
177
|
{
|
178
|
return TYPE_SPLIT_CORNER;
|
179
|
}
|
180
|
|
181
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182
|
|
183
|
public int[][][] getEnabled()
|
184
|
{
|
185
|
return new int[][][]
|
186
|
{
|
187
|
{{0,1},{3,1},{2,3},{0,2}},
|
188
|
{{2,3},{3,1},{0,1},{0,2}},
|
189
|
{{1,2},{0,1},{0,3},{2,3}},
|
190
|
{{1,2},{2,3},{0,3},{0,1}},
|
191
|
{{0,3},{0,2},{1,2},{1,3}},
|
192
|
{{1,2},{0,2},{0,3},{1,3}},
|
193
|
};
|
194
|
}
|
195
|
|
196
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
197
|
|
198
|
public float[] getDist3D(int[] numLayers)
|
199
|
{
|
200
|
return null;
|
201
|
}
|
202
|
|
203
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
204
|
|
205
|
public int getNumCubitFaces()
|
206
|
{
|
207
|
return 9;
|
208
|
}
|
209
|
|
210
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
211
|
|
212
|
public float[][] getCubitPositions(int[] numLayers)
|
213
|
{
|
214
|
if( mCenters==null )
|
215
|
{
|
216
|
final float DIST_CORNER = 1.0f;
|
217
|
final float DIST_EDGE = 1.5f;
|
218
|
|
219
|
mCenters = new float[][]
|
220
|
{
|
221
|
{ DIST_CORNER, DIST_CORNER, DIST_CORNER },
|
222
|
{ DIST_CORNER, DIST_CORNER,-DIST_CORNER },
|
223
|
{ DIST_CORNER,-DIST_CORNER, DIST_CORNER },
|
224
|
{ DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
|
225
|
{-DIST_CORNER, DIST_CORNER, DIST_CORNER },
|
226
|
{-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
|
227
|
{-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
|
228
|
{-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
|
229
|
|
230
|
{ 0.0f, DIST_EDGE, DIST_EDGE },
|
231
|
{ DIST_EDGE, 0.0f, DIST_EDGE },
|
232
|
{ 0.0f,-DIST_EDGE, DIST_EDGE },
|
233
|
{-DIST_EDGE, 0.0f, DIST_EDGE },
|
234
|
{ DIST_EDGE, DIST_EDGE, 0.0f },
|
235
|
{ DIST_EDGE,-DIST_EDGE, 0.0f },
|
236
|
{-DIST_EDGE,-DIST_EDGE, 0.0f },
|
237
|
{-DIST_EDGE, DIST_EDGE, 0.0f },
|
238
|
{ 0.0f, DIST_EDGE,-DIST_EDGE },
|
239
|
{ DIST_EDGE, 0.0f,-DIST_EDGE },
|
240
|
{ 0.0f,-DIST_EDGE,-DIST_EDGE },
|
241
|
{-DIST_EDGE, 0.0f,-DIST_EDGE }
|
242
|
};
|
243
|
}
|
244
|
|
245
|
return mCenters;
|
246
|
}
|
247
|
|
248
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
249
|
|
250
|
public ObjectShape getObjectShape(int variant)
|
251
|
{
|
252
|
if( variant==0 )
|
253
|
{
|
254
|
double[][] vertices = new double[][]
|
255
|
{
|
256
|
{ 0.0f, 0.0f, 0.0f },
|
257
|
{-0.5f, 0.5f, 0.5f },
|
258
|
{-0.5f,-0.5f, 0.5f },
|
259
|
{ 0.5f, 0.5f, 0.5f },
|
260
|
{ 0.5f,-0.5f, 0.5f },
|
261
|
{ 0.5f, 0.5f,-0.5f },
|
262
|
{ 0.5f,-0.5f,-0.5f },
|
263
|
{-0.5f, 0.5f,-0.5f },
|
264
|
};
|
265
|
|
266
|
int[][] vert_indices = new int[][]
|
267
|
{
|
268
|
{ 2,4,3,1 },
|
269
|
{ 1,3,5,7 },
|
270
|
{ 4,6,5,3 },
|
271
|
|
272
|
{ 2,4,0 },
|
273
|
{ 5,7,0 },
|
274
|
{ 4,6,0 },
|
275
|
{ 7,1,0 },
|
276
|
{ 1,2,0 },
|
277
|
{ 6,5,0 }
|
278
|
};
|
279
|
|
280
|
float[][] bands = new float[][] { {0.06f,35,0.5f,0.7f,5,2,2}, {0.01f,35,0.2f,0.4f,5,2,2} };
|
281
|
int[] bandIndices = new int[] { 0,0,0,1,1,1,1,1,1 };
|
282
|
float[][] corners = new float[][] { {0.06f,0.12f} };
|
283
|
int[] cornerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
|
284
|
float[][] centers = new float[][] { { 0.0f, 0.0f, 0.0f} };
|
285
|
int[] centerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
|
286
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
287
|
}
|
288
|
else
|
289
|
{
|
290
|
double[][] vertices = new double[][]
|
291
|
{
|
292
|
{-0.5f, 0.0f, 0.0f},
|
293
|
{ 0.5f, 0.0f, 0.0f},
|
294
|
{-0.5f,-1.0f, 0.0f},
|
295
|
{ 0.5f,-1.0f, 0.0f},
|
296
|
{ 0.0f,-1.5f, 0.0f},
|
297
|
{-0.5f, 0.0f,-1.0f},
|
298
|
{ 0.5f, 0.0f,-1.0f},
|
299
|
{ 0.0f, 0.0f,-1.5f},
|
300
|
};
|
301
|
|
302
|
int[][] vert_indices = new int[][]
|
303
|
{
|
304
|
{ 0,2,4,3,1 },
|
305
|
{ 0,1,6,7,5 },
|
306
|
{ 1,3,6 },
|
307
|
{ 0,2,5 },
|
308
|
{ 4,7,6,3 },
|
309
|
{ 4,7,5,2 }
|
310
|
};
|
311
|
|
312
|
float[][] bands = new float[][] { {0.038f,35,0.250f,0.7f,7,2,2}, {0.020f,35,0.125f,0.2f,3,1,2}, {0.020f,35,0.125f,0.2f,3,1,1} };
|
313
|
int[] bandIndices = new int[] { 0,0,1,1,2,2 };
|
314
|
float[][] corners = new float[][] { {0.06f,0.20f} };
|
315
|
int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
|
316
|
float[][] centers = new float[][] { { 0.0f,-0.75f,-0.75f} };
|
317
|
int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
|
318
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
319
|
}
|
320
|
}
|
321
|
|
322
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
323
|
|
324
|
public Static4D getQuat(int cubit, int[] numLayers)
|
325
|
{
|
326
|
if( mQuats==null ) initializeQuats();
|
327
|
|
328
|
switch(cubit)
|
329
|
{
|
330
|
case 0: return mQuats[0]; // unit quat
|
331
|
case 1: return new Static4D( SQ2/2,0,0,SQ2/2); // 90 along X
|
332
|
case 2: return new Static4D(-SQ2/2,0,0,SQ2/2); // -90 along X
|
333
|
case 3: return mQuats[1]; // 180 along X
|
334
|
case 4: return new Static4D(0, SQ2/2,0,SQ2/2); // 90 along Y
|
335
|
case 5: return mQuats[2]; // 180 along Y
|
336
|
case 6: return mQuats[3]; // 180 along Z
|
337
|
case 7: return new Static4D(SQ2/2,0,-SQ2/2,0); // 180 along (SQ2/2,0,-SQ2/2)
|
338
|
|
339
|
case 8: return mQuats[0];
|
340
|
case 9: return mQuats[5];
|
341
|
case 10: return mQuats[3];
|
342
|
case 11: return mQuats[11];
|
343
|
case 12: return mQuats[4];
|
344
|
case 13: return mQuats[7];
|
345
|
case 14: return mQuats[9];
|
346
|
case 15: return mQuats[10];
|
347
|
case 16: return mQuats[2];
|
348
|
case 17: return mQuats[8];
|
349
|
case 18: return mQuats[1];
|
350
|
case 19: return mQuats[6];
|
351
|
}
|
352
|
|
353
|
return null;
|
354
|
}
|
355
|
|
356
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
357
|
|
358
|
public int getNumCubitVariants(int[] numLayers)
|
359
|
{
|
360
|
return 2;
|
361
|
}
|
362
|
|
363
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
364
|
|
365
|
public int getCubitVariant(int cubit, int[] numLayers)
|
366
|
{
|
367
|
return cubit<8 ? 0:1;
|
368
|
}
|
369
|
|
370
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
371
|
|
372
|
public int getVariantFaceColor(int variant, int face, int[] numLayers)
|
373
|
{
|
374
|
return variant;
|
375
|
}
|
376
|
|
377
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
378
|
|
379
|
public int getCubitFaceColor(int cubit, int face, int[] numLayers)
|
380
|
{
|
381
|
if( mFaceMap==null )
|
382
|
{
|
383
|
mFaceMap = new int[][]
|
384
|
{
|
385
|
{ 4, 2, 0 },
|
386
|
{ 2, 5, 0 },
|
387
|
{ 3, 4, 0 },
|
388
|
{ 5, 3, 0 },
|
389
|
{ 1, 2, 4 },
|
390
|
{ 5, 2, 1 },
|
391
|
{ 4, 3, 1 },
|
392
|
{ 1, 3, 5 },
|
393
|
|
394
|
{ 4, 2,-1 },
|
395
|
{ 0, 4,-1 },
|
396
|
{ 4, 3,-1 },
|
397
|
{ 1, 4,-1 },
|
398
|
{ 2, 0,-1 },
|
399
|
{ 3, 0,-1 },
|
400
|
{ 3, 1,-1 },
|
401
|
{ 2, 1,-1 },
|
402
|
{ 5, 2,-1 },
|
403
|
{ 0, 5,-1 },
|
404
|
{ 5, 3,-1 },
|
405
|
{ 1, 5,-1 },
|
406
|
};
|
407
|
}
|
408
|
|
409
|
return face<3 ? mFaceMap[cubit][face] : -1;
|
410
|
}
|
411
|
|
412
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
413
|
|
414
|
public ObjectSticker retSticker(int sticker)
|
415
|
{
|
416
|
if( mStickers==null )
|
417
|
{
|
418
|
float[][] STICKERS = new float[][]
|
419
|
{
|
420
|
{ -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
|
421
|
{ -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
|
422
|
};
|
423
|
|
424
|
final float R0 = 0.09f;
|
425
|
final float R1 = 0.06f;
|
426
|
final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1} };
|
427
|
float[] strokes = { 0.09f,0.06f };
|
428
|
|
429
|
if( ObjectControl.isInIconMode() )
|
430
|
{
|
431
|
float mult = 2.2f;
|
432
|
strokes[0]*=mult;
|
433
|
strokes[1]*=mult;
|
434
|
}
|
435
|
|
436
|
mStickers = new ObjectSticker[STICKERS.length];
|
437
|
|
438
|
for(int s=0; s<STICKERS.length; s++)
|
439
|
{
|
440
|
mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
|
441
|
}
|
442
|
}
|
443
|
|
444
|
return mStickers[sticker];
|
445
|
}
|
446
|
|
447
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
448
|
// PUBLIC API
|
449
|
|
450
|
public Static3D[] getRotationAxis()
|
451
|
{
|
452
|
return ROT_AXIS;
|
453
|
}
|
454
|
|
455
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
456
|
|
457
|
public int[] getBasicAngle()
|
458
|
{
|
459
|
if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
|
460
|
return mBasicAngle;
|
461
|
}
|
462
|
|
463
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
464
|
|
465
|
public ObjectType intGetObjectType(int[] numLayers)
|
466
|
{
|
467
|
return ObjectType.REDI_3;
|
468
|
}
|
469
|
|
470
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
471
|
|
472
|
public String getObjectName()
|
473
|
{
|
474
|
return "Redi Cube";
|
475
|
}
|
476
|
|
477
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
478
|
|
479
|
public String getInventor()
|
480
|
{
|
481
|
return "Oskar van Deventer";
|
482
|
}
|
483
|
|
484
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
485
|
|
486
|
public int getYearOfInvention()
|
487
|
{
|
488
|
return 2009;
|
489
|
}
|
490
|
|
491
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
492
|
|
493
|
public int getComplexity()
|
494
|
{
|
495
|
return 4;
|
496
|
}
|
497
|
}
|