Project

General

Profile

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

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

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