Project

General

Profile

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

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

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
import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS;
33

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

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

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

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

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

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

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

    
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
           new Static4D( -0.5f, -0.5f,  0.5f,  0.5f ),
91
           new Static4D( -0.5f, -0.5f, -0.5f,  0.5f ),
92

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

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

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

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

    
146
  // Coordinates of all 20 corners of a Minx
147
  static final float[][] CORNERS = new float[][]
148
         {
149
             { 0.0f, 0.5f,   C2},
150
             { 0.0f, 0.5f,  -C2},
151
             { 0.0f,-0.5f,   C2},
152
             { 0.0f,-0.5f,  -C2},
153
             {   C2, 0.0f, 0.5f},
154
             {   C2, 0.0f,-0.5f},
155
             {  -C2, 0.0f, 0.5f},
156
             {  -C2, 0.0f,-0.5f},
157
             { 0.5f,   C2, 0.0f},
158
             { 0.5f,  -C2, 0.0f},
159
             {-0.5f,   C2, 0.0f},
160
             {-0.5f,  -C2, 0.0f},
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
             {  -C1,  -C1,   C1},
168
             {  -C1,  -C1,  -C1},
169
         };
170

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

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

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

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

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

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
  Static4D[] getQuats()
222
    {
223
    return QUATS;
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
  int getNumFaces()
229
    {
230
    return FACE_COLORS.length;
231
    }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
  boolean shouldResetTextureMaps()
236
    {
237
    return false;
238
    }
239

    
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

    
242
  int getNumCubitFaces()
243
    {
244
    return FACES_PER_CUBIT;
245
    }
246

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

    
249
  float returnMultiplier()
250
    {
251
    return 2.0f;
252
    }
253

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

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

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

    
265
    return chances;
266
    }
267

    
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269
// PUBLIC API
270

    
271
  public Static3D[] getRotationAxis()
272
    {
273
    return ROT_AXIS;
274
    }
275

    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

    
278
  public int getBasicAngle()
279
    {
280
    return 5;
281
    }
282

    
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

    
285
  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
286
    {
287
    int numAxis = ROTATION_AXIS.length;
288

    
289
    if( oldRotAxis == START_AXIS )
290
      {
291
      return rnd.nextInt(numAxis);
292
      }
293
    else
294
      {
295
      int newVector = rnd.nextInt(numAxis-1);
296
      return (newVector>=oldRotAxis ? newVector+1 : newVector);
297
      }
298
    }
299

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

    
302
  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
303
    {
304
    if( oldRotAxis<0 )
305
      {
306
      float rowFloat = rnd.nextFloat();
307

    
308
      for(int row=0; row<mRowChances.length; row++)
309
        {
310
        if( rowFloat<=mRowChances[row] ) return row;
311
        }
312

    
313
      return 0;
314
      }
315
    else
316
      {
317
      int size = mRowChances.length;
318
      int num = (size-1)/2;
319
      int row = rnd.nextInt(num);
320
      boolean opposite = OPPOSITE_ROWS[oldRotAxis][newRotAxis];
321
      boolean low = opposite^(oldRow<num);
322
      return low ? row : size-1-row;
323
      }
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)