Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyMinx.java @ 3d8237cc

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 int[] QUAT_EDGE_INDICES
202
    = {
203
        56, 40, 43, 59,  0, 55, 10, 17, 25, 49,
204
        48, 57, 18,  7, 53, 32, 20, 11, 31, 38,
205
        37, 30,  8, 28, 36, 44,  1, 46, 12, 14
206
      };
207

    
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209

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

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
  float getScreenRatio()
219
    {
220
    return 0.9f;
221
    }
222

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

    
225
  Static4D[] getQuats()
226
    {
227
    return QUATS;
228
    }
229

    
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

    
232
  int getNumFaces()
233
    {
234
    return FACE_COLORS.length;
235
    }
236

    
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

    
239
  boolean shouldResetTextureMaps()
240
    {
241
    return false;
242
    }
243

    
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245

    
246
  int getNumCubitFaces()
247
    {
248
    return FACES_PER_CUBIT;
249
    }
250

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

    
253
  float returnMultiplier()
254
    {
255
    return 2.0f;
256
    }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

    
260
  float[] getRowChances(int numLayers)
261
    {
262
    float[] chances = new float[numLayers];
263
    float denom = (float)(numLayers-1);
264
    int change  = (numLayers-1)/2;
265

    
266
    for(int i=     0; i<change   ; i++) chances[i] = (i+1)/denom;
267
    for(int i=change; i<numLayers; i++) chances[i] = (i  )/denom;
268

    
269
    return chances;
270
    }
271

    
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273
// PUBLIC API
274

    
275
  public Static3D[] getRotationAxis()
276
    {
277
    return ROT_AXIS;
278
    }
279

    
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

    
282
  public int getBasicAngle()
283
    {
284
    return 5;
285
    }
286

    
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288

    
289
  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
290
    {
291
    int numAxis = ROTATION_AXIS.length;
292

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

    
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305

    
306
  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
307
    {
308
    float rowFloat = rnd.nextFloat();
309

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

    
315
    return 0;
316
    }
317

    
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319
// only needed for solvers - there are no Minx solvers ATM)
320

    
321
  public String retObjectString()
322
    {
323
    return "";
324
    }
325
}
(25-25/30)