Project

General

Profile

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

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

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 6133be67 Leszek Koltunski
// 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 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.objectlib.objects;
11
12 0c5d8bf7 Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_MIRROR;
13 c9c71c3f Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
14 29b82486 Leszek Koltunski
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17
18 84a17011 Leszek Koltunski
import org.distorted.objectlib.helpers.FactoryCubit;
19 3ee1d662 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectFaceShape;
20 1d581993 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectSignature;
21 84a17011 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22 cf93ea4e Leszek Koltunski
import org.distorted.objectlib.main.InitAssets;
23 2dffaf22 Leszek Koltunski
import org.distorted.objectlib.main.ObjectSignatures;
24 9ba7f3f6 Leszek Koltunski
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
25 a8295031 Leszek Koltunski
import org.distorted.objectlib.main.InitData;
26 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
27 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
28 b31249d6 Leszek Koltunski
import org.distorted.objectlib.shape.ShapeHexahedron;
29 4c9ca251 Leszek Koltunski
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
30 29b82486 Leszek Koltunski
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 386af988 Leszek Koltunski
public class TwistyMirror extends ShapeHexahedron
34 29b82486 Leszek Koltunski
{
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 9ba7f3f6 Leszek Koltunski
  private int[][] mEdges;
48 29b82486 Leszek Koltunski
  private float[][] mCuts;
49 beee90ab Leszek Koltunski
  private int[][] mBasicAngle;
50 29b82486 Leszek Koltunski
  private float[][] mPositions;
51
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
54 cf93ea4e Leszek Koltunski
  public TwistyMirror(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
55 29b82486 Leszek Koltunski
    {
56 cf93ea4e Leszek Koltunski
    super(meshState, iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
57 29b82486 Leszek Koltunski
    }
58
59 253e440f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61
  @Override
62
  public int getInternalColor()
63
    {
64
    return 0xff333333;
65
    }
66
67 ed0988c0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
84
85 9ba7f3f6 Leszek Koltunski
  public int[][] getScrambleEdges()
86 29b82486 Leszek Koltunski
    {
87 9ba7f3f6 Leszek Koltunski
    if( mEdges==null )
88 29b82486 Leszek Koltunski
      {
89 27249eea Leszek Koltunski
      int nL = getNumLayers()[0];
90
      mEdges = ScrambleEdgeGenerator.getScrambleEdgesCuboid(nL,nL,nL);
91 29b82486 Leszek Koltunski
      }
92 9ba7f3f6 Leszek Koltunski
    return mEdges;
93 29b82486 Leszek Koltunski
    }
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 d0e6cf7f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
103
104
  public float[][] getCubitPositions(int[] numLayers)
105
    {
106
    if( mPositions==null )
107
      {
108
      int numL = numLayers[0];
109 05cb5de6 Leszek Koltunski
      int numCubits = getNumCubitVariants(numLayers);
110 d0e6cf7f Leszek Koltunski
      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 1597769c Leszek Koltunski
    return mObjectQuats[0];
132 d0e6cf7f Leszek Koltunski
    }
133
134 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
135
136 84a17011 Leszek Koltunski
  private float[][] getVertices(int variant)
137 29b82486 Leszek Koltunski
    {
138 3ee1d662 Leszek Koltunski
    int numL = getNumLayers()[0];
139 e30c522a Leszek Koltunski
    int xrow = getRow(variant,numL,0);  // cubit == variant
140
    int yrow = getRow(variant,numL,1);
141
    int zrow = getRow(variant,numL,2);
142 29b82486 Leszek Koltunski
143 a57e6870 Leszek Koltunski
    float XL = -0.5f + (xrow==     0 ? DX : 0);
144 84a17011 Leszek Koltunski
    float XR =  0.5f + (xrow==numL-1 ? DX : 0);
145 a57e6870 Leszek Koltunski
    float YL = -0.5f - (yrow==     0 ? DY : 0);
146 84a17011 Leszek Koltunski
    float YR =  0.5f - (yrow==numL-1 ? DY : 0);
147 a57e6870 Leszek Koltunski
    float ZL = -0.5f - (zrow==     0 ? DZ : 0);
148 84a17011 Leszek Koltunski
    float ZR =  0.5f - (zrow==numL-1 ? DZ : 0);
149 29b82486 Leszek Koltunski
150 84a17011 Leszek Koltunski
    return new float[][]
151 29b82486 Leszek Koltunski
          {
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 84a17011 Leszek Koltunski
    }
162
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164 29b82486 Leszek Koltunski
165 84a17011 Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
166
    {
167 4e9f2df5 Leszek Koltunski
    int[][] indices =
168 29b82486 Leszek Koltunski
          {
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 84a17011 Leszek Koltunski
    return new ObjectShape(getVertices(variant), indices);
178 3ee1d662 Leszek Koltunski
    }
179
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181
182
  public ObjectFaceShape getObjectFaceShape(int variant)
183
    {
184
    int extraI, extraV, num, numL = getNumLayers()[0];
185 3bf19410 Leszek Koltunski
    float height = isInIconMode() ? 0.001f : 0.045f;
186 3ee1d662 Leszek Koltunski
187
    switch(numL)
188
      {
189 3bf19410 Leszek Koltunski
      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 3ee1d662 Leszek Koltunski
      }
194
195 84a17011 Leszek Koltunski
    float[][] bands = { {height,35,0.5f,0.7f,num,extraI,extraV} };
196
    int[] indices   = { 0,0,0,0,0,0 };
197 29b82486 Leszek Koltunski
198 84a17011 Leszek Koltunski
    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 29b82486 Leszek Koltunski
    }
210
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212
213 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
214 29b82486 Leszek Koltunski
    {
215 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
216 05cb5de6 Leszek Koltunski
    return numL>1 ? 6*numL*numL - 12*numL + 8 : 1;
217 29b82486 Leszek Koltunski
    }
218
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220
221 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
222 29b82486 Leszek Koltunski
    {
223
    return cubit;
224
    }
225
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227
228 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
229 29b82486 Leszek Koltunski
    {
230
    if( mCuts==null )
231
      {
232 a57e6870 Leszek Koltunski
      int numL = numLayers[0];
233
      mCuts = new float[3][numL-1];
234 29b82486 Leszek Koltunski
235 a57e6870 Leszek Koltunski
      for(int i=0; i<numL-1; i++)
236 29b82486 Leszek Koltunski
        {
237 a57e6870 Leszek Koltunski
        float cut = (2-numL)*0.5f + i;
238 29b82486 Leszek Koltunski
        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 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
250 29b82486 Leszek Koltunski
    {
251 05cb5de6 Leszek Koltunski
    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 29b82486 Leszek Koltunski
    }
256
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258
259 11fa413d Leszek Koltunski
  public int getTouchControlType()
260 59c20632 Leszek Koltunski
    {
261 0c5d8bf7 Leszek Koltunski
    return TC_CHANGING_MIRROR;
262 59c20632 Leszek Koltunski
    }
263
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265
266 11fa413d Leszek Koltunski
  public int getTouchControlSplit()
267 59c20632 Leszek Koltunski
    {
268
    return TYPE_NOT_SPLIT;
269
    }
270
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272
273
  public int[][][] getEnabled()
274
    {
275 82904e62 Leszek Koltunski
    return null;
276 59c20632 Leszek Koltunski
    }
277
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279
280
  public float[] getDist3D(int[] numLayers)
281
    {
282 4c9ca251 Leszek Koltunski
    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 59c20632 Leszek Koltunski
    }
292
293 b0720f49 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
294
295 d53fb890 Leszek Koltunski
  public float getStickerRadius()
296 b0720f49 Leszek Koltunski
    {
297
    return 0.10f;
298
    }
299
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301
302 d53fb890 Leszek Koltunski
  public float getStickerStroke()
303 b0720f49 Leszek Koltunski
    {
304
    float stroke = 0.08f;
305
306 3bf19410 Leszek Koltunski
    if( isInIconMode() )
307 b0720f49 Leszek Koltunski
      {
308
      int[] numLayers = getNumLayers();
309
      stroke*= ( numLayers[0]==2 ? 1.8f : 2.0f );
310
      }
311
312
    return stroke;
313
    }
314
315 00f4980d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
316
317 d53fb890 Leszek Koltunski
  public float[][] getStickerAngles()
318 00f4980d Leszek Koltunski
    {
319
    return null;
320
    }
321
322 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
323
// PUBLIC API
324
325
  public Static3D[] getRotationAxis()
326
    {
327
    return ROT_AXIS;
328
    }
329
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331
332 beee90ab Leszek Koltunski
  public int[][] getBasicAngles()
333 29b82486 Leszek Koltunski
    {
334 beee90ab Leszek Koltunski
    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 29b82486 Leszek Koltunski
    return mBasicAngle;
343
    }
344
345 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
346
347 5f54927b Leszek Koltunski
  public String getShortName()
348 61aa85e4 Leszek Koltunski
    {
349 5f54927b Leszek Koltunski
    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 1d581993 Leszek Koltunski
  public ObjectSignature getSignature()
362 5f54927b Leszek Koltunski
    {
363
    switch(getNumLayers()[0])
364 61aa85e4 Leszek Koltunski
      {
365 2dffaf22 Leszek Koltunski
      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 61aa85e4 Leszek Koltunski
      }
369
370 1d581993 Leszek Koltunski
    return null;
371 61aa85e4 Leszek Koltunski
    }
372
373 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
374
375 e26eb4e7 Leszek Koltunski
  public String getObjectName()
376 29b82486 Leszek Koltunski
    {
377 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
378 29b82486 Leszek Koltunski
      {
379 e26eb4e7 Leszek Koltunski
      case 2: return "Pocket Mirror";
380
      case 3: return "Mirror Cube";
381 05cb5de6 Leszek Koltunski
      case 4: return "Master Mirror Blocks";
382 29b82486 Leszek Koltunski
      }
383 1d581993 Leszek Koltunski
    return null;
384 29b82486 Leszek Koltunski
    }
385
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387
388 e26eb4e7 Leszek Koltunski
  public String getInventor()
389 29b82486 Leszek Koltunski
    {
390 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
391 29b82486 Leszek Koltunski
      {
392 e26eb4e7 Leszek Koltunski
      case 2: return "Thomas de Bruin";
393
      case 3: return "Hidetoshi Takeji";
394 05cb5de6 Leszek Koltunski
      case 4: return "Traiphum Prungtaengkit";
395 29b82486 Leszek Koltunski
      }
396 1d581993 Leszek Koltunski
    return null;
397 29b82486 Leszek Koltunski
    }
398
399 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
400
401 e26eb4e7 Leszek Koltunski
  public int getYearOfInvention()
402 59c20632 Leszek Koltunski
    {
403 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
404 59c20632 Leszek Koltunski
      {
405
      case 2: return 2007;
406
      case 3: return 2006;
407 05cb5de6 Leszek Koltunski
      case 4: return 2014;
408 59c20632 Leszek Koltunski
      }
409
    return 2006;
410
    }
411
412 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
413
414 e26eb4e7 Leszek Koltunski
  public int getComplexity()
415 29b82486 Leszek Koltunski
    {
416 e26eb4e7 Leszek Koltunski
    switch(getNumLayers()[0])
417 29b82486 Leszek Koltunski
      {
418 b4223a92 Leszek Koltunski
      case 2: return 1;
419
      case 3: return 2;
420 05cb5de6 Leszek Koltunski
      case 4: return 3;
421 29b82486 Leszek Koltunski
      }
422 05cb5de6 Leszek Koltunski
    return 2;
423 29b82486 Leszek Koltunski
    }
424 052e0362 Leszek Koltunski
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 064b8a42 Leszek Koltunski
                          {"pl","ERUtLe30vXA","Jak ułożyć kostkę mirror 2x2","Korzuu"},
439 052e0362 Leszek Koltunski
                          {"kr","9S4QTkyNm4Y","2x2 Mirror Cube","큐브놀이터"},
440 a399e91b Leszek Koltunski
                          {"vn","6zENEJlv5gA","Hướng Dẫn Giải Mirror 2x2","Rubik Cube"},
441 052e0362 Leszek Koltunski
                         };
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 a399e91b Leszek Koltunski
                          {"vn","F3Gh6JxW1VI","Tutorial N.15 - Mirror Block","Duy Thích Rubik"},
452 052e0362 Leszek Koltunski
                         };
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 a399e91b Leszek Koltunski
                          {"vn","ZGkVOQ3FCOg","Tutorial N.137 - Mirror 4x4x4","Duy Thích Rubik"},
461 052e0362 Leszek Koltunski
                         };
462
      }
463
    return null;
464
    }
465 29b82486 Leszek Koltunski
}