Project

General

Profile

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

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

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 org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17

    
18
import org.distorted.objectlib.helpers.FactoryCubit;
19
import org.distorted.objectlib.helpers.ObjectFaceShape;
20
import org.distorted.objectlib.helpers.ObjectSignature;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitAssets;
23
import org.distorted.objectlib.main.ObjectSignatures;
24
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
25
import org.distorted.objectlib.main.InitData;
26
import org.distorted.objectlib.main.ObjectType;
27
import org.distorted.objectlib.helpers.ObjectShape;
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 int[][] mEdges;
48
  private float[][] mCuts;
49
  private int[][] mBasicAngle;
50
  private float[][] mPositions;
51

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

    
54
  public TwistyMirror(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
55
    {
56
    super(meshState, iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
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 int[][] getScrambleEdges()
86
    {
87
    if( mEdges==null )
88
      {
89
      int nL = getNumLayers()[0];
90
      mEdges = ScrambleEdgeGenerator.getScrambleEdgesCuboid(nL,nL,nL);
91
      }
92
    return mEdges;
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

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

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

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

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

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

    
124
    return mPositions;
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

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

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

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

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

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

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

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

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

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

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

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

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

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

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

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

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

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

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

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

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

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

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

    
244
    return mCuts;
245
    }
246

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

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

    
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

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

    
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

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

    
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272

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

    
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279

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

    
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287

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

    
293
///////////////////////////////////////////////////////////////////////////////////////////////////
294

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

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

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

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

    
312
    return stroke;
313
    }
314

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

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

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323
// PUBLIC API
324

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

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

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

    
342
    return mBasicAngle;
343
    }
344

    
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346

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

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

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

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

    
370
    return null;
371
    }
372

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

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

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

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

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

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

    
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413

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

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

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

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