Project

General

Profile

Download (23.8 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyKilominx.java @ 0f72365b

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