Project

General

Profile

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

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

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