Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyKilominx.java @ 1bb09f88

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