Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.objectlib.objects;
21

    
22
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_MIRROR;
23
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
24

    
25
import java.io.InputStream;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.helpers.ObjectFaceShape;
31
import org.distorted.objectlib.helpers.ObjectSignature;
32
import org.distorted.objectlib.main.ObjectType;
33
import org.distorted.objectlib.helpers.ObjectShape;
34
import org.distorted.objectlib.scrambling.ScrambleState;
35
import org.distorted.objectlib.main.ShapeHexahedron;
36
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class TwistyMirror extends ShapeHexahedron
41
{
42
  static final Static3D[] ROT_AXIS = new Static3D[]
43
         {
44
           new Static3D(1,0,0),
45
           new Static3D(0,1,0),
46
           new Static3D(0,0,1)
47
         };
48

    
49
  private static final int[] FACE_COLORS = new int[] { COLOR_WHITE };
50
  private static final float DX = 0.10f;
51
  private static final float DY = 0.25f;
52
  private static final float DZ = 0.40f;
53

    
54
  private ScrambleState[] mStates;
55
  private float[][] mCuts;
56
  private int[][] mBasicAngle;
57
  private float[][] mPositions;
58

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

    
61
  public TwistyMirror(int[] numL, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
62
    {
63
    super(numL, meshState, iconMode, numL[0], quat, move, scale, stream);
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  @Override
69
  public int getInternalColor()
70
    {
71
    return 0xff333333;
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  @Override
77
  public int getColor(int face)
78
    {
79
    return FACE_COLORS[face];
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  @Override
85
  public int getNumFaceColors()
86
    {
87
    return 1;
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  public ScrambleState[] getScrambleStates()
93
    {
94
    if( mStates==null )
95
      {
96
      int[] numLayers = getNumLayers();
97
      int[][] m = new int[16][];
98
      for(int i=1; i<16; i++) m[i] = createEdges(numLayers[0],i);
99

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

    
121
    return mStates;
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  private int[] createEdges(int size, int vertex)
127
    {
128
    int[] ret = new int[9*size];
129

    
130
    for(int l=0; l<size; l++)
131
      {
132
      ret[9*l  ] = l;
133
      ret[9*l+1] =-1;
134
      ret[9*l+2] = vertex;
135
      ret[9*l+3] = l;
136
      ret[9*l+4] = 1;
137
      ret[9*l+5] = vertex;
138
      ret[9*l+6] = l;
139
      ret[9*l+7] = 2;
140
      ret[9*l+8] = vertex;
141
      }
142

    
143
    return ret;
144
    }
145

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

    
148
  private int getRow(int cubit, int numLayers, int dim)
149
    {
150
    return (int)(mPositions[cubit][dim] + 0.5f*(numLayers-1));
151
    }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

    
155
  public float[][] getCubitPositions(int[] numLayers)
156
    {
157
    if( mPositions==null )
158
      {
159
      int numL = numLayers[0];
160
      int numCubits = getNumCubitVariants(numLayers);
161
      mPositions = new float[numCubits][];
162

    
163
      float diff = 0.5f*(numL-1);
164
      int currentPosition = 0;
165

    
166
      for(int x = 0; x<numL; x++)
167
        for(int y = 0; y<numL; y++)
168
          for(int z = 0; z<numL; z++)
169
            if( x==0 || x==numL-1 || y==0 || y==numL-1 || z==0 || z==numL-1 )
170
              {
171
              mPositions[currentPosition++] = new float[] {x-diff,y-diff,z-diff};
172
              }
173
      }
174

    
175
    return mPositions;
176
    }
177

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

    
180
  public Static4D getCubitQuats(int cubit, int[] numLayers)
181
    {
182
    return mObjectQuats[0];
183
    }
184

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

    
187
  public ObjectShape getObjectShape(int variant)
188
    {
189
    int numL = getNumLayers()[0];
190
    int xrow = getRow(variant,numL,0);  // cubit == variant
191
    int yrow = getRow(variant,numL,1);
192
    int zrow = getRow(variant,numL,2);
193

    
194
    float XL = -0.5f + (xrow==     0 ? DX : 0);
195
    float XR = +0.5f + (xrow==numL-1 ? DX : 0);
196
    float YL = -0.5f - (yrow==     0 ? DY : 0);
197
    float YR = +0.5f - (yrow==numL-1 ? DY : 0);
198
    float ZL = -0.5f - (zrow==     0 ? DZ : 0);
199
    float ZR = +0.5f - (zrow==numL-1 ? DZ : 0);
200

    
201
    float[][] vertices =
202
          {
203
              { XR, YR, ZR },
204
              { XR, YR, ZL },
205
              { XR, YL, ZR },
206
              { XR, YL, ZL },
207
              { XL, YR, ZR },
208
              { XL, YR, ZL },
209
              { XL, YL, ZR },
210
              { XL, YL, ZL },
211
          };
212

    
213
    int[][] indices =
214
          {
215
              {2,3,1,0},
216
              {7,6,4,5},
217
              {4,0,1,5},
218
              {7,3,2,6},
219
              {6,2,0,4},
220
              {3,7,5,1}
221
          };
222

    
223
    return new ObjectShape(vertices, indices);
224
    }
225

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

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

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

    
241
    float[][] bands     = { {height,35,0.5f,0.7f,num,extraI,extraV} };
242
    int[] bandIndices   = { 0,0,0,0,0,0 };
243
    float[][] corners   = { {0.036f,0.12f} };
244
    int[] cornerIndices = { 0,0,0,0,0,0,0,0 };
245
    float[][] centers   = { {0.0f, 0.0f, 0.0f} };
246
    int[] centerIndices = { 0,0,0,0,0,0,0,0 };
247

    
248
    return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
249
    }
250

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

    
253
  public int getNumCubitVariants(int[] numLayers)
254
    {
255
    int numL = numLayers[0];
256
    return numL>1 ? 6*numL*numL - 12*numL + 8 : 1;
257
    }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

    
261
  public int getCubitVariant(int cubit, int[] numLayers)
262
    {
263
    return cubit;
264
    }
265

    
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

    
268
  public float[][] getCuts(int[] numLayers)
269
    {
270
    if( mCuts==null )
271
      {
272
      int numL = numLayers[0];
273
      mCuts = new float[3][numL-1];
274

    
275
      for(int i=0; i<numL-1; i++)
276
        {
277
        float cut = (2-numL)*0.5f + i;
278
        mCuts[0][i] = cut;
279
        mCuts[1][i] = cut;
280
        mCuts[2][i] = cut;
281
        }
282
      }
283

    
284
    return mCuts;
285
    }
286

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

    
289
  public boolean[][] getLayerRotatable(int[] numLayers)
290
    {
291
    int num = numLayers[0];
292
    boolean[] tmp = new boolean[num];
293
    for(int i=0; i<num; i++) tmp[i] = true;
294
    return new boolean[][] { tmp,tmp,tmp };
295
    }
296

    
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298

    
299
  public int getTouchControlType()
300
    {
301
    return TC_CHANGING_MIRROR;
302
    }
303

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

    
306
  public int getTouchControlSplit()
307
    {
308
    return TYPE_NOT_SPLIT;
309
    }
310

    
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312

    
313
  public int[][][] getEnabled()
314
    {
315
    return null;
316
    }
317

    
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

    
320
  public float[] getDist3D(int[] numLayers)
321
    {
322
    int N = numLayers[0];
323
    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 };
324
    }
325

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327

    
328
  public Static3D[] getFaceAxis()
329
    {
330
    return TouchControlHexahedron.FACE_AXIS;
331
    }
332

    
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334

    
335
  public float getStickerRadius()
336
    {
337
    return 0.10f;
338
    }
339

    
340
///////////////////////////////////////////////////////////////////////////////////////////////////
341

    
342
  public float getStickerStroke()
343
    {
344
    float stroke = 0.08f;
345

    
346
    if( isInIconMode() )
347
      {
348
      int[] numLayers = getNumLayers();
349
      stroke*= ( numLayers[0]==2 ? 1.8f : 2.0f );
350
      }
351

    
352
    return stroke;
353
    }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

    
357
  public float[][] getStickerAngles()
358
    {
359
    return null;
360
    }
361

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363
// PUBLIC API
364

    
365
  public Static3D[] getRotationAxis()
366
    {
367
    return ROT_AXIS;
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  public int[][] getBasicAngles()
373
    {
374
    if( mBasicAngle==null )
375
      {
376
      int num = getNumLayers()[0];
377
      int[] tmp = new int[num];
378
      for(int i=0; i<num; i++) tmp[i] = 4;
379
      mBasicAngle = new int[][] { tmp,tmp,tmp };
380
      }
381

    
382
    return mBasicAngle;
383
    }
384

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386

    
387
  public String getShortName()
388
    {
389
    switch(getNumLayers()[0])
390
      {
391
      case 2: return ObjectType.MIRR_2.name();
392
      case 3: return ObjectType.MIRR_3.name();
393
      case 4: return ObjectType.MIRR_4.name();
394
      }
395

    
396
    return ObjectType.MIRR_2.name();
397
    }
398

    
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400

    
401
  public ObjectSignature getSignature()
402
    {
403
    switch(getNumLayers()[0])
404
      {
405
      case 2: return new ObjectSignature(ObjectType.MIRR_2);
406
      case 3: return new ObjectSignature(ObjectType.MIRR_3);
407
      case 4: return new ObjectSignature(ObjectType.MIRR_4);
408
      }
409

    
410
    return null;
411
    }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

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

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

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

    
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

    
441
  public int getYearOfInvention()
442
    {
443
    switch(getNumLayers()[0])
444
      {
445
      case 2: return 2007;
446
      case 3: return 2006;
447
      case 4: return 2014;
448
      }
449
    return 2006;
450
    }
451

    
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453

    
454
  public int getComplexity()
455
    {
456
    switch(getNumLayers()[0])
457
      {
458
      case 2: return 1;
459
      case 3: return 2;
460
      case 4: return 3;
461
      }
462
    return 2;
463
    }
464

    
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466

    
467
  public String[][] getTutorials()
468
    {
469
    int[] numLayers = getNumLayers();
470

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