Project

General

Profile

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

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

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_INDICES = {0,2,3,1,40,31,41,30,39,35,36,34,56,32,43,21,48,28,42,23};
196

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

    
199
  TwistyMinx(int numLayers, int realSize, Static4D quat, DistortedTexture texture, MeshSquare mesh,
200
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
201
    {
202
    super(numLayers, realSize, 30, quat, texture, mesh, effects, moves, obj, res, scrWidth);
203
    }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

    
207
  float getScreenRatio()
208
    {
209
    return 0.9f;
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  Static4D[] getQuats()
215
    {
216
    return QUATS;
217
    }
218

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

    
221
  int getNumFaces()
222
    {
223
    return FACE_COLORS.length;
224
    }
225

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

    
228
  boolean shouldResetTextureMaps()
229
    {
230
    return false;
231
    }
232

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

    
235
  int getNumCubitFaces()
236
    {
237
    return FACES_PER_CUBIT;
238
    }
239

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

    
242
  float returnMultiplier()
243
    {
244
    return 2.0f;
245
    }
246

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

    
249
  float[] getRowChances(int numLayers)
250
    {
251
    float[] chances = new float[numLayers];
252
    float denom = (float)(numLayers-1);
253
    int change  = (numLayers-1)/2;
254

    
255
    for(int i=     0; i<change   ; i++) chances[i] = (i+1)/denom;
256
    for(int i=change; i<numLayers; i++) chances[i] = (i  )/denom;
257

    
258
    return chances;
259
    }
260

    
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262
// PUBLIC API
263

    
264
  public Static3D[] getRotationAxis()
265
    {
266
    return ROT_AXIS;
267
    }
268

    
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270

    
271
  public int getBasicAngle()
272
    {
273
    return 5;
274
    }
275

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

    
278
  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
279
    {
280
    int numAxis = ROTATION_AXIS.length;
281

    
282
    if( oldRotAxis == START_AXIS )
283
      {
284
      return rnd.nextInt(numAxis);
285
      }
286
    else
287
      {
288
      int newVector = rnd.nextInt(numAxis-1);
289
      return (newVector>=oldRotAxis ? newVector+1 : newVector);
290
      }
291
    }
292

    
293
///////////////////////////////////////////////////////////////////////////////////////////////////
294

    
295
  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
296
    {
297
    float rowFloat = rnd.nextFloat();
298

    
299
    for(int row=0; row<mRowChances.length; row++)
300
      {
301
      if( rowFloat<=mRowChances[row] ) return row;
302
      }
303

    
304
    return 0;
305
    }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308
// only needed for solvers - there are no Minx solvers ATM)
309

    
310
  public String retObjectString()
311
    {
312
    return "";
313
    }
314
}
(25-25/30)