Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyMegaminx.java @ c3a033e9

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.objectlib.objects;
21
22 c9c71c3f Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.COS54;
23
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.SIN54;
24 29b82486 Leszek Koltunski
25 82eb152a Leszek Koltunski
import java.io.InputStream;
26 29b82486 Leszek Koltunski
27 ecf3d6e3 Leszek Koltunski
import org.distorted.library.type.Static3D;
28 29b82486 Leszek Koltunski
import org.distorted.library.type.Static4D;
29 a706f8e0 Leszek Koltunski
import org.distorted.library.main.QuatHelper;
30 29b82486 Leszek Koltunski
31 8592461c Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
32 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
33 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
34
import org.distorted.objectlib.helpers.ObjectSticker;
35 29b82486 Leszek Koltunski
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37
38
public class TwistyMegaminx extends TwistyMinx
39
{
40
  static final float MEGA_D = 0.04f;
41
  private int[] mQuatCenterIndices;
42
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
45 c3a033e9 Leszek Koltunski
  public TwistyMegaminx(int[] numL, int meshState, Static4D quat, Static3D move, float scale, InputStream stream)
46 29b82486 Leszek Koltunski
    {
47 c3a033e9 Leszek Koltunski
    super(numL, meshState, quat, move, scale, stream);
48 29b82486 Leszek Koltunski
    }
49
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
52
  private void initializeCenterIndices()
53
    {
54
    mQuatCenterIndices = new int[] { 16, 18, 22,  1, 20, 13, 14, 15,  0, 12,  2,  3 };
55
    }
56
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58
59
  private int numCubitsPerCorner(int numLayers)
60
    {
61
    return 3*((numLayers-1)/2)*((numLayers-3)/2) + 1;
62
    }
63
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
66
  private int numCubitsPerEdge(int numLayers)
67
    {
68
    return numLayers-2;
69
    }
70
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73 1bb09f88 Leszek Koltunski
  public int getNumStickerTypes(int[] numLayers)
74 29b82486 Leszek Koltunski
    {
75 a57e6870 Leszek Koltunski
    return (numLayers[0]+3)/2;
76 29b82486 Leszek Koltunski
    }
77
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79
80 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
81 29b82486 Leszek Koltunski
    {
82 a57e6870 Leszek Koltunski
    return genericGetCuts(numLayers[0],0.5f-MEGA_D);
83 29b82486 Leszek Koltunski
    }
84
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
87
  private float[] computeCenter(int center, int numLayers)
88
    {
89
    if( mCenterCoords==null ) initializeCenterCoords();
90
    float[] coords = mCenterCoords[center];
91
    float A = 0.33f*numLayers;
92
93
    return new float[] { A*coords[0], A*coords[1], A*coords[2] };
94
    }
95
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97
// Fill out mCurrCorner{X,Y,Z} by applying appropriate Quat to mBasicCorner{X,Y,Z}
98
// Appropriate one: QUATS[QUAT_INDICES[corner]].
99
100
  private void computeBasicCornerVectors(int corner)
101
    {
102
    if( mQuatCornerIndices==null ) initializeQuatIndices();
103
    if( mQuats==null ) initializeQuats();
104
    if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
105
106
    Static4D quat = mQuats[mQuatCornerIndices[corner]];
107
108
    mCurrCornerV[0] = QuatHelper.rotateVectorByQuat(mBasicCornerV[0],quat);
109
    mCurrCornerV[1] = QuatHelper.rotateVectorByQuat(mBasicCornerV[1],quat);
110
    mCurrCornerV[2] = QuatHelper.rotateVectorByQuat(mBasicCornerV[2],quat);
111
    }
112
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114
115
  private float[] computeCorner(int numCubitsPerCorner, int numLayers, int corner, int part)
116
    {
117
    if( mCorners==null ) initializeCorners();
118
    if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
119
120
    float D = numLayers/3.0f;
121
    float[] corn = mCorners[corner];
122
123
    if( part==0 )
124
      {
125
      return new float[] { corn[0]*D, corn[1]*D, corn[2]*D };
126
      }
127
    else
128
      {
129
      float E = 2.0f*D*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
130
      int N = (numCubitsPerCorner-1)/3;
131
      int block = (part-1) % N;
132
      int index = (part-1) / N;
133
      Static4D pri = mCurrCornerV[index];
134
      Static4D sec = mCurrCornerV[(index+2)%3];
135
136
      int layers= (numLayers-3)/2;
137
      int multP = (block % layers) + 1;
138
      int multS = (block / layers);
139
140
      return new float[] {
141
                          corn[0]*D + (pri.get0()*multP + sec.get0()*multS)*E,
142
                          corn[1]*D + (pri.get1()*multP + sec.get1()*multS)*E,
143
                          corn[2]*D + (pri.get2()*multP + sec.get2()*multS)*E
144
                         };
145
      }
146
    }
147
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149
150
  private int computeEdgeType(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
151
    {
152
    int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
153
    return (part+1)/2;
154
    }
155
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157
158
  private float[] computeEdge(int numLayers, int edge, int part)
159
    {
160
    if( mCenterCoords==null ) initializeCenterCoords();
161
    if( mCorners==null ) initializeCorners();
162
    if( mEdgeMap==null ) initializeEdgeMap();
163
164
    float D = numLayers/3.0f;
165
    float[] c1 = mCorners[ mEdgeMap[edge][0] ];
166
    float[] c2 = mCorners[ mEdgeMap[edge][1] ];
167
    float x = D * (c1[0]+c2[0]) / 2;
168
    float y = D * (c1[1]+c2[1]) / 2;
169
    float z = D * (c1[2]+c2[2]) / 2;
170
171
    if( part==0 )
172
      {
173
      return new float[] { x, y, z };
174
      }
175
    else
176
      {
177
      int mult = (part+1)/2;
178
      int dir  = (part+1)%2;
179
      float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ];
180
181
      float vX = D*center[0] - x;
182
      float vY = D*center[1] - y;
183
      float vZ = D*center[2] - z;
184
185
      float A = 3*mult*D*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
186
      A /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
187
188
      return new float[] { x+A*vX, y+A*vY, z+A*vZ };
189
      }
190
    }
191
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193
194 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
195 29b82486 Leszek Koltunski
    {
196 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
197
    int numCubitsPerCorner = numCubitsPerCorner(numL);
198
    int numCubitsPerEdge   = numCubitsPerEdge(numL);
199 29b82486 Leszek Koltunski
    int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge + NUM_CENTERS;
200
    int index=0;
201
202
    final float[][] CENTERS = new float[numCubits][];
203
204
    for(int corner=0; corner<NUM_CORNERS; corner++)
205
      {
206
      computeBasicCornerVectors(corner);
207
208
      for(int part=0; part<numCubitsPerCorner; part++, index++)
209
        {
210 a57e6870 Leszek Koltunski
        CENTERS[index] = computeCorner(numCubitsPerCorner,numL,corner,part);
211 29b82486 Leszek Koltunski
        }
212
      }
213
214
    for(int edge=0; edge<NUM_EDGES; edge++)
215
      {
216
      for(int part=0; part<numCubitsPerEdge; part++, index++)
217
        {
218 a57e6870 Leszek Koltunski
        CENTERS[index] = computeEdge(numL, edge, part );
219 29b82486 Leszek Koltunski
        }
220
      }
221
222
    for(int center=0; center<NUM_CENTERS; center++, index++)
223
      {
224 a57e6870 Leszek Koltunski
      CENTERS[index] = computeCenter(center, numL);
225 29b82486 Leszek Koltunski
      }
226
227
    return CENTERS;
228
    }
229
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231
232
  private int getQuat(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
233
    {
234
    if( mQuatCornerIndices==null || mQuatEdgeIndices==null ) initializeQuatIndices();
235
    if( mQuatCenterIndices==null ) initializeCenterIndices();
236
237
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
238
      {
239
      int corner = cubit/numCubitsPerCorner;
240
      return mQuatCornerIndices[corner];
241
      }
242
243
    if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
244
      {
245
      int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge;
246
      return mQuatEdgeIndices[edge];
247
      }
248
249
    int center = cubit - NUM_CORNERS*numCubitsPerCorner - NUM_EDGES*numCubitsPerEdge;
250
    return mQuatCenterIndices[center];
251
    }
252
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254
255 e30c522a Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
256 29b82486 Leszek Koltunski
    {
257 e30c522a Leszek Koltunski
    int[] numLayers = getNumLayers();
258 29b82486 Leszek Koltunski
    int numVariants = getNumCubitVariants(numLayers);
259 e30c522a Leszek Koltunski
    int numL        = numLayers[0];
260 66de0d91 Leszek Koltunski
    boolean small   = numL<=3;
261 29b82486 Leszek Koltunski
262
    if( variant==0 )
263
      {
264 a57e6870 Leszek Koltunski
      float width = numL*(0.5f-MEGA_D)/(0.5f*(numL-1));
265 29b82486 Leszek Koltunski
      float A = (2*SQ3/3)*SIN54;
266
      float B = 0.4f;
267 57ef6378 Leszek Koltunski
      float X = width*COS18*SIN_HALFD;
268
      float Y = width*SIN18;
269
      float Z = width*COS18*COS_HALFD;
270 29b82486 Leszek Koltunski
271 57ef6378 Leszek Koltunski
      float[][] vertices = new float[][]
272 29b82486 Leszek Koltunski
        {
273 57ef6378 Leszek Koltunski
            {   0,   0      ,   0 },
274 29b82486 Leszek Koltunski
            {   X,   Y      ,  -Z },
275 57ef6378 Leszek Koltunski
            {   0, 2*Y      ,-2*Z },
276 29b82486 Leszek Koltunski
            {  -X,   Y      ,  -Z },
277 57ef6378 Leszek Koltunski
            {   0,   0-width,   0 },
278 29b82486 Leszek Koltunski
            {   X,   Y-width,  -Z },
279 57ef6378 Leszek Koltunski
            {   0, 2*Y-width,-2*Z },
280 29b82486 Leszek Koltunski
            {  -X,   Y-width,  -Z },
281
        };
282
283
      int[][] vertIndexes = new int[][]
284
        {
285
            {4,5,1,0},
286
            {7,4,0,3},
287
            {0,1,2,3},
288
            {4,5,6,7},
289
            {6,5,1,2},
290
            {7,6,2,3}
291
        };
292
293
      float[][] bands    = new float[][]
294
        {
295 66de0d91 Leszek Koltunski
         {0.04f,34,0.3f,0.2f, 3, 0, 0},
296
         {0.00f, 0,0.0f,0.0f, 2, 0, 0}
297 29b82486 Leszek Koltunski
        };
298
299
      int[] bandIndices   = new int[] { 0,0,0,1,1,1};
300
      float[][] corners   = new float[][] { {0.04f,0.10f} };
301
      int[] cornerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
302
      float[][] centers   = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
303
      int[] centerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
304
305
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
306
      }
307
    if( variant<numVariants-1 )
308
      {
309 e30c522a Leszek Koltunski
      int type = variant-1;
310 a57e6870 Leszek Koltunski
      float height= numL*(0.5f-MEGA_D)*COS18/((numL-1)*0.5f);
311
      float width = numL*2*MEGA_D + 2*type*height*SIN18/COS18;
312 29b82486 Leszek Koltunski
313 57ef6378 Leszek Koltunski
      float W = width/2;
314
      float X = height*SIN_HALFD;
315
      float Y = height*SIN18/COS18;
316
      float Z = height*COS_HALFD;
317 29b82486 Leszek Koltunski
318 57ef6378 Leszek Koltunski
      float[][] vertices = new float[][]
319 29b82486 Leszek Koltunski
        {
320 57ef6378 Leszek Koltunski
            {   0,   W   ,   0 },
321 29b82486 Leszek Koltunski
            {   X, W+Y   ,  -Z },
322 57ef6378 Leszek Koltunski
            {   0, W+2*Y ,-2*Z },
323 29b82486 Leszek Koltunski
            {  -X, W+Y   ,  -Z },
324 57ef6378 Leszek Koltunski
            {   0,  -W   ,   0 },
325 29b82486 Leszek Koltunski
            {   X,-W-Y   ,  -Z },
326 57ef6378 Leszek Koltunski
            {   0,-W-2*Y ,-2*Z },
327 29b82486 Leszek Koltunski
            {  -X,-W-Y   ,  -Z },
328
        };
329
330
      int[][] vertIndexes = new int[][]
331
        {
332
            {4,5,1,0},
333
            {7,4,0,3},
334
            {7,6,2,3},
335
            {6,5,1,2},
336
            {0,1,2,3},
337
            {4,5,6,7}
338
        };
339
340 66de0d91 Leszek Koltunski
      int N = small ? 5 : 3;
341 29b82486 Leszek Koltunski
342 a57e6870 Leszek Koltunski
      float[][] bands = new float[][]
343 29b82486 Leszek Koltunski
        {
344
         {0.04f,34,0.2f,0.2f,N,0,0},
345 66de0d91 Leszek Koltunski
         {0.00f,34,0.3f,0.2f,2,0,0}
346 29b82486 Leszek Koltunski
        };
347
      int[] bandIndices   = new int[] { 0,0,1,1,1,1};
348
      float[][] corners   = new float[][] { {0.04f,0.10f} };
349
      int[] cornerIndices = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
350
      float[][] centers   = new float[][] { {0.0f, 0.0f, (float)(-2*Z)} };
351
      int[] centerIndices = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
352
353
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
354
      }
355
    else
356
      {
357 a57e6870 Leszek Koltunski
      float width = 2*numL*(MEGA_D+(0.5f-MEGA_D)*SIN18);
358 57ef6378 Leszek Koltunski
      final float V = 0.83f;   // ??
359 29b82486 Leszek Koltunski
      final double ANGLE = V*Math.PI;
360 57ef6378 Leszek Koltunski
      final float cosA  = (float)Math.cos(ANGLE);
361
      final float sinA  = (float)Math.sin(ANGLE);
362 29b82486 Leszek Koltunski
363
      float R  = 0.5f*width/COS54;
364
      float X1 = R*COS54;
365
      float Y1 = R*SIN54;
366
      float X2 = R*COS18;
367
      float Y2 = R*SIN18;
368
369 57ef6378 Leszek Koltunski
      float[][] vertices = new float[][]
370 29b82486 Leszek Koltunski
        {
371
          {-X1,+Y1*sinA, Y1*cosA},
372
          {-X2,-Y2*sinA,-Y2*cosA},
373 c3a033e9 Leszek Koltunski
          { 0 ,-R*sinA ,-R*cosA },
374 29b82486 Leszek Koltunski
          {+X2,-Y2*sinA,-Y2*cosA},
375 c3a033e9 Leszek Koltunski
          {+X1,+Y1*sinA, Y1*cosA},
376
          { 0 , R*cosA ,-R*sinA }
377 29b82486 Leszek Koltunski
        };
378
379
      int[][] vertIndexes = new int[][]
380
        {
381
          {0,1,2,3,4},
382 c3a033e9 Leszek Koltunski
          {0,1,5},
383
          {1,2,5},
384
          {2,3,5},
385
          {3,4,5},
386
          {4,0,5}
387 29b82486 Leszek Koltunski
        };
388
389 66de0d91 Leszek Koltunski
      int N = small ? 4 : 3;
390 29b82486 Leszek Koltunski
391
      float[][] bands = new float[][]
392
        {
393
         {0.04f,45, R/3,0.2f,N,0,0},
394 66de0d91 Leszek Koltunski
         {0.00f,45, R/3,0.2f,2,0,0}
395 29b82486 Leszek Koltunski
        };
396
397 c3a033e9 Leszek Koltunski
      int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
398 29b82486 Leszek Koltunski
      float[][] corners   = new float[][] { {0.04f,0.10f} };
399 c3a033e9 Leszek Koltunski
      int[] cornerIndices = new int[] { -1,-1,-1,-1, -1,-1 };
400 29b82486 Leszek Koltunski
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
401 c3a033e9 Leszek Koltunski
      int[] centerIndices = new int[] { -1,-1,-1,-1, -1,-1 };
402 29b82486 Leszek Koltunski
403
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
404
      }
405
    }
406
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408
409 7b832206 Leszek Koltunski
  public Static4D getQuat(int cubit, int[] numLayers)
410 29b82486 Leszek Koltunski
    {
411
    if( mQuats==null ) initializeQuats();
412 a57e6870 Leszek Koltunski
413
    int numL = numLayers[0];
414
    int numCubitsPerCorner = numCubitsPerCorner(numL);
415
    int numCubitsPerEdge   = numCubitsPerEdge(numL);
416 29b82486 Leszek Koltunski
417
    return mQuats[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
418
    }
419
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421
422 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
423 29b82486 Leszek Koltunski
    {
424 a57e6870 Leszek Koltunski
    switch(numLayers[0])
425 61aa85e4 Leszek Koltunski
      {
426
      case 3: return 3;
427
      case 5: return 4;
428
      }
429 29b82486 Leszek Koltunski
430 61aa85e4 Leszek Koltunski
    return 3;
431 29b82486 Leszek Koltunski
    }
432
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434
435 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
436 29b82486 Leszek Koltunski
    {
437 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
438
    int numCubitsPerCorner = numCubitsPerCorner(numL);
439 29b82486 Leszek Koltunski
440
    if( cubit<NUM_CORNERS*numCubitsPerCorner ) return 0;
441
442 a57e6870 Leszek Koltunski
    int numCubitsPerEdge = numCubitsPerEdge(numL);
443 29b82486 Leszek Koltunski
444
    if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
445
      {
446
      int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
447
      return type+1;
448
      }
449
450 61aa85e4 Leszek Koltunski
    return getNumCubitVariants(numLayers)-1;
451 29b82486 Leszek Koltunski
    }
452
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454
455
  int getCornerColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner)
456
    {
457
    if( mCornerFaceMap==null ) initializeCornerFaceMap();
458 a75ae1ee Leszek Koltunski
    if( cubitface<0 || cubitface>2 ) return -1;
459 29b82486 Leszek Koltunski
460
    int part  = cubit % numCubitsPerCorner;
461
    int corner= cubit / numCubitsPerCorner;
462
463
    if( part==0 )
464
      {
465
      return mCornerFaceMap[corner][cubitface];
466
      }
467
    else
468
      {
469
      int N = (numCubitsPerCorner-1)/3;
470
      int block = (part-1) % N;
471
      int index = (part-1) / N;
472
473
      if( block< (numLayers-3)/2 )
474
        {
475
        switch(index)
476
          {
477 a75ae1ee Leszek Koltunski
          case 0: return cubitface==1 ? -1 : mCornerFaceMap[corner][cubitface];
478
          case 1: return cubitface==0 ? -1 : mCornerFaceMap[corner][cubitface];
479
          case 2: return cubitface==2 ? -1 : mCornerFaceMap[corner][cubitface];
480 29b82486 Leszek Koltunski
          }
481
        }
482
      else
483
        {
484
        switch(index)
485
          {
486 a75ae1ee Leszek Koltunski
          case 0: return cubitface==0 ? mCornerFaceMap[corner][cubitface] : -1;
487
          case 1: return cubitface==2 ? mCornerFaceMap[corner][cubitface] : -1;
488
          case 2: return cubitface==1 ? mCornerFaceMap[corner][cubitface] : -1;
489 29b82486 Leszek Koltunski
          }
490
        }
491
      }
492
493
    return NUM_TEXTURES;
494
    }
495
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497
498
  int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
499
    {
500 a75ae1ee Leszek Koltunski
    if( cubitface<0 || cubitface>1 ) return -1;
501 29b82486 Leszek Koltunski
502
    int part    = edge % numCubitsPerEdge;
503
    int variant = edge / numCubitsPerEdge;
504
    if( mEdgeMap==null ) initializeEdgeMap();
505
506 a75ae1ee Leszek Koltunski
    return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] : -1;
507 29b82486 Leszek Koltunski
    }
508
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510
511 43a4ccff Leszek Koltunski
  int getCenterColor(int center, int cubitface)
512 29b82486 Leszek Koltunski
    {
513 a75ae1ee Leszek Koltunski
    return cubitface>0 ? -1 : center;
514 29b82486 Leszek Koltunski
    }
515
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517
518 a75ae1ee Leszek Koltunski
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
519 29b82486 Leszek Koltunski
    {
520 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
521
    int numCubitsPerCorner = numCubitsPerCorner(numL);
522
    int numCubitsPerEdge   = numCubitsPerEdge(numL);
523 29b82486 Leszek Koltunski
524
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
525
      {
526 a75ae1ee Leszek Koltunski
      return getCornerColor(cubit,face,numL,numCubitsPerCorner);
527 29b82486 Leszek Koltunski
      }
528
    else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
529
      {
530
      int edge = cubit - NUM_CORNERS*numCubitsPerCorner;
531 a75ae1ee Leszek Koltunski
      return getEdgeColor(edge,face,numCubitsPerEdge);
532 29b82486 Leszek Koltunski
      }
533
    else
534
      {
535
      int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge;
536 a75ae1ee Leszek Koltunski
      return getCenterColor( center, face );
537
      }
538
    }
539
540
///////////////////////////////////////////////////////////////////////////////////////////////////
541
542
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
543
    {
544
    if( variant==0 ) return 0;
545
    else
546
      {
547
      if( variant==getNumCubitVariants(numLayers)-1 ) return 1;
548
      else return variant+1;
549 29b82486 Leszek Koltunski
      }
550
    }
551
552
///////////////////////////////////////////////////////////////////////////////////////////////////
553
554 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
555 29b82486 Leszek Koltunski
    {
556
    if( mStickers==null )
557
      {
558 43a4ccff Leszek Koltunski
      float[][] STICKERS;
559
      int[] numLayers = getNumLayers();
560
      int numL = numLayers[0];
561
562
      if( numL==3 )
563 29b82486 Leszek Koltunski
        {
564 43a4ccff Leszek Koltunski
        STICKERS = new float[][]
565
          {
566
            { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
567
            { -0.29389262f, 0.4045085f, -0.47552824f, -0.1545085f, 0.0f, -0.5f, 0.47552824f, -0.1545085f, 0.29389262f, 0.4045085f },
568
            { -0.5f, -0.0914315f, 0.5f, -0.4163512f, 0.5f, 0.4163512f, -0.5f, 0.0914315f }
569
          };
570
        }
571
      else
572
        {
573
        STICKERS = new float[][]
574
          {
575
            { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
576
            { -0.29389262f, 0.4045085f, -0.47552824f, -0.1545085f, 0.0f, -0.5f, 0.47552824f, -0.1545085f, 0.29389262f, 0.4045085f },
577
            { -0.49233657f, -0.18006028f, 0.49233657f, -0.5f, 0.49233657f, 0.5f, -0.49233657f, 0.18006028f },
578
            { -0.3002273f, -0.30490047f, 0.3002273f, -0.5f, 0.3002273f, 0.5f, -0.3002273f, 0.30490047f }
579
          };
580
        }
581 29b82486 Leszek Koltunski
582
      mStickers = new ObjectSticker[STICKERS.length];
583
584
      final float R0 = 0.08f;
585 43a4ccff Leszek Koltunski
      final float R1 = 0.10f;
586 29b82486 Leszek Koltunski
      final float R2 = 0.12f;
587
      final float R3 = 0.08f;
588 43a4ccff Leszek Koltunski
589
      final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
590
      float[] strokes = { 0.10f,0.065f,0.12f,0.08f };
591 8592461c Leszek Koltunski
592
      if( ObjectControl.isInIconMode() )
593
        {
594 43a4ccff Leszek Koltunski
        float mult = numL==3 ? 1.5f : 2.2f;
595 8592461c Leszek Koltunski
596
        strokes[0]*=mult;
597
        strokes[1]*=mult;
598
        strokes[2]*=mult;
599
        strokes[3]*=mult;
600
        strokes[4]*=mult;
601
        }
602 29b82486 Leszek Koltunski
603
      for(int s=0; s<STICKERS.length; s++)
604
        {
605
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
606
        }
607
      }
608
609 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
610 29b82486 Leszek Koltunski
    }
611
612 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
613
614 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
615 61aa85e4 Leszek Koltunski
    {
616 a57e6870 Leszek Koltunski
    switch(numLayers[0])
617 61aa85e4 Leszek Koltunski
      {
618 8005e762 Leszek Koltunski
      case 3: return ObjectType.MEGA_3;
619
      case 5: return ObjectType.MEGA_5;
620 61aa85e4 Leszek Koltunski
      }
621 8005e762 Leszek Koltunski
    return ObjectType.MEGA_3;
622 61aa85e4 Leszek Koltunski
    }
623
624 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
625
626 e26eb4e7 Leszek Koltunski
  public String getObjectName()
627 29b82486 Leszek Koltunski
    {
628 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
629
      {
630
      case 3: return "Megaminx";
631
      case 5: return "Gigaminx";
632
      }
633
    return "Megaminx";
634 29b82486 Leszek Koltunski
    }
635
636
///////////////////////////////////////////////////////////////////////////////////////////////////
637
638 e26eb4e7 Leszek Koltunski
  public String getInventor()
639 29b82486 Leszek Koltunski
    {
640 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
641
      {
642
      case 3: return "Ferenc Szlivka";
643
      case 5: return "Tyler Fox";
644
      }
645
    return "Ferenc Szlivka";
646 29b82486 Leszek Koltunski
    }
647
648 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
649
650 e26eb4e7 Leszek Koltunski
  public int getYearOfInvention()
651 59c20632 Leszek Koltunski
    {
652 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
653 59c20632 Leszek Koltunski
      {
654
      case 3: return 1982;
655
      case 5: return 2006;
656
      }
657 e26eb4e7 Leszek Koltunski
    return 2006;
658 59c20632 Leszek Koltunski
    }
659
660 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
661
662 e26eb4e7 Leszek Koltunski
  public int getComplexity()
663 29b82486 Leszek Koltunski
    {
664 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
665
      {
666 b4223a92 Leszek Koltunski
      case 3: return 3;
667
      case 5: return 4;
668 e26eb4e7 Leszek Koltunski
      }
669 a57e6870 Leszek Koltunski
    return 9;
670 29b82486 Leszek Koltunski
    }
671
}