Project

General

Profile

Download (23.2 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyKilominx.java @ aec5cc91

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