Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyAxis.java @ 5d09301e

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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 org.distorted.library.type.Static3D;
13
import org.distorted.library.type.Static4D;
14
import org.distorted.objectlib.helpers.ObjectFaceShape;
15
import org.distorted.objectlib.helpers.ObjectShape;
16
import org.distorted.objectlib.helpers.ObjectSignature;
17
import org.distorted.objectlib.main.InitData;
18
import org.distorted.objectlib.scrambling.ScrambleState;
19
import org.distorted.objectlib.main.ObjectType;
20
import org.distorted.objectlib.main.ShapeHexahedron;
21
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
22

    
23
import java.io.InputStream;
24

    
25
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD;
26
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public class TwistyAxis extends ShapeHexahedron
31
{
32
  static final Static3D[] ROT_AXIS = new Static3D[]
33
         {
34
           new Static3D(-2.0f/3, 1.0f/3, 2.0f/3),
35
           new Static3D( 1.0f/3,-2.0f/3, 2.0f/3),
36
           new Static3D( 2.0f/3, 2.0f/3, 1.0f/3),
37
         };
38

    
39
  private ScrambleState[] mStates;
40
  private int[][] mBasicAngle;
41
  private float[][] mCuts;
42
  private float[][] mCenters;
43
  private int[] mQuatIndex;
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
  public TwistyAxis(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
48
    {
49
    super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
50
    }
51

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

    
54
  @Override
55
  public int getInternalColor()
56
    {
57
    return 0xff222222;
58
    }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
// same as in a 3x3
62

    
63
  public ScrambleState[] getScrambleStates()
64
    {
65
    if( mStates==null )
66
      {
67
      int[][] m = new int[16][];
68

    
69
      for(int i=0; i<16; i++) m[i] = new int[] { 0,-1,i,0,1,i,0,2,i, 1,-1,i,1,1,i,1,2,i, 2,-1,i,2,1,i,2,2,i};
70

    
71
      mStates = new ScrambleState[]
72
          {
73
          new ScrambleState( new int[][] { m[ 1], m[ 2], m[ 3] } ),  //  0 0
74
          new ScrambleState( new int[][] {  null, m[ 4], m[ 5] } ),  //  1 x
75
          new ScrambleState( new int[][] { m[ 6],  null, m[ 7] } ),  //  2 y
76
          new ScrambleState( new int[][] { m[ 8], m[ 9],  null } ),  //  3 z
77
          new ScrambleState( new int[][] { m[10],  null, m[ 7] } ),  //  4 xy
78
          new ScrambleState( new int[][] { m[11], m[ 9],  null } ),  //  5 xz
79
          new ScrambleState( new int[][] {  null, m[12], m[ 5] } ),  //  6 yx
80
          new ScrambleState( new int[][] { m[ 8], m[13],  null } ),  //  7 yz
81
          new ScrambleState( new int[][] {  null, m[ 4], m[14] } ),  //  8 zx
82
          new ScrambleState( new int[][] { m[ 6],  null, m[15] } ),  //  9 zy
83
          new ScrambleState( new int[][] {  null,  null, m[ 5] } ),  // 10 xyx
84
          new ScrambleState( new int[][] {  null, m[ 4],  null } ),  // 11 xzx
85
          new ScrambleState( new int[][] {  null,  null, m[ 7] } ),  // 12 yxy
86
          new ScrambleState( new int[][] { m[ 6],  null,  null } ),  // 13 yzy
87
          new ScrambleState( new int[][] {  null, m[ 9],  null } ),  // 14 zxz
88
          new ScrambleState( new int[][] { m[ 8],  null,  null } ),  // 15 zyz
89
          };
90
      }
91

    
92
    return mStates;
93
    }
94

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

    
97
  public float[][] getCuts(int[] numLayers)
98
    {
99
    if( mCuts==null )
100
      {
101
      float C = 0.5f;
102
      float[] cut = new float[] {-C,+C};
103
      mCuts = new float[][] { cut,cut,cut };
104
      }
105

    
106
    return mCuts;
107
    }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
  public boolean[][] getLayerRotatable(int[] numLayers)
112
    {
113
    boolean[] tmp = new boolean[] {true,true,true};
114
    return new boolean[][] { tmp,tmp,tmp };
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  public int getTouchControlType()
120
    {
121
    return TC_CHANGING_SHAPEMOD;
122
    }
123

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

    
126
  public int getTouchControlSplit()
127
    {
128
    return TYPE_NOT_SPLIT;
129
    }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
  public int[][][] getEnabled()
134
    {
135
    return null;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  public float[] getDist3D(int[] numLayers)
141
    {
142
    return TouchControlHexahedron.D3D;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  public Static3D[] getFaceAxis()
148
    {
149
    return TouchControlHexahedron.FACE_AXIS;
150
    }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
  public float[][] getCubitPositions(int[] numLayers)
155
    {
156
    if( mCenters==null )
157
      {
158
      mCenters = new float[][]
159
         {
160
             { 1.50f, 1.50f, 0.75f},
161
             {-0.75f, 1.50f,-1.50f},
162
             { 1.50f,-0.75f,-1.50f},
163
             {-1.50f, 0.75f, 1.50f},
164
             { 0.75f,-1.50f, 1.50f},
165
             {-1.50f,-1.50f,-0.75f},
166

    
167
             {0.375f, 1.50f,-0.375f},
168
             {0.375f,0.375f,-1.50f },
169
             { 1.50f,0.375f,-0.375f},
170
             {-0.375f,-0.375f,1.50f},
171
             {-0.375f,-1.50f,0.375f},
172
             {-1.50f,-0.375f,0.375f},
173

    
174
             { 0.00f, 1.50f, 1.50f},
175
             {-1.50f, 0.00f,-1.50f},
176
             { 1.50f,-1.50f, 0.00f},
177

    
178
             {-1.50f, 1.50f, 0.00f},
179
             { 0.00f,-1.50f,-1.50f},
180
             { 1.50f, 0.00f, 1.50f},
181

    
182
             { 1.50f, 1.50f,-1.50f},
183
             {-1.50f,-1.50f, 1.50f},
184

    
185
             {-0.5f, 1.5f, 0.5f},
186
             { 0.5f,-1.5f,-0.5f},
187
             { 1.5f,-0.5f, 0.5f},
188
             {-1.5f, 0.5f,-0.5f},
189
             { 0.5f, 0.5f, 1.5f},
190
             {-0.5f,-0.5f,-1.5f},
191
         };
192
      }
193

    
194
    return mCenters;
195
    }
196

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

    
199
  public Static4D getCubitQuats(int cubit, int[] numLayers)
200
    {
201
    if( mQuatIndex==null )
202
      {
203
      mQuatIndex = new int[] { 0,22,10,17,14,19,
204
                               0,22,10,17,14,19,
205
                               0,22,10,
206
                               0,22,10,
207
                               0,14,
208
                               0,14,10,19,17,22
209
                             };
210
      }
211
    return mObjectQuats[mQuatIndex[cubit]];
212
    }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

    
216
  public ObjectShape getObjectShape(int variant)
217
    {
218
    final float T = 1.0f/3;
219

    
220
    if( variant==0 )  // center
221
      {
222
      float[][] vertices =
223
          {
224
              { -1.0f, 0.0f, -0.25f  },
225
              {  0.0f, 0.0f, -0.75f  },
226
              {  0.0f, 0.0f,  0.75f  },
227
              {  0.0f,-1.0f, -0.25f  },
228
              {  -5*T, -2*T, -1.75f*T},
229
              { -1.0f,-1.0f, -1.25f  },
230
              {  -4*T, -4*T,  0.25f*T},
231
              {  -2*T, -5*T, -1.75f*T}
232
          };
233

    
234
      int[][] indices =
235
          {
236
              {2,1,0},
237
              {2,3,1},
238
              {4,6,2,0},
239
              {6,7,3,2},
240
              {7,5,1,3},
241
              {5,4,0,1},
242
              {7,6,4,5}
243
          };
244

    
245
      return new ObjectShape(vertices, indices);
246
      }
247
    else if( variant==1 ) // edge type 1
248
      {
249
      float[][] vertices =
250
          {
251
              {-0.375f  , 0.0f, -1.125f  },
252
              { 1.125f  , 0.0f,  0.375f  },
253
              {-0.875f  , 0.0f, -0.125f  },
254
              { 0.125f  , 0.0f,  0.875f  },
255
              {-1.625f*T, -2*T,  1.625f*T},
256
              { 0.125f  ,-1.0f, -0.125f  }
257
          };
258

    
259
      int[][] indices =
260
          {
261
              {2,3,1,0},
262
              {2,4,3},
263
              {4,5,1,3},
264
              {5,0,1},
265
              {5,4,2,0}
266
          };
267

    
268
      return new ObjectShape(vertices, indices);
269
      }
270
    else if( variant==2 ) // edge type 2
271
      {
272
      float[][] vertices =
273
          {
274
              {-1.5f  , 0.0f, 0.0f},
275
              { 0.5f  , 0.0f,-1.0f},
276
              { 1.5f  , 0.0f, 0.0f},
277
              {-0.5f  ,-1.0f, 0.0f},
278
              {-0.5f*T, -2*T, -4*T},
279
              { 0.5f*T, -4*T, -2*T},
280
          };
281

    
282
      int[][] indices =
283
          {
284
              {0,2,1},
285
              {0,3,2},
286
              {3,5,2},
287
              {1,4,0},
288
              {4,5,3,0},
289
              {5,4,1,2}
290
          };
291

    
292
      return new ObjectShape(vertices, indices);
293
      }
294
    else if( variant==3 ) // edge type 3
295
      {
296
      float[][] vertices =
297
          {
298
              {0.0f, 0.0f, -1.5f  },
299
              {1.0f, 0.0f, -0.5f  },
300
              {0.0f, 0.0f,  1.5f  },
301
              {0.0f,-1.0f,  0.5f  },
302
              { 4*T, -2*T,  0.5f*T},
303
              { 2*T, -4*T, -0.5f*T}
304
          };
305

    
306
      int[][] indices =
307
          {
308
              {0,2,1},
309
              {0,3,2},
310
              {0,5,3},
311
              {5,4,2,3},
312
              {4,1,2},
313
              {4,5,0,1}
314
          };
315

    
316
      return new ObjectShape(vertices, indices);
317
      }
318
    else if( variant==4 ) // corner type 1
319
      {
320
      float[][] vertices =
321
          {
322
              { 0.0f, 0.0f, 0.0f},
323
              {-1.5f, 0.0f, 0.0f},
324
              { 0.0f,-1.5f, 0.0f},
325
              { 0.0f, 0.0f, 1.5f},
326
              {-1.0f,-1.0f, 1.0f}
327
          };
328

    
329
      int[][] indices =
330
          {
331
              {1,3,0},
332
              {3,2,0},
333
              {2,1,0},
334
              {3,1,4},
335
              {2,3,4},
336
              {1,2,4}
337
          };
338

    
339
      return new ObjectShape(vertices, indices);
340
      }
341
    else                 // corner type 2
342
      {
343
      float[][] vertices =
344
          {
345
              {-1.0f, 0.0f, 1.0f},
346
              { 0.0f, 0.0f,-1.0f},
347
              { 1.0f, 0.0f, 0.0f},
348
              {    T, -2*T,   -T}
349
          };
350

    
351
      int[][] indices =
352
          {
353
              {0,2,1},
354
              {0,3,2},
355
              {2,3,1},
356
              {1,3,0}
357
          };
358

    
359
      return new ObjectShape(vertices, indices);
360
      }
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

    
365
  public ObjectFaceShape getObjectFaceShape(int variant)
366
    {
367
    float height = isInIconMode() ? 0.001f : 0.025f;
368

    
369
    if( variant==0 )
370
      {
371
      float[][] bands   = { {height,20,0.2f,0.4f,5,1,0}, {0.001f,20,0.2f,0.4f,5,1,0} };
372
      int[] bandIndices = { 0,0,1,1,1,1,1 };
373
      float[][] corners = { {0.04f,0.09f} };
374
      int[] indices     = { 0,0,0,0,-1,-1,-1,-1 };
375
      float[][] centers = { { -0.5f, -0.5f, 0.0f } };
376
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
377
      }
378
    else if( variant==1 )
379
      {
380
      float[][] bands   = { {height,20,0.2f,0.4f,5,1,0}, {0.001f,20,0.2f,0.4f,5,1,0} };
381
      int[] bandIndices = { 0,1,1,1,1 };
382
      float[][] corners = { {0.04f,0.09f} };
383
      int[] indices     = { 0,0,0,0,-1,-1 };
384
      float[][] centers = { { -5.0f/24, -5.0f/6, 5.0f/24} };
385
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
386
      }
387
    else if( variant==2 )
388
      {
389
      float[][] bands   = { {height,20,0.2f,0.4f,5,1,0}, {0.001f,20,0.2f,0.4f,5,1,0} };
390
      int[] bandIndices = { 0,0,1,1,1,1 };
391
      float[][] corners = { {0.04f,0.09f} };
392
      int[] indices     = { 0,0,0,0,-1,-1 };
393
      float[][] centers = { { 0.0f, -1.0f, -1.0f } };
394
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
395
      }
396
    else if( variant==3 )
397
      {
398
      float[][] bands   = { {height,20,0.2f,0.4f,5,1,0}, {0.001f,20,0.2f,0.4f,5,1,0} };
399
      int[] bandIndices = { 0,0,1,1,1,1 };
400
      float[][] corners = { {0.04f,0.09f} };
401
      int[] indices     = { 0,0,0,0,-1,-1 };
402
      float[][] centers = { { 1.0f, -1.0f, 0.0f } };
403
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
404
      }
405
    else if( variant==4 )
406
      {
407
      float[][] bands   = { {height,20,0.2f,0.4f,5,1,0}, {0.001f,20,0.2f,0.4f,5,1,0} };
408
      int[] bandIndices = { 0,0,0,1,1,1 };
409
      float[][] corners = { {0.03f,0.08f} };
410
      int[] indices     = { 0,0,0,0,-1 };
411
      float[][] centers = { { -1.0f, -1.0f, 1.0f } };
412
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
413
      }
414
    else
415
      {
416
      float h1 = isInIconMode() ? 0.001f : 0.05f;
417
      float h2 = isInIconMode() ? 0.001f : 0.01f;
418
      float[][] bands   = { {h1,35,0.25f,0.7f,5,1,0}, {h2,35,0.25f,0.7f,5,1,0} };
419
      int[] bandIndices = { 0,1,1,1 };
420
      float[][] corners = { {0.04f,0.12f} };
421
      int[] indices     = { 0,0,0,-1 };
422
      float[][] centers = { { 1.0f/3, -2.0f/3,-1.0f/3 } };
423
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
424
      }
425
    }
426

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

    
429
  public int getNumCubitVariants(int[] numLayers)
430
    {
431
    return 6;
432
    }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
  public int getCubitVariant(int cubit, int[] numLayers)
437
    {
438
    if( cubit<6 ) return 0;
439
    if( cubit<12) return 1;
440
    if( cubit<15) return 2;
441
    if( cubit<18) return 3;
442
    if( cubit<20) return 4;
443

    
444
    return 5;
445
    }
446

    
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448

    
449
  public float getStickerRadius()
450
    {
451
    return 0.13f;
452
    }
453

    
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455

    
456
  public float getStickerStroke()
457
    {
458
    return isInIconMode() ? 0.22f : 0.10f;
459
    }
460

    
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462

    
463
  public float[][] getStickerAngles()
464
    {
465
    return null;
466
    }
467

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469
// PUBLIC API
470

    
471
  public Static3D[] getRotationAxis()
472
    {
473
    return ROT_AXIS;
474
    }
475

    
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477

    
478
  public String getShortName()
479
    {
480
    return ObjectType.AXIS_3.name();
481
    }
482

    
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484

    
485
  public ObjectSignature getSignature()
486
    {
487
    return new ObjectSignature(ObjectType.AXIS_3);
488
    }
489

    
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491

    
492
  public int[][] getBasicAngles()
493
    {
494
    if( mBasicAngle ==null )
495
      {
496
      int num = getNumLayers()[0];
497
      int[] tmp = new int[num];
498
      for(int i=0; i<num; i++) tmp[i] = 4;
499
      mBasicAngle = new int[][] { tmp,tmp,tmp };
500
      }
501

    
502
    return mBasicAngle;
503
    }
504

    
505
///////////////////////////////////////////////////////////////////////////////////////////////////
506

    
507
  public String getObjectName()
508
    {
509
    return "Axis Cube";
510
    }
511

    
512
///////////////////////////////////////////////////////////////////////////////////////////////////
513

    
514
  public String getInventor()
515
    {
516
    return "Aleh Hladzilin";
517
    }
518

    
519
///////////////////////////////////////////////////////////////////////////////////////////////////
520

    
521
  public int getYearOfInvention()
522
    {
523
    return 2008;
524
    }
525

    
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527

    
528
  public int getComplexity()
529
    {
530
    return 2;
531
    }
532

    
533
///////////////////////////////////////////////////////////////////////////////////////////////////
534

    
535
  public String[][] getTutorials()
536
    {
537
    return new String[][]{
538
                          {"gb","DdYBkV07WpM","How to Solve the Axis Cube","Z3"},
539
                          {"es","oLWCj8-6G4Q","Resolver Axis Cube","Cuby"},
540
                          {"ru","pgPtyD7DV7A","Как собрать Аксис Куб","Алексей Ярыгин"},
541
                          {"fr","4M7cOgjZHSY","Résolution de l'Axis Cube","asthalis"},
542
                          {"de","CVPII1-sEqw","Axis Cube Tutorial","Pezcraft"},
543
                          {"pl","Yrmq0m4vjfE","Axis Cube TUTORIAL PL","MrUk"},
544
                          {"br","5HoM4_fQOM8","Como resolver o axis cube ","Gabriel Sihnel"},
545
                          {"kr","8KjHoNOGWLE","엑시스 큐브 해법","듀나메스 큐브 해법연구소"},
546
                          {"vn","ESdOqn7Tikg","Tutorial N.17 - Axis Cube","Duy Thích Rubik"},
547
                         };
548
    }
549
}
(1-1/36)