Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyKilominx.java @ 55fa6993

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 55fa6993 Leszek Koltunski
      case 3: return R.raw.kilo_3;
96
      case 5: return R.raw.kilo_5;
97 4e1dc313 Leszek Koltunski
      }
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 a75ae1ee Leszek Koltunski
    int color = mCornerFaceMap[corner][cubitface];
562 29b82486 Leszek Koltunski
563
    if( part==0 )
564
      {
565 43a4ccff Leszek Koltunski
      return color;
566 29b82486 Leszek Koltunski
      }
567
    else
568
      {
569
      int N = (numCubitsPerCorner-1)/3;
570
      int block = (part-1) % N;
571
      int index = (part-1) / N;
572
573
      if( block< (numLayers-3)/2 )
574
        {
575
        switch(index)
576
          {
577 43a4ccff Leszek Koltunski
          case 0: return cubitface==1 ? NUM_TEXTURES : color;
578
          case 1: return cubitface==0 ? NUM_TEXTURES : color;
579
          case 2: return cubitface==2 ? NUM_TEXTURES : color;
580 29b82486 Leszek Koltunski
          }
581
        }
582
      else
583
        {
584
        switch(index)
585
          {
586 43a4ccff Leszek Koltunski
          case 0: return cubitface==0 ? color : NUM_TEXTURES;
587
          case 1: return cubitface==2 ? color : NUM_TEXTURES;
588
          case 2: return cubitface==1 ? color : NUM_TEXTURES;
589 29b82486 Leszek Koltunski
          }
590
        }
591
      }
592
593
    return NUM_TEXTURES;
594
    }
595
596
///////////////////////////////////////////////////////////////////////////////////////////////////
597
598
  int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
599
    {
600 a75ae1ee Leszek Koltunski
    if( cubitface<0 || cubitface>1 ) return -1;
601 29b82486 Leszek Koltunski
602
    int part    = edge % numCubitsPerEdge;
603
    int variant = edge / numCubitsPerEdge;
604
    if( mEdgeMap==null ) initializeEdgeMap();
605
606 a75ae1ee Leszek Koltunski
    part /= 2;
607 29b82486 Leszek Koltunski
608 a75ae1ee Leszek Koltunski
    return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] : -1;
609 29b82486 Leszek Koltunski
    }
610
611
///////////////////////////////////////////////////////////////////////////////////////////////////
612
613
  int getCenterColor(int center, int cubitface, int numLayers)
614
    {
615
    if( mCenterFaceMap==null ) initializeCenterFaceMap();
616
    if( mCornerFaceMap==null ) initializeCornerFaceMap();
617
618
    if( numLayers==3 )
619
      {
620 a75ae1ee Leszek Koltunski
      return cubitface>=0 && cubitface<3 ? mCornerFaceMap[center][cubitface] : -1;
621 29b82486 Leszek Koltunski
      }
622
623 a75ae1ee Leszek Koltunski
    return cubitface==mCenterFaceMap[center] ? center/5 : -1;
624 29b82486 Leszek Koltunski
    }
625
626
///////////////////////////////////////////////////////////////////////////////////////////////////
627
628 a75ae1ee Leszek Koltunski
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
629 29b82486 Leszek Koltunski
    {
630 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
631
    int numCubitsPerCorner = numCubitsPerCorner(numL);
632
    int numCubitsPerEdge   = numCubitsPerEdge(numL);
633 29b82486 Leszek Koltunski
634
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
635
      {
636 a75ae1ee Leszek Koltunski
      return getCornerColor(cubit,face,numL,numCubitsPerCorner);
637 29b82486 Leszek Koltunski
      }
638
    else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
639
      {
640
      int edge = cubit - NUM_CORNERS*numCubitsPerCorner;
641 a75ae1ee Leszek Koltunski
      return getEdgeColor(edge,face,numCubitsPerEdge);
642 29b82486 Leszek Koltunski
      }
643
    else
644
      {
645
      int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge;
646 a75ae1ee Leszek Koltunski
      return getCenterColor( center, face, numL);
647
      }
648
    }
649
650
///////////////////////////////////////////////////////////////////////////////////////////////////
651
652
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
653
    {
654
    if( numLayers[0]==3 ) return 0;
655
656
    switch(variant)
657
      {
658
      case  0: return 1;
659
      case  3: return 0;
660
      default: return 2;
661 29b82486 Leszek Koltunski
      }
662
    }
663
664
///////////////////////////////////////////////////////////////////////////////////////////////////
665
666 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
667 29b82486 Leszek Koltunski
    {
668
    if( mStickers==null )
669
      {
670 43a4ccff Leszek Koltunski
      float[][] STICKERS;
671
      int[] numLayers = getNumLayers();
672
      int numL = numLayers[0];
673
674
      if( numL==3 )
675 29b82486 Leszek Koltunski
        {
676 43a4ccff Leszek Koltunski
        STICKERS = new float[][]
677
          {
678
            { -0.36616942f, -0.36327124f, 0.5f, -0.36327124f, 0.23233888f, 0.4605048f, -0.36616942f, 0.26603764f }
679
          };
680
        }
681
      else
682
        {
683
        STICKERS = new float[][]
684
          {
685
            { -0.36616942f, -0.36327124f, 0.5f, -0.36327124f, 0.23233888f, 0.4605048f, -0.36616942f, 0.26603764f },
686
            { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
687
            { -0.3249197f, -0.39442718f, 0.3249197f, -0.39442718f, 0.3249197f, 0.5f, -0.3249197f, 0.2888544f }
688
          };
689
        }
690 29b82486 Leszek Koltunski
691
      float CENTER_CORR = 0.87f;
692
      float C = 1.14f; // make the 'center' sticker artificially larger, so that we paint over the area in the center of the face.
693
694
      STICKERS[0][0] *= C;
695
      STICKERS[0][1] *= C;
696
      STICKERS[0][2] *= C;
697
      STICKERS[0][3] *= C;
698
      STICKERS[0][4] *= C;
699
      STICKERS[0][5] *= C;
700
      STICKERS[0][6] *= C;
701
      STICKERS[0][7] *= C;
702
703
      STICKERS[0][2] *= CENTER_CORR;
704
      STICKERS[0][3] *= CENTER_CORR;
705
706
      mStickers = new ObjectSticker[STICKERS.length];
707
708
      float R = 0.10f;
709 43a4ccff Leszek Koltunski
      float S = numL==3 ? 0.20f : 0.15f;
710 29b82486 Leszek Koltunski
      final float[][] radii = { {R,R,R,R},{R,R,R,R},{R,R,R,R} };
711 43a4ccff Leszek Koltunski
      float[] strokes = { S, 0.11f, 0.10f };
712 8592461c Leszek Koltunski
713
      if( ObjectControl.isInIconMode() )
714
        {
715 43a4ccff Leszek Koltunski
        float mult = numL==3 ? 1.0f : 1.5f;
716 8592461c Leszek Koltunski
717
        strokes[0]*=mult;
718
        strokes[1]*=mult;
719
        strokes[2]*=mult;
720
        }
721 29b82486 Leszek Koltunski
722
      for(int s=0; s<STICKERS.length; s++)
723
        {
724
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
725
        }
726
      }
727
728 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
729 29b82486 Leszek Koltunski
    }
730
731 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
732
733 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
734 61aa85e4 Leszek Koltunski
    {
735 a57e6870 Leszek Koltunski
    switch(numLayers[0])
736 61aa85e4 Leszek Koltunski
      {
737 8005e762 Leszek Koltunski
      case 3: return ObjectType.KILO_3;
738
      case 5: return ObjectType.KILO_5;
739 61aa85e4 Leszek Koltunski
      }
740
741 8005e762 Leszek Koltunski
    return ObjectType.KILO_3;
742 61aa85e4 Leszek Koltunski
    }
743
744 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
745
746 a57e6870 Leszek Koltunski
  public int getObjectName(int[] numLayers)
747 29b82486 Leszek Koltunski
    {
748 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
749
750
    if( numL==3 ) return R.string.minx2;
751
    if( numL==5 ) return R.string.minx4;
752 29b82486 Leszek Koltunski
753
    return 0;
754
    }
755
756
///////////////////////////////////////////////////////////////////////////////////////////////////
757
758 a57e6870 Leszek Koltunski
  public int getInventor(int[] numLayers)
759 29b82486 Leszek Koltunski
    {
760 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
761
762
    if( numL==3 ) return R.string.minx2_inventor;
763
    if( numL==5 ) return R.string.minx4_inventor;
764 29b82486 Leszek Koltunski
765
    return 0;
766
    }
767
768 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
769
770
  public int getYearOfInvention(int[] numLayers)
771
    {
772
    switch(numLayers[0])
773
      {
774
      case 3: return 2008;
775
      case 5: return 2010;
776
      }
777
    return 2008;
778
    }
779
780 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
781
782 a57e6870 Leszek Koltunski
  public int getComplexity(int[] numLayers)
783 29b82486 Leszek Koltunski
    {
784 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
785
786
    if( numL==3 ) return 5;
787
    if( numL==5 ) return 8;
788
789
    return 8;
790 29b82486 Leszek Koltunski
    }
791
}