Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyMinx.java @ c3203fb1

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import org.distorted.helpers.FactoryCubit;
25
import org.distorted.library.main.DistortedEffects;
26
import org.distorted.library.main.DistortedTexture;
27
import org.distorted.library.mesh.MeshBase;
28
import org.distorted.library.mesh.MeshSquare;
29
import org.distorted.library.type.Static3D;
30
import org.distorted.library.type.Static4D;
31

    
32
import java.util.Random;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
abstract class TwistyMinx extends TwistyObject
37
{
38
  private static final int FACES_PER_CUBIT =6;
39

    
40
  static final int NUM_CORNERS = 20;
41
  static final int NUM_CENTERS = 12;
42
  static final int NUM_EDGES   = 30;
43

    
44
  static final float C2       = (SQ5+3)/4;
45
  static final float LEN      = (float)(Math.sqrt(1.25f+0.5f*SQ5));
46
  static final float SIN54    = (SQ5+1)/4;
47
  static final float COS54    = (float)(Math.sqrt(10-2*SQ5)/4);
48
  static final float SIN18    = (SQ5-1)/4;
49
  static final float COS18    = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
50
  static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
51
  static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
52

    
53
  // the six rotation axis of a Minx. Must be normalized.
54
  static final Static3D[] ROT_AXIS = new Static3D[]
55
         {
56
           new Static3D(    C2/LEN, SIN54/LEN,    0      ),
57
           new Static3D(   -C2/LEN, SIN54/LEN,    0      ),
58
           new Static3D( 0        ,    C2/LEN, SIN54/LEN ),
59
           new Static3D( 0        ,   -C2/LEN, SIN54/LEN ),
60
           new Static3D( SIN54/LEN,    0     ,    C2/LEN ),
61
           new Static3D( SIN54/LEN,    0     ,   -C2/LEN )
62
         };
63

    
64
  private static final int[] BASIC_ANGLE = new int[] { 5,5,5,5,5,5 };
65

    
66
  static final int MINX_LGREEN = 0xff53aa00;
67
  static final int MINX_PINK   = 0xfffd7ab7;
68
  static final int MINX_SANDY  = 0xffefd48b;
69
  static final int MINX_LBLUE  = 0xff00a2d7;
70
  static final int MINX_ORANGE = 0xffff6200;
71
  static final int MINX_VIOLET = 0xff7d59a4;
72
  static final int MINX_DGREEN = 0xff007a47;
73
  static final int MINX_DRED   = 0xffbd0000;
74
  static final int MINX_DBLUE  = 0xff1a29b2;
75
  static final int MINX_DYELLOW= 0xffffc400;
76
  static final int MINX_WHITE  = 0xffffffff;
77
  static final int MINX_GREY   = 0xff727c7b;
78

    
79
  static final int[] FACE_COLORS = new int[]
80
         {
81
           MINX_LGREEN, MINX_PINK   , MINX_SANDY , MINX_LBLUE,
82
           MINX_ORANGE, MINX_VIOLET , MINX_DGREEN, MINX_DRED ,
83
           MINX_DBLUE , MINX_DYELLOW, MINX_WHITE , MINX_GREY
84
         };
85

    
86
  // All 60 legal rotation quats of a Minx
87
  static final Static4D[] QUATS = new Static4D[]
88
         {
89
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),  //0
90
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
91
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
92
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
93

    
94
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),  //4
95
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
96
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
97
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
98
           new Static4D( -0.5f,  0.5f,  0.5f,  0.5f ),
99
           new Static4D( -0.5f,  0.5f, -0.5f,  0.5f ),
100
           new Static4D( -0.5f, -0.5f,  0.5f,  0.5f ),
101
           new Static4D( -0.5f, -0.5f, -0.5f,  0.5f ),
102

    
103
           new Static4D(  0.5f, SIN54, SIN18,  0.0f ), // 12
104
           new Static4D(  0.5f, SIN54,-SIN18,  0.0f ),
105
           new Static4D(  0.5f,-SIN54, SIN18,  0.0f ),
106
           new Static4D(  0.5f,-SIN54,-SIN18,  0.0f ),
107
           new Static4D( SIN18,  0.5f, SIN54,  0.0f ),
108
           new Static4D( SIN18,  0.5f,-SIN54,  0.0f ),
109
           new Static4D(-SIN18,  0.5f, SIN54,  0.0f ),
110
           new Static4D(-SIN18,  0.5f,-SIN54,  0.0f ),
111
           new Static4D( SIN54, SIN18,  0.5f,  0.0f ),
112
           new Static4D( SIN54,-SIN18,  0.5f,  0.0f ),
113
           new Static4D(-SIN54, SIN18,  0.5f,  0.0f ),
114
           new Static4D(-SIN54,-SIN18,  0.5f,  0.0f ),
115

    
116
           new Static4D(  0.0f, SIN18, SIN54,  0.5f ), //24
117
           new Static4D(  0.0f, SIN18,-SIN54,  0.5f ),
118
           new Static4D(  0.0f,-SIN18, SIN54,  0.5f ),
119
           new Static4D(  0.0f,-SIN18,-SIN54,  0.5f ),
120
           new Static4D( SIN18, SIN54,  0.0f,  0.5f ),
121
           new Static4D( SIN18,-SIN54,  0.0f,  0.5f ),
122
           new Static4D(-SIN18, SIN54,  0.0f,  0.5f ),
123
           new Static4D(-SIN18,-SIN54,  0.0f,  0.5f ),
124
           new Static4D( SIN54,  0.0f, SIN18,  0.5f ),
125
           new Static4D( SIN54,  0.0f,-SIN18,  0.5f ),
126
           new Static4D(-SIN54,  0.0f, SIN18,  0.5f ),
127
           new Static4D(-SIN54,  0.0f,-SIN18,  0.5f ),
128

    
129
           new Static4D(  0.0f, SIN54,  0.5f, SIN18 ), //36
130
           new Static4D(  0.0f, SIN54, -0.5f, SIN18 ),
131
           new Static4D(  0.0f,-SIN54,  0.5f, SIN18 ),
132
           new Static4D(  0.0f,-SIN54, -0.5f, SIN18 ),
133
           new Static4D(  0.5f,  0.0f, SIN54, SIN18 ),
134
           new Static4D(  0.5f,  0.0f,-SIN54, SIN18 ),
135
           new Static4D( -0.5f,  0.0f, SIN54, SIN18 ),
136
           new Static4D( -0.5f,  0.0f,-SIN54, SIN18 ),
137
           new Static4D( SIN54,  0.5f,  0.0f, SIN18 ),
138
           new Static4D( SIN54, -0.5f,  0.0f, SIN18 ),
139
           new Static4D(-SIN54,  0.5f,  0.0f, SIN18 ),
140
           new Static4D(-SIN54, -0.5f,  0.0f, SIN18 ),
141

    
142
           new Static4D(  0.0f,  0.5f, SIN18, SIN54 ), //48
143
           new Static4D(  0.0f,  0.5f,-SIN18, SIN54 ),
144
           new Static4D(  0.0f, -0.5f, SIN18, SIN54 ),
145
           new Static4D(  0.0f, -0.5f,-SIN18, SIN54 ),
146
           new Static4D(  0.5f, SIN18,  0.0f, SIN54 ),
147
           new Static4D(  0.5f,-SIN18,  0.0f, SIN54 ),
148
           new Static4D( -0.5f, SIN18,  0.0f, SIN54 ),
149
           new Static4D( -0.5f,-SIN18,  0.0f, SIN54 ),
150
           new Static4D( SIN18,  0.0f,  0.5f, SIN54 ),
151
           new Static4D( SIN18,  0.0f, -0.5f, SIN54 ),
152
           new Static4D(-SIN18,  0.0f,  0.5f, SIN54 ),
153
           new Static4D(-SIN18,  0.0f, -0.5f, SIN54 ),
154
         };
155

    
156
  // Coordinates of all 20 corners of a Minx
157
  static final float[][] CORNERS = new float[][]
158
         {
159
             {  0.0f,  0.5f,    C2},
160
             {  0.0f,  0.5f,   -C2},
161
             {  0.0f, -0.5f,    C2},
162
             {  0.0f, -0.5f,   -C2},
163
             {    C2,  0.0f,  0.5f},
164
             {    C2,  0.0f, -0.5f},
165
             {   -C2,  0.0f,  0.5f},
166
             {   -C2,  0.0f, -0.5f},
167
             {  0.5f,    C2,  0.0f},
168
             {  0.5f,   -C2,  0.0f},
169
             { -0.5f,    C2,  0.0f},
170
             { -0.5f,   -C2,  0.0f},
171
             { SIN54, SIN54, SIN54},
172
             { SIN54, SIN54,-SIN54},
173
             { SIN54,-SIN54, SIN54},
174
             { SIN54,-SIN54,-SIN54},
175
             {-SIN54, SIN54, SIN54},
176
             {-SIN54, SIN54,-SIN54},
177
             {-SIN54,-SIN54, SIN54},
178
             {-SIN54,-SIN54,-SIN54},
179
         };
180

    
181
  static final int[][] mCornerFaceMap =
182
         {
183
           {  0, 1, 8 },
184
           {  6, 5,10 },
185
           {  1, 0,11 },
186
           {  5, 6, 3 },
187
           {  0, 9, 4 },
188
           {  5, 4, 9 },
189
           {  7, 1, 2 },
190
           {  2, 6, 7 },
191
           { 10, 9, 8 },
192
           {  4, 3,11 },
193
           {  7,10, 8 },
194
           {  3, 2,11 },
195
           {  0, 8, 9 },
196
           {  9,10, 5 },
197
           {  0, 4,11 },
198
           {  4, 5, 3 },
199
           {  1, 7, 8 },
200
           {  7, 6,10 },
201
           {  2, 1,11 },
202
           {  6, 2, 3 },
203
         };
204

    
205
  static final int[] QUAT_EDGE_INDICES =
206
      {
207
        56, 40, 43, 59,  0, 19,  9, 54, 58, 49,
208
        48, 24, 52,  4, 16, 32, 20, 11, 21, 35 ,
209
        37, 30,  8, 28, 36, 44,  1, 46, 12, 47
210
      };
211

    
212

    
213
  static final int[] QUAT_CORNER_INDICES =
214
      {
215
         0,  2,  3,  1, 40, 31, 41, 30, 39, 35,
216
        36, 34, 56, 32, 43, 21, 48, 28, 42, 23
217
      };
218

    
219
  static final boolean[][] OPPOSITE_ROWS =
220
      {
221
          {false,  true, false,  true, false, false},
222
          { true, false, false,  true,  true,  true},
223
          {false, false, false,  true, false,  true},
224
          { true,  true,  true, false, false,  true},
225
          {false,  true, false, false, false,  true},
226
          {false,  true,  true,  true,  true, false}
227
      };
228

    
229
  // the quadruple ( corner1, corner2, face1, face2 ) defining an edge.
230
  // In fact the 2 corners already define it, the faces only provide easy
231
  // way to get to know the colors. Order: arbitrary. Face1 arbitrarily on
232
  // the 'left' or right of vector corner1 --> corner2, according to Quat.
233
  static final int[][] mEdgeMap =
234
         {
235
           {  0, 12,  0,  8}, //0
236
           { 12,  4,  0,  9},
237
           {  4, 14,  0,  4},
238
           { 14,  2,  0, 11},
239
           {  2,  0,  0,  1},
240
           { 14,  9, 11,  4}, //5
241
           {  9, 11, 11,  3},
242
           { 11, 18, 11,  2},
243
           { 18,  2, 11,  1},
244
           { 18,  6,  1,  2},
245
           {  6, 16,  1,  7}, //10
246
           { 16,  0,  1,  8},
247
           { 16, 10,  8,  7},
248
           { 10,  8,  8, 10},
249
           {  8, 12,  8,  9},
250
           {  8, 13,  9, 10}, //15
251
           { 13,  5,  9,  5},
252
           {  5,  4,  9,  4},
253
           {  5, 15,  4,  5},
254
           { 15,  9,  4,  3},
255
           { 11, 19,  2,  3}, //20
256
           { 19,  7,  2,  6},
257
           {  7,  6,  2,  7},
258
           {  7, 17,  7,  6},
259
           { 17, 10,  7, 10},
260
           { 17,  1, 10,  6}, //25
261
           {  1,  3,  5,  6},
262
           {  3, 19,  3,  6},
263
           {  1, 13, 10,  5},
264
           {  3, 15,  5,  3},
265
         };
266

    
267
  // the five vertices that form a given face. Order: the same as colors
268
  // of the faces in TwistyMinx.
269
  static final int[][] mCenterMap =
270
         {
271
           { 0, 12,  4, 14,  2},
272
           { 0,  2, 18,  6, 16},
273
           { 6, 18, 11, 19,  7},
274
           { 3, 15,  9, 11, 19},
275
           { 4,  5, 15,  9, 14},
276
           { 1, 13,  5, 15,  3},
277
           { 1,  3, 19,  7, 17},
278
           {10, 16,  6,  7, 17},
279
           { 0, 12,  8, 10, 16},
280
           { 8, 13,  5,  4, 12},
281
           { 1, 13,  8, 10, 17},
282
           { 2, 14,  9, 11, 18},
283
         };
284

    
285
  static final float[][] mCenterCoords = new float[NUM_CENTERS][3];
286

    
287
  static
288
    {
289
    for(int center=0; center<NUM_CENTERS; center++)
290
      {
291
      int[] map = mCenterMap[center];
292

    
293
      float x = CORNERS[map[0]][0] +
294
                CORNERS[map[1]][0] +
295
                CORNERS[map[2]][0] +
296
                CORNERS[map[3]][0] +
297
                CORNERS[map[4]][0] ;
298

    
299
      float y = CORNERS[map[0]][1] +
300
                CORNERS[map[1]][1] +
301
                CORNERS[map[2]][1] +
302
                CORNERS[map[3]][1] +
303
                CORNERS[map[4]][1] ;
304

    
305
      float z = CORNERS[map[0]][2] +
306
                CORNERS[map[1]][2] +
307
                CORNERS[map[2]][2] +
308
                CORNERS[map[3]][2] +
309
                CORNERS[map[4]][2] ;
310

    
311
      mCenterCoords[center][0] = x/5;
312
      mCenterCoords[center][1] = y/5;
313
      mCenterCoords[center][2] = z/5;
314
      }
315
    }
316

    
317
  static final Static4D[] mBasicCornerV, mCurrCornerV;
318

    
319
  static
320
    {
321
    mBasicCornerV = new Static4D[3];
322
    mCurrCornerV  = new Static4D[3];
323

    
324
    mBasicCornerV[0] = new Static4D( (SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
325
    mBasicCornerV[1] = new Static4D(-(SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
326
    mBasicCornerV[2] = new Static4D(              0,        -0.500f,    0.0f, 0.0f );
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

    
331
  TwistyMinx(int numLayers, int realSize, Static4D quat, DistortedTexture texture, MeshSquare mesh,
332
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
333
    {
334
    super(numLayers, realSize, quat, texture, mesh, effects, moves, obj, res, scrWidth);
335
    }
336

    
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

    
339
  Static4D[] getQuats()
340
    {
341
    return QUATS;
342
    }
343

    
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345

    
346
  int getNumFaces()
347
    {
348
    return FACE_COLORS.length;
349
    }
350

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

    
353
  boolean shouldResetTextureMaps()
354
    {
355
    return false;
356
    }
357

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

    
360
  int getNumCubitFaces()
361
    {
362
    return FACES_PER_CUBIT;
363
    }
364

    
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366

    
367
  float returnMultiplier()
368
    {
369
    return 2.0f;
370
    }
371

    
372
///////////////////////////////////////////////////////////////////////////////////////////////////
373

    
374
  MeshBase createCornerMesh(int numLayers, float width)
375
    {
376
    float A = (2*SQ3/3)*SIN54;
377
    float B = 0.4f;
378
    int   N = numLayers==3 ? 5 : 3;
379
    int   E1= numLayers==3 ? 1 : 0;
380
    int   E2= numLayers==3 ? 3 : 0;
381

    
382
    double X = width*COS18*SIN_HALFD;
383
    double Y = width*SIN18;
384
    double Z = width*COS18*COS_HALFD;
385

    
386
    double[][] vertices = new double[][]
387
        {
388
            { 0.0, 0.0      , 0.0 },
389
            {   X,   Y      ,  -Z },
390
            { 0.0, 2*Y      ,-2*Z },
391
            {  -X,   Y      ,  -Z },
392
            { 0.0, 0.0-width, 0.0 },
393
            {   X,   Y-width,  -Z },
394
            { 0.0, 2*Y-width,-2*Z },
395
            {  -X,   Y-width,  -Z },
396
        };
397

    
398
    int[][] vertIndexes = new int[][]
399
        {
400
            {4,5,1,0},
401
            {7,4,0,3},
402
            {0,1,2,3},
403
            {4,5,6,7},
404
            {6,5,1,2},
405
            {7,6,2,3}
406
        };
407

    
408
    float[][] bands     = new float[][]
409
      {
410
         {0.04f,34,0.3f,0.2f, N, 1, E1},
411
         {0.00f, 0,0.0f,0.0f, 2, 1, E2}
412
      };
413
    int[] bandIndexes   = new int[] { 0,0,0,1,1,1};
414
    float[][] corners   = new float[][] { {0.04f,0.10f} };
415
    int[] cornerIndexes = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
416
    float[][] centers   = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
417
    int[] centerIndexes = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
418

    
419
    FactoryCubit factory = FactoryCubit.getInstance();
420
    factory.createNewFaceTransform(vertices,vertIndexes);
421

    
422
    return factory.createRoundedSolid(vertices, vertIndexes,
423
                                      bands, bandIndexes,
424
                                      corners, cornerIndexes,
425
                                      centers, centerIndexes,
426
                                      getNumCubitFaces() );
427
    }
428

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430
// PUBLIC API
431

    
432
  public Static3D[] getRotationAxis()
433
    {
434
    return ROT_AXIS;
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

    
439
  public int[] getBasicAngle()
440
    {
441
    return BASIC_ANGLE;
442
    }
443

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445

    
446
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
447
    {
448
    int numLayers = getNumLayers();
449

    
450
    if( num==0 )
451
      {
452
      scramble[num][0] = rnd.nextInt(NUM_AXIS);
453
      }
454
    else
455
      {
456
      int newVector = rnd.nextInt(NUM_AXIS -1);
457
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
458
      }
459

    
460
    if( num==0 )
461
      {
462
      int nom = (numLayers-1)/2;
463
      int row = rnd.nextInt(nom);
464
      int lf  = rnd.nextInt(2);
465
      scramble[num][1] = (lf==0 ? row : numLayers-1-row);
466
      }
467
    else
468
      {
469
      int nom = (numLayers-1)/2;
470
      int row = rnd.nextInt(nom);
471
      boolean opposite = OPPOSITE_ROWS[scramble[num-1][0]][scramble[num][0]];
472
      boolean low = opposite^(scramble[num-1][1]<nom);
473
      scramble[num][1] = low ? row : numLayers-1-row;
474
      }
475

    
476
    switch( rnd.nextInt(4) )
477
      {
478
      case 0: scramble[num][2] = -2; break;
479
      case 1: scramble[num][2] = -1; break;
480
      case 2: scramble[num][2] =  1; break;
481
      case 3: scramble[num][2] =  2; break;
482
      }
483
    }
484

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486
// only needed for solvers - there are no Minx solvers ATM)
487

    
488
  public String retObjectString()
489
    {
490
    return "";
491
    }
492
}
(30-30/39)