Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyKilominx.java @ 588ace55

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