Project

General

Profile

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

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

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.InitData;
33
import org.distorted.objectlib.main.ObjectType;
34
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.scrambling.ScrambleState;
36
import org.distorted.objectlib.main.ShapeHexahedron;
37
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
38

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

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

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

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

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
  public TwistyMirror(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
63
    {
64
    super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
65
    }
66

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

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

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

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

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

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

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

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

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

    
122
    return mStates;
123
    }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

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

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

    
144
    return ret;
145
    }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

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

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

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

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

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

    
176
    return mPositions;
177
    }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

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

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

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

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

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

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

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

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

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

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

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

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

    
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

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

    
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

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

    
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

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

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

    
285
    return mCuts;
286
    }
287

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

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

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

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

    
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306

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

    
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

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

    
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320

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

    
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328

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

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

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

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

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

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

    
353
    return stroke;
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

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

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364
// PUBLIC API
365

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

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

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

    
383
    return mBasicAngle;
384
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

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

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

    
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401

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

    
411
    return null;
412
    }
413

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

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

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

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

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

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

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

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

    
466
///////////////////////////////////////////////////////////////////////////////////////////////////
467

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

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