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 TwistyKilominx extends TwistyMinx
|
36
|
{
|
37
|
private int[] mCenterFaceMap;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
TwistyKilominx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
42
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
43
|
{
|
44
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.KILO, res, scrWidth);
|
45
|
}
|
46
|
|
47
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48
|
|
49
|
void initializeCenterFaceMap()
|
50
|
{
|
51
|
mCenterFaceMap = new int[]
|
52
|
{
|
53
|
0,0,0,0,1,
|
54
|
1,0,1,1,0,
|
55
|
2,0,1,1,0,
|
56
|
2,2,1,0,2,
|
57
|
2,1,0,0,1,
|
58
|
1,2,0,1,0,
|
59
|
0,1,0,1,1,
|
60
|
0,1,0,2,0,
|
61
|
2,1,2,2,2,
|
62
|
1,0,2,1,2,
|
63
|
2,1,0,1,2,
|
64
|
2,2,2,2,2
|
65
|
};
|
66
|
}
|
67
|
|
68
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69
|
|
70
|
private int numCubitsPerCorner(int numLayers)
|
71
|
{
|
72
|
return 3*((numLayers-3)/2)*((numLayers-5)/2) + (numLayers<5 ? 0:1);
|
73
|
}
|
74
|
|
75
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76
|
|
77
|
private int numCubitsPerEdge(int numLayers)
|
78
|
{
|
79
|
return numLayers<5 ? 0 : 2*(numLayers-4);
|
80
|
}
|
81
|
|
82
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83
|
|
84
|
int getNumStickerTypes(int numLayers)
|
85
|
{
|
86
|
return numLayers<5 ? 1 : numLayers/2 + 1;
|
87
|
}
|
88
|
|
89
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90
|
|
91
|
float getScreenRatio()
|
92
|
{
|
93
|
return 1.00f;
|
94
|
}
|
95
|
|
96
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97
|
|
98
|
float[][] getCuts(int numLayers)
|
99
|
{
|
100
|
float[][] cuts = new float[6][numLayers-1];
|
101
|
float D = numLayers*MovementMinx.DIST3D;
|
102
|
float E = 2*SIN54;
|
103
|
float X = 2*D*E/(1+2*E); // height of the 'upper' part of a dodecahedron, i.e. put it on a table,
|
104
|
// its height is then D*2*DIST3D, it has one 'lower' part of height X, one
|
105
|
// 'middle' part of height Y and one upper part of height X again.
|
106
|
// It's edge length = numLayers/3.0f.
|
107
|
int num = (numLayers-1)/2;
|
108
|
float G = X*0.5f/num; // height of one Layer
|
109
|
|
110
|
for(int i=0; i<num; i++)
|
111
|
{
|
112
|
float cut = -D + (i+0.5f)*G;
|
113
|
int j = 2*num-1-i;
|
114
|
cuts[0][i] = +cut;
|
115
|
cuts[0][j] = -cut;
|
116
|
cuts[1][i] = +cut;
|
117
|
cuts[1][j] = -cut;
|
118
|
cuts[2][i] = +cut;
|
119
|
cuts[2][j] = -cut;
|
120
|
cuts[3][i] = +cut;
|
121
|
cuts[3][j] = -cut;
|
122
|
cuts[4][i] = +cut;
|
123
|
cuts[4][j] = -cut;
|
124
|
cuts[5][i] = +cut;
|
125
|
cuts[5][j] = -cut;
|
126
|
}
|
127
|
|
128
|
return cuts;
|
129
|
}
|
130
|
|
131
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132
|
// Fill out mCurrCorner{X,Y,Z} by applying appropriate Quat to mBasicCorner{X,Y,Z}
|
133
|
// Appropriate one: QUATS[QUAT_INDICES[corner]].
|
134
|
|
135
|
private void computeBasicCornerVectors(int corner)
|
136
|
{
|
137
|
if( mQuatCornerIndices==null ) initializeQuatIndices();
|
138
|
if( mQuats==null ) initializeQuats();
|
139
|
if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
|
140
|
|
141
|
Static4D quat = mQuats[mQuatCornerIndices[corner]];
|
142
|
|
143
|
mCurrCornerV[0] = QuatHelper.rotateVectorByQuat(mBasicCornerV[0],quat);
|
144
|
mCurrCornerV[1] = QuatHelper.rotateVectorByQuat(mBasicCornerV[1],quat);
|
145
|
mCurrCornerV[2] = QuatHelper.rotateVectorByQuat(mBasicCornerV[2],quat);
|
146
|
}
|
147
|
|
148
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
149
|
|
150
|
private float[] computeCorner(int numCubitsPerCorner, int numLayers, int corner, int part)
|
151
|
{
|
152
|
if( mCorners==null ) initializeCorners();
|
153
|
if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
|
154
|
|
155
|
float D = numLayers/3.0f;
|
156
|
float[] corn = mCorners[corner];
|
157
|
|
158
|
if( part==0 )
|
159
|
{
|
160
|
return new float[] { corn[0]*D, corn[1]*D, corn[2]*D };
|
161
|
}
|
162
|
else
|
163
|
{
|
164
|
float E = D/(0.5f*(numLayers-1)); // ?? maybe 0.5*
|
165
|
int N = (numCubitsPerCorner-1)/3;
|
166
|
int block = (part-1) % N;
|
167
|
int index = (part-1) / N;
|
168
|
Static4D pri = mCurrCornerV[index];
|
169
|
Static4D sec = mCurrCornerV[(index+2)%3];
|
170
|
|
171
|
int layers= (numLayers-5)/2;
|
172
|
int multP = (block % layers) + 1;
|
173
|
int multS = (block / layers);
|
174
|
|
175
|
return new float[] {
|
176
|
corn[0]*D + (pri.get0()*multP + sec.get0()*multS)*E,
|
177
|
corn[1]*D + (pri.get1()*multP + sec.get1()*multS)*E,
|
178
|
corn[2]*D + (pri.get2()*multP + sec.get2()*multS)*E
|
179
|
};
|
180
|
}
|
181
|
}
|
182
|
|
183
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
184
|
|
185
|
private float[] computeCenter(int numLayers, int center, int part)
|
186
|
{
|
187
|
if( mCenterCoords==null ) initializeCenterCoords();
|
188
|
if( mCorners ==null ) initializeCorners();
|
189
|
if( mCenterMap ==null ) initializeCenterMap();
|
190
|
|
191
|
int corner = mCenterMap[center][part];
|
192
|
float[] cent = mCenterCoords[center];
|
193
|
float[] corn = mCorners[corner];
|
194
|
float D = numLayers/3.0f;
|
195
|
float F = 1.0f - (2.0f*numLayers-6.0f)/(numLayers-1)*COS54*COS54;
|
196
|
|
197
|
return new float[]
|
198
|
{
|
199
|
D * ( cent[0] + (corn[0]-cent[0])*F),
|
200
|
D * ( cent[1] + (corn[1]-cent[1])*F),
|
201
|
D * ( cent[2] + (corn[2]-cent[2])*F)
|
202
|
};
|
203
|
}
|
204
|
|
205
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
206
|
|
207
|
private int computeEdgeType(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
208
|
{
|
209
|
int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
|
210
|
return part - 2*(part/4);
|
211
|
}
|
212
|
|
213
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
214
|
|
215
|
private float[] computeEdge(int numLayers, int edge, int part)
|
216
|
{
|
217
|
if( mCenterCoords==null ) initializeCenterCoords();
|
218
|
if( mCorners==null ) initializeCorners();
|
219
|
if( mEdgeMap==null ) initializeEdgeMap();
|
220
|
|
221
|
float D = numLayers/3.0f;
|
222
|
float[] c1 = mCorners[ mEdgeMap[edge][0] ];
|
223
|
float[] c2 = mCorners[ mEdgeMap[edge][1] ];
|
224
|
|
225
|
int leftRight = 2*(part%2) -1;
|
226
|
part /= 2;
|
227
|
|
228
|
if( part==0 )
|
229
|
{
|
230
|
float T = 0.5f + leftRight/(numLayers-1.0f);
|
231
|
float x = D * (T*c1[0]+(1.0f-T)*c2[0]);
|
232
|
float y = D * (T*c1[1]+(1.0f-T)*c2[1]);
|
233
|
float z = D * (T*c1[2]+(1.0f-T)*c2[2]);
|
234
|
|
235
|
return new float[] { x, y, z };
|
236
|
}
|
237
|
else
|
238
|
{
|
239
|
int mult = (part+1)/2;
|
240
|
int dir = (part+1)%2;
|
241
|
float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ];
|
242
|
float x = 0.5f * D * (c1[0]+c2[0]);
|
243
|
float y = 0.5f * D * (c1[1]+c2[1]);
|
244
|
float z = 0.5f * D * (c1[2]+c2[2]);
|
245
|
|
246
|
float vX = D*center[0] - x;
|
247
|
float vY = D*center[1] - y;
|
248
|
float vZ = D*center[2] - z;
|
249
|
|
250
|
float T = 0.5f + leftRight*(mult*SIN18 + 1.0f)/(numLayers-1);
|
251
|
|
252
|
x = D * (T*c1[0]+(1.0f-T)*c2[0]);
|
253
|
y = D * (T*c1[1]+(1.0f-T)*c2[1]);
|
254
|
z = D * (T*c1[2]+(1.0f-T)*c2[2]);
|
255
|
|
256
|
float H = mult*D*COS18/(numLayers-1);
|
257
|
H /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
|
258
|
|
259
|
return new float[] { x + H*vX, y + H*vY, z + H*vZ };
|
260
|
}
|
261
|
}
|
262
|
|
263
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
264
|
|
265
|
float[][] getCubitPositions(int numLayers)
|
266
|
{
|
267
|
if( mCorners==null ) initializeCorners();
|
268
|
if( numLayers<5 ) return mCorners;
|
269
|
|
270
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
271
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
272
|
int numCubitsPerCenter = 5;
|
273
|
int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge + NUM_CENTERS*numCubitsPerCenter;
|
274
|
int index=0;
|
275
|
|
276
|
final float[][] CENTERS = new float[numCubits][];
|
277
|
|
278
|
for(int corner=0; corner<NUM_CORNERS; corner++)
|
279
|
{
|
280
|
computeBasicCornerVectors(corner);
|
281
|
|
282
|
for(int part=0; part<numCubitsPerCorner; part++, index++)
|
283
|
{
|
284
|
CENTERS[index] = computeCorner(numCubitsPerCorner,numLayers,corner,part);
|
285
|
}
|
286
|
}
|
287
|
|
288
|
for(int edge=0; edge<NUM_EDGES; edge++)
|
289
|
{
|
290
|
for(int part=0; part<numCubitsPerEdge; part++, index++)
|
291
|
{
|
292
|
CENTERS[index] = computeEdge(numLayers, edge, part );
|
293
|
}
|
294
|
}
|
295
|
|
296
|
for(int center=0; center<NUM_CENTERS; center++)
|
297
|
{
|
298
|
for(int part=0; part<numCubitsPerCenter; part++, index++)
|
299
|
{
|
300
|
CENTERS[index] = computeCenter(numLayers,center, part);
|
301
|
}
|
302
|
}
|
303
|
|
304
|
return CENTERS;
|
305
|
}
|
306
|
|
307
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
308
|
|
309
|
private int getQuat(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
310
|
{
|
311
|
if( mQuatCornerIndices==null || mQuatEdgeIndices==null ) initializeQuatIndices();
|
312
|
if( mCenterMap==null ) initializeCenterMap();
|
313
|
|
314
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
315
|
{
|
316
|
int corner = cubit/numCubitsPerCorner;
|
317
|
return mQuatCornerIndices[corner];
|
318
|
}
|
319
|
|
320
|
if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
321
|
{
|
322
|
int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge;
|
323
|
return mQuatEdgeIndices[edge];
|
324
|
}
|
325
|
|
326
|
if( numCubitsPerCorner==0 )
|
327
|
{
|
328
|
return mQuatCornerIndices[cubit];
|
329
|
}
|
330
|
else
|
331
|
{
|
332
|
cubit -= (NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge);
|
333
|
int numCubitsPerCenter = 5;
|
334
|
int face = cubit/numCubitsPerCenter;
|
335
|
int index= cubit%numCubitsPerCenter;
|
336
|
int corner=mCenterMap[face][index];
|
337
|
|
338
|
return mQuatCornerIndices[corner];
|
339
|
}
|
340
|
}
|
341
|
|
342
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
343
|
|
344
|
ObjectShape getObjectShape(int cubit, int numLayers)
|
345
|
{
|
346
|
int variant = getCubitVariant(cubit,numLayers);
|
347
|
int numVariants = getNumCubitVariants(numLayers);
|
348
|
|
349
|
if( variant==0 )
|
350
|
{
|
351
|
float width = (numLayers/3.0f)/(numLayers-1);
|
352
|
float A = (2*SQ3/3)*SIN54;
|
353
|
float B = 0.4f;
|
354
|
double X = width*COS18*SIN_HALFD;
|
355
|
double Y = width*SIN18;
|
356
|
double Z = width*COS18*COS_HALFD;
|
357
|
|
358
|
double[][] vertices = new double[][]
|
359
|
{
|
360
|
{ 0.0, 0.0 , 0.0 },
|
361
|
{ X, Y , -Z },
|
362
|
{ 0.0, 2*Y ,-2*Z },
|
363
|
{ -X, Y , -Z },
|
364
|
{ 0.0, 0.0-width, 0.0 },
|
365
|
{ X, Y-width, -Z },
|
366
|
{ 0.0, 2*Y-width,-2*Z },
|
367
|
{ -X, Y-width, -Z },
|
368
|
};
|
369
|
|
370
|
int[][] vertIndexes = new int[][]
|
371
|
{
|
372
|
{4,5,1,0},
|
373
|
{7,4,0,3},
|
374
|
{0,1,2,3},
|
375
|
{4,5,6,7},
|
376
|
{6,5,1,2},
|
377
|
{7,6,2,3}
|
378
|
};
|
379
|
|
380
|
float[][] bands = new float[][]
|
381
|
{
|
382
|
{0.04f,34,0.3f,0.2f, 3, 1, 0},
|
383
|
{0.00f, 0,0.0f,0.0f, 2, 1, 0}
|
384
|
};
|
385
|
|
386
|
int[] bandIndices = new int[] { 0,0,0,1,1,1};
|
387
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
388
|
int[] cornerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
|
389
|
float[][] centers = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
|
390
|
int[] centerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
|
391
|
|
392
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
393
|
}
|
394
|
if( variant<numVariants-1 )
|
395
|
{
|
396
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
397
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
398
|
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
|
399
|
float tmpVal= (numLayers/3.0f)/(numLayers-1);
|
400
|
float height= tmpVal*COS18;
|
401
|
float width = tmpVal + (type/2)*tmpVal*SIN18;
|
402
|
boolean left = (type%2)==0;
|
403
|
|
404
|
double X = height*SIN_HALFD;
|
405
|
double Y = height*SIN18/COS18;
|
406
|
double Z = height*COS_HALFD;
|
407
|
|
408
|
double[][] vertices = new double[][]
|
409
|
{
|
410
|
{ 0.0, 0.0 , 0.0 },
|
411
|
{ X, Y , -Z },
|
412
|
{ 0.0, 2*Y ,-2*Z },
|
413
|
{ -X, Y , -Z },
|
414
|
{ 0.0, -width, 0.0 },
|
415
|
{ X, -width, -Z },
|
416
|
{ 0.0, -width,-2*Z },
|
417
|
{ -X, -width, -Z },
|
418
|
};
|
419
|
|
420
|
int[][] vertIndexes = new int[][]
|
421
|
{
|
422
|
{4,5,1,0},
|
423
|
{7,4,0,3},
|
424
|
{7,6,2,3},
|
425
|
{6,5,1,2},
|
426
|
{0,1,2,3},
|
427
|
{4,5,6,7}
|
428
|
};
|
429
|
|
430
|
if( !left )
|
431
|
{
|
432
|
int tmp, len = vertices.length;
|
433
|
for(int i=0; i<len; i++) vertices[i][1] = -vertices[i][1];
|
434
|
|
435
|
len = vertIndexes.length;
|
436
|
for(int i=0; i<len; i++)
|
437
|
{
|
438
|
tmp = vertIndexes[i][0];
|
439
|
vertIndexes[i][0] = vertIndexes[i][3];
|
440
|
vertIndexes[i][3] = tmp;
|
441
|
tmp = vertIndexes[i][1];
|
442
|
vertIndexes[i][1] = vertIndexes[i][2];
|
443
|
vertIndexes[i][2] = tmp;
|
444
|
}
|
445
|
}
|
446
|
|
447
|
int numBands0 = numLayers<=5 ? 4 : 3;
|
448
|
int numBands1 = numLayers<=5 ? 3 : 2;
|
449
|
|
450
|
float[][] bands = new float[][]
|
451
|
{
|
452
|
{0.04f,34,0.2f,0.2f,numBands0,1,1},
|
453
|
{0.00f, 0,0.0f,0.0f,numBands1,0,0}
|
454
|
};
|
455
|
|
456
|
int[] bandIndices = new int[] { 0,0,1,1,1,1};
|
457
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
458
|
int[] cornerIndices = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 };
|
459
|
float[][] centers = new float[][] { {0.0f, -width/2, (float)(-2*Z)} };
|
460
|
int[] centerIndices = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 };
|
461
|
|
462
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
463
|
}
|
464
|
else
|
465
|
{
|
466
|
float width = (1+0.5f*(numLayers-3)*SIN18)*(numLayers/3.0f)/(numLayers-1);
|
467
|
|
468
|
double X = width*COS18*SIN_HALFD;
|
469
|
double Y = width*SIN18;
|
470
|
double Z = width*COS18*COS_HALFD;
|
471
|
double H = width*(SIN54/COS54);
|
472
|
double H3= H/COS_HALFD;
|
473
|
double X3= H*SIN_HALFD;
|
474
|
double Z3= H*COS_HALFD;
|
475
|
double C = 1/(COS54*Math.sqrt(2-2*SIN18));
|
476
|
int N = numLayers==3 ? 4 : 3;
|
477
|
int E = numLayers==3 ? 1 : 0;
|
478
|
|
479
|
double[][] vertices = new double[][]
|
480
|
{
|
481
|
{ 0.0, 0.0 , 0.0 },
|
482
|
{ X, Y , -Z },
|
483
|
{ 0.0,C*2*Y ,-2*C*Z },
|
484
|
{ -X, Y , -Z },
|
485
|
{ 0.0,-width, 0.0 },
|
486
|
{ X3,-width, -Z3 },
|
487
|
{ 0.0,-width, -H3 },
|
488
|
{ -X3,-width, -Z3 }
|
489
|
};
|
490
|
|
491
|
int[][] vertIndexes = new int[][]
|
492
|
{
|
493
|
{4,5,1,0},
|
494
|
{7,4,0,3},
|
495
|
{0,1,2,3},
|
496
|
{7,6,2,3},
|
497
|
{6,5,1,2},
|
498
|
{4,5,6,7}
|
499
|
};
|
500
|
|
501
|
float[][] bands = new float[][]
|
502
|
{
|
503
|
{0.04f,17,0.3f,0.2f,N,1,E},
|
504
|
{0.00f,17,0.3f,0.2f,N,1,E}
|
505
|
};
|
506
|
|
507
|
float A = (2*SQ3/3)*SIN54;
|
508
|
float B = 0.4f;
|
509
|
|
510
|
int[] bandIndices = new int[] { 0,0,0,1,1,1};
|
511
|
float[][] corners = new float[][] { {0.03f,0.10f} };
|
512
|
int[] cornerIndices = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 };
|
513
|
float[][] centers = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
|
514
|
int[] centerIndices = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 };
|
515
|
|
516
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
517
|
}
|
518
|
}
|
519
|
|
520
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
521
|
|
522
|
Static4D getQuat(int cubit, int numLayers)
|
523
|
{
|
524
|
if( mQuats==null ) initializeQuats();
|
525
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
526
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
527
|
|
528
|
return mQuats[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
|
529
|
}
|
530
|
|
531
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
532
|
|
533
|
int getNumCubitVariants(int numLayers)
|
534
|
{
|
535
|
int[] sizes = ObjectList.KILO.getSizes();
|
536
|
int variants = sizes.length;
|
537
|
int highestSize = sizes[variants-1];
|
538
|
|
539
|
return highestSize-1;
|
540
|
}
|
541
|
|
542
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
543
|
|
544
|
int getCubitVariant(int cubit, int numLayers)
|
545
|
{
|
546
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
547
|
|
548
|
if( cubit<NUM_CORNERS*numCubitsPerCorner ) return 0;
|
549
|
|
550
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
551
|
|
552
|
if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
553
|
{
|
554
|
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
|
555
|
return type+1;
|
556
|
}
|
557
|
|
558
|
int[] sizes = ObjectList.KILO.getSizes();
|
559
|
int variants = sizes.length;
|
560
|
int highestSize = sizes[variants-1];
|
561
|
|
562
|
return highestSize-2;
|
563
|
}
|
564
|
|
565
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
566
|
|
567
|
int getCornerColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner)
|
568
|
{
|
569
|
if( mCornerFaceMap==null ) initializeCornerFaceMap();
|
570
|
if( cubitface<0 || cubitface>2 ) return NUM_TEXTURES;
|
571
|
|
572
|
int part = cubit % numCubitsPerCorner;
|
573
|
int corner= cubit / numCubitsPerCorner;
|
574
|
|
575
|
if( part==0 )
|
576
|
{
|
577
|
return mCornerFaceMap[corner][cubitface];
|
578
|
}
|
579
|
else
|
580
|
{
|
581
|
int N = (numCubitsPerCorner-1)/3;
|
582
|
int block = (part-1) % N;
|
583
|
int index = (part-1) / N;
|
584
|
|
585
|
if( block< (numLayers-3)/2 )
|
586
|
{
|
587
|
switch(index)
|
588
|
{
|
589
|
case 0: return cubitface==1 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
590
|
case 1: return cubitface==0 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
591
|
case 2: return cubitface==2 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
592
|
}
|
593
|
}
|
594
|
else
|
595
|
{
|
596
|
switch(index)
|
597
|
{
|
598
|
case 0: return cubitface==0 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
599
|
case 1: return cubitface==2 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
600
|
case 2: return cubitface==1 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
601
|
}
|
602
|
}
|
603
|
}
|
604
|
|
605
|
return NUM_TEXTURES;
|
606
|
}
|
607
|
|
608
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
609
|
|
610
|
int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
|
611
|
{
|
612
|
if( cubitface<0 || cubitface>1 ) return NUM_TEXTURES;
|
613
|
|
614
|
int part = edge % numCubitsPerEdge;
|
615
|
int variant = edge / numCubitsPerEdge;
|
616
|
if( mEdgeMap==null ) initializeEdgeMap();
|
617
|
|
618
|
part /=2;
|
619
|
|
620
|
return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] + ((part+3)/2)*NUM_FACES : NUM_TEXTURES;
|
621
|
}
|
622
|
|
623
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
624
|
|
625
|
int getCenterColor(int center, int cubitface, int numLayers)
|
626
|
{
|
627
|
if( mCenterFaceMap==null ) initializeCenterFaceMap();
|
628
|
if( mCornerFaceMap==null ) initializeCornerFaceMap();
|
629
|
|
630
|
if( numLayers==3 )
|
631
|
{
|
632
|
return cubitface>=0 && cubitface<3 ? mCornerFaceMap[center][cubitface] : NUM_TEXTURES;
|
633
|
}
|
634
|
|
635
|
return cubitface==mCenterFaceMap[center] ? center/5 + NUM_FACES*(numLayers-1)/2 : NUM_TEXTURES;
|
636
|
}
|
637
|
|
638
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
639
|
|
640
|
int getFaceColor(int cubit, int cubitface, int numLayers)
|
641
|
{
|
642
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
643
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
644
|
|
645
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
646
|
{
|
647
|
return getCornerColor(cubit,cubitface,numLayers,numCubitsPerCorner);
|
648
|
}
|
649
|
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
650
|
{
|
651
|
int edge = cubit - NUM_CORNERS*numCubitsPerCorner;
|
652
|
return getEdgeColor(edge,cubitface,numCubitsPerEdge);
|
653
|
}
|
654
|
else
|
655
|
{
|
656
|
int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge;
|
657
|
return getCenterColor( center, cubitface, numLayers);
|
658
|
}
|
659
|
}
|
660
|
|
661
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
662
|
|
663
|
int getColor(int face)
|
664
|
{
|
665
|
return FACE_COLORS[face];
|
666
|
}
|
667
|
|
668
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
669
|
|
670
|
ObjectSticker retSticker(int face)
|
671
|
{
|
672
|
if( mStickers==null )
|
673
|
{
|
674
|
float[][] STICKERS = new float[][]
|
675
|
{
|
676
|
{ -0.36616942f, -0.36327124f, 0.5f, -0.36327124f, 0.23233888f, 0.4605048f, -0.36616942f, 0.26603764f },
|
677
|
{ -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
|
678
|
{ -0.3249197f, -0.39442718f, 0.3249197f, -0.39442718f, 0.3249197f, 0.5f, -0.3249197f, 0.2888544f }
|
679
|
};
|
680
|
|
681
|
float CENTER_CORR = 0.87f;
|
682
|
float C = 1.14f; // make the 'center' sticker artificially larger, so that we paint over the area in the center of the face.
|
683
|
|
684
|
STICKERS[0][0] *= C;
|
685
|
STICKERS[0][1] *= C;
|
686
|
STICKERS[0][2] *= C;
|
687
|
STICKERS[0][3] *= C;
|
688
|
STICKERS[0][4] *= C;
|
689
|
STICKERS[0][5] *= C;
|
690
|
STICKERS[0][6] *= C;
|
691
|
STICKERS[0][7] *= C;
|
692
|
|
693
|
STICKERS[0][2] *= CENTER_CORR;
|
694
|
STICKERS[0][3] *= CENTER_CORR;
|
695
|
|
696
|
mStickers = new ObjectSticker[STICKERS.length];
|
697
|
|
698
|
float R = 0.10f;
|
699
|
final float[][] radii = { {R,R,R,R},{R,R,R,R},{R,R,R,R} };
|
700
|
final float[] strokes = { 0.20f, 0.11f, 0.10f };
|
701
|
|
702
|
for(int s=0; s<STICKERS.length; s++)
|
703
|
{
|
704
|
mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
|
705
|
}
|
706
|
}
|
707
|
|
708
|
return mStickers[getStickerIndex(face)];
|
709
|
}
|
710
|
|
711
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
712
|
|
713
|
private int getStickerIndex(int face)
|
714
|
{
|
715
|
int variant = face/NUM_FACES;
|
716
|
int numLayers = getNumLayers();
|
717
|
|
718
|
if( variant == (numLayers-1)/2 || numLayers==3 ) return 0;
|
719
|
if( variant==0 ) return 1;
|
720
|
|
721
|
return 2;
|
722
|
}
|
723
|
|
724
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
725
|
|
726
|
public int getObjectName(int numLayers)
|
727
|
{
|
728
|
if( numLayers==3 ) return R.string.minx2;
|
729
|
if( numLayers==5 ) return R.string.minx4;
|
730
|
|
731
|
return 0;
|
732
|
}
|
733
|
|
734
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
735
|
|
736
|
public int getInventor(int numLayers)
|
737
|
{
|
738
|
if( numLayers==3 ) return R.string.minx2_inventor;
|
739
|
if( numLayers==5 ) return R.string.minx4_inventor;
|
740
|
|
741
|
return 0;
|
742
|
}
|
743
|
|
744
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
745
|
|
746
|
public int getComplexity(int numLayers)
|
747
|
{
|
748
|
return 3;
|
749
|
}
|
750
|
}
|