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.helpers.ObjectShape;
|
25
|
import org.distorted.helpers.ObjectSticker;
|
26
|
import org.distorted.helpers.QuatHelper;
|
27
|
import org.distorted.library.main.DistortedEffects;
|
28
|
import org.distorted.library.main.DistortedTexture;
|
29
|
import org.distorted.library.mesh.MeshSquare;
|
30
|
import org.distorted.library.type.Static4D;
|
31
|
import org.distorted.main.R;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class TwistyMegaminx extends TwistyMinx
|
36
|
{
|
37
|
static final float MEGA_D = 0.04f;
|
38
|
private int[] mQuatCenterIndices;
|
39
|
|
40
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41
|
|
42
|
TwistyMegaminx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
43
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
44
|
{
|
45
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.MEGA, res, scrWidth);
|
46
|
}
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
|
50
|
private void initializeCenterIndices()
|
51
|
{
|
52
|
mQuatCenterIndices = new int[] { 16, 18, 22, 1, 20, 13, 14, 15, 0, 12, 2, 3 };
|
53
|
}
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
private int numCubitsPerCorner(int numLayers)
|
58
|
{
|
59
|
return 3*((numLayers-1)/2)*((numLayers-3)/2) + 1;
|
60
|
}
|
61
|
|
62
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63
|
|
64
|
private int numCubitsPerEdge(int numLayers)
|
65
|
{
|
66
|
return numLayers-2;
|
67
|
}
|
68
|
|
69
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70
|
|
71
|
float getScreenRatio()
|
72
|
{
|
73
|
return 1.07f;
|
74
|
}
|
75
|
|
76
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77
|
|
78
|
int getNumStickerTypes(int numLayers)
|
79
|
{
|
80
|
return (numLayers+3)/2;
|
81
|
}
|
82
|
|
83
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84
|
|
85
|
float[][] getCuts(int numLayers)
|
86
|
{
|
87
|
float[][] cuts = new float[6][numLayers-1];
|
88
|
float D = numLayers*MovementMinx.DIST3D;
|
89
|
float E = 2*SIN54;
|
90
|
float X = 2*D*E/(1+2*E); // height of the 'upper' part of a dodecahedron, i.e. put it on a table,
|
91
|
// its height is then D*2*DIST3D, it has one 'lower' part of height X, one
|
92
|
// 'middle' part of height Y and one upper part of height X again.
|
93
|
// It's edge length = numLayers/3.0f.
|
94
|
int num = (numLayers-1)/2;
|
95
|
float G = X*(0.5f-MEGA_D)/num; // height of one Layer
|
96
|
|
97
|
for(int i=0; i<num; i++)
|
98
|
{
|
99
|
float cut = -D + (i+0.5f)*G;
|
100
|
int j = 2*num-1-i;
|
101
|
cuts[0][i] = +cut;
|
102
|
cuts[0][j] = -cut;
|
103
|
cuts[1][i] = +cut;
|
104
|
cuts[1][j] = -cut;
|
105
|
cuts[2][i] = +cut;
|
106
|
cuts[2][j] = -cut;
|
107
|
cuts[3][i] = +cut;
|
108
|
cuts[3][j] = -cut;
|
109
|
cuts[4][i] = +cut;
|
110
|
cuts[4][j] = -cut;
|
111
|
cuts[5][i] = +cut;
|
112
|
cuts[5][j] = -cut;
|
113
|
}
|
114
|
|
115
|
return cuts;
|
116
|
}
|
117
|
|
118
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119
|
|
120
|
private float[] computeCenter(int center, int numLayers)
|
121
|
{
|
122
|
if( mCenterCoords==null ) initializeCenterCoords();
|
123
|
float[] coords = mCenterCoords[center];
|
124
|
float A = numLayers/3.0f;
|
125
|
|
126
|
return new float[] { A*coords[0], A*coords[1], A*coords[2] };
|
127
|
}
|
128
|
|
129
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130
|
// Fill out mCurrCorner{X,Y,Z} by applying appropriate Quat to mBasicCorner{X,Y,Z}
|
131
|
// Appropriate one: QUATS[QUAT_INDICES[corner]].
|
132
|
|
133
|
private void computeBasicCornerVectors(int corner)
|
134
|
{
|
135
|
if( mQuatCornerIndices==null ) initializeQuatIndices();
|
136
|
if( mQuats==null ) initializeQuats();
|
137
|
if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
|
138
|
|
139
|
Static4D quat = mQuats[mQuatCornerIndices[corner]];
|
140
|
|
141
|
mCurrCornerV[0] = QuatHelper.rotateVectorByQuat(mBasicCornerV[0],quat);
|
142
|
mCurrCornerV[1] = QuatHelper.rotateVectorByQuat(mBasicCornerV[1],quat);
|
143
|
mCurrCornerV[2] = QuatHelper.rotateVectorByQuat(mBasicCornerV[2],quat);
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
private float[] computeCorner(int numCubitsPerCorner, int numLayers, int corner, int part)
|
149
|
{
|
150
|
if( mCorners==null ) initializeCorners();
|
151
|
if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
|
152
|
|
153
|
float D = numLayers/3.0f;
|
154
|
float[] corn = mCorners[corner];
|
155
|
|
156
|
if( part==0 )
|
157
|
{
|
158
|
return new float[] { corn[0]*D, corn[1]*D, corn[2]*D };
|
159
|
}
|
160
|
else
|
161
|
{
|
162
|
float E = 2.0f*D*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
|
163
|
int N = (numCubitsPerCorner-1)/3;
|
164
|
int block = (part-1) % N;
|
165
|
int index = (part-1) / N;
|
166
|
Static4D pri = mCurrCornerV[index];
|
167
|
Static4D sec = mCurrCornerV[(index+2)%3];
|
168
|
|
169
|
int layers= (numLayers-3)/2;
|
170
|
int multP = (block % layers) + 1;
|
171
|
int multS = (block / layers);
|
172
|
|
173
|
return new float[] {
|
174
|
corn[0]*D + (pri.get0()*multP + sec.get0()*multS)*E,
|
175
|
corn[1]*D + (pri.get1()*multP + sec.get1()*multS)*E,
|
176
|
corn[2]*D + (pri.get2()*multP + sec.get2()*multS)*E
|
177
|
};
|
178
|
}
|
179
|
}
|
180
|
|
181
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182
|
|
183
|
private int computeEdgeType(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
184
|
{
|
185
|
int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
|
186
|
return (part+1)/2;
|
187
|
}
|
188
|
|
189
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
190
|
|
191
|
private float[] computeEdge(int numLayers, int edge, int part)
|
192
|
{
|
193
|
if( mCenterCoords==null ) initializeCenterCoords();
|
194
|
if( mCorners==null ) initializeCorners();
|
195
|
if( mEdgeMap==null ) initializeEdgeMap();
|
196
|
|
197
|
float D = numLayers/3.0f;
|
198
|
float[] c1 = mCorners[ mEdgeMap[edge][0] ];
|
199
|
float[] c2 = mCorners[ mEdgeMap[edge][1] ];
|
200
|
float x = D * (c1[0]+c2[0]) / 2;
|
201
|
float y = D * (c1[1]+c2[1]) / 2;
|
202
|
float z = D * (c1[2]+c2[2]) / 2;
|
203
|
|
204
|
if( part==0 )
|
205
|
{
|
206
|
return new float[] { x, y, z };
|
207
|
}
|
208
|
else
|
209
|
{
|
210
|
int mult = (part+1)/2;
|
211
|
int dir = (part+1)%2;
|
212
|
float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ];
|
213
|
|
214
|
float vX = D*center[0] - x;
|
215
|
float vY = D*center[1] - y;
|
216
|
float vZ = D*center[2] - z;
|
217
|
|
218
|
float A = mult*D*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
|
219
|
A /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
|
220
|
|
221
|
return new float[] { x+A*vX, y+A*vY, z+A*vZ };
|
222
|
}
|
223
|
}
|
224
|
|
225
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226
|
|
227
|
float[][] getCubitPositions(int numLayers)
|
228
|
{
|
229
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
230
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
231
|
int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge + NUM_CENTERS;
|
232
|
int index=0;
|
233
|
|
234
|
final float[][] CENTERS = new float[numCubits][];
|
235
|
|
236
|
for(int corner=0; corner<NUM_CORNERS; corner++)
|
237
|
{
|
238
|
computeBasicCornerVectors(corner);
|
239
|
|
240
|
for(int part=0; part<numCubitsPerCorner; part++, index++)
|
241
|
{
|
242
|
CENTERS[index] = computeCorner(numCubitsPerCorner,numLayers,corner,part);
|
243
|
}
|
244
|
}
|
245
|
|
246
|
for(int edge=0; edge<NUM_EDGES; edge++)
|
247
|
{
|
248
|
for(int part=0; part<numCubitsPerEdge; part++, index++)
|
249
|
{
|
250
|
CENTERS[index] = computeEdge(numLayers, edge, part );
|
251
|
}
|
252
|
}
|
253
|
|
254
|
for(int center=0; center<NUM_CENTERS; center++, index++)
|
255
|
{
|
256
|
CENTERS[index] = computeCenter(center, numLayers);
|
257
|
}
|
258
|
|
259
|
return CENTERS;
|
260
|
}
|
261
|
|
262
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
263
|
|
264
|
private int getQuat(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
265
|
{
|
266
|
if( mQuatCornerIndices==null || mQuatEdgeIndices==null ) initializeQuatIndices();
|
267
|
if( mQuatCenterIndices==null ) initializeCenterIndices();
|
268
|
|
269
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
270
|
{
|
271
|
int corner = cubit/numCubitsPerCorner;
|
272
|
return mQuatCornerIndices[corner];
|
273
|
}
|
274
|
|
275
|
if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
276
|
{
|
277
|
int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge;
|
278
|
return mQuatEdgeIndices[edge];
|
279
|
}
|
280
|
|
281
|
int center = cubit - NUM_CORNERS*numCubitsPerCorner - NUM_EDGES*numCubitsPerEdge;
|
282
|
return mQuatCenterIndices[center];
|
283
|
}
|
284
|
|
285
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
286
|
|
287
|
ObjectShape getObjectShape(int cubit, int numLayers)
|
288
|
{
|
289
|
int variant = getCubitVariant(cubit,numLayers);
|
290
|
int numVariants = getNumCubitVariants(numLayers);
|
291
|
|
292
|
if( variant==0 )
|
293
|
{
|
294
|
float width = (numLayers/3.0f)*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
|
295
|
float A = (2*SQ3/3)*SIN54;
|
296
|
float B = 0.4f;
|
297
|
double X = width*COS18*SIN_HALFD;
|
298
|
double Y = width*SIN18;
|
299
|
double Z = width*COS18*COS_HALFD;
|
300
|
int N = numLayers==3 ? 1:0;
|
301
|
|
302
|
double[][] vertices = new double[][]
|
303
|
{
|
304
|
{ 0.0, 0.0 , 0.0 },
|
305
|
{ X, Y , -Z },
|
306
|
{ 0.0, 2*Y ,-2*Z },
|
307
|
{ -X, Y , -Z },
|
308
|
{ 0.0, 0.0-width, 0.0 },
|
309
|
{ X, Y-width, -Z },
|
310
|
{ 0.0, 2*Y-width,-2*Z },
|
311
|
{ -X, Y-width, -Z },
|
312
|
};
|
313
|
|
314
|
int[][] vertIndexes = new int[][]
|
315
|
{
|
316
|
{4,5,1,0},
|
317
|
{7,4,0,3},
|
318
|
{0,1,2,3},
|
319
|
{4,5,6,7},
|
320
|
{6,5,1,2},
|
321
|
{7,6,2,3}
|
322
|
};
|
323
|
|
324
|
float[][] bands = new float[][]
|
325
|
{
|
326
|
{0.04f,34,0.3f,0.2f, 3, N, 0},
|
327
|
{0.00f, 0,0.0f,0.0f, 2, N, 0}
|
328
|
};
|
329
|
|
330
|
int[] bandIndices = new int[] { 0,0,0,1,1,1};
|
331
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
332
|
int[] cornerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
|
333
|
float[][] centers = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
|
334
|
int[] centerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
|
335
|
|
336
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
337
|
}
|
338
|
if( variant<numVariants-1 )
|
339
|
{
|
340
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
341
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
342
|
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
|
343
|
float height= (numLayers/3.0f)*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
|
344
|
float width = (numLayers/3.0f)*2*MEGA_D + 2*type*height*SIN18/COS18;
|
345
|
|
346
|
double W = width/2;
|
347
|
double X = height*SIN_HALFD;
|
348
|
double Y = height*SIN18/COS18;
|
349
|
double Z = height*COS_HALFD;
|
350
|
|
351
|
double[][] vertices = new double[][]
|
352
|
{
|
353
|
{ 0.0, W , 0.0 },
|
354
|
{ X, W+Y , -Z },
|
355
|
{ 0.0, W+2*Y ,-2*Z },
|
356
|
{ -X, W+Y , -Z },
|
357
|
{ 0.0, -W , 0.0 },
|
358
|
{ X,-W-Y , -Z },
|
359
|
{ 0.0,-W-2*Y ,-2*Z },
|
360
|
{ -X,-W-Y , -Z },
|
361
|
};
|
362
|
|
363
|
int[][] vertIndexes = new int[][]
|
364
|
{
|
365
|
{4,5,1,0},
|
366
|
{7,4,0,3},
|
367
|
{7,6,2,3},
|
368
|
{6,5,1,2},
|
369
|
{0,1,2,3},
|
370
|
{4,5,6,7}
|
371
|
};
|
372
|
|
373
|
int N = numLayers<=5 ? 5 : 3;
|
374
|
|
375
|
float[][] bands = new float[][]
|
376
|
{
|
377
|
{0.04f,34,0.2f,0.2f,N,0,0},
|
378
|
{0.00f, 0,0.3f,0.2f,2,0,0}
|
379
|
};
|
380
|
int[] bandIndices = new int[] { 0,0,1,1,1,1};
|
381
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
382
|
int[] cornerIndices = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
|
383
|
float[][] centers = new float[][] { {0.0f, 0.0f, (float)(-2*Z)} };
|
384
|
int[] centerIndices = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
|
385
|
|
386
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
387
|
}
|
388
|
else
|
389
|
{
|
390
|
float width = 2 * (numLayers/3.0f) * (MEGA_D+(0.5f-MEGA_D)*SIN18);
|
391
|
final double V = 0.83; // ??
|
392
|
final double ANGLE = V*Math.PI;
|
393
|
final double cosA = Math.cos(ANGLE);
|
394
|
final double sinA = Math.sin(ANGLE);
|
395
|
|
396
|
float R = 0.5f*width/COS54;
|
397
|
float X1 = R*COS54;
|
398
|
float Y1 = R*SIN54;
|
399
|
float X2 = R*COS18;
|
400
|
float Y2 = R*SIN18;
|
401
|
|
402
|
double[][] vertices = new double[][]
|
403
|
{
|
404
|
{-X1,+Y1*sinA, Y1*cosA},
|
405
|
{-X2,-Y2*sinA,-Y2*cosA},
|
406
|
{0.0f,-R*sinA, -R*cosA},
|
407
|
{+X2,-Y2*sinA,-Y2*cosA},
|
408
|
{+X1,+Y1*sinA, Y1*cosA}
|
409
|
};
|
410
|
|
411
|
int[][] vertIndexes = new int[][]
|
412
|
{
|
413
|
{0,1,2,3,4},
|
414
|
{0,1,2,3,4}
|
415
|
};
|
416
|
|
417
|
int N = numLayers==3 ? 4 : 3;
|
418
|
|
419
|
float[][] bands = new float[][]
|
420
|
{
|
421
|
{0.04f,45, R/3,0.2f,N,0,0},
|
422
|
{0.00f, 0, R/3,0.2f,2,0,0}
|
423
|
};
|
424
|
|
425
|
int[] bandIndices = new int[] { 0,1 };
|
426
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
427
|
int[] cornerIndices = new int[] { -1,-1,-1,-1, -1 };
|
428
|
float[][] centers = new float[][] { {0.0f, 0.0f, 0.0f} };
|
429
|
int[] centerIndices = new int[] { -1,-1,-1,-1, -1 };
|
430
|
|
431
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
432
|
}
|
433
|
}
|
434
|
|
435
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
436
|
|
437
|
Static4D getQuat(int cubit, int numLayers)
|
438
|
{
|
439
|
if( mQuats==null ) initializeQuats();
|
440
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
441
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
442
|
|
443
|
return mQuats[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
|
444
|
}
|
445
|
|
446
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
447
|
|
448
|
int getNumCubitVariants(int numLayers)
|
449
|
{
|
450
|
int[] sizes = ObjectList.MEGA.getSizes();
|
451
|
int variants = sizes.length;
|
452
|
|
453
|
return 2+(sizes[variants-1]-1)/2;
|
454
|
}
|
455
|
|
456
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
457
|
|
458
|
int getCubitVariant(int cubit, int numLayers)
|
459
|
{
|
460
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
461
|
|
462
|
if( cubit<NUM_CORNERS*numCubitsPerCorner ) return 0;
|
463
|
|
464
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
465
|
|
466
|
if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
467
|
{
|
468
|
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
|
469
|
return type+1;
|
470
|
}
|
471
|
|
472
|
int[] sizes = ObjectList.MEGA.getSizes();
|
473
|
int variants = sizes.length;
|
474
|
int numShapes = 2+(sizes[variants-1]-1)/2;
|
475
|
|
476
|
return numShapes-1;
|
477
|
}
|
478
|
|
479
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
480
|
|
481
|
int getCornerColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner)
|
482
|
{
|
483
|
if( mCornerFaceMap==null ) initializeCornerFaceMap();
|
484
|
if( cubitface<0 || cubitface>2 ) return NUM_TEXTURES;
|
485
|
|
486
|
int part = cubit % numCubitsPerCorner;
|
487
|
int corner= cubit / numCubitsPerCorner;
|
488
|
|
489
|
if( part==0 )
|
490
|
{
|
491
|
return mCornerFaceMap[corner][cubitface];
|
492
|
}
|
493
|
else
|
494
|
{
|
495
|
int N = (numCubitsPerCorner-1)/3;
|
496
|
int block = (part-1) % N;
|
497
|
int index = (part-1) / N;
|
498
|
|
499
|
if( block< (numLayers-3)/2 )
|
500
|
{
|
501
|
switch(index)
|
502
|
{
|
503
|
case 0: return cubitface==1 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
504
|
case 1: return cubitface==0 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
505
|
case 2: return cubitface==2 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
506
|
}
|
507
|
}
|
508
|
else
|
509
|
{
|
510
|
switch(index)
|
511
|
{
|
512
|
case 0: return cubitface==0 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
513
|
case 1: return cubitface==2 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
514
|
case 2: return cubitface==1 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
515
|
}
|
516
|
}
|
517
|
}
|
518
|
|
519
|
return NUM_TEXTURES;
|
520
|
}
|
521
|
|
522
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
523
|
|
524
|
int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
|
525
|
{
|
526
|
if( cubitface<0 || cubitface>1 ) return NUM_TEXTURES;
|
527
|
|
528
|
int part = edge % numCubitsPerEdge;
|
529
|
int variant = edge / numCubitsPerEdge;
|
530
|
if( mEdgeMap==null ) initializeEdgeMap();
|
531
|
|
532
|
return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] + ((part+3)/2)*NUM_FACES : NUM_TEXTURES;
|
533
|
}
|
534
|
|
535
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
536
|
|
537
|
int getCenterColor(int center, int cubitface, int numLayers)
|
538
|
{
|
539
|
return cubitface>0 ? NUM_TEXTURES : center + NUM_FACES*(numLayers+1)/2;
|
540
|
}
|
541
|
|
542
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
543
|
|
544
|
int getFaceColor(int cubit, int cubitface, int numLayers)
|
545
|
{
|
546
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
547
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
548
|
|
549
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
550
|
{
|
551
|
return getCornerColor(cubit,cubitface,numLayers,numCubitsPerCorner);
|
552
|
}
|
553
|
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
554
|
{
|
555
|
int edge = cubit - NUM_CORNERS*numCubitsPerCorner;
|
556
|
return getEdgeColor(edge,cubitface,numCubitsPerEdge);
|
557
|
}
|
558
|
else
|
559
|
{
|
560
|
int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge;
|
561
|
return getCenterColor( center, cubitface, numLayers);
|
562
|
}
|
563
|
}
|
564
|
|
565
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
566
|
|
567
|
int getColor(int face)
|
568
|
{
|
569
|
return FACE_COLORS[face];
|
570
|
}
|
571
|
|
572
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
573
|
|
574
|
ObjectSticker retSticker(int face)
|
575
|
{
|
576
|
if( mStickers==null )
|
577
|
{
|
578
|
float[][] STICKERS = new float[][]
|
579
|
{
|
580
|
{ -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
|
581
|
{ -0.5f, -0.0914315f, 0.5f, -0.4163512f, 0.5f, 0.4163512f, -0.5f, 0.0914315f },
|
582
|
{ -0.49233657f, -0.18006028f, 0.49233657f, -0.5f, 0.49233657f, 0.5f, -0.49233657f, 0.18006028f },
|
583
|
{ -0.3002273f, -0.30490047f, 0.3002273f, -0.5f, 0.3002273f, 0.5f, -0.3002273f, 0.30490047f },
|
584
|
{ -0.29389262f, 0.4045085f, -0.47552824f, -0.1545085f, 0.0f, -0.5f, 0.47552824f, -0.1545085f, 0.29389262f, 0.4045085f }
|
585
|
};
|
586
|
|
587
|
mStickers = new ObjectSticker[STICKERS.length];
|
588
|
|
589
|
final float R0 = 0.08f;
|
590
|
final float R1 = 0.12f;
|
591
|
final float R2 = 0.12f;
|
592
|
final float R3 = 0.08f;
|
593
|
final float R4 = 0.10f;
|
594
|
final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3},{R4,R4,R4,R4,R4} };
|
595
|
final float[] strokes = { 0.10f,0.12f,0.12f,0.08f,0.07f };
|
596
|
|
597
|
for(int s=0; s<STICKERS.length; s++)
|
598
|
{
|
599
|
mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
|
600
|
}
|
601
|
}
|
602
|
|
603
|
return mStickers[getStickerIndex(face)];
|
604
|
}
|
605
|
|
606
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
607
|
|
608
|
private int getStickerIndex(int face)
|
609
|
{
|
610
|
int variant = face/NUM_FACES;
|
611
|
|
612
|
if( variant==0 ) return 0;
|
613
|
|
614
|
int numLayers = getNumLayers();
|
615
|
|
616
|
if( variant < (numLayers+1)/2 )
|
617
|
{
|
618
|
if( numLayers==3 ) return 1;
|
619
|
else
|
620
|
{
|
621
|
if( variant==1 ) return 2;
|
622
|
else return 3;
|
623
|
}
|
624
|
}
|
625
|
|
626
|
return 4;
|
627
|
}
|
628
|
|
629
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
630
|
|
631
|
public int getObjectName(int numLayers)
|
632
|
{
|
633
|
if( numLayers==3 ) return R.string.minx3;
|
634
|
if( numLayers==5 ) return R.string.minx5;
|
635
|
|
636
|
return 0;
|
637
|
}
|
638
|
|
639
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
640
|
|
641
|
public int getInventor(int numLayers)
|
642
|
{
|
643
|
if( numLayers==3 ) return R.string.minx3_inventor;
|
644
|
if( numLayers==5 ) return R.string.minx5_inventor;
|
645
|
|
646
|
return 0;
|
647
|
}
|
648
|
|
649
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
650
|
|
651
|
public int getComplexity(int numLayers)
|
652
|
{
|
653
|
if( numLayers==3 ) return 4;
|
654
|
|
655
|
return 5;
|
656
|
}
|
657
|
}
|