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.MovementC;
|
35
|
import org.distorted.objectlib.main.ObjectControl;
|
36
|
import org.distorted.objectlib.main.ObjectType;
|
37
|
import org.distorted.objectlib.helpers.ObjectShape;
|
38
|
import org.distorted.objectlib.helpers.ObjectSticker;
|
39
|
import org.distorted.objectlib.helpers.ScrambleState;
|
40
|
import org.distorted.objectlib.main.Twisty6;
|
41
|
|
42
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43
|
|
44
|
public class TwistyCuboid extends Twisty6
|
45
|
{
|
46
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
47
|
{
|
48
|
new Static3D(1,0,0),
|
49
|
new Static3D(0,1,0),
|
50
|
new Static3D(0,0,1)
|
51
|
};
|
52
|
|
53
|
private static final int[][][] ENABLED = new int[][][]
|
54
|
{
|
55
|
{{1,2}},{{1,2}},{{0,2}},{{0,2}},{{0,1}},{{0,1}},
|
56
|
};
|
57
|
|
58
|
private ScrambleState[] mStates;
|
59
|
private Static4D[] mQuats;
|
60
|
private float[][] mCuts;
|
61
|
private boolean[][] mLayerRotatable;
|
62
|
private int[] mBasicAngle;
|
63
|
private ObjectSticker[] mStickers;
|
64
|
private Movement mMovement;
|
65
|
|
66
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67
|
|
68
|
public TwistyCuboid(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
|
69
|
MeshSquare mesh, DistortedEffects effects, Resources res, int surfaceW, int surfaceH)
|
70
|
{
|
71
|
super(numL, (numL[0]+numL[1]+numL[2])/3.0f, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
|
72
|
}
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
|
76
|
private int[] createEdges(int size, boolean full, int vertex)
|
77
|
{
|
78
|
if( size==1 ) return null;
|
79
|
|
80
|
if( full )
|
81
|
{
|
82
|
int[] ret = new int[9*size];
|
83
|
|
84
|
for(int l=0; l<size; l++)
|
85
|
{
|
86
|
ret[9*l ] = l;
|
87
|
ret[9*l+1] =-1;
|
88
|
ret[9*l+2] = vertex;
|
89
|
ret[9*l+3] = l;
|
90
|
ret[9*l+4] = 1;
|
91
|
ret[9*l+5] = vertex;
|
92
|
ret[9*l+6] = l;
|
93
|
ret[9*l+7] = 2;
|
94
|
ret[9*l+8] = vertex;
|
95
|
}
|
96
|
|
97
|
return ret;
|
98
|
}
|
99
|
else
|
100
|
{
|
101
|
int[] ret = new int[6*size];
|
102
|
|
103
|
for(int l=0; l<size; l++)
|
104
|
{
|
105
|
ret[6*l ] = l;
|
106
|
ret[6*l+1] = 1;
|
107
|
ret[6*l+2] = vertex;
|
108
|
ret[6*l+3] = l;
|
109
|
ret[6*l+4] =-1;
|
110
|
ret[6*l+5] = vertex;
|
111
|
}
|
112
|
|
113
|
return ret;
|
114
|
}
|
115
|
}
|
116
|
|
117
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118
|
|
119
|
protected ScrambleState[] getScrambleStates()
|
120
|
{
|
121
|
if( mStates==null )
|
122
|
{
|
123
|
int[] numLayers = getNumLayers();
|
124
|
|
125
|
int X = numLayers[0];
|
126
|
int Y = numLayers[1];
|
127
|
int Z = numLayers[2];
|
128
|
|
129
|
int[][] mX = new int[16][];
|
130
|
int[][] mY = new int[16][];
|
131
|
int[][] mZ = new int[16][];
|
132
|
|
133
|
for(int i=0; i<16; i++)
|
134
|
{
|
135
|
mX[i] = createEdges(X,Y==Z,i);
|
136
|
mY[i] = createEdges(Y,X==Z,i);
|
137
|
mZ[i] = createEdges(Z,X==Y,i);
|
138
|
}
|
139
|
|
140
|
if( X>1 && Y>1 && Z>1 )
|
141
|
{
|
142
|
mStates = new ScrambleState[]
|
143
|
{
|
144
|
new ScrambleState( new int[][] { mX[ 1], mY[ 2], mZ[ 3] } ), // 0 0
|
145
|
new ScrambleState( new int[][] { null, mY[ 4], mZ[ 5] } ), // 1 x
|
146
|
new ScrambleState( new int[][] { mX[ 6], null, mZ[ 7] } ), // 2 y
|
147
|
new ScrambleState( new int[][] { mX[ 8], mY[ 9], null } ), // 3 z
|
148
|
new ScrambleState( new int[][] { mX[10], null, mZ[ 7] } ), // 4 xy
|
149
|
new ScrambleState( new int[][] { mX[11], mY[ 9], null } ), // 5 xz
|
150
|
new ScrambleState( new int[][] { null, mY[12], mZ[ 5] } ), // 6 yx
|
151
|
new ScrambleState( new int[][] { mX[ 8], mY[13], null } ), // 7 yz
|
152
|
new ScrambleState( new int[][] { null, mY[ 4], mZ[14] } ), // 8 zx
|
153
|
new ScrambleState( new int[][] { mX[ 6], null, mZ[15] } ), // 9 zy
|
154
|
new ScrambleState( new int[][] { null, null, mZ[ 5] } ), // 10 xyx
|
155
|
new ScrambleState( new int[][] { null, mY[ 4], null } ), // 11 xzx
|
156
|
new ScrambleState( new int[][] { null, null, mZ[ 7] } ), // 12 yxy
|
157
|
new ScrambleState( new int[][] { mX[ 6], null, null } ), // 13 yzy
|
158
|
new ScrambleState( new int[][] { null, mY[ 9], null } ), // 14 zxz
|
159
|
new ScrambleState( new int[][] { mX[ 8], null, null } ), // 15 zyz
|
160
|
};
|
161
|
}
|
162
|
else if( X==1 && Y==1 && Z==1 )
|
163
|
{
|
164
|
int[] state = new int[] {0,-1,0,0,1,0,0,2,0};
|
165
|
|
166
|
mStates = new ScrambleState[]
|
167
|
{
|
168
|
new ScrambleState( new int[][] { state, state, state } )
|
169
|
};
|
170
|
}
|
171
|
else
|
172
|
{
|
173
|
mStates = new ScrambleState[]
|
174
|
{
|
175
|
new ScrambleState( new int[][] { mX[ 0], mY[ 0], mZ[ 0] } )
|
176
|
};
|
177
|
}
|
178
|
|
179
|
}
|
180
|
|
181
|
return mStates;
|
182
|
}
|
183
|
|
184
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
185
|
|
186
|
protected int getResource(int[] numLayers)
|
187
|
{
|
188
|
int x = numLayers[0];
|
189
|
int y = numLayers[1];
|
190
|
|
191
|
switch(x)
|
192
|
{
|
193
|
case 2: return y==2 ? R.raw.cube2 : R.raw.cu_232;
|
194
|
case 3: switch(y)
|
195
|
{
|
196
|
case 2: return R.raw.cu_323;
|
197
|
case 3: return R.raw.cube3;
|
198
|
case 4: return R.raw.cu_343;
|
199
|
}
|
200
|
case 4: return R.raw.cube4;
|
201
|
case 5: return R.raw.cube5;
|
202
|
}
|
203
|
|
204
|
return 0;
|
205
|
}
|
206
|
|
207
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
208
|
|
209
|
private void initializeQuats()
|
210
|
{
|
211
|
mQuats = new Static4D[]
|
212
|
{
|
213
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f),
|
214
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f),
|
215
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f),
|
216
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f),
|
217
|
|
218
|
new Static4D( SQ2/2, SQ2/2, 0.0f , 0.0f),
|
219
|
new Static4D( SQ2/2, -SQ2/2, 0.0f , 0.0f),
|
220
|
new Static4D( SQ2/2, 0.0f, SQ2/2, 0.0f),
|
221
|
new Static4D(-SQ2/2, 0.0f, SQ2/2, 0.0f),
|
222
|
new Static4D( SQ2/2, 0.0f, 0.0f, SQ2/2),
|
223
|
new Static4D( SQ2/2, 0.0f, 0.0f, -SQ2/2),
|
224
|
new Static4D( 0.0f, SQ2/2, SQ2/2, 0.0f),
|
225
|
new Static4D( 0.0f, SQ2/2, -SQ2/2, 0.0f),
|
226
|
new Static4D( 0.0f, SQ2/2, 0.0f, SQ2/2),
|
227
|
new Static4D( 0.0f, SQ2/2, 0.0f, -SQ2/2),
|
228
|
new Static4D( 0.0f, 0.0f, SQ2/2, SQ2/2),
|
229
|
new Static4D( 0.0f, 0.0f, SQ2/2, -SQ2/2),
|
230
|
|
231
|
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f),
|
232
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f),
|
233
|
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f),
|
234
|
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f),
|
235
|
new Static4D( -0.5f, -0.5f, -0.5f, 0.5f),
|
236
|
new Static4D( -0.5f, 0.5f, -0.5f, -0.5f),
|
237
|
new Static4D( -0.5f, 0.5f, 0.5f, -0.5f),
|
238
|
new Static4D( -0.5f, 0.5f, 0.5f, 0.5f)
|
239
|
};
|
240
|
}
|
241
|
|
242
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
243
|
|
244
|
protected int[] getSolvedQuats(int cubit, int[] numLayers)
|
245
|
{
|
246
|
if( mQuats ==null ) initializeQuats();
|
247
|
int status = retCubitSolvedStatus(cubit,numLayers);
|
248
|
return status<0 ? null : buildSolvedQuats(MovementC.FACE_AXIS[status], mQuats);
|
249
|
}
|
250
|
|
251
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
252
|
|
253
|
protected ObjectShape getObjectShape(int cubit, int[] numLayers)
|
254
|
{
|
255
|
int extraI, extraV, num;
|
256
|
float height;
|
257
|
int variant = getCubitVariant(cubit,numLayers);
|
258
|
int numL = numLayers[0];
|
259
|
|
260
|
switch(numL)
|
261
|
{
|
262
|
case 2 : num = 6; extraI = 2; extraV = 2; height = 0.045f; break;
|
263
|
case 3 : num = 5; extraI = 2; extraV = 2; height = 0.045f; break;
|
264
|
case 4 : num = 5; extraI = 1; extraV = 1; height = 0.045f; break;
|
265
|
default: num = 5; extraI = 0; extraV = 0; height = 0.045f; break;
|
266
|
}
|
267
|
|
268
|
double[][] vertices = new double[][]
|
269
|
{
|
270
|
{ 0.5, 0.5, 0.5 },
|
271
|
{ 0.5, 0.5,-0.5 },
|
272
|
{ 0.5,-0.5, 0.5 },
|
273
|
{ 0.5,-0.5,-0.5 },
|
274
|
{-0.5, 0.5, 0.5 },
|
275
|
{-0.5, 0.5,-0.5 },
|
276
|
{-0.5,-0.5, 0.5 },
|
277
|
{-0.5,-0.5,-0.5 },
|
278
|
};
|
279
|
|
280
|
int[][] vert_indices = new int[][]
|
281
|
{
|
282
|
{2,3,1,0},
|
283
|
{7,6,4,5},
|
284
|
{4,0,1,5},
|
285
|
{7,3,2,6},
|
286
|
{6,2,0,4},
|
287
|
{3,7,5,1}
|
288
|
};
|
289
|
|
290
|
float[][] corners = new float[][] { {0.036f,0.12f} };
|
291
|
int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
|
292
|
float[][] centers = new float[][] { {0.0f, 0.0f, 0.0f} };
|
293
|
int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
|
294
|
|
295
|
if( variant==0 )
|
296
|
{
|
297
|
float[][] bands = new float[][] { {height,35,0.5f,0.7f,num,extraI,extraV} };
|
298
|
int[] bandIndices = new int[] { 0,0,0,0,0,0};
|
299
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
300
|
}
|
301
|
else
|
302
|
{
|
303
|
int extraI2, extraV2, num2;
|
304
|
|
305
|
switch(numL)
|
306
|
{
|
307
|
case 2 : num2 = 6; extraI2 = 2; extraV2 = 2; break;
|
308
|
case 3 : num2 = 5; extraI2 = 1; extraV2 = 0; break;
|
309
|
case 4 : num2 = 4; extraI2 = 0; extraV2 = 0; break;
|
310
|
default: num2 = 3; extraI2 = 0; extraV2 = 0; break;
|
311
|
}
|
312
|
|
313
|
float[][] bands = new float[][]
|
314
|
{
|
315
|
{height,35,0.5f,0.7f,num ,extraI ,extraV },
|
316
|
{height,35,0.5f,0.7f,num2,extraI2,extraV2},
|
317
|
{height,35,0.5f,0.7f, 2, 0, 0},
|
318
|
};
|
319
|
int[] bandIndices = new int[] { 1,1,1,1,0,2};
|
320
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
321
|
}
|
322
|
}
|
323
|
|
324
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
325
|
|
326
|
private int getCenterNum(int cubit, int[] numLayers)
|
327
|
{
|
328
|
int num = cubit - getNumCornersAndEdges(numLayers);
|
329
|
|
330
|
if( num>=0 )
|
331
|
{
|
332
|
int numLR = (numLayers[1]-2)*(numLayers[2]-2);
|
333
|
if( num< numLR ) return 0;
|
334
|
if( num<2*numLR ) return 1;
|
335
|
num -= 2*numLR;
|
336
|
|
337
|
int numTD = (numLayers[0]-2)*(numLayers[2]-2);
|
338
|
if( num< numTD ) return 2;
|
339
|
if( num<2*numTD ) return 3;
|
340
|
num -= 2*numTD;
|
341
|
|
342
|
int numFB = (numLayers[0]-2)*(numLayers[1]-2);
|
343
|
if( num< numFB ) return 4;
|
344
|
if( num<2*numFB ) return 5;
|
345
|
}
|
346
|
|
347
|
return -1;
|
348
|
}
|
349
|
|
350
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
351
|
|
352
|
private int getNumCornersAndEdges(int[] numLayers)
|
353
|
{
|
354
|
int x = numLayers[0];
|
355
|
int y = numLayers[1];
|
356
|
int z = numLayers[2];
|
357
|
|
358
|
return ( x==1 || y==1 || z==1 ) ? x*y*z : 4*( (x-2)+(y-2)+(z-2) ) + 8;
|
359
|
}
|
360
|
|
361
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
362
|
|
363
|
protected float[][] getCubitPositions(int[] numLayers)
|
364
|
{
|
365
|
final int X = numLayers[0];
|
366
|
final int Y = numLayers[1];
|
367
|
final int Z = numLayers[2];
|
368
|
|
369
|
final float lenX = 0.5f*(X-1);
|
370
|
final float lenY = 0.5f*(Y-1);
|
371
|
final float lenZ = 0.5f*(Z-1);
|
372
|
|
373
|
int curPos = 0;
|
374
|
|
375
|
if( X==1 )
|
376
|
{
|
377
|
float[][] pos = new float[X*Y*Z][];
|
378
|
|
379
|
for(int y=0; y<Y; y++)
|
380
|
for(int z=0; z<Z; z++) pos[curPos++] = new float[] {+lenX,y-lenY,z-lenZ};
|
381
|
|
382
|
return pos;
|
383
|
}
|
384
|
|
385
|
if( Y==1 )
|
386
|
{
|
387
|
float[][] pos = new float[X*Y*Z][];
|
388
|
|
389
|
for(int x=0; x<X; x++)
|
390
|
for(int z=0; z<Z; z++) pos[curPos++] = new float[] {x-lenX,+lenY,z-lenZ};
|
391
|
|
392
|
return pos;
|
393
|
}
|
394
|
|
395
|
if( Z==1 )
|
396
|
{
|
397
|
float[][] pos = new float[X*Y*Z][];
|
398
|
|
399
|
for(int x=0; x<X; x++)
|
400
|
for(int y=0; y<Y; y++) pos[curPos++] = new float[] {x-lenX,y-lenY,+lenZ};
|
401
|
|
402
|
return pos;
|
403
|
}
|
404
|
|
405
|
int numCubits = X*Y*Z - (X-2)*(Y-2)*(Z-2);
|
406
|
float[][] pos = new float[numCubits][];
|
407
|
|
408
|
pos[curPos++] = new float[] {-lenX,-lenY,-lenZ};
|
409
|
pos[curPos++] = new float[] {-lenX,-lenY,+lenZ};
|
410
|
pos[curPos++] = new float[] {-lenX,+lenY,-lenZ};
|
411
|
pos[curPos++] = new float[] {-lenX,+lenY,+lenZ};
|
412
|
pos[curPos++] = new float[] {+lenX,-lenY,-lenZ};
|
413
|
pos[curPos++] = new float[] {+lenX,-lenY,+lenZ};
|
414
|
pos[curPos++] = new float[] {+lenX,+lenY,-lenZ};
|
415
|
pos[curPos++] = new float[] {+lenX,+lenY,+lenZ};
|
416
|
|
417
|
for(int i=1; i<X-1; i++) pos[curPos++] = new float[] { i-lenX, -lenY, -lenZ };
|
418
|
for(int i=1; i<X-1; i++) pos[curPos++] = new float[] { i-lenX, -lenY, +lenZ };
|
419
|
for(int i=1; i<X-1; i++) pos[curPos++] = new float[] { i-lenX, +lenY, -lenZ };
|
420
|
for(int i=1; i<X-1; i++) pos[curPos++] = new float[] { i-lenX, +lenY, +lenZ };
|
421
|
for(int i=1; i<Y-1; i++) pos[curPos++] = new float[] { -lenX, i-lenY, -lenZ };
|
422
|
for(int i=1; i<Y-1; i++) pos[curPos++] = new float[] { -lenX, i-lenY, +lenZ };
|
423
|
for(int i=1; i<Y-1; i++) pos[curPos++] = new float[] { +lenX, i-lenY, -lenZ };
|
424
|
for(int i=1; i<Y-1; i++) pos[curPos++] = new float[] { +lenX, i-lenY, +lenZ };
|
425
|
for(int i=1; i<Z-1; i++) pos[curPos++] = new float[] { -lenX, -lenY, i-lenZ };
|
426
|
for(int i=1; i<Z-1; i++) pos[curPos++] = new float[] { -lenX, +lenY, i-lenZ };
|
427
|
for(int i=1; i<Z-1; i++) pos[curPos++] = new float[] { +lenX, -lenY, i-lenZ };
|
428
|
for(int i=1; i<Z-1; i++) pos[curPos++] = new float[] { +lenX, +lenY, i-lenZ };
|
429
|
|
430
|
for(int y=1; y<Y-1; y++)
|
431
|
for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {+lenX,y-lenY,z-lenZ};
|
432
|
|
433
|
for(int y=1; y<Y-1; y++)
|
434
|
for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {-lenX,y-lenY,z-lenZ};
|
435
|
|
436
|
for(int x=1; x<X-1; x++)
|
437
|
for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {x-lenX,+lenY,z-lenZ};
|
438
|
|
439
|
for(int x=1; x<X-1; x++)
|
440
|
for(int z=1; z<Z-1; z++) pos[curPos++] = new float[] {x-lenX,-lenY,z-lenZ};
|
441
|
|
442
|
for(int x=1; x<X-1; x++)
|
443
|
for(int y=1; y<Y-1; y++) pos[curPos++] = new float[] {x-lenX,y-lenY,+lenZ};
|
444
|
|
445
|
for(int x=1; x<X-1; x++)
|
446
|
for(int y=1; y<Y-1; y++) pos[curPos++] = new float[] {x-lenX,y-lenY,-lenZ};
|
447
|
|
448
|
return pos;
|
449
|
}
|
450
|
|
451
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
452
|
|
453
|
protected Static4D getQuat(int cubit, int[] numLayers)
|
454
|
{
|
455
|
if( mQuats ==null ) initializeQuats();
|
456
|
|
457
|
int centerNum = getCenterNum(cubit,numLayers);
|
458
|
|
459
|
switch(centerNum)
|
460
|
{
|
461
|
case 0 : return mQuats[13];
|
462
|
case 1 : return mQuats[12];
|
463
|
case 2 : return mQuats[ 8];
|
464
|
case 3 : return mQuats[ 9];
|
465
|
case 4 : return mQuats[ 0];
|
466
|
case 5 : return mQuats[ 1];
|
467
|
default: return mQuats[ 0];
|
468
|
}
|
469
|
}
|
470
|
|
471
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
472
|
|
473
|
protected int getNumCubitVariants(int[] numLayers)
|
474
|
{
|
475
|
return numLayers[0]>2 ? 2:1;
|
476
|
}
|
477
|
|
478
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
479
|
|
480
|
protected int getCubitVariant(int cubit, int[] numLayers)
|
481
|
{
|
482
|
return cubit < getNumCornersAndEdges(numLayers) ? 0 : 1;
|
483
|
}
|
484
|
|
485
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
486
|
|
487
|
protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
|
488
|
{
|
489
|
int centerNum = getCenterNum(cubit,numLayers);
|
490
|
|
491
|
if( centerNum<0 )
|
492
|
{
|
493
|
int axis = cubitface/2;
|
494
|
return CUBITS[cubit].getRotRow(axis) == (cubitface%2==0 ? (1<<(numLayers[axis]-1)):1) ? cubitface : NUM_TEXTURES;
|
495
|
}
|
496
|
else
|
497
|
{
|
498
|
return cubitface == 4 ? centerNum : NUM_TEXTURES;
|
499
|
}
|
500
|
}
|
501
|
|
502
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
503
|
|
504
|
protected ObjectSticker retSticker(int face)
|
505
|
{
|
506
|
if( mStickers==null )
|
507
|
{
|
508
|
final float[][] STICKERS = new float[][] { { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f } };
|
509
|
final float radius = 0.10f;
|
510
|
final float[] radii = {radius,radius,radius,radius};
|
511
|
mStickers = new ObjectSticker[STICKERS.length];
|
512
|
float stroke = 0.08f;
|
513
|
|
514
|
if( ObjectControl.isInIconMode() )
|
515
|
{
|
516
|
int[] numLayers = getNumLayers();
|
517
|
|
518
|
switch(numLayers[0])
|
519
|
{
|
520
|
case 2: stroke*=1.8f; break;
|
521
|
case 3: stroke*=2.0f; break;
|
522
|
case 4: stroke*=2.1f; break;
|
523
|
default:stroke*=2.2f; break;
|
524
|
}
|
525
|
}
|
526
|
|
527
|
mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke );
|
528
|
}
|
529
|
|
530
|
return mStickers[face/NUM_FACE_COLORS];
|
531
|
}
|
532
|
|
533
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
534
|
|
535
|
protected Static4D[] getQuats()
|
536
|
{
|
537
|
if( mQuats ==null ) initializeQuats();
|
538
|
return mQuats;
|
539
|
}
|
540
|
|
541
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
542
|
|
543
|
protected float[][] getCuts(int[] numLayers)
|
544
|
{
|
545
|
if( mCuts==null )
|
546
|
{
|
547
|
mCuts = new float[3][];
|
548
|
|
549
|
for(int axis=0; axis<3; axis++)
|
550
|
{
|
551
|
int len = numLayers[axis];
|
552
|
float start = (2-len)*0.5f;
|
553
|
|
554
|
if( len>=2 )
|
555
|
{
|
556
|
mCuts[axis] = new float[len-1];
|
557
|
for(int i=0; i<len-1; i++) mCuts[axis][i] = start+i;
|
558
|
}
|
559
|
}
|
560
|
}
|
561
|
|
562
|
return mCuts;
|
563
|
}
|
564
|
|
565
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
566
|
|
567
|
private void getLayerRotatable(int[] numLayers)
|
568
|
{
|
569
|
if( mLayerRotatable==null )
|
570
|
{
|
571
|
int numAxis = ROT_AXIS.length;
|
572
|
mLayerRotatable = new boolean[numAxis][];
|
573
|
|
574
|
for(int i=0; i<numAxis; i++)
|
575
|
{
|
576
|
mLayerRotatable[i] = new boolean[numLayers[i]];
|
577
|
for(int j=0; j<numLayers[i]; j++) mLayerRotatable[i][j] = true;
|
578
|
}
|
579
|
}
|
580
|
}
|
581
|
|
582
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
583
|
|
584
|
protected int getSolvedFunctionIndex()
|
585
|
{
|
586
|
return 0;
|
587
|
}
|
588
|
|
589
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
590
|
|
591
|
protected int getNumStickerTypes(int[] numLayers)
|
592
|
{
|
593
|
return 1;
|
594
|
}
|
595
|
|
596
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
597
|
|
598
|
protected int getNumCubitFaces()
|
599
|
{
|
600
|
return 6;
|
601
|
}
|
602
|
|
603
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
604
|
// PUBLIC API
|
605
|
|
606
|
public Static3D[] getRotationAxis()
|
607
|
{
|
608
|
return ROT_AXIS;
|
609
|
}
|
610
|
|
611
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
612
|
|
613
|
public Movement getMovement()
|
614
|
{
|
615
|
if( mMovement==null )
|
616
|
{
|
617
|
int[] numLayers = getNumLayers();
|
618
|
if( mCuts==null ) getCuts(numLayers);
|
619
|
getLayerRotatable(numLayers);
|
620
|
float avg = (numLayers[0]+numLayers[1]+numLayers[2])/3.0f;
|
621
|
|
622
|
float[] dist3D =
|
623
|
{
|
624
|
0.5f*numLayers[0]/avg,
|
625
|
0.5f*numLayers[0]/avg,
|
626
|
0.5f*numLayers[1]/avg,
|
627
|
0.5f*numLayers[1]/avg,
|
628
|
0.5f*numLayers[2]/avg,
|
629
|
0.5f*numLayers[2]/avg,
|
630
|
};
|
631
|
|
632
|
mMovement = new MovementC(ROT_AXIS,mCuts,mLayerRotatable,avg,TYPE_NOT_SPLIT,ENABLED,dist3D);
|
633
|
}
|
634
|
return mMovement;
|
635
|
}
|
636
|
|
637
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
638
|
|
639
|
public int[] getBasicAngle()
|
640
|
{
|
641
|
if( mBasicAngle==null )
|
642
|
{
|
643
|
int[] num = getNumLayers();
|
644
|
int x = num[1]==num[2] ? 4 : 2;
|
645
|
int y = num[0]==num[2] ? 4 : 2;
|
646
|
int z = num[0]==num[1] ? 4 : 2;
|
647
|
|
648
|
mBasicAngle = new int[] { x,y,z };
|
649
|
}
|
650
|
return mBasicAngle;
|
651
|
}
|
652
|
|
653
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
654
|
|
655
|
public ObjectType intGetObjectType(int[] numLayers)
|
656
|
{
|
657
|
int x = numLayers[0];
|
658
|
int y = numLayers[1];
|
659
|
|
660
|
switch(x)
|
661
|
{
|
662
|
case 2: switch(y)
|
663
|
{
|
664
|
case 2: return ObjectType.CUBE_2;
|
665
|
case 3: return ObjectType.CU_232;
|
666
|
}
|
667
|
case 3: switch(y)
|
668
|
{
|
669
|
case 2: return ObjectType.CU_323;
|
670
|
case 3: return ObjectType.CUBE_3;
|
671
|
case 4: return ObjectType.CU_343;
|
672
|
}
|
673
|
case 4: return ObjectType.CUBE_4;
|
674
|
case 5: return ObjectType.CUBE_5;
|
675
|
}
|
676
|
|
677
|
return ObjectType.CUBE_3;
|
678
|
}
|
679
|
|
680
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
681
|
|
682
|
public int getObjectName(int[] numLayers)
|
683
|
{
|
684
|
switch(numLayers[0])
|
685
|
{
|
686
|
case 2: return R.string.cube2;
|
687
|
case 3: return R.string.cube3;
|
688
|
case 4: return R.string.cube4;
|
689
|
case 5: return R.string.cube5;
|
690
|
}
|
691
|
return R.string.cube3;
|
692
|
}
|
693
|
|
694
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
695
|
|
696
|
public int getInventor(int[] numLayers)
|
697
|
{
|
698
|
switch(numLayers[0])
|
699
|
{
|
700
|
case 2: return R.string.cube2_inventor;
|
701
|
case 3: return R.string.cube3_inventor;
|
702
|
case 4: return R.string.cube4_inventor;
|
703
|
case 5: return R.string.cube5_inventor;
|
704
|
}
|
705
|
return R.string.cube3_inventor;
|
706
|
}
|
707
|
|
708
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
709
|
|
710
|
public int getComplexity(int[] numLayers)
|
711
|
{
|
712
|
switch(numLayers[0])
|
713
|
{
|
714
|
case 2: return 4;
|
715
|
case 3: return 6;
|
716
|
case 4: return 8;
|
717
|
case 5: return 10;
|
718
|
}
|
719
|
return 6;
|
720
|
}
|
721
|
}
|