Project

General

Profile

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

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

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 Static3D[] CORNERS = new Static3D[]
148
         {
149
           new Static3D( 0.0f, 0.5f,   C2),
150
           new Static3D( 0.0f, 0.5f,  -C2),
151
           new Static3D( 0.0f,-0.5f,   C2),
152
           new Static3D( 0.0f,-0.5f,  -C2),
153
           new Static3D(   C2, 0.0f, 0.5f),
154
           new Static3D(   C2, 0.0f,-0.5f),
155
           new Static3D(  -C2, 0.0f, 0.5f),
156
           new Static3D(  -C2, 0.0f,-0.5f),
157
           new Static3D( 0.5f,   C2, 0.0f),
158
           new Static3D( 0.5f,  -C2, 0.0f),
159
           new Static3D(-0.5f,   C2, 0.0f),
160
           new Static3D(-0.5f,  -C2, 0.0f),
161
           new Static3D(   C1,   C1,   C1),
162
           new Static3D(   C1,   C1,  -C1),
163
           new Static3D(   C1,  -C1,   C1),
164
           new Static3D(   C1,  -C1,  -C1),
165
           new Static3D(  -C1,   C1,   C1),
166
           new Static3D(  -C1,   C1,  -C1),
167
           new Static3D(  -C1,  -C1,   C1),
168
           new Static3D(  -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, 30, quat, texture, mesh, effects, moves, obj, res, scrWidth);
217
    }
218

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

    
221
  float getScreenRatio()
222
    {
223
    return 0.9f;
224
    }
225

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

    
228
  Static4D[] getQuats()
229
    {
230
    return QUATS;
231
    }
232

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

    
235
  int getNumFaces()
236
    {
237
    return FACE_COLORS.length;
238
    }
239

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

    
242
  boolean shouldResetTextureMaps()
243
    {
244
    return false;
245
    }
246

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

    
249
  int getNumCubitFaces()
250
    {
251
    return FACES_PER_CUBIT;
252
    }
253

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

    
256
  float returnMultiplier()
257
    {
258
    return 2.0f;
259
    }
260

    
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262

    
263
  float[] getRowChances(int numLayers)
264
    {
265
    float[] chances = new float[numLayers];
266
    float denom = (float)(numLayers-1);
267
    int change  = (numLayers-1)/2;
268

    
269
    for(int i=     0; i<change   ; i++) chances[i] = (i+1)/denom;
270
    for(int i=change; i<numLayers; i++) chances[i] = (i  )/denom;
271

    
272
    return chances;
273
    }
274

    
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276
// PUBLIC API
277

    
278
  public Static3D[] getRotationAxis()
279
    {
280
    return ROT_AXIS;
281
    }
282

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

    
285
  public int getBasicAngle()
286
    {
287
    return 5;
288
    }
289

    
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

    
292
  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
293
    {
294
    int numAxis = ROTATION_AXIS.length;
295

    
296
    if( oldRotAxis == START_AXIS )
297
      {
298
      return rnd.nextInt(numAxis);
299
      }
300
    else
301
      {
302
      int newVector = rnd.nextInt(numAxis-1);
303
      return (newVector>=oldRotAxis ? newVector+1 : newVector);
304
      }
305
    }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

    
309
  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
310
    {
311
    if( oldRotAxis<0 )
312
      {
313
      float rowFloat = rnd.nextFloat();
314

    
315
      for(int row=0; row<mRowChances.length; row++)
316
        {
317
        if( rowFloat<=mRowChances[row] ) return row;
318
        }
319

    
320
      return 0;
321
      }
322
    else
323
      {
324
      int size = mRowChances.length;
325
      int num = (size-1)/2;
326
      int row = rnd.nextInt(num);
327
      boolean opposite = OPPOSITE_ROWS[oldRotAxis][newRotAxis];
328
      boolean low = opposite^(oldRow<num);
329
      return low ? row : size-1-row;
330
      }
331
    }
332

    
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334
// only needed for solvers - there are no Minx solvers ATM)
335

    
336
  public String retObjectString()
337
    {
338
    return "";
339
    }
340
}
(25-25/30)