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