Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyMegaminx.java @ ef018c1b

1 a64e07d0 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 8e4a3670 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 a64e07d0 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
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35
public class TwistyMegaminx extends TwistyMinx
36
{
37 e4bf4d02 Leszek Koltunski
  static final float MEGA_D = 0.04f;
38 af0de0af Leszek Koltunski
  private int[] mQuatCenterIndices;
39 a64e07d0 Leszek Koltunski
40 af0de0af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
41 e4bf4d02 Leszek Koltunski
42 af0de0af Leszek Koltunski
  TwistyMegaminx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
43
                 DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
44 9c06394a Leszek Koltunski
    {
45 af0de0af Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.MEGA, res, scrWidth);
46 9c06394a Leszek Koltunski
    }
47
48 a64e07d0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50 af0de0af Leszek Koltunski
  private void initializeCenterIndices()
51 a64e07d0 Leszek Koltunski
    {
52 af0de0af Leszek Koltunski
    mQuatCenterIndices = new int[] { 16, 18, 22,  1, 20, 13, 14, 15,  0, 12,  2,  3 };
53 a64e07d0 Leszek Koltunski
    }
54
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
57
  private int numCubitsPerCorner(int numLayers)
58
    {
59
    return 3*((numLayers-1)/2)*((numLayers-3)/2) + 1;
60
    }
61
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
64
  private int numCubitsPerEdge(int numLayers)
65
    {
66
    return numLayers-2;
67
    }
68
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
71
  int getNumStickerTypes(int numLayers)
72
    {
73 e4bf4d02 Leszek Koltunski
    return (numLayers+3)/2;
74 a64e07d0 Leszek Koltunski
    }
75
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
78 e6734aa9 Leszek Koltunski
  float[][] getCuts(int numLayers)
79 a64e07d0 Leszek Koltunski
    {
80 ef018c1b Leszek Koltunski
    return genericGetCuts(numLayers,0.5f-MEGA_D);
81 a64e07d0 Leszek Koltunski
    }
82
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84
85 e6cf7283 Leszek Koltunski
  private float[] computeCenter(int center, int numLayers)
86 a64e07d0 Leszek Koltunski
    {
87 af0de0af Leszek Koltunski
    if( mCenterCoords==null ) initializeCenterCoords();
88 d38f1397 Leszek Koltunski
    float[] coords = mCenterCoords[center];
89 387b6326 Leszek Koltunski
    float A = 0.33f*numLayers;
90 e4bf4d02 Leszek Koltunski
91 e6cf7283 Leszek Koltunski
    return new float[] { A*coords[0], A*coords[1], A*coords[2] };
92 a64e07d0 Leszek Koltunski
    }
93
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95 d38f1397 Leszek Koltunski
// Fill out mCurrCorner{X,Y,Z} by applying appropriate Quat to mBasicCorner{X,Y,Z}
96 a64e07d0 Leszek Koltunski
// Appropriate one: QUATS[QUAT_INDICES[corner]].
97
98 d38f1397 Leszek Koltunski
  private void computeBasicCornerVectors(int corner)
99 a64e07d0 Leszek Koltunski
    {
100 af0de0af Leszek Koltunski
    if( mQuatCornerIndices==null ) initializeQuatIndices();
101
    if( mQuats==null ) initializeQuats();
102
    if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
103
104
    Static4D quat = mQuats[mQuatCornerIndices[corner]];
105 a64e07d0 Leszek Koltunski
106 b9d4aa3b Leszek Koltunski
    mCurrCornerV[0] = QuatHelper.rotateVectorByQuat(mBasicCornerV[0],quat);
107
    mCurrCornerV[1] = QuatHelper.rotateVectorByQuat(mBasicCornerV[1],quat);
108
    mCurrCornerV[2] = QuatHelper.rotateVectorByQuat(mBasicCornerV[2],quat);
109 a64e07d0 Leszek Koltunski
    }
110
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112
113 e6cf7283 Leszek Koltunski
  private float[] computeCorner(int numCubitsPerCorner, int numLayers, int corner, int part)
114 a64e07d0 Leszek Koltunski
    {
115 af0de0af Leszek Koltunski
    if( mCorners==null ) initializeCorners();
116
    if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
117
118 a64e07d0 Leszek Koltunski
    float D = numLayers/3.0f;
119 af0de0af Leszek Koltunski
    float[] corn = mCorners[corner];
120 a64e07d0 Leszek Koltunski
121
    if( part==0 )
122
      {
123 e6cf7283 Leszek Koltunski
      return new float[] { corn[0]*D, corn[1]*D, corn[2]*D };
124 a64e07d0 Leszek Koltunski
      }
125
    else
126
      {
127 ead91342 Leszek Koltunski
      float E = 2.0f*D*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
128 a64e07d0 Leszek Koltunski
      int N = (numCubitsPerCorner-1)/3;
129 6e7146df Leszek Koltunski
      int block = (part-1) % N;
130
      int index = (part-1) / N;
131 d38f1397 Leszek Koltunski
      Static4D pri = mCurrCornerV[index];
132
      Static4D sec = mCurrCornerV[(index+2)%3];
133 a64e07d0 Leszek Koltunski
134 7764a67a Leszek Koltunski
      int layers= (numLayers-3)/2;
135 ead91342 Leszek Koltunski
      int multP = (block % layers) + 1;
136
      int multS = (block / layers);
137 a64e07d0 Leszek Koltunski
138 e6cf7283 Leszek Koltunski
      return new float[] {
139
                          corn[0]*D + (pri.get0()*multP + sec.get0()*multS)*E,
140
                          corn[1]*D + (pri.get1()*multP + sec.get1()*multS)*E,
141
                          corn[2]*D + (pri.get2()*multP + sec.get2()*multS)*E
142
                         };
143 a64e07d0 Leszek Koltunski
      }
144
    }
145
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147
148 d38f1397 Leszek Koltunski
  private int computeEdgeType(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
149 a64e07d0 Leszek Koltunski
    {
150 d38f1397 Leszek Koltunski
    int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
151
    return (part+1)/2;
152
    }
153 a64e07d0 Leszek Koltunski
154 d38f1397 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
155
156 e6cf7283 Leszek Koltunski
  private float[] computeEdge(int numLayers, int edge, int part)
157 d38f1397 Leszek Koltunski
    {
158 af0de0af Leszek Koltunski
    if( mCenterCoords==null ) initializeCenterCoords();
159
    if( mCorners==null ) initializeCorners();
160
    if( mEdgeMap==null ) initializeEdgeMap();
161 3d8237cc Leszek Koltunski
162 af0de0af Leszek Koltunski
    float D = numLayers/3.0f;
163
    float[] c1 = mCorners[ mEdgeMap[edge][0] ];
164
    float[] c2 = mCorners[ mEdgeMap[edge][1] ];
165 ead91342 Leszek Koltunski
    float x = D * (c1[0]+c2[0]) / 2;
166
    float y = D * (c1[1]+c2[1]) / 2;
167
    float z = D * (c1[2]+c2[2]) / 2;
168 d38f1397 Leszek Koltunski
169
    if( part==0 )
170
      {
171 e6cf7283 Leszek Koltunski
      return new float[] { x, y, z };
172 d38f1397 Leszek Koltunski
      }
173
    else
174
      {
175
      int mult = (part+1)/2;
176
      int dir  = (part+1)%2;
177
      float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ];
178
179 ead91342 Leszek Koltunski
      float vX = D*center[0] - x;
180
      float vY = D*center[1] - y;
181
      float vZ = D*center[2] - z;
182 d38f1397 Leszek Koltunski
183 387b6326 Leszek Koltunski
      float A = 3*mult*D*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
184 ead91342 Leszek Koltunski
      A /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
185 d38f1397 Leszek Koltunski
186 e6cf7283 Leszek Koltunski
      return new float[] { x+A*vX, y+A*vY, z+A*vZ };
187 d38f1397 Leszek Koltunski
      }
188 a64e07d0 Leszek Koltunski
    }
189
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
192 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int numLayers)
193 a64e07d0 Leszek Koltunski
    {
194
    int numCubitsPerCorner = numCubitsPerCorner(numLayers);
195 d38f1397 Leszek Koltunski
    int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
196 e4bf4d02 Leszek Koltunski
    int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge + NUM_CENTERS;
197 a64e07d0 Leszek Koltunski
    int index=0;
198
199 e6cf7283 Leszek Koltunski
    final float[][] CENTERS = new float[numCubits][];
200 a64e07d0 Leszek Koltunski
201
    for(int corner=0; corner<NUM_CORNERS; corner++)
202
      {
203 d38f1397 Leszek Koltunski
      computeBasicCornerVectors(corner);
204 a64e07d0 Leszek Koltunski
205
      for(int part=0; part<numCubitsPerCorner; part++, index++)
206
        {
207 e6cf7283 Leszek Koltunski
        CENTERS[index] = computeCorner(numCubitsPerCorner,numLayers,corner,part);
208 a64e07d0 Leszek Koltunski
        }
209
      }
210 d38f1397 Leszek Koltunski
211 a64e07d0 Leszek Koltunski
    for(int edge=0; edge<NUM_EDGES; edge++)
212
      {
213
      for(int part=0; part<numCubitsPerEdge; part++, index++)
214
        {
215 e6cf7283 Leszek Koltunski
        CENTERS[index] = computeEdge(numLayers, edge, part );
216 a64e07d0 Leszek Koltunski
        }
217
      }
218 e4bf4d02 Leszek Koltunski
219 a64e07d0 Leszek Koltunski
    for(int center=0; center<NUM_CENTERS; center++, index++)
220
      {
221 e6cf7283 Leszek Koltunski
      CENTERS[index] = computeCenter(center, numLayers);
222 a64e07d0 Leszek Koltunski
      }
223 e4bf4d02 Leszek Koltunski
224 a64e07d0 Leszek Koltunski
    return CENTERS;
225
    }
226
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228
229 e4bf4d02 Leszek Koltunski
  private int getQuat(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
230 a64e07d0 Leszek Koltunski
    {
231 af0de0af Leszek Koltunski
    if( mQuatCornerIndices==null || mQuatEdgeIndices==null ) initializeQuatIndices();
232
    if( mQuatCenterIndices==null ) initializeCenterIndices();
233
234 a64e07d0 Leszek Koltunski
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
235
      {
236
      int corner = cubit/numCubitsPerCorner;
237 af0de0af Leszek Koltunski
      return mQuatCornerIndices[corner];
238 a64e07d0 Leszek Koltunski
      }
239
240 d38f1397 Leszek Koltunski
    if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
241
      {
242
      int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge;
243 af0de0af Leszek Koltunski
      return mQuatEdgeIndices[edge];
244 d38f1397 Leszek Koltunski
      }
245
246 e4bf4d02 Leszek Koltunski
    int center = cubit - NUM_CORNERS*numCubitsPerCorner - NUM_EDGES*numCubitsPerEdge;
247 af0de0af Leszek Koltunski
    return mQuatCenterIndices[center];
248 a64e07d0 Leszek Koltunski
    }
249
250 bb11be2a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
251
252 8e4a3670 Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
253 bb11be2a Leszek Koltunski
    {
254 8e4a3670 Leszek Koltunski
    int variant = getCubitVariant(cubit,numLayers);
255
    int numVariants = getNumCubitVariants(numLayers);
256 bb11be2a Leszek Koltunski
257 8e4a3670 Leszek Koltunski
    if( variant==0 )
258
      {
259 387b6326 Leszek Koltunski
      float width = numLayers*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
260 8e4a3670 Leszek Koltunski
      float A = (2*SQ3/3)*SIN54;
261
      float B = 0.4f;
262
      double X = width*COS18*SIN_HALFD;
263
      double Y = width*SIN18;
264
      double Z = width*COS18*COS_HALFD;
265
      int N = numLayers==3 ? 1:0;
266
267
      double[][] vertices = new double[][]
268
        {
269
            { 0.0, 0.0      , 0.0 },
270
            {   X,   Y      ,  -Z },
271
            { 0.0, 2*Y      ,-2*Z },
272
            {  -X,   Y      ,  -Z },
273
            { 0.0, 0.0-width, 0.0 },
274
            {   X,   Y-width,  -Z },
275
            { 0.0, 2*Y-width,-2*Z },
276
            {  -X,   Y-width,  -Z },
277
        };
278
279
      int[][] vertIndexes = new int[][]
280
        {
281
            {4,5,1,0},
282
            {7,4,0,3},
283
            {0,1,2,3},
284
            {4,5,6,7},
285
            {6,5,1,2},
286
            {7,6,2,3}
287
        };
288
289
      float[][] bands    = new float[][]
290
        {
291
         {0.04f,34,0.3f,0.2f, 3, N, 0},
292
         {0.00f, 0,0.0f,0.0f, 2, N, 0}
293
        };
294
295
      int[] bandIndices   = new int[] { 0,0,0,1,1,1};
296
      float[][] corners   = new float[][] { {0.04f,0.10f} };
297
      int[] cornerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
298
      float[][] centers   = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
299
      int[] centerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
300
301
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
302
      }
303
    if( variant<numVariants-1 )
304
      {
305
      int numCubitsPerCorner = numCubitsPerCorner(numLayers);
306
      int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
307
      int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
308 387b6326 Leszek Koltunski
      float height= numLayers*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
309
      float width = numLayers*2*MEGA_D + 2*type*height*SIN18/COS18;
310 8e4a3670 Leszek Koltunski
311
      double W = width/2;
312
      double X = height*SIN_HALFD;
313
      double Y = height*SIN18/COS18;
314
      double Z = height*COS_HALFD;
315
316
      double[][] vertices = new double[][]
317 bb11be2a Leszek Koltunski
        {
318
            { 0.0,   W   , 0.0 },
319
            {   X, W+Y   ,  -Z },
320
            { 0.0, W+2*Y ,-2*Z },
321
            {  -X, W+Y   ,  -Z },
322
            { 0.0,  -W   , 0.0 },
323
            {   X,-W-Y   ,  -Z },
324
            { 0.0,-W-2*Y ,-2*Z },
325
            {  -X,-W-Y   ,  -Z },
326
        };
327
328 8e4a3670 Leszek Koltunski
      int[][] vertIndexes = new int[][]
329 bb11be2a Leszek Koltunski
        {
330
            {4,5,1,0},
331
            {7,4,0,3},
332
            {7,6,2,3},
333
            {6,5,1,2},
334
            {0,1,2,3},
335
            {4,5,6,7}
336
        };
337
338 8e4a3670 Leszek Koltunski
      int N = numLayers<=5 ? 5 : 3;
339 bb11be2a Leszek Koltunski
340 8e4a3670 Leszek Koltunski
      float[][] bands     = new float[][]
341
        {
342 bb11be2a Leszek Koltunski
         {0.04f,34,0.2f,0.2f,N,0,0},
343
         {0.00f, 0,0.3f,0.2f,2,0,0}
344 8e4a3670 Leszek Koltunski
        };
345
      int[] bandIndices   = new int[] { 0,0,1,1,1,1};
346
      float[][] corners   = new float[][] { {0.04f,0.10f} };
347
      int[] cornerIndices = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
348
      float[][] centers   = new float[][] { {0.0f, 0.0f, (float)(-2*Z)} };
349
      int[] centerIndices = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
350 bb11be2a Leszek Koltunski
351 8e4a3670 Leszek Koltunski
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
352
      }
353
    else
354 bb11be2a Leszek Koltunski
      {
355 387b6326 Leszek Koltunski
      float width = 2*numLayers*(MEGA_D+(0.5f-MEGA_D)*SIN18);
356 8e4a3670 Leszek Koltunski
      final double V = 0.83;   // ??
357
      final double ANGLE = V*Math.PI;
358
      final double cosA  = Math.cos(ANGLE);
359
      final double sinA  = Math.sin(ANGLE);
360
361
      float R  = 0.5f*width/COS54;
362
      float X1 = R*COS54;
363
      float Y1 = R*SIN54;
364
      float X2 = R*COS18;
365
      float Y2 = R*SIN18;
366
367
      double[][] vertices = new double[][]
368
        {
369 bb11be2a Leszek Koltunski
          {-X1,+Y1*sinA, Y1*cosA},
370
          {-X2,-Y2*sinA,-Y2*cosA},
371
          {0.0f,-R*sinA, -R*cosA},
372
          {+X2,-Y2*sinA,-Y2*cosA},
373
          {+X1,+Y1*sinA, Y1*cosA}
374 8e4a3670 Leszek Koltunski
        };
375 bb11be2a Leszek Koltunski
376 8e4a3670 Leszek Koltunski
      int[][] vertIndexes = new int[][]
377
        {
378 bb11be2a Leszek Koltunski
          {0,1,2,3,4},
379
          {0,1,2,3,4}
380 8e4a3670 Leszek Koltunski
        };
381 bb11be2a Leszek Koltunski
382 8e4a3670 Leszek Koltunski
      int N = numLayers==3 ? 4 : 3;
383 bb11be2a Leszek Koltunski
384 8e4a3670 Leszek Koltunski
      float[][] bands = new float[][]
385
        {
386 bb11be2a Leszek Koltunski
         {0.04f,45, R/3,0.2f,N,0,0},
387
         {0.00f, 0, R/3,0.2f,2,0,0}
388 8e4a3670 Leszek Koltunski
        };
389
390
      int[] bandIndices   = new int[] { 0,1 };
391
      float[][] corners   = new float[][] { {0.04f,0.10f} };
392
      int[] cornerIndices = new int[] { -1,-1,-1,-1, -1 };
393
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
394
      int[] centerIndices = new int[] { -1,-1,-1,-1, -1 };
395
396
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
397
      }
398 bb11be2a Leszek Koltunski
    }
399
400 a64e07d0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
401
402 3e605536 Leszek Koltunski
  Static4D getQuat(int cubit, int numLayers)
403 a64e07d0 Leszek Koltunski
    {
404 af0de0af Leszek Koltunski
    if( mQuats==null ) initializeQuats();
405 a64e07d0 Leszek Koltunski
    int numCubitsPerCorner = numCubitsPerCorner(numLayers);
406
    int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
407 8e4a3670 Leszek Koltunski
408 af0de0af Leszek Koltunski
    return mQuats[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
409 8e4a3670 Leszek Koltunski
    }
410
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412
413 3e605536 Leszek Koltunski
  int getNumCubitVariants(int numLayers)
414 8e4a3670 Leszek Koltunski
    {
415 db608887 Leszek Koltunski
    int[] sizes = ObjectList.MEGA.getSizes();
416
    int variants = sizes.length;
417 a64e07d0 Leszek Koltunski
418 8e4a3670 Leszek Koltunski
    return 2+(sizes[variants-1]-1)/2;
419
    }
420
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422 28b54fe3 Leszek Koltunski
423 8e4a3670 Leszek Koltunski
  int getCubitVariant(int cubit, int numLayers)
424
    {
425
    int numCubitsPerCorner = numCubitsPerCorner(numLayers);
426
427
    if( cubit<NUM_CORNERS*numCubitsPerCorner ) return 0;
428
429
    int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
430
431
    if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
432 a64e07d0 Leszek Koltunski
      {
433 d38f1397 Leszek Koltunski
      int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
434 8e4a3670 Leszek Koltunski
      return type+1;
435
      }
436 d38f1397 Leszek Koltunski
437 8e4a3670 Leszek Koltunski
    int[] sizes = ObjectList.MEGA.getSizes();
438
    int variants = sizes.length;
439
    int numShapes = 2+(sizes[variants-1]-1)/2;
440 3d8237cc Leszek Koltunski
441 8e4a3670 Leszek Koltunski
    return numShapes-1;
442
    }
443
444 a64e07d0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
445
446 d38f1397 Leszek Koltunski
  int getCornerColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner)
447 a64e07d0 Leszek Koltunski
    {
448 af0de0af Leszek Koltunski
    if( mCornerFaceMap==null ) initializeCornerFaceMap();
449 0e7a13b4 Leszek Koltunski
    if( cubitface<0 || cubitface>2 ) return NUM_TEXTURES;
450 6e7146df Leszek Koltunski
451
    int part  = cubit % numCubitsPerCorner;
452 a64e07d0 Leszek Koltunski
    int corner= cubit / numCubitsPerCorner;
453
454 6e7146df Leszek Koltunski
    if( part==0 )
455 a64e07d0 Leszek Koltunski
      {
456 6e7146df Leszek Koltunski
      return mCornerFaceMap[corner][cubitface];
457 a64e07d0 Leszek Koltunski
      }
458
    else
459
      {
460
      int N = (numCubitsPerCorner-1)/3;
461 6e7146df Leszek Koltunski
      int block = (part-1) % N;
462
      int index = (part-1) / N;
463 a64e07d0 Leszek Koltunski
464 0e7a13b4 Leszek Koltunski
      if( block< (numLayers-3)/2 )
465 a64e07d0 Leszek Koltunski
        {
466 6e7146df Leszek Koltunski
        switch(index)
467
          {
468 0e7a13b4 Leszek Koltunski
          case 0: return cubitface==1 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
469
          case 1: return cubitface==0 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
470
          case 2: return cubitface==2 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
471 6e7146df Leszek Koltunski
          }
472 a64e07d0 Leszek Koltunski
        }
473
      else
474
        {
475 6e7146df Leszek Koltunski
        switch(index)
476
          {
477 0e7a13b4 Leszek Koltunski
          case 0: return cubitface==0 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
478
          case 1: return cubitface==2 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
479
          case 2: return cubitface==1 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
480 6e7146df Leszek Koltunski
          }
481 a64e07d0 Leszek Koltunski
        }
482
      }
483 6e7146df Leszek Koltunski
484 0e7a13b4 Leszek Koltunski
    return NUM_TEXTURES;
485 a64e07d0 Leszek Koltunski
    }
486
487 d38f1397 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
488
489 e4bf4d02 Leszek Koltunski
  int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
490 d38f1397 Leszek Koltunski
    {
491 0e7a13b4 Leszek Koltunski
    if( cubitface<0 || cubitface>1 ) return NUM_TEXTURES;
492 d38f1397 Leszek Koltunski
493 e4bf4d02 Leszek Koltunski
    int part    = edge % numCubitsPerEdge;
494
    int variant = edge / numCubitsPerEdge;
495 af0de0af Leszek Koltunski
    if( mEdgeMap==null ) initializeEdgeMap();
496 d38f1397 Leszek Koltunski
497 abf36986 Leszek Koltunski
    return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] + ((part+3)/2)*NUM_FACE_COLORS : NUM_TEXTURES;
498 d38f1397 Leszek Koltunski
    }
499
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501
502 e4bf4d02 Leszek Koltunski
  int getCenterColor(int center, int cubitface, int numLayers)
503 d38f1397 Leszek Koltunski
    {
504 abf36986 Leszek Koltunski
    return cubitface>0 ? NUM_TEXTURES : center + NUM_FACE_COLORS*(numLayers+1)/2;
505 d38f1397 Leszek Koltunski
    }
506
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508
509
  int getFaceColor(int cubit, int cubitface, int numLayers)
510
    {
511
    int numCubitsPerCorner = numCubitsPerCorner(numLayers);
512
    int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
513
514
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
515
      {
516
      return getCornerColor(cubit,cubitface,numLayers,numCubitsPerCorner);
517
      }
518
    else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
519
      {
520 e4bf4d02 Leszek Koltunski
      int edge = cubit - NUM_CORNERS*numCubitsPerCorner;
521
      return getEdgeColor(edge,cubitface,numCubitsPerEdge);
522 d38f1397 Leszek Koltunski
      }
523
    else
524
      {
525 e4bf4d02 Leszek Koltunski
      int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge;
526
      return getCenterColor( center, cubitface, numLayers);
527 d38f1397 Leszek Koltunski
      }
528
    }
529
530 9c06394a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
531
532
  ObjectSticker retSticker(int face)
533
    {
534 af0de0af Leszek Koltunski
    if( mStickers==null )
535
      {
536
      float[][] STICKERS = new float[][]
537
        {
538
          { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
539
          { -0.5f, -0.0914315f, 0.5f, -0.4163512f, 0.5f, 0.4163512f, -0.5f, 0.0914315f },
540
          { -0.49233657f, -0.18006028f, 0.49233657f, -0.5f, 0.49233657f, 0.5f, -0.49233657f, 0.18006028f },
541
          { -0.3002273f, -0.30490047f, 0.3002273f, -0.5f, 0.3002273f, 0.5f, -0.3002273f, 0.30490047f },
542
          { -0.29389262f, 0.4045085f, -0.47552824f, -0.1545085f, 0.0f, -0.5f, 0.47552824f, -0.1545085f, 0.29389262f, 0.4045085f }
543
        };
544
545
      mStickers = new ObjectSticker[STICKERS.length];
546
547
      final float R0 = 0.08f;
548
      final float R1 = 0.12f;
549
      final float R2 = 0.12f;
550
      final float R3 = 0.08f;
551
      final float R4 = 0.10f;
552
      final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3},{R4,R4,R4,R4,R4} };
553
      final float[] strokes = { 0.10f,0.12f,0.12f,0.08f,0.07f };
554
555
      for(int s=0; s<STICKERS.length; s++)
556
        {
557
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
558
        }
559
      }
560
561 9c06394a Leszek Koltunski
    return mStickers[getStickerIndex(face)];
562
    }
563
564
///////////////////////////////////////////////////////////////////////////////////////////////////
565
566
  private int getStickerIndex(int face)
567
    {
568 abf36986 Leszek Koltunski
    int variant = face/NUM_FACE_COLORS;
569 ede1b68c Leszek Koltunski
570 9c06394a Leszek Koltunski
    if( variant==0 ) return 0;
571
572
    int numLayers = getNumLayers();
573
574
    if( variant < (numLayers+1)/2 )
575
      {
576
      if( numLayers==3 ) return 1;
577
      else
578 ede1b68c Leszek Koltunski
        {
579 9c06394a Leszek Koltunski
        if( variant==1 ) return 2;
580
        else             return 3;
581 ede1b68c Leszek Koltunski
        }
582
      }
583
584 9c06394a Leszek Koltunski
    return 4;
585 a64e07d0 Leszek Koltunski
    }
586
587
///////////////////////////////////////////////////////////////////////////////////////////////////
588
589
  public int getObjectName(int numLayers)
590
    {
591
    if( numLayers==3 ) return R.string.minx3;
592 f6e46300 Leszek Koltunski
    if( numLayers==5 ) return R.string.minx5;
593 a64e07d0 Leszek Koltunski
594
    return 0;
595
    }
596
597
///////////////////////////////////////////////////////////////////////////////////////////////////
598
599
  public int getInventor(int numLayers)
600
    {
601
    if( numLayers==3 ) return R.string.minx3_inventor;
602 f6e46300 Leszek Koltunski
    if( numLayers==5 ) return R.string.minx5_inventor;
603 a64e07d0 Leszek Koltunski
604
    return 0;
605
    }
606
607
///////////////////////////////////////////////////////////////////////////////////////////////////
608
609
  public int getComplexity(int numLayers)
610
    {
611
    if( numLayers==3 ) return 4;
612
613
    return 5;
614
    }
615
}