Project

General

Profile

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

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

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 float C0 = (SQ5-1)/4;                       // cos(72 deg)
39
  static final float C1 = (SQ5+1)/4;                       // cos(36 deg)
40
  static final float C2 = (SQ5+3)/4;
41
  static final float LEN= (float)(Math.sqrt(1.25f+0.5f*SQ5));
42

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

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

    
67
  static final int[] FACE_COLORS = new int[]
68
         {
69
           MINX_LGREEN, MINX_PINK   , MINX_SANDY , MINX_LBLUE,
70
           MINX_ORANGE, MINX_VIOLET , MINX_DGREEN, MINX_DRED ,
71
           MINX_DBLUE , MINX_DYELLOW, MINX_WHITE , MINX_GREY
72
         };
73

    
74
  // All 60 legal rotation quats of a Minx
75
  static final Static4D[] QUATS = new Static4D[]
76
         {
77
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
78
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
79
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
80
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
81

    
82
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
83
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
84
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
85
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
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

    
91
           new Static4D(  0.5f,    C1,    C0,  0.0f ),
92
           new Static4D(  0.5f,    C1,   -C0,  0.0f ),
93
           new Static4D(  0.5f,   -C1,    C0,  0.0f ),
94
           new Static4D(  0.5f,   -C1,   -C0,  0.0f ),
95
           new Static4D(    C0,  0.5f,    C1,  0.0f ),
96
           new Static4D(    C0,  0.5f,   -C1,  0.0f ),
97
           new Static4D(   -C0,  0.5f,    C1,  0.0f ),
98
           new Static4D(   -C0,  0.5f,   -C1,  0.0f ),
99
           new Static4D(    C1,    C0,  0.5f,  0.0f ),
100
           new Static4D(    C1,   -C0,  0.5f,  0.0f ),
101
           new Static4D(   -C1,    C0,  0.5f,  0.0f ),
102
           new Static4D(   -C1,   -C0,  0.5f,  0.0f ),
103

    
104
           new Static4D(  0.0f,    C0,    C1,  0.5f ),
105
           new Static4D(  0.0f,    C0,   -C1,  0.5f ),
106
           new Static4D(  0.0f,   -C0,    C1,  0.5f ),
107
           new Static4D(  0.0f,   -C0,   -C1,  0.5f ),
108
           new Static4D(    C0,    C1,  0.0f,  0.5f ),
109
           new Static4D(    C0,   -C1,  0.0f,  0.5f ),
110
           new Static4D(   -C0,    C1,  0.0f,  0.5f ),
111
           new Static4D(   -C0,   -C1,  0.0f,  0.5f ),
112
           new Static4D(    C1,  0.0f,    C0,  0.5f ),
113
           new Static4D(    C1,  0.0f,   -C0,  0.5f ),
114
           new Static4D(   -C1,  0.0f,    C0,  0.5f ),
115
           new Static4D(   -C1,  0.0f,   -C0,  0.5f ),
116

    
117
           new Static4D(  0.0f,    C1,  0.5f,    C0 ),
118
           new Static4D(  0.0f,    C1, -0.5f,    C0 ),
119
           new Static4D(  0.0f,   -C1,  0.5f,    C0 ),
120
           new Static4D(  0.0f,   -C1, -0.5f,    C0 ),
121
           new Static4D(  0.5f,  0.0f,    C1,    C0 ),
122
           new Static4D(  0.5f,  0.0f,   -C1,    C0 ),
123
           new Static4D( -0.5f,  0.0f,    C1,    C0 ),
124
           new Static4D( -0.5f,  0.0f,   -C1,    C0 ),
125
           new Static4D(    C1,  0.5f,  0.0f,    C0 ),
126
           new Static4D(    C1, -0.5f,  0.0f,    C0 ),
127
           new Static4D(   -C1,  0.5f,  0.0f,    C0 ),
128
           new Static4D(   -C1, -0.5f,  0.0f,    C0 ),
129

    
130
           new Static4D(  0.0f,  0.5f,    C0,    C1 ),
131
           new Static4D(  0.0f,  0.5f,   -C0,    C1 ),
132
           new Static4D(  0.0f, -0.5f,    C0,    C1 ),
133
           new Static4D(  0.0f, -0.5f,   -C0,    C1 ),
134
           new Static4D(  0.5f,    C0,  0.0f,    C1 ),
135
           new Static4D(  0.5f,   -C0,  0.0f,    C1 ),
136
           new Static4D( -0.5f,    C0,  0.0f,    C1 ),
137
           new Static4D( -0.5f,   -C0,  0.0f,    C1 ),
138
           new Static4D(    C0,  0.0f,  0.5f,    C1 ),
139
           new Static4D(    C0,  0.0f, -0.5f,    C1 ),
140
           new Static4D(   -C0,  0.0f,  0.5f,    C1 ),
141
           new Static4D(   -C0,  0.0f, -0.5f,    C1 ),
142
         };
143

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

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

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

    
199
  static final boolean[][] OPPOSITE_ROWS =
200
      {
201
          {false,  true, false,  true, false, false},
202
          { true, false, false,  true,  true,  true},
203
          {false, false, false,  true, false,  true},
204
          { true,  true,  true, false, false,  true},
205
          {false,  true, false, false, false,  true},
206
          {false,  true,  true,  true,  true, false}
207
      };
208

    
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210

    
211
  TwistyMinx(int numLayers, int realSize, Static4D quat, DistortedTexture texture, MeshSquare mesh,
212
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
213
    {
214
    super(numLayers, realSize, quat, texture, mesh, effects, moves, obj, res, scrWidth);
215
    }
216

    
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

    
219
  Static4D[] getQuats()
220
    {
221
    return QUATS;
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  int getNumFaces()
227
    {
228
    return FACE_COLORS.length;
229
    }
230

    
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232

    
233
  boolean shouldResetTextureMaps()
234
    {
235
    return false;
236
    }
237

    
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

    
240
  int getNumCubitFaces()
241
    {
242
    return FACES_PER_CUBIT;
243
    }
244

    
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

    
247
  float returnMultiplier()
248
    {
249
    return 2.0f;
250
    }
251

    
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

    
254
  float[] getRowChances(int numLayers)
255
    {
256
    float[] chances = new float[numLayers];
257
    float denom = (float)(numLayers-1);
258
    int change  = (numLayers-1)/2;
259

    
260
    for(int i=     0; i<change   ; i++) chances[i] = (i+1)/denom;
261
    for(int i=change; i<numLayers; i++) chances[i] = (i  )/denom;
262

    
263
    return chances;
264
    }
265

    
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267
// PUBLIC API
268

    
269
  public Static3D[] getRotationAxis()
270
    {
271
    return ROT_AXIS;
272
    }
273

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

    
276
  public int getBasicAngle()
277
    {
278
    return 5;
279
    }
280

    
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

    
283
  public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow,
284
                                   int numScramble, int remScrambles, int remDoubleScrambles)
285
    {
286
    if( numScramble==1 )
287
      {
288
      scramble[0] = rnd.nextInt(ROTATION_AXIS.length);
289
      }
290
    else
291
      {
292
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
293
      scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
294
      }
295

    
296
    if( numScramble==1 )
297
      {
298
      float rowFloat = rnd.nextFloat();
299

    
300
      for(int row=0; row<mRowChances.length; row++)
301
        {
302
        if( rowFloat<=mRowChances[row] )
303
          {
304
          scramble[1] = row;
305
          break;
306
          }
307
        }
308
      }
309
    else
310
      {
311
      int size = mRowChances.length;
312
      int num = (size-1)/2;
313
      int row = rnd.nextInt(num);
314
      boolean opposite = OPPOSITE_ROWS[oldRotAxis][scramble[0]];
315
      boolean low = opposite^(oldRow<num);
316
      scramble[1] = low ? row : size-1-row;
317
      }
318

    
319
    int random = rnd.nextInt(remScrambles);
320
    int result = random<remDoubleScrambles ? 2:1;
321
    int sign   = rnd.nextInt(2);
322

    
323
    scramble[2] = sign==0 ? result : -result;
324
    }
325

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327
// only needed for solvers - there are no Minx solvers ATM)
328

    
329
  public String retObjectString()
330
    {
331
    return "";
332
    }
333
}
(30-30/35)