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.objects;
|
21
|
|
22
|
import android.content.res.Resources;
|
23
|
|
24
|
import org.distorted.library.main.DistortedEffects;
|
25
|
import org.distorted.library.main.DistortedTexture;
|
26
|
import org.distorted.library.mesh.MeshSquare;
|
27
|
import org.distorted.library.type.Static3D;
|
28
|
import org.distorted.library.type.Static4D;
|
29
|
|
30
|
import java.util.Random;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
abstract class TwistyMinx extends TwistyObject
|
35
|
{
|
36
|
private static final int FACES_PER_CUBIT =6;
|
37
|
|
38
|
static final int NUM_CORNERS = 20;
|
39
|
static final int NUM_CENTERS = 12;
|
40
|
static final int NUM_EDGES = 30;
|
41
|
|
42
|
static final float C0 = (SQ5-1)/4; // cos(72 deg)
|
43
|
static final float C1 = (SQ5+1)/4; // cos(36 deg)
|
44
|
static final float C2 = (SQ5+3)/4;
|
45
|
static final float LEN= (float)(Math.sqrt(1.25f+0.5f*SQ5));
|
46
|
|
47
|
// the six rotation axis of a Minx. Must be normalized.
|
48
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
49
|
{
|
50
|
new Static3D( C2/LEN, C1/LEN, 0 ),
|
51
|
new Static3D(-C2/LEN, C1/LEN, 0 ),
|
52
|
new Static3D( 0 , C2/LEN, C1/LEN ),
|
53
|
new Static3D( 0 ,-C2/LEN, C1/LEN ),
|
54
|
new Static3D( C1/LEN, 0 , C2/LEN ),
|
55
|
new Static3D( C1/LEN, 0 ,-C2/LEN )
|
56
|
};
|
57
|
|
58
|
private static final int MINX_LGREEN = 0xff53aa00;
|
59
|
private static final int MINX_PINK = 0xfffd7ab7;
|
60
|
private static final int MINX_SANDY = 0xffefd48b;
|
61
|
private static final int MINX_LBLUE = 0xff00a2d7;
|
62
|
private static final int MINX_ORANGE = 0xffff6200;
|
63
|
private static final int MINX_VIOLET = 0xff7d59a4;
|
64
|
private static final int MINX_DGREEN = 0xff007a47;
|
65
|
private static final int MINX_DRED = 0xffbd0000;
|
66
|
private static final int MINX_DBLUE = 0xff1a29b2;
|
67
|
private static final int MINX_DYELLOW= 0xffffc400;
|
68
|
private static final int MINX_WHITE = 0xffffffff;
|
69
|
private static final int MINX_GREY = 0xff727c7b;
|
70
|
|
71
|
static final int[] FACE_COLORS = new int[]
|
72
|
{
|
73
|
MINX_LGREEN, MINX_PINK , MINX_SANDY , MINX_LBLUE,
|
74
|
MINX_ORANGE, MINX_VIOLET , MINX_DGREEN, MINX_DRED ,
|
75
|
MINX_DBLUE , MINX_DYELLOW, MINX_WHITE , MINX_GREY
|
76
|
};
|
77
|
|
78
|
// All 60 legal rotation quats of a Minx
|
79
|
static final Static4D[] QUATS = new Static4D[]
|
80
|
{
|
81
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ), //0
|
82
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
83
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
84
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
85
|
|
86
|
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ), //4
|
87
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f ),
|
88
|
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ),
|
89
|
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ),
|
90
|
new Static4D( -0.5f, 0.5f, 0.5f, 0.5f ),
|
91
|
new Static4D( -0.5f, 0.5f, -0.5f, 0.5f ),
|
92
|
new Static4D( -0.5f, -0.5f, 0.5f, 0.5f ),
|
93
|
new Static4D( -0.5f, -0.5f, -0.5f, 0.5f ),
|
94
|
|
95
|
new Static4D( 0.5f, C1, C0, 0.0f ), // 12
|
96
|
new Static4D( 0.5f, C1, -C0, 0.0f ),
|
97
|
new Static4D( 0.5f, -C1, C0, 0.0f ),
|
98
|
new Static4D( 0.5f, -C1, -C0, 0.0f ),
|
99
|
new Static4D( C0, 0.5f, C1, 0.0f ),
|
100
|
new Static4D( C0, 0.5f, -C1, 0.0f ),
|
101
|
new Static4D( -C0, 0.5f, C1, 0.0f ),
|
102
|
new Static4D( -C0, 0.5f, -C1, 0.0f ),
|
103
|
new Static4D( C1, C0, 0.5f, 0.0f ),
|
104
|
new Static4D( C1, -C0, 0.5f, 0.0f ),
|
105
|
new Static4D( -C1, C0, 0.5f, 0.0f ),
|
106
|
new Static4D( -C1, -C0, 0.5f, 0.0f ),
|
107
|
|
108
|
new Static4D( 0.0f, C0, C1, 0.5f ), //24
|
109
|
new Static4D( 0.0f, C0, -C1, 0.5f ),
|
110
|
new Static4D( 0.0f, -C0, C1, 0.5f ),
|
111
|
new Static4D( 0.0f, -C0, -C1, 0.5f ),
|
112
|
new Static4D( C0, C1, 0.0f, 0.5f ),
|
113
|
new Static4D( C0, -C1, 0.0f, 0.5f ),
|
114
|
new Static4D( -C0, C1, 0.0f, 0.5f ),
|
115
|
new Static4D( -C0, -C1, 0.0f, 0.5f ),
|
116
|
new Static4D( C1, 0.0f, C0, 0.5f ),
|
117
|
new Static4D( C1, 0.0f, -C0, 0.5f ),
|
118
|
new Static4D( -C1, 0.0f, C0, 0.5f ),
|
119
|
new Static4D( -C1, 0.0f, -C0, 0.5f ),
|
120
|
|
121
|
new Static4D( 0.0f, C1, 0.5f, C0 ), //36
|
122
|
new Static4D( 0.0f, C1, -0.5f, C0 ),
|
123
|
new Static4D( 0.0f, -C1, 0.5f, C0 ),
|
124
|
new Static4D( 0.0f, -C1, -0.5f, C0 ),
|
125
|
new Static4D( 0.5f, 0.0f, C1, C0 ),
|
126
|
new Static4D( 0.5f, 0.0f, -C1, C0 ),
|
127
|
new Static4D( -0.5f, 0.0f, C1, C0 ),
|
128
|
new Static4D( -0.5f, 0.0f, -C1, C0 ),
|
129
|
new Static4D( C1, 0.5f, 0.0f, C0 ),
|
130
|
new Static4D( C1, -0.5f, 0.0f, C0 ),
|
131
|
new Static4D( -C1, 0.5f, 0.0f, C0 ),
|
132
|
new Static4D( -C1, -0.5f, 0.0f, C0 ),
|
133
|
|
134
|
new Static4D( 0.0f, 0.5f, C0, C1 ), //48
|
135
|
new Static4D( 0.0f, 0.5f, -C0, C1 ),
|
136
|
new Static4D( 0.0f, -0.5f, C0, C1 ),
|
137
|
new Static4D( 0.0f, -0.5f, -C0, C1 ),
|
138
|
new Static4D( 0.5f, C0, 0.0f, C1 ),
|
139
|
new Static4D( 0.5f, -C0, 0.0f, C1 ),
|
140
|
new Static4D( -0.5f, C0, 0.0f, C1 ),
|
141
|
new Static4D( -0.5f, -C0, 0.0f, C1 ),
|
142
|
new Static4D( C0, 0.0f, 0.5f, C1 ),
|
143
|
new Static4D( C0, 0.0f, -0.5f, C1 ),
|
144
|
new Static4D( -C0, 0.0f, 0.5f, C1 ),
|
145
|
new Static4D( -C0, 0.0f, -0.5f, C1 ),
|
146
|
};
|
147
|
|
148
|
// Coordinates of all 20 corners of a Minx
|
149
|
static final float[][] CORNERS = new float[][]
|
150
|
{
|
151
|
{ 0.0f, 0.5f, C2},
|
152
|
{ 0.0f, 0.5f, -C2},
|
153
|
{ 0.0f,-0.5f, C2},
|
154
|
{ 0.0f,-0.5f, -C2},
|
155
|
{ C2, 0.0f, 0.5f},
|
156
|
{ C2, 0.0f,-0.5f},
|
157
|
{ -C2, 0.0f, 0.5f},
|
158
|
{ -C2, 0.0f,-0.5f},
|
159
|
{ 0.5f, C2, 0.0f},
|
160
|
{ 0.5f, -C2, 0.0f},
|
161
|
{-0.5f, C2, 0.0f},
|
162
|
{-0.5f, -C2, 0.0f},
|
163
|
{ C1, C1, C1},
|
164
|
{ C1, C1, -C1},
|
165
|
{ C1, -C1, C1},
|
166
|
{ C1, -C1, -C1},
|
167
|
{ -C1, C1, C1},
|
168
|
{ -C1, C1, -C1},
|
169
|
{ -C1, -C1, C1},
|
170
|
{ -C1, -C1, -C1},
|
171
|
};
|
172
|
|
173
|
static final int[][] mCornerFaceMap =
|
174
|
{
|
175
|
{ 0, 1, 8 },
|
176
|
{ 6, 5,10 },
|
177
|
{ 1, 0,11 },
|
178
|
{ 5, 6, 3 },
|
179
|
{ 0, 9, 4 },
|
180
|
{ 5, 4, 9 },
|
181
|
{ 7, 1, 2 },
|
182
|
{ 2, 6, 7 },
|
183
|
{ 10, 9, 8 },
|
184
|
{ 4, 3,11 },
|
185
|
{ 7,10, 8 },
|
186
|
{ 3, 2,11 },
|
187
|
{ 0, 8, 9 },
|
188
|
{ 9,10, 5 },
|
189
|
{ 0, 4,11 },
|
190
|
{ 4, 5, 3 },
|
191
|
{ 1, 7, 8 },
|
192
|
{ 7, 6,10 },
|
193
|
{ 2, 1,11 },
|
194
|
{ 6, 2, 3 },
|
195
|
};
|
196
|
|
197
|
static final int[] QUAT_EDGE_INDICES =
|
198
|
{
|
199
|
56, 40, 43, 59, 0, 19, 9, 54, 58, 49,
|
200
|
48, 24, 52, 4, 16, 32, 20, 11, 21, 35 ,
|
201
|
37, 30, 8, 28, 36, 44, 1, 46, 12, 47
|
202
|
};
|
203
|
|
204
|
|
205
|
static final int[] QUAT_CORNER_INDICES =
|
206
|
{
|
207
|
0, 2, 3, 1, 40, 31, 41, 30, 39, 35,
|
208
|
36, 34, 56, 32, 43, 21, 48, 28, 42, 23
|
209
|
};
|
210
|
|
211
|
static final boolean[][] OPPOSITE_ROWS =
|
212
|
{
|
213
|
{false, true, false, true, false, false},
|
214
|
{ true, false, false, true, true, true},
|
215
|
{false, false, false, true, false, true},
|
216
|
{ true, true, true, false, false, true},
|
217
|
{false, true, false, false, false, true},
|
218
|
{false, true, true, true, true, false}
|
219
|
};
|
220
|
|
221
|
// the quadruple ( corner1, corner2, face1, face2 ) defining an edge.
|
222
|
// In fact the 2 corners already define it, the faces only provide easy
|
223
|
// way to get to know the colors. Order: arbitrary. Face1 arbitrarily on
|
224
|
// the 'left' or right of vector corner1 --> corner2, according to Quat.
|
225
|
static final int[][] mEdgeMap =
|
226
|
{
|
227
|
{ 0, 12, 0, 8}, //0
|
228
|
{ 12, 4, 0, 9},
|
229
|
{ 4, 14, 0, 4},
|
230
|
{ 14, 2, 0, 11},
|
231
|
{ 2, 0, 0, 1},
|
232
|
{ 14, 9, 11, 4}, //5
|
233
|
{ 9, 11, 11, 3},
|
234
|
{ 11, 18, 11, 2},
|
235
|
{ 18, 2, 11, 1},
|
236
|
{ 18, 6, 1, 2},
|
237
|
{ 6, 16, 1, 7}, //10
|
238
|
{ 16, 0, 1, 8},
|
239
|
{ 16, 10, 8, 7},
|
240
|
{ 10, 8, 8, 10},
|
241
|
{ 8, 12, 8, 9},
|
242
|
{ 8, 13, 9, 10}, //15
|
243
|
{ 13, 5, 9, 5},
|
244
|
{ 5, 4, 9, 4},
|
245
|
{ 5, 15, 4, 5},
|
246
|
{ 15, 9, 4, 3},
|
247
|
{ 11, 19, 2, 3}, //20
|
248
|
{ 19, 7, 2, 6},
|
249
|
{ 7, 6, 2, 7},
|
250
|
{ 7, 17, 7, 6},
|
251
|
{ 17, 10, 7, 10},
|
252
|
{ 17, 1, 10, 6}, //25
|
253
|
{ 1, 3, 5, 6},
|
254
|
{ 3, 19, 3, 6},
|
255
|
{ 1, 13, 10, 5},
|
256
|
{ 3, 15, 5, 3},
|
257
|
};
|
258
|
|
259
|
// the five vertices that form a given face. Order: the same as colors
|
260
|
// of the faces in TwistyMinx.
|
261
|
static final int[][] mCenterMap =
|
262
|
{
|
263
|
{ 0, 12, 4, 14, 2},
|
264
|
{ 0, 2, 18, 6, 16},
|
265
|
{ 6, 18, 11, 19, 7},
|
266
|
{ 3, 15, 9, 11, 19},
|
267
|
{ 4, 5, 15, 9, 14},
|
268
|
{ 1, 13, 5, 15, 3},
|
269
|
{ 1, 3, 19, 7, 17},
|
270
|
{10, 16, 6, 7, 17},
|
271
|
{ 0, 12, 8, 10, 16},
|
272
|
{ 8, 13, 5, 4, 12},
|
273
|
{ 1, 13, 8, 10, 17},
|
274
|
{ 2, 14, 9, 11, 18},
|
275
|
};
|
276
|
|
277
|
static final float[][] mCenterCoords = new float[NUM_CENTERS][3];
|
278
|
|
279
|
static
|
280
|
{
|
281
|
for(int center=0; center<NUM_CENTERS; center++)
|
282
|
{
|
283
|
int[] map = mCenterMap[center];
|
284
|
|
285
|
float x = CORNERS[map[0]][0] +
|
286
|
CORNERS[map[1]][0] +
|
287
|
CORNERS[map[2]][0] +
|
288
|
CORNERS[map[3]][0] +
|
289
|
CORNERS[map[4]][0] ;
|
290
|
|
291
|
float y = CORNERS[map[0]][1] +
|
292
|
CORNERS[map[1]][1] +
|
293
|
CORNERS[map[2]][1] +
|
294
|
CORNERS[map[3]][1] +
|
295
|
CORNERS[map[4]][1] ;
|
296
|
|
297
|
float z = CORNERS[map[0]][2] +
|
298
|
CORNERS[map[1]][2] +
|
299
|
CORNERS[map[2]][2] +
|
300
|
CORNERS[map[3]][2] +
|
301
|
CORNERS[map[4]][2] ;
|
302
|
|
303
|
mCenterCoords[center][0] = x/5;
|
304
|
mCenterCoords[center][1] = y/5;
|
305
|
mCenterCoords[center][2] = z/5;
|
306
|
}
|
307
|
}
|
308
|
|
309
|
static final Static4D[] mBasicCornerV, mCurrCornerV;
|
310
|
|
311
|
static
|
312
|
{
|
313
|
mBasicCornerV = new Static4D[3];
|
314
|
mCurrCornerV = new Static4D[3];
|
315
|
|
316
|
mBasicCornerV[0] = new Static4D( (SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
|
317
|
mBasicCornerV[1] = new Static4D(-(SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
|
318
|
mBasicCornerV[2] = new Static4D( 0, -0.500f, 0.0f, 0.0f );
|
319
|
}
|
320
|
|
321
|
|
322
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
323
|
|
324
|
TwistyMinx(int numLayers, int realSize, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
325
|
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
|
326
|
{
|
327
|
super(numLayers, realSize, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
328
|
}
|
329
|
|
330
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
331
|
|
332
|
Static4D[] getQuats()
|
333
|
{
|
334
|
return QUATS;
|
335
|
}
|
336
|
|
337
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
338
|
|
339
|
int getNumFaces()
|
340
|
{
|
341
|
return FACE_COLORS.length;
|
342
|
}
|
343
|
|
344
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
345
|
|
346
|
boolean shouldResetTextureMaps()
|
347
|
{
|
348
|
return false;
|
349
|
}
|
350
|
|
351
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
352
|
|
353
|
int getNumCubitFaces()
|
354
|
{
|
355
|
return FACES_PER_CUBIT;
|
356
|
}
|
357
|
|
358
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
359
|
|
360
|
float returnMultiplier()
|
361
|
{
|
362
|
return 2.0f;
|
363
|
}
|
364
|
|
365
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
366
|
|
367
|
float[] getRowChances(int numLayers)
|
368
|
{
|
369
|
float[] chances = new float[numLayers];
|
370
|
float denom = (float)(numLayers-1);
|
371
|
int change = (numLayers-1)/2;
|
372
|
|
373
|
for(int i= 0; i<change ; i++) chances[i] = (i+1)/denom;
|
374
|
for(int i=change; i<numLayers; i++) chances[i] = (i )/denom;
|
375
|
|
376
|
return chances;
|
377
|
}
|
378
|
|
379
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
380
|
// PUBLIC API
|
381
|
|
382
|
public Static3D[] getRotationAxis()
|
383
|
{
|
384
|
return ROT_AXIS;
|
385
|
}
|
386
|
|
387
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
388
|
|
389
|
public int getBasicAngle()
|
390
|
{
|
391
|
return 5;
|
392
|
}
|
393
|
|
394
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
395
|
|
396
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
|
397
|
{
|
398
|
if( num==0 )
|
399
|
{
|
400
|
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
401
|
}
|
402
|
else
|
403
|
{
|
404
|
int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
|
405
|
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
406
|
}
|
407
|
|
408
|
if( num==0 )
|
409
|
{
|
410
|
float rowFloat = rnd.nextFloat();
|
411
|
|
412
|
for(int row=0; row<mRowChances.length; row++)
|
413
|
{
|
414
|
if( rowFloat<=mRowChances[row] )
|
415
|
{
|
416
|
scramble[num][1] = row;
|
417
|
break;
|
418
|
}
|
419
|
}
|
420
|
}
|
421
|
else
|
422
|
{
|
423
|
int size = mRowChances.length;
|
424
|
int nom = (size-1)/2;
|
425
|
int row = rnd.nextInt(nom);
|
426
|
boolean opposite = OPPOSITE_ROWS[scramble[num-1][0]][scramble[num][0]];
|
427
|
boolean low = opposite^(scramble[num-1][1]<nom);
|
428
|
scramble[num][1] = low ? row : size-1-row;
|
429
|
}
|
430
|
|
431
|
switch( rnd.nextInt(4) )
|
432
|
{
|
433
|
case 0: scramble[num][2] = -2; break;
|
434
|
case 1: scramble[num][2] = -1; break;
|
435
|
case 2: scramble[num][2] = 1; break;
|
436
|
case 3: scramble[num][2] = 2; break;
|
437
|
}
|
438
|
}
|
439
|
|
440
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
441
|
// only needed for solvers - there are no Minx solvers ATM)
|
442
|
|
443
|
public String retObjectString()
|
444
|
{
|
445
|
return "";
|
446
|
}
|
447
|
}
|