Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyKilominx.java @ 7b832206

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 7b832206 Leszek Koltunski
  public 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 e30c522a Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
332 29b82486 Leszek Koltunski
    {
333 e30c522a Leszek Koltunski
    int[] numLayers = getNumLayers();
334 29b82486 Leszek Koltunski
    int numVariants = getNumCubitVariants(numLayers);
335 e30c522a Leszek Koltunski
    int numL        = numLayers[0];
336 29b82486 Leszek Koltunski
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 e30c522a Leszek Koltunski
      int type = variant-1;
385 a57e6870 Leszek Koltunski
      float tmpVal= numL/(numL-1.0f);
386 29b82486 Leszek Koltunski
      float height= tmpVal*COS18;
387
      float width = tmpVal + (type/2)*tmpVal*SIN18;
388
      boolean left = (type%2)==0;
389
390
      double X = height*SIN_HALFD;
391
      double Y = height*SIN18/COS18;
392
      double Z = height*COS_HALFD;
393
394
      double[][] vertices = new double[][]
395
        {
396
            { 0.0, 0.0   , 0.0 },
397
            {   X,   Y   ,  -Z },
398
            { 0.0, 2*Y   ,-2*Z },
399
            {  -X,   Y   ,  -Z },
400
            { 0.0, -width, 0.0 },
401
            {   X, -width,  -Z },
402
            { 0.0, -width,-2*Z },
403
            {  -X, -width,  -Z },
404
        };
405
406
      int[][] vertIndexes = new int[][]
407
        {
408
            {4,5,1,0},
409
            {7,4,0,3},
410
            {7,6,2,3},
411
            {6,5,1,2},
412
            {0,1,2,3},
413
            {4,5,6,7}
414
        };
415
416
      if( !left )
417
        {
418
        int tmp, len = vertices.length;
419
        for(int i=0; i<len; i++) vertices[i][1] = -vertices[i][1];
420
421
        len = vertIndexes.length;
422
        for(int i=0; i<len; i++)
423
          {
424
          tmp = vertIndexes[i][0];
425
          vertIndexes[i][0] = vertIndexes[i][3];
426
          vertIndexes[i][3] = tmp;
427
          tmp = vertIndexes[i][1];
428
          vertIndexes[i][1] = vertIndexes[i][2];
429
          vertIndexes[i][2] = tmp;
430
          }
431
        }
432
433 a57e6870 Leszek Koltunski
      int numBands0 = numL<=5 ? 4 : 3;
434
      int numBands1 = numL<=5 ? 3 : 2;
435 29b82486 Leszek Koltunski
436 a57e6870 Leszek Koltunski
      float[][] bands = new float[][]
437 29b82486 Leszek Koltunski
        {
438
         {0.04f,34,0.2f,0.2f,numBands0,1,1},
439
         {0.00f, 0,0.0f,0.0f,numBands1,0,0}
440
        };
441
442
      int[] bandIndices   = new int[] { 0,0,1,1,1,1};
443
      float[][] corners   = new float[][] { {0.04f,0.10f} };
444
      int[] cornerIndices = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 };
445
      float[][] centers   = new float[][] { {0.0f, -width/2, (float)(-2*Z)} };
446
      int[] centerIndices = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 };
447
448
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
449
      }
450
    else
451
      {
452 a57e6870 Leszek Koltunski
      float width = (1+0.5f*(numL-3)*SIN18)*numL/(numL-1);
453 29b82486 Leszek Koltunski
454
      double X = width*COS18*SIN_HALFD;
455
      double Y = width*SIN18;
456
      double Z = width*COS18*COS_HALFD;
457
      double H = width*(SIN54/COS54);
458
      double H3= H/COS_HALFD;
459
      double X3= H*SIN_HALFD;
460
      double Z3= H*COS_HALFD;
461
      double C = 1/(COS54*Math.sqrt(2-2*SIN18));
462 a57e6870 Leszek Koltunski
      int N = numL==3 ? 4 : 3;
463
      int E = numL==3 ? 1 : 0;
464 29b82486 Leszek Koltunski
465
      double[][] vertices = new double[][]
466
        {
467
            { 0.0, 0.0  ,   0.0 },
468
            {   X,   Y  ,    -Z },
469
            { 0.0,C*2*Y ,-2*C*Z },
470
            {  -X,   Y  ,    -Z },
471
            { 0.0,-width,   0.0 },
472
            {  X3,-width,   -Z3 },
473
            { 0.0,-width,   -H3 },
474
            { -X3,-width,   -Z3 }
475
        };
476
477
      int[][] vertIndexes = new int[][]
478
        {
479
            {4,5,1,0},
480
            {7,4,0,3},
481
            {0,1,2,3},
482
            {7,6,2,3},
483
            {6,5,1,2},
484
            {4,5,6,7}
485
        };
486
487
      float[][] bands = new float[][]
488
        {
489
         {0.04f,17,0.3f,0.2f,N,1,E},
490
         {0.00f,17,0.3f,0.2f,N,1,E}
491
        };
492
493
      float A = (2*SQ3/3)*SIN54;
494
      float B = 0.4f;
495
496
      int[] bandIndices   = new int[] { 0,0,0,1,1,1};
497
      float[][] corners   = new float[][] { {0.03f,0.10f} };
498
      int[] cornerIndices = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 };
499
      float[][] centers   = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
500
      int[] centerIndices = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 };
501
502
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
503
      }
504
    }
505
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507
508 7b832206 Leszek Koltunski
  public Static4D getQuat(int cubit, int[] numLayers)
509 29b82486 Leszek Koltunski
    {
510
    if( mQuats==null ) initializeQuats();
511 a57e6870 Leszek Koltunski
512
    int numL = numLayers[0];
513
    int numCubitsPerCorner = numCubitsPerCorner(numL);
514
    int numCubitsPerEdge   = numCubitsPerEdge(numL);
515 29b82486 Leszek Koltunski
516
    return mQuats[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
517
    }
518
519
///////////////////////////////////////////////////////////////////////////////////////////////////
520
521 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
522 29b82486 Leszek Koltunski
    {
523 a57e6870 Leszek Koltunski
    switch(numLayers[0])
524 61aa85e4 Leszek Koltunski
      {
525
      case 3: return 1;
526
      case 5: return 4;
527
      }
528 29b82486 Leszek Koltunski
529 61aa85e4 Leszek Koltunski
    return 1;
530 29b82486 Leszek Koltunski
    }
531
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533
534 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
535 29b82486 Leszek Koltunski
    {
536 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
537
    int numCubitsPerCorner = numCubitsPerCorner(numL);
538 29b82486 Leszek Koltunski
539
    if( cubit<NUM_CORNERS*numCubitsPerCorner ) return 0;
540
541 a57e6870 Leszek Koltunski
    int numCubitsPerEdge = numCubitsPerEdge(numL);
542 29b82486 Leszek Koltunski
543
    if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
544
      {
545
      int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
546
      return type+1;
547
      }
548
549 61aa85e4 Leszek Koltunski
    return getNumCubitVariants(numLayers)-1;
550 29b82486 Leszek Koltunski
    }
551
552
///////////////////////////////////////////////////////////////////////////////////////////////////
553
554
  int getCornerColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner)
555
    {
556
    if( mCornerFaceMap==null ) initializeCornerFaceMap();
557
    if( cubitface<0 || cubitface>2 ) return NUM_TEXTURES;
558
559
    int part  = cubit % numCubitsPerCorner;
560
    int corner= cubit / numCubitsPerCorner;
561
562
    if( part==0 )
563
      {
564
      return mCornerFaceMap[corner][cubitface];
565
      }
566
    else
567
      {
568
      int N = (numCubitsPerCorner-1)/3;
569
      int block = (part-1) % N;
570
      int index = (part-1) / N;
571
572
      if( block< (numLayers-3)/2 )
573
        {
574
        switch(index)
575
          {
576
          case 0: return cubitface==1 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
577
          case 1: return cubitface==0 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
578
          case 2: return cubitface==2 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
579
          }
580
        }
581
      else
582
        {
583
        switch(index)
584
          {
585
          case 0: return cubitface==0 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
586
          case 1: return cubitface==2 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
587
          case 2: return cubitface==1 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
588
          }
589
        }
590
      }
591
592
    return NUM_TEXTURES;
593
    }
594
595
///////////////////////////////////////////////////////////////////////////////////////////////////
596
597
  int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
598
    {
599
    if( cubitface<0 || cubitface>1 ) return NUM_TEXTURES;
600
601
    int part    = edge % numCubitsPerEdge;
602
    int variant = edge / numCubitsPerEdge;
603
    if( mEdgeMap==null ) initializeEdgeMap();
604
605
    part /=2;
606
607
    return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] + ((part+3)/2)*NUM_FACE_COLORS : NUM_TEXTURES;
608
    }
609
610
///////////////////////////////////////////////////////////////////////////////////////////////////
611
612
  int getCenterColor(int center, int cubitface, int numLayers)
613
    {
614
    if( mCenterFaceMap==null ) initializeCenterFaceMap();
615
    if( mCornerFaceMap==null ) initializeCornerFaceMap();
616
617
    if( numLayers==3 )
618
      {
619
      return cubitface>=0 && cubitface<3 ? mCornerFaceMap[center][cubitface] : NUM_TEXTURES;
620
      }
621
622
    return cubitface==mCenterFaceMap[center] ? center/5 + NUM_FACE_COLORS*(numLayers-1)/2 : NUM_TEXTURES;
623
    }
624
625
///////////////////////////////////////////////////////////////////////////////////////////////////
626
627 a57e6870 Leszek Koltunski
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
628 29b82486 Leszek Koltunski
    {
629 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
630
    int numCubitsPerCorner = numCubitsPerCorner(numL);
631
    int numCubitsPerEdge   = numCubitsPerEdge(numL);
632 29b82486 Leszek Koltunski
633
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
634
      {
635 a57e6870 Leszek Koltunski
      return getCornerColor(cubit,cubitface,numL,numCubitsPerCorner);
636 29b82486 Leszek Koltunski
      }
637
    else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
638
      {
639
      int edge = cubit - NUM_CORNERS*numCubitsPerCorner;
640
      return getEdgeColor(edge,cubitface,numCubitsPerEdge);
641
      }
642
    else
643
      {
644
      int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge;
645 a57e6870 Leszek Koltunski
      return getCenterColor( center, cubitface, numL);
646 29b82486 Leszek Koltunski
      }
647
    }
648
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650
651 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
652 29b82486 Leszek Koltunski
    {
653
    if( mStickers==null )
654
      {
655
      float[][] STICKERS = new float[][]
656
        {
657
          { -0.36616942f, -0.36327124f, 0.5f, -0.36327124f, 0.23233888f, 0.4605048f, -0.36616942f, 0.26603764f },
658
          { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
659
          { -0.3249197f, -0.39442718f, 0.3249197f, -0.39442718f, 0.3249197f, 0.5f, -0.3249197f, 0.2888544f }
660
        };
661
662
      float CENTER_CORR = 0.87f;
663
      float C = 1.14f; // make the 'center' sticker artificially larger, so that we paint over the area in the center of the face.
664
665
      STICKERS[0][0] *= C;
666
      STICKERS[0][1] *= C;
667
      STICKERS[0][2] *= C;
668
      STICKERS[0][3] *= C;
669
      STICKERS[0][4] *= C;
670
      STICKERS[0][5] *= C;
671
      STICKERS[0][6] *= C;
672
      STICKERS[0][7] *= C;
673
674
      STICKERS[0][2] *= CENTER_CORR;
675
      STICKERS[0][3] *= CENTER_CORR;
676
677
      mStickers = new ObjectSticker[STICKERS.length];
678
679
      float R = 0.10f;
680
      final float[][] radii = { {R,R,R,R},{R,R,R,R},{R,R,R,R} };
681 8592461c Leszek Koltunski
      float[] strokes = { 0.20f, 0.11f, 0.10f };
682
683
      if( ObjectControl.isInIconMode() )
684
        {
685 a57e6870 Leszek Koltunski
        int[] numLayers = getNumLayers();
686
        float mult = numLayers[0]==3 ? 1.0f : 1.5f;
687 8592461c Leszek Koltunski
688
        strokes[0]*=mult;
689
        strokes[1]*=mult;
690
        strokes[2]*=mult;
691
        }
692 29b82486 Leszek Koltunski
693
      for(int s=0; s<STICKERS.length; s++)
694
        {
695
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
696
        }
697
      }
698
699 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
700 29b82486 Leszek Koltunski
    }
701
702
///////////////////////////////////////////////////////////////////////////////////////////////////
703
704 1bb09f88 Leszek Koltunski
  protected int getStickerIndex(int face)
705 29b82486 Leszek Koltunski
    {
706
    int variant = face/NUM_FACE_COLORS;
707 a57e6870 Leszek Koltunski
    int[] numLayers = getNumLayers();
708
    int numL = numLayers[0];
709 29b82486 Leszek Koltunski
710 a57e6870 Leszek Koltunski
    if( variant == (numL-1)/2 || numL==3 ) return 0;
711 29b82486 Leszek Koltunski
    if( variant==0 ) return 1;
712
713
    return 2;
714
    }
715
716 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
717
718 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
719 61aa85e4 Leszek Koltunski
    {
720 a57e6870 Leszek Koltunski
    switch(numLayers[0])
721 61aa85e4 Leszek Koltunski
      {
722 8005e762 Leszek Koltunski
      case 3: return ObjectType.KILO_3;
723
      case 5: return ObjectType.KILO_5;
724 61aa85e4 Leszek Koltunski
      }
725
726 8005e762 Leszek Koltunski
    return ObjectType.KILO_3;
727 61aa85e4 Leszek Koltunski
    }
728
729 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
730
731 a57e6870 Leszek Koltunski
  public int getObjectName(int[] numLayers)
732 29b82486 Leszek Koltunski
    {
733 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
734
735
    if( numL==3 ) return R.string.minx2;
736
    if( numL==5 ) return R.string.minx4;
737 29b82486 Leszek Koltunski
738
    return 0;
739
    }
740
741
///////////////////////////////////////////////////////////////////////////////////////////////////
742
743 a57e6870 Leszek Koltunski
  public int getInventor(int[] numLayers)
744 29b82486 Leszek Koltunski
    {
745 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
746
747
    if( numL==3 ) return R.string.minx2_inventor;
748
    if( numL==5 ) return R.string.minx4_inventor;
749 29b82486 Leszek Koltunski
750
    return 0;
751
    }
752
753 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
754
755
  public int getYearOfInvention(int[] numLayers)
756
    {
757
    switch(numLayers[0])
758
      {
759
      case 3: return 2008;
760
      case 5: return 2010;
761
      }
762
    return 2008;
763
    }
764
765 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
766
767 a57e6870 Leszek Koltunski
  public int getComplexity(int[] numLayers)
768 29b82486 Leszek Koltunski
    {
769 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
770
771
    if( numL==3 ) return 5;
772
    if( numL==5 ) return 8;
773
774
    return 8;
775 29b82486 Leszek Koltunski
    }
776
}