Project

General

Profile

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

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

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
  private static final float AXIS_LEN = 1.0f/(float)Math.sqrt(2.5f+0.5f*SQ5);
45
  private static final float C0 = (SQ5-1)/4;
46
  private static final float C1 = (SQ5+1)/4;
47

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

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

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

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

    
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
           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

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

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

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

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

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

    
173
  private static MeshBase mMesh;
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

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

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  float getScreenRatio()
186
    {
187
    return 1.0f;
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  Static4D[] getQuats()
193
    {
194
    return QUATS;
195
    }
196

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

    
199
  int getNumFaces()
200
    {
201
    return FACE_COLORS.length;
202
    }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
  boolean shouldResetTextureMaps()
207
    {
208
    return false;
209
    }
210

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

    
213
  int getNumStickerTypes()
214
    {
215
    return 1;
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

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

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
  int getNumCubitFaces()
228
    {
229
    return FACES_PER_CUBIT;
230
    }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
  Static3D[] getCubitPositions(int numLayers)
235
    {
236
    final float C0 = (SQ5+1)/4;
237
    final float C1 = (SQ5+3)/4;
238

    
239
    final Static3D[] CENTERS = new Static3D[20];
240

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

    
262
    return CENTERS;
263
    }
264

    
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

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

    
293
    return 0;
294
    }
295

    
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

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

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

    
306
    return mesh;
307
    }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

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

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

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

    
323
    float[] vertices = {  };   // TODO
324

    
325
    FactorySticker factory = FactorySticker.getInstance();
326
    factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

    
331
  float returnMultiplier()
332
    {
333
    return 2.0f;
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  float[] getRowChances()
339
    {
340
    return new float[] { 0.5f, 0.5f, 1.0f };
341
    }
342

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344
// PUBLIC API
345

    
346
  public Static3D[] getRotationAxis()
347
    {
348
    return ROT_AXIS;
349
    }
350

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

    
353
  public int getBasicAngle()
354
    {
355
    return 5;
356
    }
357

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

    
360
  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
361
    {
362
    int numAxis = ROTATION_AXIS.length;
363

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

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376

    
377
  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
378
    {
379
    float rowFloat = rnd.nextFloat();
380

    
381
    for(int row=0; row<mRowChances.length; row++)
382
      {
383
      if( rowFloat<=mRowChances[row] ) return row;
384
      }
385

    
386
    return 0;
387
    }
388

    
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390
// The Kilominx is solved if and only if:
391
//
392
// all cubits are rotated with the same quat.
393

    
394
  public boolean isSolved()
395
    {
396
    int q = CUBITS[0].mQuatIndex;
397

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

    
403
    return true;
404
    }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407
// only needed for solvers - there are no Ivy solvers ATM)
408

    
409
  public String retObjectString()
410
    {
411
    return "";
412
    }
413

    
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415

    
416
  public int getObjectName(int numLayers)
417
    {
418
    return R.string.minx2;
419
    }
420

    
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422

    
423
  public int getInventor(int numLayers)
424
    {
425
    return R.string.minx2_inventor;
426
    }
427

    
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429

    
430
  public int getComplexity(int numLayers)
431
    {
432
    return 3;
433
    }
434
}
(23-23/28)