Project

General

Profile

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

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

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