Project

General

Profile

Download (16.6 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyMirror.java @ 1f329dcc

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.objects;
11

    
12
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_MIRROR;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
14

    
15
import java.io.InputStream;
16

    
17
import org.distorted.library.type.Static3D;
18
import org.distorted.library.type.Static4D;
19

    
20
import org.distorted.objectlib.helpers.FactoryCubit;
21
import org.distorted.objectlib.helpers.ObjectFaceShape;
22
import org.distorted.objectlib.helpers.ObjectSignature;
23
import org.distorted.objectlib.helpers.ObjectVertexEffects;
24
import org.distorted.objectlib.main.InitData;
25
import org.distorted.objectlib.main.ObjectType;
26
import org.distorted.objectlib.helpers.ObjectShape;
27
import org.distorted.objectlib.scrambling.ScrambleState;
28
import org.distorted.objectlib.shape.ShapeHexahedron;
29
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class TwistyMirror extends ShapeHexahedron
34
{
35
  static final Static3D[] ROT_AXIS = new Static3D[]
36
         {
37
           new Static3D(1,0,0),
38
           new Static3D(0,1,0),
39
           new Static3D(0,0,1)
40
         };
41

    
42
  private static final int[] FACE_COLORS = new int[] { COLOR_WHITE };
43
  private static final float DX = 0.10f;
44
  private static final float DY = 0.25f;
45
  private static final float DZ = 0.40f;
46

    
47
  private ScrambleState[] mStates;
48
  private float[][] mCuts;
49
  private int[][] mBasicAngle;
50
  private float[][] mPositions;
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  public TwistyMirror(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
55
    {
56
    super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
57
    }
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
  @Override
62
  public int getInternalColor()
63
    {
64
    return 0xff333333;
65
    }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  @Override
70
  public int getColor(int face)
71
    {
72
    return FACE_COLORS[face];
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  @Override
78
  public int getNumFaceColors()
79
    {
80
    return 1;
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  public ScrambleState[] getScrambleStates()
86
    {
87
    if( mStates==null )
88
      {
89
      int[] numLayers = getNumLayers();
90
      int[][] m = new int[16][];
91
      for(int i=1; i<16; i++) m[i] = createEdges(numLayers[0],i);
92

    
93
      mStates = new ScrambleState[]
94
        {
95
        new ScrambleState( new int[][] { m[ 1], m[ 2], m[ 3] } ),  // 0
96
        new ScrambleState( new int[][] {  null, m[ 4], m[ 5] } ),  // x
97
        new ScrambleState( new int[][] { m[ 6],  null, m[ 7] } ),  // y
98
        new ScrambleState( new int[][] { m[ 8], m[ 8],  null } ),  // z
99
        new ScrambleState( new int[][] { m[10],  null, m[ 7] } ),  // xy
100
        new ScrambleState( new int[][] { m[11], m[ 9],  null } ),  // xz
101
        new ScrambleState( new int[][] {  null, m[12], m[ 5] } ),  // yx
102
        new ScrambleState( new int[][] { m[ 8], m[13],  null } ),  // yz
103
        new ScrambleState( new int[][] {  null, m[ 4], m[14] } ),  // zx
104
        new ScrambleState( new int[][] { m[ 6],  null, m[15] } ),  // zy
105
        new ScrambleState( new int[][] {  null,  null, m[ 5] } ),  // xyx
106
        new ScrambleState( new int[][] {  null, m[ 4],  null } ),  // xzx
107
        new ScrambleState( new int[][] {  null,  null, m[ 7] } ),  // yxy
108
        new ScrambleState( new int[][] { m[ 6],  null,  null } ),  // yzy
109
        new ScrambleState( new int[][] {  null, m[ 9],  null } ),  // zxz
110
        new ScrambleState( new int[][] { m[ 8],  null,  null } ),  // zyz
111
        };
112
      }
113

    
114
    return mStates;
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  private int[] createEdges(int size, int vertex)
120
    {
121
    int[] ret = new int[9*size];
122

    
123
    for(int l=0; l<size; l++)
124
      {
125
      ret[9*l  ] = l;
126
      ret[9*l+1] =-1;
127
      ret[9*l+2] = vertex;
128
      ret[9*l+3] = l;
129
      ret[9*l+4] = 1;
130
      ret[9*l+5] = vertex;
131
      ret[9*l+6] = l;
132
      ret[9*l+7] = 2;
133
      ret[9*l+8] = vertex;
134
      }
135

    
136
    return ret;
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  private int getRow(int cubit, int numLayers, int dim)
142
    {
143
    return (int)(mPositions[cubit][dim] + 0.5f*(numLayers-1));
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  public float[][] getCubitPositions(int[] numLayers)
149
    {
150
    if( mPositions==null )
151
      {
152
      int numL = numLayers[0];
153
      int numCubits = getNumCubitVariants(numLayers);
154
      mPositions = new float[numCubits][];
155

    
156
      float diff = 0.5f*(numL-1);
157
      int currentPosition = 0;
158

    
159
      for(int x = 0; x<numL; x++)
160
        for(int y = 0; y<numL; y++)
161
          for(int z = 0; z<numL; z++)
162
            if( x==0 || x==numL-1 || y==0 || y==numL-1 || z==0 || z==numL-1 )
163
              {
164
              mPositions[currentPosition++] = new float[] {x-diff,y-diff,z-diff};
165
              }
166
      }
167

    
168
    return mPositions;
169
    }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

    
173
  public Static4D getCubitQuats(int cubit, int[] numLayers)
174
    {
175
    return mObjectQuats[0];
176
    }
177

    
178
///////////////////////////////////////////////////////////////////////////////////////////////////
179

    
180
  private float[][] getVertices(int variant)
181
    {
182
    int numL = getNumLayers()[0];
183
    int xrow = getRow(variant,numL,0);  // cubit == variant
184
    int yrow = getRow(variant,numL,1);
185
    int zrow = getRow(variant,numL,2);
186

    
187
    float XL = -0.5f + (xrow==     0 ? DX : 0);
188
    float XR =  0.5f + (xrow==numL-1 ? DX : 0);
189
    float YL = -0.5f - (yrow==     0 ? DY : 0);
190
    float YR =  0.5f - (yrow==numL-1 ? DY : 0);
191
    float ZL = -0.5f - (zrow==     0 ? DZ : 0);
192
    float ZR =  0.5f - (zrow==numL-1 ? DZ : 0);
193

    
194
    return new float[][]
195
          {
196
              { XR, YR, ZR },
197
              { XR, YR, ZL },
198
              { XR, YL, ZR },
199
              { XR, YL, ZL },
200
              { XL, YR, ZR },
201
              { XL, YR, ZL },
202
              { XL, YL, ZR },
203
              { XL, YL, ZL },
204
          };
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

    
209
  public ObjectShape getObjectShape(int variant)
210
    {
211
    int[][] indices =
212
          {
213
              {2,3,1,0},
214
              {7,6,4,5},
215
              {4,0,1,5},
216
              {7,3,2,6},
217
              {6,2,0,4},
218
              {3,7,5,1}
219
          };
220

    
221
    return new ObjectShape(getVertices(variant), indices);
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  public ObjectFaceShape getObjectFaceShape(int variant)
227
    {
228
    int extraI, extraV, num, numL = getNumLayers()[0];
229
    float height = isInIconMode() ? 0.001f : 0.045f;
230

    
231
    switch(numL)
232
      {
233
      case 2 : num = 6; extraI = 2; extraV = 2; break;
234
      case 3 : num = 5; extraI = 2; extraV = 2; break;
235
      case 4 : num = 5; extraI = 0; extraV = 0; break;
236
      default: num = 4; extraI = 0; extraV = 0; break;
237
      }
238

    
239
    float[][] bands = { {height,35,0.5f,0.7f,num,extraI,extraV} };
240
    int[] indices   = { 0,0,0,0,0,0 };
241

    
242
    return new ObjectFaceShape(bands,indices,null);
243
    }
244

    
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

    
247
  public ObjectVertexEffects getVertexEffects(int variant)
248
    {
249
    float[][] corners = { {0.036f,0.12f} };
250
    int[] indices     = { 0,0,0,0,0,0,0,0 };
251
    float[][] centers = { {0.0f, 0.0f, 0.0f} };
252
    return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
253
    }
254

    
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

    
257
  public int getNumCubitVariants(int[] numLayers)
258
    {
259
    int numL = numLayers[0];
260
    return numL>1 ? 6*numL*numL - 12*numL + 8 : 1;
261
    }
262

    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

    
265
  public int getCubitVariant(int cubit, int[] numLayers)
266
    {
267
    return cubit;
268
    }
269

    
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

    
272
  public float[][] getCuts(int[] numLayers)
273
    {
274
    if( mCuts==null )
275
      {
276
      int numL = numLayers[0];
277
      mCuts = new float[3][numL-1];
278

    
279
      for(int i=0; i<numL-1; i++)
280
        {
281
        float cut = (2-numL)*0.5f + i;
282
        mCuts[0][i] = cut;
283
        mCuts[1][i] = cut;
284
        mCuts[2][i] = cut;
285
        }
286
      }
287

    
288
    return mCuts;
289
    }
290

    
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292

    
293
  public boolean[][] getLayerRotatable(int[] numLayers)
294
    {
295
    int num = numLayers[0];
296
    boolean[] tmp = new boolean[num];
297
    for(int i=0; i<num; i++) tmp[i] = true;
298
    return new boolean[][] { tmp,tmp,tmp };
299
    }
300

    
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302

    
303
  public int getTouchControlType()
304
    {
305
    return TC_CHANGING_MIRROR;
306
    }
307

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

    
310
  public int getTouchControlSplit()
311
    {
312
    return TYPE_NOT_SPLIT;
313
    }
314

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

    
317
  public int[][][] getEnabled()
318
    {
319
    return null;
320
    }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
  public float[] getDist3D(int[] numLayers)
325
    {
326
    int N = numLayers[0];
327
    return new float[] { 0.5f+DX/N, 0.5f-DX/N, 0.5f-DY/N, 0.5f+DY/N, 0.5f-DZ/N, 0.5f+DZ/N };
328
    }
329

    
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331

    
332
  public Static3D[] getFaceAxis()
333
    {
334
    return TouchControlHexahedron.FACE_AXIS;
335
    }
336

    
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

    
339
  public float getStickerRadius()
340
    {
341
    return 0.10f;
342
    }
343

    
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345

    
346
  public float getStickerStroke()
347
    {
348
    float stroke = 0.08f;
349

    
350
    if( isInIconMode() )
351
      {
352
      int[] numLayers = getNumLayers();
353
      stroke*= ( numLayers[0]==2 ? 1.8f : 2.0f );
354
      }
355

    
356
    return stroke;
357
    }
358

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360

    
361
  public float[][] getStickerAngles()
362
    {
363
    return null;
364
    }
365

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367
// PUBLIC API
368

    
369
  public Static3D[] getRotationAxis()
370
    {
371
    return ROT_AXIS;
372
    }
373

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

    
376
  public int[][] getBasicAngles()
377
    {
378
    if( mBasicAngle==null )
379
      {
380
      int num = getNumLayers()[0];
381
      int[] tmp = new int[num];
382
      for(int i=0; i<num; i++) tmp[i] = 4;
383
      mBasicAngle = new int[][] { tmp,tmp,tmp };
384
      }
385

    
386
    return mBasicAngle;
387
    }
388

    
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390

    
391
  public String getShortName()
392
    {
393
    switch(getNumLayers()[0])
394
      {
395
      case 2: return ObjectType.MIRR_2.name();
396
      case 3: return ObjectType.MIRR_3.name();
397
      case 4: return ObjectType.MIRR_4.name();
398
      }
399

    
400
    return ObjectType.MIRR_2.name();
401
    }
402

    
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404

    
405
  public ObjectSignature getSignature()
406
    {
407
    switch(getNumLayers()[0])
408
      {
409
      case 2: return new ObjectSignature(ObjectType.MIRR_2);
410
      case 3: return new ObjectSignature(ObjectType.MIRR_3);
411
      case 4: return new ObjectSignature(ObjectType.MIRR_4);
412
      }
413

    
414
    return null;
415
    }
416

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

    
419
  public String getObjectName()
420
    {
421
    switch(getNumLayers()[0])
422
      {
423
      case 2: return "Pocket Mirror";
424
      case 3: return "Mirror Cube";
425
      case 4: return "Master Mirror Blocks";
426
      }
427
    return null;
428
    }
429

    
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431

    
432
  public String getInventor()
433
    {
434
    switch(getNumLayers()[0])
435
      {
436
      case 2: return "Thomas de Bruin";
437
      case 3: return "Hidetoshi Takeji";
438
      case 4: return "Traiphum Prungtaengkit";
439
      }
440
    return null;
441
    }
442

    
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444

    
445
  public int getYearOfInvention()
446
    {
447
    switch(getNumLayers()[0])
448
      {
449
      case 2: return 2007;
450
      case 3: return 2006;
451
      case 4: return 2014;
452
      }
453
    return 2006;
454
    }
455

    
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457

    
458
  public int getComplexity()
459
    {
460
    switch(getNumLayers()[0])
461
      {
462
      case 2: return 1;
463
      case 3: return 2;
464
      case 4: return 3;
465
      }
466
    return 2;
467
    }
468

    
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470

    
471
  public String[][] getTutorials()
472
    {
473
    int[] numLayers = getNumLayers();
474

    
475
    switch(numLayers[0])
476
      {
477
      case 2: return new String[][] {
478
                          {"gb","rSH-ZEqTmxs","Solve 2x2 Mirror Blocks","King of Cubing"},
479
                          {"es","Ipz-Ajpd4Fg","Como resolver el mirror 2x2","RUBI CUBI"},
480
                          {"ru","rGqZq0bjZlM","Как собрать Зеркальный кубик 2x2","maggam1000"},
481
                          {"de","fFMf1G7MYmA","2x2 Mirror Cube Anfängerlösung","rofrisch"},
482
                          {"pl","C6B_ZT6xilw","Jak ułożyć kostkę mirror 2x2","Lisek Smolisek"},
483
                          {"kr","9S4QTkyNm4Y","2x2 Mirror Cube","큐브놀이터"},
484
                          {"vn","6zENEJlv5gA","Hướng Dẫn Giải Mirror 2x2","Rubik Cube"},
485
                         };
486
      case 3: return new String[][] {
487
                          {"gb","YkzXIWnqbSw","How to Solve the Mirror Cube","Z3"},
488
                          {"es","ZTkunMo51l0","Resolver cubo de Rubik MIRROR","Cuby"},
489
                          {"ru","1QPAD3Q4r78","Как собрать Зеркальный Куб","Алексей Ярыгин"},
490
                          {"fr","tlFLE2UvjFo","Tutoriel: le rubik's cube mirroir","Le Cubiste"},
491
                          {"de","Qf2EadLLiZo","Mirror Cube lösen","Pezcraft"},
492
                          {"pl","r1-MzAL3TxE","Jak ułożyć kostkę mirror","Cube Masters"},
493
                          {"br","HWGGpIKRT_I","Como resolver o Mirror Blocks","Pedro Filho"},
494
                          {"kr","p3OJSbWopqg","미러블럭 해법","듀나메스 큐브 해법연구소"},
495
                          {"vn","F3Gh6JxW1VI","Tutorial N.15 - Mirror Block","Duy Thích Rubik"},
496
                         };
497
      case 4: return new String[][] {
498
                          {"gb","6gyQ5qBK8GU","4x4 Mirror: Introduction","SuperAntoniovivaldi"},
499
                          {"gb","jvKLW7vxKx4","4x4 Mirror: Layer by Layer","SuperAntoniovivaldi"},
500
                          {"gb","efHeHrXFNTQ","4x4 Mirror: Reduction","SuperAntoniovivaldi"},
501
                          {"gb","bKHQn_ARNZ8","4x4 Mirror: Parity Free Solve","SuperAntoniovivaldi"},
502
                          {"gb","Us1Dlr0PyEA","4x4 Mirror: Superparity","SuperAntoniovivaldi"},
503
                          {"es","tN2D3j0o-wk","Como hacer un mirror 4x4x4","JGOM Designer"},
504
                          {"vn","ZGkVOQ3FCOg","Tutorial N.137 - Mirror 4x4x4","Duy Thích Rubik"},
505
                         };
506
      }
507
    return null;
508
    }
509
}
(20-20/39)