Project

General

Profile

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

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

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
import android.graphics.Canvas;
24
import android.graphics.Paint;
25

    
26
import org.distorted.library.effect.MatrixEffectQuaternion;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshBase;
30
import org.distorted.library.mesh.MeshSquare;
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33
import org.distorted.main.R;
34

    
35
import java.util.Random;
36

    
37
import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
public class TwistyMinx extends TwistyObject
42
{
43
  private static final int FACES_PER_CUBIT =6;
44

    
45
  static final float C0 = (SQ5-1)/4;                       // cos(72 deg)
46
  static final float C1 = (SQ5+1)/4;                       // cos(36 deg)
47
  static final float C2 = (SQ5+3)/4;
48
  static final float C3 = (float)(Math.sqrt(10-2*SQ5)/4);  // cos(54 deg)
49

    
50
  // the six rotation axis of a RubikMegaminx. Must be normalized.
51
  static final Static3D[] ROT_AXIS = new Static3D[]
52
         {
53
           new Static3D( C1/(2*C3), 1/(2*C3) , 0        ),
54
           new Static3D(-C1/(2*C3), 1/(2*C3) , 0        ),
55
           new Static3D( 0        , C1/(2*C3), 1/(2*C3) ),
56
           new Static3D( 0        ,-C1/(2*C3), 1/(2*C3) ),
57
           new Static3D( 1/(2*C3) , 0        , C1/(2*C3)),
58
           new Static3D( 1/(2*C3) , 0        ,-C1/(2*C3))
59
         };
60

    
61
  private static final int MINX_LGREEN = 0xff53aa00;
62
  private static final int MINX_PINK   = 0xfffd7ab7;
63
  private static final int MINX_SANDY  = 0xffefd48b;
64
  private static final int MINX_LBLUE  = 0xff00a2d7;
65
  private static final int MINX_ORANGE = 0xffff6200;
66
  private static final int MINX_VIOLET = 0xff7d59a4;
67
  private static final int MINX_DGREEN = 0xff007a47;
68
  private static final int MINX_DRED   = 0xffbd0000;
69
  private static final int MINX_DBLUE  = 0xff1a29b2;
70
  private static final int MINX_DYELLOW= 0xffffc400;
71
  private static final int MINX_WHITE  = 0xffffffff;
72
  private static final int MINX_GREY   = 0xff727c7b;
73

    
74
  private static final int[] FACE_COLORS = new int[]
75
         {
76
           MINX_LGREEN, MINX_PINK   , MINX_SANDY , MINX_LBLUE,
77
           MINX_ORANGE, MINX_VIOLET , MINX_DGREEN, MINX_DRED ,
78
           MINX_DBLUE , MINX_DYELLOW, MINX_WHITE , MINX_GREY
79
         };
80

    
81
  // All 60 legal rotation quats of a RubikMegaminx
82
  private static final Static4D[] QUATS = new Static4D[]
83
         {
84
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
85
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
86
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
87
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
88

    
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
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
93
           new Static4D( -0.5f,  0.5f,  0.5f,  0.5f ),
94
           new Static4D( -0.5f,  0.5f, -0.5f,  0.5f ),
95
           new Static4D( -0.5f, -0.5f,  0.5f,  0.5f ),
96
           new Static4D( -0.5f, -0.5f, -0.5f,  0.5f ),
97

    
98
           new Static4D(  0.5f,    C1,    C0,  0.0f ),
99
           new Static4D(  0.5f,    C1,   -C0,  0.0f ),
100
           new Static4D(  0.5f,   -C1,    C0,  0.0f ),
101
           new Static4D(  0.5f,   -C1,   -C0,  0.0f ),
102
           new Static4D(    C0,  0.5f,    C1,  0.0f ),
103
           new Static4D(    C0,  0.5f,   -C1,  0.0f ),
104
           new Static4D(   -C0,  0.5f,    C1,  0.0f ),
105
           new Static4D(   -C0,  0.5f,   -C1,  0.0f ),
106
           new Static4D(    C1,    C0,  0.5f,  0.0f ),
107
           new Static4D(    C1,   -C0,  0.5f,  0.0f ),
108
           new Static4D(   -C1,    C0,  0.5f,  0.0f ),
109
           new Static4D(   -C1,   -C0,  0.5f,  0.0f ),
110

    
111
           new Static4D(  0.0f,    C0,    C1,  0.5f ),
112
           new Static4D(  0.0f,    C0,   -C1,  0.5f ),
113
           new Static4D(  0.0f,   -C0,    C1,  0.5f ),
114
           new Static4D(  0.0f,   -C0,   -C1,  0.5f ),
115
           new Static4D(    C0,    C1,  0.0f,  0.5f ),
116
           new Static4D(    C0,   -C1,  0.0f,  0.5f ),
117
           new Static4D(   -C0,    C1,  0.0f,  0.5f ),
118
           new Static4D(   -C0,   -C1,  0.0f,  0.5f ),
119
           new Static4D(    C1,  0.0f,    C0,  0.5f ),
120
           new Static4D(    C1,  0.0f,   -C0,  0.5f ),
121
           new Static4D(   -C1,  0.0f,    C0,  0.5f ),
122
           new Static4D(   -C1,  0.0f,   -C0,  0.5f ),
123

    
124
           new Static4D(  0.0f,    C1,  0.5f,    C0 ),
125
           new Static4D(  0.0f,    C1, -0.5f,    C0 ),
126
           new Static4D(  0.0f,   -C1,  0.5f,    C0 ),
127
           new Static4D(  0.0f,   -C1, -0.5f,    C0 ),
128
           new Static4D(  0.5f,  0.0f,    C1,    C0 ),
129
           new Static4D(  0.5f,  0.0f,   -C1,    C0 ),
130
           new Static4D( -0.5f,  0.0f,    C1,    C0 ),
131
           new Static4D( -0.5f,  0.0f,   -C1,    C0 ),
132
           new Static4D(    C1,  0.5f,  0.0f,    C0 ),
133
           new Static4D(    C1, -0.5f,  0.0f,    C0 ),
134
           new Static4D(   -C1,  0.5f,  0.0f,    C0 ),
135
           new Static4D(   -C1, -0.5f,  0.0f,    C0 ),
136

    
137
           new Static4D(  0.0f,  0.5f,    C0,    C1 ),
138
           new Static4D(  0.0f,  0.5f,   -C0,    C1 ),
139
           new Static4D(  0.0f, -0.5f,    C0,    C1 ),
140
           new Static4D(  0.0f, -0.5f,   -C0,    C1 ),
141
           new Static4D(  0.5f,    C0,  0.0f,    C1 ),
142
           new Static4D(  0.5f,   -C0,  0.0f,    C1 ),
143
           new Static4D( -0.5f,    C0,  0.0f,    C1 ),
144
           new Static4D( -0.5f,   -C0,  0.0f,    C1 ),
145
           new Static4D(    C0,  0.0f,  0.5f,    C1 ),
146
           new Static4D(    C0,  0.0f, -0.5f,    C1 ),
147
           new Static4D(   -C0,  0.0f,  0.5f,    C1 ),
148
           new Static4D(   -C0,  0.0f, -0.5f,    C1 ),
149
         };
150

    
151
  private static final int[][] mFaceMap =
152
         {
153
           {  0, 1, 8, 12,12,12 },
154
           {  6, 5,10, 12,12,12 },
155
           {  1, 0,11, 12,12,12 },
156
           {  5, 6, 3, 12,12,12 },
157
           {  0, 9, 4, 12,12,12 },
158
           {  5, 4, 9, 12,12,12 },
159
           {  7, 1, 2, 12,12,12 },
160
           {  2, 6, 7, 12,12,12 },
161
           { 10, 9, 8, 12,12,12 },
162
           {  4, 3,11, 12,12,12 },
163
           {  7,10, 8, 12,12,12 },
164
           {  3, 2,11, 12,12,12 },
165
           {  0, 8, 9, 12,12,12 },
166
           {  9,10, 5, 12,12,12 },
167
           {  0, 4,11, 12,12,12 },
168
           {  4, 5, 3, 12,12,12 },
169
           {  1, 7, 8, 12,12,12 },
170
           {  7, 6,10, 12,12,12 },
171
           {  2, 1,11, 12,12,12 },
172
           {  6, 2, 3, 12,12,12 },
173
         };
174

    
175
  private static MeshBase mMesh;
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  TwistyMinx(int size, Static4D quat, DistortedTexture texture,
180
             MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
181
    {
182
    super(size, size, 60, quat, texture, mesh, effects, moves, ObjectList.MINX, res, scrWidth);
183
    }
184

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

    
187
  float getScreenRatio()
188
    {
189
    return 0.9f;
190
    }
191

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

    
194
  Static4D[] getQuats()
195
    {
196
    return QUATS;
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
  int getNumFaces()
202
    {
203
    return FACE_COLORS.length;
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  boolean shouldResetTextureMaps()
209
    {
210
    return false;
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
  int getNumStickerTypes()
216
    {
217
    return 1;
218
    }
219

    
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

    
222
  float[] getCuts(int numLayers)
223
    {
224
    return new float[] { -0.5f , 0.5f };
225
    }
226

    
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228

    
229
  int getNumCubitFaces()
230
    {
231
    return FACES_PER_CUBIT;
232
    }
233

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

    
236
  Static3D[] getCubitPositions(int numLayers)
237
    {
238
    final Static3D[] CENTERS = new Static3D[20];
239

    
240
    CENTERS[ 0] = new Static3D( 0.0f, 0.5f,   C2);
241
    CENTERS[ 1] = new Static3D( 0.0f, 0.5f,  -C2);
242
    CENTERS[ 2] = new Static3D( 0.0f,-0.5f,   C2);
243
    CENTERS[ 3] = new Static3D( 0.0f,-0.5f,  -C2);
244
    CENTERS[ 4] = new Static3D(   C2, 0.0f, 0.5f);
245
    CENTERS[ 5] = new Static3D(   C2, 0.0f,-0.5f);
246
    CENTERS[ 6] = new Static3D(  -C2, 0.0f, 0.5f);
247
    CENTERS[ 7] = new Static3D(  -C2, 0.0f,-0.5f);
248
    CENTERS[ 8] = new Static3D( 0.5f,   C2, 0.0f);
249
    CENTERS[ 9] = new Static3D( 0.5f,  -C2, 0.0f);
250
    CENTERS[10] = new Static3D(-0.5f,   C2, 0.0f);
251
    CENTERS[11] = new Static3D(-0.5f,  -C2, 0.0f);
252
    CENTERS[12] = new Static3D(   C1,   C1,   C1);
253
    CENTERS[13] = new Static3D(   C1,   C1,  -C1);
254
    CENTERS[14] = new Static3D(   C1,  -C1,   C1);
255
    CENTERS[15] = new Static3D(   C1,  -C1,  -C1);
256
    CENTERS[16] = new Static3D(  -C1,   C1,   C1);
257
    CENTERS[17] = new Static3D(  -C1,   C1,  -C1);
258
    CENTERS[18] = new Static3D(  -C1,  -C1,   C1);
259
    CENTERS[19] = new Static3D(  -C1,  -C1,  -C1);
260

    
261
    return CENTERS;
262
    }
263

    
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

    
266
  private int getQuat(int cubit)
267
    {
268
    switch(cubit)
269
      {
270
      case  0: return 0;
271
      case  1: return 2;
272
      case  2: return 3;
273
      case  3: return 1;
274
      case  4: return 40;
275
      case  5: return 31;
276
      case  6: return 41;
277
      case  7: return 30;
278
      case  8: return 39;
279
      case  9: return 35;
280
      case 10: return 36;
281
      case 11: return 34;
282
      case 12: return 56;
283
      case 13: return 32;
284
      case 14: return 43;
285
      case 15: return 21;
286
      case 16: return 48;
287
      case 17: return 28;
288
      case 18: return 42;
289
      case 19: return 23;
290
      }
291

    
292
    return 0;
293
    }
294

    
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296

    
297
  MeshBase createCubitMesh(int cubit)
298
    {
299
    if( mMesh==null ) mMesh = FactoryCubit.getInstance().createMinxCornerMesh();
300
    MeshBase mesh = mMesh.copy(true);
301

    
302
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[getQuat(cubit)], new Static3D(0,0,0) );
303
    mesh.apply(quat,0xffffffff,0);
304

    
305
    return mesh;
306
    }
307

    
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309

    
310
  int getFaceColor(int cubit, int cubitface, int numLayers)
311
    {
312
    return mFaceMap[cubit][cubitface];
313
    }
314

    
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

    
317
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
318
    {
319
    float S = 0.07f;
320
    float R = 0.09f;
321

    
322
    float X1= (SQ5+1)/8;
323
    float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
324
    float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8);
325

    
326
    float[] vertices = { -X1, Y2, 0, -Y1, X1, Y2, 0, Y1 };
327

    
328
    FactorySticker factory = FactorySticker.getInstance();
329
    factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
330
    }
331

    
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

    
334
  float returnMultiplier()
335
    {
336
    return 2.0f;
337
    }
338

    
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340

    
341
  float[] getRowChances()
342
    {
343
    return new float[] { 0.5f, 0.5f, 1.0f };
344
    }
345

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347
// PUBLIC API
348

    
349
  public Static3D[] getRotationAxis()
350
    {
351
    return ROT_AXIS;
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

    
356
  public int getBasicAngle()
357
    {
358
    return 5;
359
    }
360

    
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362

    
363
  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
364
    {
365
    int numAxis = ROTATION_AXIS.length;
366

    
367
    if( oldRotAxis == START_AXIS )
368
      {
369
      return rnd.nextInt(numAxis);
370
      }
371
    else
372
      {
373
      int newVector = rnd.nextInt(numAxis-1);
374
      return (newVector>=oldRotAxis ? newVector+1 : newVector);
375
      }
376
    }
377

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

    
380
  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
381
    {
382
    float rowFloat = rnd.nextFloat();
383

    
384
    for(int row=0; row<mRowChances.length; row++)
385
      {
386
      if( rowFloat<=mRowChances[row] ) return row;
387
      }
388

    
389
    return 0;
390
    }
391

    
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393
// The Kilominx is solved if and only if:
394
//
395
// all cubits are rotated with the same quat.
396

    
397
  public boolean isSolved()
398
    {
399
    int q = CUBITS[0].mQuatIndex;
400

    
401
    for(int i=0; i<NUM_CUBITS; i++)
402
      {
403
      if( CUBITS[i].mQuatIndex != q ) return false;
404
      }
405

    
406
    return true;
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410
// only needed for solvers - there are no Ivy solvers ATM)
411

    
412
  public String retObjectString()
413
    {
414
    return "";
415
    }
416

    
417
///////////////////////////////////////////////////////////////////////////////////////////////////
418

    
419
  public int getObjectName(int numLayers)
420
    {
421
    return R.string.minx2;
422
    }
423

    
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425

    
426
  public int getInventor(int numLayers)
427
    {
428
    return R.string.minx2_inventor;
429
    }
430

    
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432

    
433
  public int getComplexity(int numLayers)
434
    {
435
    return 3;
436
    }
437
}
(23-23/28)