Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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 org.distorted.library.type.Static3D;
23
import org.distorted.library.type.Static4D;
24
import org.distorted.objectlib.helpers.ObjectFaceShape;
25
import org.distorted.objectlib.helpers.ObjectShape;
26
import org.distorted.objectlib.helpers.ObjectSignature;
27
import org.distorted.objectlib.main.InitData;
28
import org.distorted.objectlib.scrambling.ScrambleState;
29
import org.distorted.objectlib.main.ObjectType;
30
import org.distorted.objectlib.main.ShapeHexahedron;
31
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
32

    
33
import java.io.InputStream;
34

    
35
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD;
36
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class TwistyAxis extends ShapeHexahedron
41
{
42
  static final Static3D[] ROT_AXIS = new Static3D[]
43
         {
44
           new Static3D(-2.0f/3, 1.0f/3, 2.0f/3),
45
           new Static3D( 1.0f/3,-2.0f/3, 2.0f/3),
46
           new Static3D( 2.0f/3, 2.0f/3, 1.0f/3),
47
         };
48

    
49
  private ScrambleState[] mStates;
50
  private int[][] mBasicAngle;
51
  private float[][] mCuts;
52
  private float[][] mCenters;
53
  private int[] mQuatIndex;
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

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

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  @Override
65
  public int getInternalColor()
66
    {
67
    return 0xff222222;
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
// same as in a 3x3
72

    
73
  public ScrambleState[] getScrambleStates()
74
    {
75
    if( mStates==null )
76
      {
77
      int[][] m = new int[16][];
78

    
79
      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};
80

    
81
      mStates = new ScrambleState[]
82
          {
83
          new ScrambleState( new int[][] { m[ 1], m[ 2], m[ 3] } ),  //  0 0
84
          new ScrambleState( new int[][] {  null, m[ 4], m[ 5] } ),  //  1 x
85
          new ScrambleState( new int[][] { m[ 6],  null, m[ 7] } ),  //  2 y
86
          new ScrambleState( new int[][] { m[ 8], m[ 9],  null } ),  //  3 z
87
          new ScrambleState( new int[][] { m[10],  null, m[ 7] } ),  //  4 xy
88
          new ScrambleState( new int[][] { m[11], m[ 9],  null } ),  //  5 xz
89
          new ScrambleState( new int[][] {  null, m[12], m[ 5] } ),  //  6 yx
90
          new ScrambleState( new int[][] { m[ 8], m[13],  null } ),  //  7 yz
91
          new ScrambleState( new int[][] {  null, m[ 4], m[14] } ),  //  8 zx
92
          new ScrambleState( new int[][] { m[ 6],  null, m[15] } ),  //  9 zy
93
          new ScrambleState( new int[][] {  null,  null, m[ 5] } ),  // 10 xyx
94
          new ScrambleState( new int[][] {  null, m[ 4],  null } ),  // 11 xzx
95
          new ScrambleState( new int[][] {  null,  null, m[ 7] } ),  // 12 yxy
96
          new ScrambleState( new int[][] { m[ 6],  null,  null } ),  // 13 yzy
97
          new ScrambleState( new int[][] {  null, m[ 9],  null } ),  // 14 zxz
98
          new ScrambleState( new int[][] { m[ 8],  null,  null } ),  // 15 zyz
99
          };
100
      }
101

    
102
    return mStates;
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  public float[][] getCuts(int[] numLayers)
108
    {
109
    if( mCuts==null )
110
      {
111
      float C = 0.5f;
112
      float[] cut = new float[] {-C,+C};
113
      mCuts = new float[][] { cut,cut,cut };
114
      }
115

    
116
    return mCuts;
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
  public boolean[][] getLayerRotatable(int[] numLayers)
122
    {
123
    boolean[] tmp = new boolean[] {true,true,true};
124
    return new boolean[][] { tmp,tmp,tmp };
125
    }
126

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

    
129
  public int getTouchControlType()
130
    {
131
    return TC_CHANGING_SHAPEMOD;
132
    }
133

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

    
136
  public int getTouchControlSplit()
137
    {
138
    return TYPE_NOT_SPLIT;
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
  public int[][][] getEnabled()
144
    {
145
    return null;
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  public float[] getDist3D(int[] numLayers)
151
    {
152
    return TouchControlHexahedron.D3D;
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  public Static3D[] getFaceAxis()
158
    {
159
    return TouchControlHexahedron.FACE_AXIS;
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  public float[][] getCubitPositions(int[] numLayers)
165
    {
166
    if( mCenters==null )
167
      {
168
      mCenters = new float[][]
169
         {
170
             { 1.50f, 1.50f, 0.75f},
171
             {-0.75f, 1.50f,-1.50f},
172
             { 1.50f,-0.75f,-1.50f},
173
             {-1.50f, 0.75f, 1.50f},
174
             { 0.75f,-1.50f, 1.50f},
175
             {-1.50f,-1.50f,-0.75f},
176

    
177
             {0.375f, 1.50f,-0.375f},
178
             {0.375f,0.375f,-1.50f },
179
             { 1.50f,0.375f,-0.375f},
180
             {-0.375f,-0.375f,1.50f},
181
             {-0.375f,-1.50f,0.375f},
182
             {-1.50f,-0.375f,0.375f},
183

    
184
             { 0.00f, 1.50f, 1.50f},
185
             {-1.50f, 0.00f,-1.50f},
186
             { 1.50f,-1.50f, 0.00f},
187

    
188
             {-1.50f, 1.50f, 0.00f},
189
             { 0.00f,-1.50f,-1.50f},
190
             { 1.50f, 0.00f, 1.50f},
191

    
192
             { 1.50f, 1.50f,-1.50f},
193
             {-1.50f,-1.50f, 1.50f},
194

    
195
             {-0.5f, 1.5f, 0.5f},
196
             { 0.5f,-1.5f,-0.5f},
197
             { 1.5f,-0.5f, 0.5f},
198
             {-1.5f, 0.5f,-0.5f},
199
             { 0.5f, 0.5f, 1.5f},
200
             {-0.5f,-0.5f,-1.5f},
201
         };
202
      }
203

    
204
    return mCenters;
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

    
209
  public Static4D getCubitQuats(int cubit, int[] numLayers)
210
    {
211
    if( mQuatIndex==null )
212
      {
213
      mQuatIndex = new int[] { 0,22,10,17,14,19,
214
                               0,22,10,17,14,19,
215
                               0,22,10,
216
                               0,22,10,
217
                               0,14,
218
                               0,14,10,19,17,22
219
                             };
220
      }
221
    return mObjectQuats[mQuatIndex[cubit]];
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  public ObjectShape getObjectShape(int variant)
227
    {
228
    final float T = 1.0f/3;
229

    
230
    if( variant==0 )  // center
231
      {
232
      float[][] vertices =
233
          {
234
              { -1.0f, 0.0f, -0.25f  },
235
              {  0.0f, 0.0f, -0.75f  },
236
              {  0.0f, 0.0f,  0.75f  },
237
              {  0.0f,-1.0f, -0.25f  },
238
              {  -5*T, -2*T, -1.75f*T},
239
              { -1.0f,-1.0f, -1.25f  },
240
              {  -4*T, -4*T,  0.25f*T},
241
              {  -2*T, -5*T, -1.75f*T}
242
          };
243

    
244
      int[][] indices =
245
          {
246
              {2,1,0},
247
              {2,3,1},
248
              {4,6,2,0},
249
              {6,7,3,2},
250
              {7,5,1,3},
251
              {5,4,0,1},
252
              {7,6,4,5}
253
          };
254

    
255
      return new ObjectShape(vertices, indices);
256
      }
257
    else if( variant==1 ) // edge type 1
258
      {
259
      float[][] vertices =
260
          {
261
              {-0.375f  , 0.0f, -1.125f  },
262
              { 1.125f  , 0.0f,  0.375f  },
263
              {-0.875f  , 0.0f, -0.125f  },
264
              { 0.125f  , 0.0f,  0.875f  },
265
              {-1.625f*T, -2*T,  1.625f*T},
266
              { 0.125f  ,-1.0f, -0.125f  }
267
          };
268

    
269
      int[][] indices =
270
          {
271
              {2,3,1,0},
272
              {2,4,3},
273
              {4,5,1,3},
274
              {5,0,1},
275
              {5,4,2,0}
276
          };
277

    
278
      return new ObjectShape(vertices, indices);
279
      }
280
    else if( variant==2 ) // edge type 2
281
      {
282
      float[][] vertices =
283
          {
284
              {-1.5f  , 0.0f, 0.0f},
285
              { 0.5f  , 0.0f,-1.0f},
286
              { 1.5f  , 0.0f, 0.0f},
287
              {-0.5f  ,-1.0f, 0.0f},
288
              {-0.5f*T, -2*T, -4*T},
289
              { 0.5f*T, -4*T, -2*T},
290
          };
291

    
292
      int[][] indices =
293
          {
294
              {0,2,1},
295
              {0,3,2},
296
              {3,5,2},
297
              {1,4,0},
298
              {4,5,3,0},
299
              {5,4,1,2}
300
          };
301

    
302
      return new ObjectShape(vertices, indices);
303
      }
304
    else if( variant==3 ) // edge type 3
305
      {
306
      float[][] vertices =
307
          {
308
              {0.0f, 0.0f, -1.5f  },
309
              {1.0f, 0.0f, -0.5f  },
310
              {0.0f, 0.0f,  1.5f  },
311
              {0.0f,-1.0f,  0.5f  },
312
              { 4*T, -2*T,  0.5f*T},
313
              { 2*T, -4*T, -0.5f*T}
314
          };
315

    
316
      int[][] indices =
317
          {
318
              {0,2,1},
319
              {0,3,2},
320
              {0,5,3},
321
              {5,4,2,3},
322
              {4,1,2},
323
              {4,5,0,1}
324
          };
325

    
326
      return new ObjectShape(vertices, indices);
327
      }
328
    else if( variant==4 ) // corner type 1
329
      {
330
      float[][] vertices =
331
          {
332
              { 0.0f, 0.0f, 0.0f},
333
              {-1.5f, 0.0f, 0.0f},
334
              { 0.0f,-1.5f, 0.0f},
335
              { 0.0f, 0.0f, 1.5f},
336
              {-1.0f,-1.0f, 1.0f}
337
          };
338

    
339
      int[][] indices =
340
          {
341
              {1,3,0},
342
              {3,2,0},
343
              {2,1,0},
344
              {3,1,4},
345
              {2,3,4},
346
              {1,2,4}
347
          };
348

    
349
      return new ObjectShape(vertices, indices);
350
      }
351
    else                 // corner type 2
352
      {
353
      float[][] vertices =
354
          {
355
              {-1.0f, 0.0f, 1.0f},
356
              { 0.0f, 0.0f,-1.0f},
357
              { 1.0f, 0.0f, 0.0f},
358
              {    T, -2*T,   -T}
359
          };
360

    
361
      int[][] indices =
362
          {
363
              {0,2,1},
364
              {0,3,2},
365
              {2,3,1},
366
              {1,3,0}
367
          };
368

    
369
      return new ObjectShape(vertices, indices);
370
      }
371
    }
372

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

    
375
  public ObjectFaceShape getObjectFaceShape(int variant)
376
    {
377
    float height = isInIconMode() ? 0.001f : 0.025f;
378

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

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

    
439
  public int getNumCubitVariants(int[] numLayers)
440
    {
441
    return 6;
442
    }
443

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445

    
446
  public int getCubitVariant(int cubit, int[] numLayers)
447
    {
448
    if( cubit<6 ) return 0;
449
    if( cubit<12) return 1;
450
    if( cubit<15) return 2;
451
    if( cubit<18) return 3;
452
    if( cubit<20) return 4;
453

    
454
    return 5;
455
    }
456

    
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458

    
459
  public float getStickerRadius()
460
    {
461
    return 0.13f;
462
    }
463

    
464
///////////////////////////////////////////////////////////////////////////////////////////////////
465

    
466
  public float getStickerStroke()
467
    {
468
    return isInIconMode() ? 0.22f : 0.10f;
469
    }
470

    
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472

    
473
  public float[][] getStickerAngles()
474
    {
475
    return null;
476
    }
477

    
478
///////////////////////////////////////////////////////////////////////////////////////////////////
479
// PUBLIC API
480

    
481
  public Static3D[] getRotationAxis()
482
    {
483
    return ROT_AXIS;
484
    }
485

    
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487

    
488
  public String getShortName()
489
    {
490
    return ObjectType.AXIS_3.name();
491
    }
492

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494

    
495
  public ObjectSignature getSignature()
496
    {
497
    return new ObjectSignature(ObjectType.AXIS_3);
498
    }
499

    
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501

    
502
  public int[][] getBasicAngles()
503
    {
504
    if( mBasicAngle ==null )
505
      {
506
      int num = getNumLayers()[0];
507
      int[] tmp = new int[num];
508
      for(int i=0; i<num; i++) tmp[i] = 4;
509
      mBasicAngle = new int[][] { tmp,tmp,tmp };
510
      }
511

    
512
    return mBasicAngle;
513
    }
514

    
515
///////////////////////////////////////////////////////////////////////////////////////////////////
516

    
517
  public String getObjectName()
518
    {
519
    return "Axis Cube";
520
    }
521

    
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523

    
524
  public String getInventor()
525
    {
526
    return "Aleh Hladzilin";
527
    }
528

    
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530

    
531
  public int getYearOfInvention()
532
    {
533
    return 2008;
534
    }
535

    
536
///////////////////////////////////////////////////////////////////////////////////////////////////
537

    
538
  public int getComplexity()
539
    {
540
    return 2;
541
    }
542

    
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544

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