Project

General

Profile

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

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

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.ObjectSignatures;
25
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
26
import org.distorted.objectlib.main.InitData;
27
import org.distorted.objectlib.main.ObjectType;
28
import org.distorted.objectlib.helpers.ObjectShape;
29
import org.distorted.objectlib.shape.ShapeHexahedron;
30
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

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

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

    
48
  private int[][] mEdges;
49
  private float[][] mCuts;
50
  private int[][] mBasicAngle;
51
  private float[][] mPositions;
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

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

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

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

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

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

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

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

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
  public int[][] getScrambleEdges()
87
    {
88
    if( mEdges==null )
89
      {
90
      int nL = getNumLayers()[0];
91
      mEdges = ScrambleEdgeGenerator.getScrambleEdgesCuboid(nL,nL,nL);
92
      }
93
    return mEdges;
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
  private int getRow(int cubit, int numLayers, int dim)
99
    {
100
    return (int)(mPositions[cubit][dim] + 0.5f*(numLayers-1));
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  public float[][] getCubitPositions(int[] numLayers)
106
    {
107
    if( mPositions==null )
108
      {
109
      int numL = numLayers[0];
110
      int numCubits = getNumCubitVariants(numLayers);
111
      mPositions = new float[numCubits][];
112

    
113
      float diff = 0.5f*(numL-1);
114
      int currentPosition = 0;
115

    
116
      for(int x = 0; x<numL; x++)
117
        for(int y = 0; y<numL; y++)
118
          for(int z = 0; z<numL; z++)
119
            if( x==0 || x==numL-1 || y==0 || y==numL-1 || z==0 || z==numL-1 )
120
              {
121
              mPositions[currentPosition++] = new float[] {x-diff,y-diff,z-diff};
122
              }
123
      }
124

    
125
    return mPositions;
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  public Static4D getCubitQuats(int cubit, int[] numLayers)
131
    {
132
    return mObjectQuats[0];
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  private float[][] getVertices(int variant)
138
    {
139
    int numL = getNumLayers()[0];
140
    int xrow = getRow(variant,numL,0);  // cubit == variant
141
    int yrow = getRow(variant,numL,1);
142
    int zrow = getRow(variant,numL,2);
143

    
144
    float XL = -0.5f + (xrow==     0 ? DX : 0);
145
    float XR =  0.5f + (xrow==numL-1 ? DX : 0);
146
    float YL = -0.5f - (yrow==     0 ? DY : 0);
147
    float YR =  0.5f - (yrow==numL-1 ? DY : 0);
148
    float ZL = -0.5f - (zrow==     0 ? DZ : 0);
149
    float ZR =  0.5f - (zrow==numL-1 ? DZ : 0);
150

    
151
    return new float[][]
152
          {
153
              { XR, YR, ZR },
154
              { XR, YR, ZL },
155
              { XR, YL, ZR },
156
              { XR, YL, ZL },
157
              { XL, YR, ZR },
158
              { XL, YR, ZL },
159
              { XL, YL, ZR },
160
              { XL, YL, ZL },
161
          };
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

    
166
  public ObjectShape getObjectShape(int variant)
167
    {
168
    int[][] indices =
169
          {
170
              {2,3,1,0},
171
              {7,6,4,5},
172
              {4,0,1,5},
173
              {7,3,2,6},
174
              {6,2,0,4},
175
              {3,7,5,1}
176
          };
177

    
178
    return new ObjectShape(getVertices(variant), indices);
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  public ObjectFaceShape getObjectFaceShape(int variant)
184
    {
185
    int extraI, extraV, num, numL = getNumLayers()[0];
186
    float height = isInIconMode() ? 0.001f : 0.045f;
187

    
188
    switch(numL)
189
      {
190
      case 2 : num = 6; extraI = 2; extraV = 2; break;
191
      case 3 : num = 5; extraI = 2; extraV = 2; break;
192
      case 4 : num = 5; extraI = 0; extraV = 0; break;
193
      default: num = 4; extraI = 0; extraV = 0; break;
194
      }
195

    
196
    float[][] bands = { {height,35,0.5f,0.7f,num,extraI,extraV} };
197
    int[] indices   = { 0,0,0,0,0,0 };
198

    
199
    return new ObjectFaceShape(bands,indices,null);
200
    }
201

    
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

    
204
  public ObjectVertexEffects getVertexEffects(int variant)
205
    {
206
    float[][] corners = { {0.036f,0.12f} };
207
    int[] indices     = { 0,0,0,0,0,0,0,0 };
208
    float[][] centers = { {0.0f, 0.0f, 0.0f} };
209
    return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  public int getNumCubitVariants(int[] numLayers)
215
    {
216
    int numL = numLayers[0];
217
    return numL>1 ? 6*numL*numL - 12*numL + 8 : 1;
218
    }
219

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

    
222
  public int getCubitVariant(int cubit, int[] numLayers)
223
    {
224
    return cubit;
225
    }
226

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

    
229
  public float[][] getCuts(int[] numLayers)
230
    {
231
    if( mCuts==null )
232
      {
233
      int numL = numLayers[0];
234
      mCuts = new float[3][numL-1];
235

    
236
      for(int i=0; i<numL-1; i++)
237
        {
238
        float cut = (2-numL)*0.5f + i;
239
        mCuts[0][i] = cut;
240
        mCuts[1][i] = cut;
241
        mCuts[2][i] = cut;
242
        }
243
      }
244

    
245
    return mCuts;
246
    }
247

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

    
250
  public boolean[][] getLayerRotatable(int[] numLayers)
251
    {
252
    int num = numLayers[0];
253
    boolean[] tmp = new boolean[num];
254
    for(int i=0; i<num; i++) tmp[i] = true;
255
    return new boolean[][] { tmp,tmp,tmp };
256
    }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

    
260
  public int getTouchControlType()
261
    {
262
    return TC_CHANGING_MIRROR;
263
    }
264

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

    
267
  public int getTouchControlSplit()
268
    {
269
    return TYPE_NOT_SPLIT;
270
    }
271

    
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

    
274
  public int[][][] getEnabled()
275
    {
276
    return null;
277
    }
278

    
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280

    
281
  public float[] getDist3D(int[] numLayers)
282
    {
283
    int N = numLayers[0];
284
    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 };
285
    }
286

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

    
289
  public Static3D[] getFaceAxis()
290
    {
291
    return TouchControlHexahedron.FACE_AXIS;
292
    }
293

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

    
296
  public float getStickerRadius()
297
    {
298
    return 0.10f;
299
    }
300

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

    
303
  public float getStickerStroke()
304
    {
305
    float stroke = 0.08f;
306

    
307
    if( isInIconMode() )
308
      {
309
      int[] numLayers = getNumLayers();
310
      stroke*= ( numLayers[0]==2 ? 1.8f : 2.0f );
311
      }
312

    
313
    return stroke;
314
    }
315

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

    
318
  public float[][] getStickerAngles()
319
    {
320
    return null;
321
    }
322

    
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324
// PUBLIC API
325

    
326
  public Static3D[] getRotationAxis()
327
    {
328
    return ROT_AXIS;
329
    }
330

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

    
333
  public int[][] getBasicAngles()
334
    {
335
    if( mBasicAngle==null )
336
      {
337
      int num = getNumLayers()[0];
338
      int[] tmp = new int[num];
339
      for(int i=0; i<num; i++) tmp[i] = 4;
340
      mBasicAngle = new int[][] { tmp,tmp,tmp };
341
      }
342

    
343
    return mBasicAngle;
344
    }
345

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

    
348
  public String getShortName()
349
    {
350
    switch(getNumLayers()[0])
351
      {
352
      case 2: return ObjectType.MIRR_2.name();
353
      case 3: return ObjectType.MIRR_3.name();
354
      case 4: return ObjectType.MIRR_4.name();
355
      }
356

    
357
    return ObjectType.MIRR_2.name();
358
    }
359

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

    
362
  public ObjectSignature getSignature()
363
    {
364
    switch(getNumLayers()[0])
365
      {
366
      case 2: return new ObjectSignature(ObjectSignatures.MIRR_2);
367
      case 3: return new ObjectSignature(ObjectSignatures.MIRR_3);
368
      case 4: return new ObjectSignature(ObjectSignatures.MIRR_4);
369
      }
370

    
371
    return null;
372
    }
373

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

    
376
  public String getObjectName()
377
    {
378
    switch(getNumLayers()[0])
379
      {
380
      case 2: return "Pocket Mirror";
381
      case 3: return "Mirror Cube";
382
      case 4: return "Master Mirror Blocks";
383
      }
384
    return null;
385
    }
386

    
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388

    
389
  public String getInventor()
390
    {
391
    switch(getNumLayers()[0])
392
      {
393
      case 2: return "Thomas de Bruin";
394
      case 3: return "Hidetoshi Takeji";
395
      case 4: return "Traiphum Prungtaengkit";
396
      }
397
    return null;
398
    }
399

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

    
402
  public int getYearOfInvention()
403
    {
404
    switch(getNumLayers()[0])
405
      {
406
      case 2: return 2007;
407
      case 3: return 2006;
408
      case 4: return 2014;
409
      }
410
    return 2006;
411
    }
412

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

    
415
  public int getComplexity()
416
    {
417
    switch(getNumLayers()[0])
418
      {
419
      case 2: return 1;
420
      case 3: return 2;
421
      case 4: return 3;
422
      }
423
    return 2;
424
    }
425

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

    
428
  public String[][] getTutorials()
429
    {
430
    int[] numLayers = getNumLayers();
431

    
432
    switch(numLayers[0])
433
      {
434
      case 2: return new String[][] {
435
                          {"gb","rSH-ZEqTmxs","Solve 2x2 Mirror Blocks","King of Cubing"},
436
                          {"es","Ipz-Ajpd4Fg","Como resolver el mirror 2x2","RUBI CUBI"},
437
                          {"ru","rGqZq0bjZlM","Как собрать Зеркальный кубик 2x2","maggam1000"},
438
                          {"de","fFMf1G7MYmA","2x2 Mirror Cube Anfängerlösung","rofrisch"},
439
                          {"pl","ERUtLe30vXA","Jak ułożyć kostkę mirror 2x2","Korzuu"},
440
                          {"kr","9S4QTkyNm4Y","2x2 Mirror Cube","큐브놀이터"},
441
                          {"vn","6zENEJlv5gA","Hướng Dẫn Giải Mirror 2x2","Rubik Cube"},
442
                         };
443
      case 3: return new String[][] {
444
                          {"gb","YkzXIWnqbSw","How to Solve the Mirror Cube","Z3"},
445
                          {"es","ZTkunMo51l0","Resolver cubo de Rubik MIRROR","Cuby"},
446
                          {"ru","1QPAD3Q4r78","Как собрать Зеркальный Куб","Алексей Ярыгин"},
447
                          {"fr","tlFLE2UvjFo","Tutoriel: le rubik's cube mirroir","Le Cubiste"},
448
                          {"de","Qf2EadLLiZo","Mirror Cube lösen","Pezcraft"},
449
                          {"pl","r1-MzAL3TxE","Jak ułożyć kostkę mirror","Cube Masters"},
450
                          {"br","HWGGpIKRT_I","Como resolver o Mirror Blocks","Pedro Filho"},
451
                          {"kr","p3OJSbWopqg","미러블럭 해법","듀나메스 큐브 해법연구소"},
452
                          {"vn","F3Gh6JxW1VI","Tutorial N.15 - Mirror Block","Duy Thích Rubik"},
453
                         };
454
      case 4: return new String[][] {
455
                          {"gb","6gyQ5qBK8GU","4x4 Mirror: Introduction","SuperAntoniovivaldi"},
456
                          {"gb","jvKLW7vxKx4","4x4 Mirror: Layer by Layer","SuperAntoniovivaldi"},
457
                          {"gb","efHeHrXFNTQ","4x4 Mirror: Reduction","SuperAntoniovivaldi"},
458
                          {"gb","bKHQn_ARNZ8","4x4 Mirror: Parity Free Solve","SuperAntoniovivaldi"},
459
                          {"gb","Us1Dlr0PyEA","4x4 Mirror: Superparity","SuperAntoniovivaldi"},
460
                          {"es","tN2D3j0o-wk","Como hacer un mirror 4x4x4","JGOM Designer"},
461
                          {"vn","ZGkVOQ3FCOg","Tutorial N.137 - Mirror 4x4x4","Duy Thích Rubik"},
462
                         };
463
      }
464
    return null;
465
    }
466
}
(22-22/41)