Project

General

Profile

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

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

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.library.main.DistortedEffects;
25
import org.distorted.library.main.DistortedTexture;
26
import org.distorted.library.mesh.MeshSquare;
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import java.util.Random;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

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

    
38
  static final int NUM_CORNERS = 20;
39
  static final int NUM_CENTERS = 12;
40
  static final int NUM_EDGES   = 30;
41

    
42
  static final float C0 = (SQ5-1)/4;                       // cos(72 deg)
43
  static final float C1 = (SQ5+1)/4;                       // cos(36 deg)
44
  static final float C2 = (SQ5+3)/4;
45
  static final float LEN= (float)(Math.sqrt(1.25f+0.5f*SQ5));
46

    
47
  // the six rotation axis of a Minx. Must be normalized.
48
  static final Static3D[] ROT_AXIS = new Static3D[]
49
         {
50
           new Static3D( C2/LEN, C1/LEN, 0      ),
51
           new Static3D(-C2/LEN, C1/LEN, 0      ),
52
           new Static3D( 0     , C2/LEN, C1/LEN ),
53
           new Static3D( 0     ,-C2/LEN, C1/LEN ),
54
           new Static3D( C1/LEN, 0     , C2/LEN ),
55
           new Static3D( C1/LEN, 0     ,-C2/LEN )
56
         };
57

    
58
  private static final int MINX_LGREEN = 0xff53aa00;
59
  private static final int MINX_PINK   = 0xfffd7ab7;
60
  private static final int MINX_SANDY  = 0xffefd48b;
61
  private static final int MINX_LBLUE  = 0xff00a2d7;
62
  private static final int MINX_ORANGE = 0xffff6200;
63
  private static final int MINX_VIOLET = 0xff7d59a4;
64
  private static final int MINX_DGREEN = 0xff007a47;
65
  private static final int MINX_DRED   = 0xffbd0000;
66
  private static final int MINX_DBLUE  = 0xff1a29b2;
67
  private static final int MINX_DYELLOW= 0xffffc400;
68
  private static final int MINX_WHITE  = 0xffffffff;
69
  private static final int MINX_GREY   = 0xff727c7b;
70

    
71
  static final int[] FACE_COLORS = new int[]
72
         {
73
           MINX_LGREEN, MINX_PINK   , MINX_SANDY , MINX_LBLUE,
74
           MINX_ORANGE, MINX_VIOLET , MINX_DGREEN, MINX_DRED ,
75
           MINX_DBLUE , MINX_DYELLOW, MINX_WHITE , MINX_GREY
76
         };
77

    
78
  // All 60 legal rotation quats of a Minx
79
  static final Static4D[] QUATS = new Static4D[]
80
         {
81
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
82
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
83
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
84
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
85

    
86
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
87
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
88
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
89
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
90
           new Static4D( -0.5f,  0.5f,  0.5f,  0.5f ),
91
           new Static4D( -0.5f,  0.5f, -0.5f,  0.5f ),
92
           new Static4D( -0.5f, -0.5f,  0.5f,  0.5f ),
93
           new Static4D( -0.5f, -0.5f, -0.5f,  0.5f ),
94

    
95
           new Static4D(  0.5f,    C1,    C0,  0.0f ),
96
           new Static4D(  0.5f,    C1,   -C0,  0.0f ),
97
           new Static4D(  0.5f,   -C1,    C0,  0.0f ),
98
           new Static4D(  0.5f,   -C1,   -C0,  0.0f ),
99
           new Static4D(    C0,  0.5f,    C1,  0.0f ),
100
           new Static4D(    C0,  0.5f,   -C1,  0.0f ),
101
           new Static4D(   -C0,  0.5f,    C1,  0.0f ),
102
           new Static4D(   -C0,  0.5f,   -C1,  0.0f ),
103
           new Static4D(    C1,    C0,  0.5f,  0.0f ),
104
           new Static4D(    C1,   -C0,  0.5f,  0.0f ),
105
           new Static4D(   -C1,    C0,  0.5f,  0.0f ),
106
           new Static4D(   -C1,   -C0,  0.5f,  0.0f ),
107

    
108
           new Static4D(  0.0f,    C0,    C1,  0.5f ),
109
           new Static4D(  0.0f,    C0,   -C1,  0.5f ),
110
           new Static4D(  0.0f,   -C0,    C1,  0.5f ),
111
           new Static4D(  0.0f,   -C0,   -C1,  0.5f ),
112
           new Static4D(    C0,    C1,  0.0f,  0.5f ),
113
           new Static4D(    C0,   -C1,  0.0f,  0.5f ),
114
           new Static4D(   -C0,    C1,  0.0f,  0.5f ),
115
           new Static4D(   -C0,   -C1,  0.0f,  0.5f ),
116
           new Static4D(    C1,  0.0f,    C0,  0.5f ),
117
           new Static4D(    C1,  0.0f,   -C0,  0.5f ),
118
           new Static4D(   -C1,  0.0f,    C0,  0.5f ),
119
           new Static4D(   -C1,  0.0f,   -C0,  0.5f ),
120

    
121
           new Static4D(  0.0f,    C1,  0.5f,    C0 ),
122
           new Static4D(  0.0f,    C1, -0.5f,    C0 ),
123
           new Static4D(  0.0f,   -C1,  0.5f,    C0 ),
124
           new Static4D(  0.0f,   -C1, -0.5f,    C0 ),
125
           new Static4D(  0.5f,  0.0f,    C1,    C0 ),
126
           new Static4D(  0.5f,  0.0f,   -C1,    C0 ),
127
           new Static4D( -0.5f,  0.0f,    C1,    C0 ),
128
           new Static4D( -0.5f,  0.0f,   -C1,    C0 ),
129
           new Static4D(    C1,  0.5f,  0.0f,    C0 ),
130
           new Static4D(    C1, -0.5f,  0.0f,    C0 ),
131
           new Static4D(   -C1,  0.5f,  0.0f,    C0 ),
132
           new Static4D(   -C1, -0.5f,  0.0f,    C0 ),
133

    
134
           new Static4D(  0.0f,  0.5f,    C0,    C1 ),
135
           new Static4D(  0.0f,  0.5f,   -C0,    C1 ),
136
           new Static4D(  0.0f, -0.5f,    C0,    C1 ),
137
           new Static4D(  0.0f, -0.5f,   -C0,    C1 ),
138
           new Static4D(  0.5f,    C0,  0.0f,    C1 ),
139
           new Static4D(  0.5f,   -C0,  0.0f,    C1 ),
140
           new Static4D( -0.5f,    C0,  0.0f,    C1 ),
141
           new Static4D( -0.5f,   -C0,  0.0f,    C1 ),
142
           new Static4D(    C0,  0.0f,  0.5f,    C1 ),
143
           new Static4D(    C0,  0.0f, -0.5f,    C1 ),
144
           new Static4D(   -C0,  0.0f,  0.5f,    C1 ),
145
           new Static4D(   -C0,  0.0f, -0.5f,    C1 ),
146
         };
147

    
148
  // Coordinates of all 20 corners of a Minx
149
  static final float[][] CORNERS = new float[][]
150
         {
151
             { 0.0f, 0.5f,   C2},
152
             { 0.0f, 0.5f,  -C2},
153
             { 0.0f,-0.5f,   C2},
154
             { 0.0f,-0.5f,  -C2},
155
             {   C2, 0.0f, 0.5f},
156
             {   C2, 0.0f,-0.5f},
157
             {  -C2, 0.0f, 0.5f},
158
             {  -C2, 0.0f,-0.5f},
159
             { 0.5f,   C2, 0.0f},
160
             { 0.5f,  -C2, 0.0f},
161
             {-0.5f,   C2, 0.0f},
162
             {-0.5f,  -C2, 0.0f},
163
             {   C1,   C1,   C1},
164
             {   C1,   C1,  -C1},
165
             {   C1,  -C1,   C1},
166
             {   C1,  -C1,  -C1},
167
             {  -C1,   C1,   C1},
168
             {  -C1,   C1,  -C1},
169
             {  -C1,  -C1,   C1},
170
             {  -C1,  -C1,  -C1},
171
         };
172

    
173
  static final int[][] mCornerFaceMap =
174
         {
175
           {  0, 1, 8 },
176
           {  6, 5,10 },
177
           {  1, 0,11 },
178
           {  5, 6, 3 },
179
           {  0, 9, 4 },
180
           {  5, 4, 9 },
181
           {  7, 1, 2 },
182
           {  2, 6, 7 },
183
           { 10, 9, 8 },
184
           {  4, 3,11 },
185
           {  7,10, 8 },
186
           {  3, 2,11 },
187
           {  0, 8, 9 },
188
           {  9,10, 5 },
189
           {  0, 4,11 },
190
           {  4, 5, 3 },
191
           {  1, 7, 8 },
192
           {  7, 6,10 },
193
           {  2, 1,11 },
194
           {  6, 2, 3 },
195
         };
196

    
197
  static final int[] QUAT_CORNER_INDICES =
198
      {
199
         0,  2,  3,  1, 40, 31, 41, 30, 39, 35,
200
        36, 34, 56, 32, 43, 21, 48, 28, 42, 23
201
      };
202

    
203
  static final boolean[][] OPPOSITE_ROWS =
204
      {
205
          {false,  true, false,  true, false, false},
206
          { true, false, false,  true,  true,  true},
207
          {false, false, false,  true, false,  true},
208
          { true,  true,  true, false, false,  true},
209
          {false,  true, false, false, false,  true},
210
          {false,  true,  true,  true,  true, false}
211
      };
212

    
213
  // the quadruple ( vertex1, vertex2, face1, face2 ) defining an edge.
214
  // In fact the 2 vertices already define it, the faces only provide easy
215
  // way to get to know the colors. Order: arbitrary. Face1 arbitrarily on
216
  // the 'left' or right of vector vertex1 --> vertex2, according to Quat.
217
  static final int[][] mEdgeMap =
218
         {
219
           {  0, 12,  0,  8},
220
           { 12,  4,  0,  9},
221
           {  4, 14,  0,  4},
222
           { 14,  2,  0, 11},
223
           {  2,  0,  0,  1},
224
           { 14,  9,  4, 11},
225
           {  9, 11,  3, 11},
226
           { 11, 18,  2, 11},
227
           { 18,  2,  1, 11},
228
           { 18,  6,  1,  2},
229
           {  6, 16,  1,  7},
230
           { 16,  0,  8,  1},
231
           { 16, 10,  7,  8},
232
           { 10,  8, 10,  8},
233
           {  8, 12,  9,  8},
234
           {  8, 13,  9, 10},
235
           { 13,  5,  9,  5},
236
           {  5,  4,  9,  4},
237
           {  5, 15,  5,  4},
238
           { 15,  9,  3,  4},
239
           { 11, 19,  2,  3},
240
           { 19,  7,  2,  6},
241
           {  7,  6,  2,  7},
242
           {  7, 17,  7,  6},
243
           { 17, 10,  7, 10},
244
           { 17,  1, 10,  6},
245
           {  1,  3,  5,  6},
246
           {  3, 19,  3,  6},
247
           {  1, 13, 10,  5},
248
           {  3, 15,  3,  5},
249
         };
250

    
251
  // the five vertices that form a given face. Order: the same as colors
252
  // of the faces in TwistyMinx.
253
  static final int[][] mCenterMap =
254
         {
255
           { 0, 12,  4, 14,  2},
256
           { 0,  2, 18,  6, 16},
257
           { 6, 18, 11, 19,  7},
258
           { 3, 15,  9, 11, 19},
259
           { 4,  5, 15,  9, 14},
260
           { 1, 13,  5, 15,  3},
261
           { 1,  3, 19,  7, 17},
262
           {10, 16,  6,  7, 17},
263
           { 0, 12,  8, 10, 16},
264
           { 8, 13,  5,  4, 12},
265
           { 1, 13,  8, 10, 17},
266
           { 2, 14,  9, 11, 18},
267
         };
268

    
269
  static final float[][] mCenterCoords = new float[NUM_CENTERS][3];
270

    
271
  static
272
    {
273
    for(int center=0; center<NUM_CENTERS; center++)
274
      {
275
      int[] map = mCenterMap[center];
276

    
277
      float x = CORNERS[map[0]][0] +
278
                CORNERS[map[1]][0] +
279
                CORNERS[map[2]][0] +
280
                CORNERS[map[3]][0] +
281
                CORNERS[map[4]][0] ;
282

    
283
      float y = CORNERS[map[0]][1] +
284
                CORNERS[map[1]][1] +
285
                CORNERS[map[2]][1] +
286
                CORNERS[map[3]][1] +
287
                CORNERS[map[4]][1] ;
288

    
289
      float z = CORNERS[map[0]][2] +
290
                CORNERS[map[1]][2] +
291
                CORNERS[map[2]][2] +
292
                CORNERS[map[3]][2] +
293
                CORNERS[map[4]][2] ;
294

    
295
      mCenterCoords[center][0] = x/5;
296
      mCenterCoords[center][1] = y/5;
297
      mCenterCoords[center][2] = z/5;
298
      }
299
    }
300

    
301
  static final Static4D[] mBasicCornerV, mCurrCornerV;
302

    
303
  static
304
    {
305
    mBasicCornerV = new Static4D[3];
306
    mCurrCornerV  = new Static4D[3];
307

    
308
    mBasicCornerV[0] = new Static4D( (SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
309
    mBasicCornerV[1] = new Static4D(-(SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
310
    mBasicCornerV[2] = new Static4D(              0,        -0.500f,    0.0f, 0.0f );
311
    }
312

    
313

    
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315

    
316
  TwistyMinx(int numLayers, int realSize, Static4D quat, DistortedTexture texture, MeshSquare mesh,
317
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
318
    {
319
    super(numLayers, realSize, quat, texture, mesh, effects, moves, obj, res, scrWidth);
320
    }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
  Static4D[] getQuats()
325
    {
326
    return QUATS;
327
    }
328

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

    
331
  int getNumFaces()
332
    {
333
    return FACE_COLORS.length;
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  boolean shouldResetTextureMaps()
339
    {
340
    return false;
341
    }
342

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344

    
345
  int getNumCubitFaces()
346
    {
347
    return FACES_PER_CUBIT;
348
    }
349

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351

    
352
  float returnMultiplier()
353
    {
354
    return 2.0f;
355
    }
356

    
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358

    
359
  float[] getRowChances(int numLayers)
360
    {
361
    float[] chances = new float[numLayers];
362
    float denom = (float)(numLayers-1);
363
    int change  = (numLayers-1)/2;
364

    
365
    for(int i=     0; i<change   ; i++) chances[i] = (i+1)/denom;
366
    for(int i=change; i<numLayers; i++) chances[i] = (i  )/denom;
367

    
368
    return chances;
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372
// PUBLIC API
373

    
374
  public Static3D[] getRotationAxis()
375
    {
376
    return ROT_AXIS;
377
    }
378

    
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

    
381
  public int getBasicAngle()
382
    {
383
    return 5;
384
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

    
388
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
389
    {
390
    if( num==0 )
391
      {
392
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
393
      }
394
    else
395
      {
396
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
397
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
398
      }
399

    
400
    if( num==0 )
401
      {
402
      float rowFloat = rnd.nextFloat();
403

    
404
      for(int row=0; row<mRowChances.length; row++)
405
        {
406
        if( rowFloat<=mRowChances[row] )
407
          {
408
          scramble[num][1] = row;
409
          break;
410
          }
411
        }
412
      }
413
    else
414
      {
415
      int size = mRowChances.length;
416
      int nom = (size-1)/2;
417
      int row = rnd.nextInt(nom);
418
      boolean opposite = OPPOSITE_ROWS[scramble[num-1][0]][scramble[num][0]];
419
      boolean low = opposite^(scramble[num-1][1]<nom);
420
      scramble[num][1] = low ? row : size-1-row;
421
      }
422

    
423
    switch( rnd.nextInt(4) )
424
      {
425
      case 0: scramble[num][2] = -2; break;
426
      case 1: scramble[num][2] = -1; break;
427
      case 2: scramble[num][2] =  1; break;
428
      case 3: scramble[num][2] =  2; break;
429
      }
430
    }
431

    
432
///////////////////////////////////////////////////////////////////////////////////////////////////
433
// only needed for solvers - there are no Minx solvers ATM)
434

    
435
  public String retObjectString()
436
    {
437
    return "";
438
    }
439
}
(30-30/35)