Project

General

Profile

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

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

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.FactoryCubit;
15
import org.distorted.objectlib.helpers.ObjectFaceShape;
16
import org.distorted.objectlib.helpers.ObjectShape;
17
import org.distorted.objectlib.helpers.ObjectSignature;
18
import org.distorted.objectlib.helpers.ObjectVertexEffects;
19
import org.distorted.objectlib.main.InitData;
20
import org.distorted.objectlib.scrambling.ScrambleState;
21
import org.distorted.objectlib.main.ObjectType;
22
import org.distorted.objectlib.shape.ShapeHexahedron;
23
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
24

    
25
import java.io.InputStream;
26

    
27
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD;
28
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

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

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

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

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

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

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

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
// same as in a 3x3
64

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

    
71
      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};
72

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

    
94
    return mStates;
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

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

    
108
    return mCuts;
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

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

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

    
121
  public int getTouchControlType()
122
    {
123
    return TC_CHANGING_SHAPEMOD;
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
  public int getTouchControlSplit()
129
    {
130
    return TYPE_NOT_SPLIT;
131
    }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
  public int[][][] getEnabled()
136
    {
137
    return null;
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

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

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

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

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

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

    
169
             {0.375f, 1.50f,-0.375f},
170
             {0.375f,0.375f,-1.50f },
171
             { 1.50f,0.375f,-0.375f},
172
             {-0.375f,-0.375f,1.50f},
173
             {-0.375f,-1.50f,0.375f},
174
             {-1.50f,-0.375f,0.375f},
175

    
176
             { 0.00f, 1.50f, 1.50f},
177
             {-1.50f, 0.00f,-1.50f},
178
             { 1.50f,-1.50f, 0.00f},
179

    
180
             {-1.50f, 1.50f, 0.00f},
181
             { 0.00f,-1.50f,-1.50f},
182
             { 1.50f, 0.00f, 1.50f},
183

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

    
187
             {-0.5f, 1.5f, 0.5f},
188
             { 0.5f,-1.5f,-0.5f},
189
             { 1.5f,-0.5f, 0.5f},
190
             {-1.5f, 0.5f,-0.5f},
191
             { 0.5f, 0.5f, 1.5f},
192
             {-0.5f,-0.5f,-1.5f},
193
         };
194
      }
195

    
196
    return mCenters;
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

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

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
  private float[][] getVertices(int variant)
219
    {
220
    final float T = 1.0f/3;
221

    
222
    if( variant==0 )
223
      {
224
      return new float[][]
225
          {
226
              { -1.0f, 0.0f, -0.25f  },
227
              {  0.0f, 0.0f, -0.75f  },
228
              {  0.0f, 0.0f,  0.75f  },
229
              {  0.0f,-1.0f, -0.25f  },
230
              {  -5*T, -2*T, -1.75f*T},
231
              { -1.0f,-1.0f, -1.25f  },
232
              {  -4*T, -4*T,  0.25f*T},
233
              {  -2*T, -5*T, -1.75f*T}
234
          };
235
      }
236
    else if( variant==1 )
237
      {
238
      return new float[][]
239
          {
240
              {-0.375f  , 0.0f, -1.125f  },
241
              { 1.125f  , 0.0f,  0.375f  },
242
              {-0.875f  , 0.0f, -0.125f  },
243
              { 0.125f  , 0.0f,  0.875f  },
244
              {-1.625f*T, -2*T,  1.625f*T},
245
              { 0.125f  ,-1.0f, -0.125f  }
246
          };
247
      }
248
    else if( variant==2 )
249
      {
250
      return new float[][]
251
          {
252
              {-1.5f  , 0.0f, 0.0f},
253
              { 0.5f  , 0.0f,-1.0f},
254
              { 1.5f  , 0.0f, 0.0f},
255
              {-0.5f  ,-1.0f, 0.0f},
256
              {-0.5f*T, -2*T, -4*T},
257
              { 0.5f*T, -4*T, -2*T},
258
          };
259
      }
260
    else if( variant==3 )
261
      {
262
      return new float[][]
263
          {
264
              {0.0f, 0.0f, -1.5f  },
265
              {1.0f, 0.0f, -0.5f  },
266
              {0.0f, 0.0f,  1.5f  },
267
              {0.0f,-1.0f,  0.5f  },
268
              { 4*T, -2*T,  0.5f*T},
269
              { 2*T, -4*T, -0.5f*T}
270
          };
271
      }
272
    else if( variant==4 )
273
      {
274
      return new float[][]
275
          {
276
              { 0.0f, 0.0f, 0.0f},
277
              {-1.5f, 0.0f, 0.0f},
278
              { 0.0f,-1.5f, 0.0f},
279
              { 0.0f, 0.0f, 1.5f},
280
              {-1.0f,-1.0f, 1.0f}
281
          };
282
      }
283
    else
284
      {
285
      return new float[][]
286
          {
287
              {-1.0f, 0.0f, 1.0f},
288
              { 0.0f, 0.0f,-1.0f},
289
              { 1.0f, 0.0f, 0.0f},
290
              {    T, -2*T,   -T}
291
          };
292
      }
293
    }
294

    
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296

    
297
  public ObjectShape getObjectShape(int variant)
298
    {
299
    if( variant==0 )  // center
300
      {
301
      int[][] indices =
302
          {
303
              {2,1,0},
304
              {2,3,1},
305
              {4,6,2,0},
306
              {6,7,3,2},
307
              {7,5,1,3},
308
              {5,4,0,1},
309
              {7,6,4,5}
310
          };
311

    
312
      return new ObjectShape(getVertices(variant), indices);
313
      }
314
    else if( variant==1 ) // edge type 1
315
      {
316
      int[][] indices =
317
          {
318
              {2,3,1,0},
319
              {2,4,3},
320
              {4,5,1,3},
321
              {5,0,1},
322
              {5,4,2,0}
323
          };
324

    
325
      return new ObjectShape(getVertices(variant), indices);
326
      }
327
    else if( variant==2 ) // edge type 2
328
      {
329
      int[][] indices =
330
          {
331
              {0,2,1},
332
              {0,3,2},
333
              {3,5,2},
334
              {1,4,0},
335
              {4,5,3,0},
336
              {5,4,1,2}
337
          };
338

    
339
      return new ObjectShape(getVertices(variant), indices);
340
      }
341
    else if( variant==3 ) // edge type 3
342
      {
343
      int[][] indices =
344
          {
345
              {0,2,1},
346
              {0,3,2},
347
              {0,5,3},
348
              {5,4,2,3},
349
              {4,1,2},
350
              {4,5,0,1}
351
          };
352

    
353
      return new ObjectShape(getVertices(variant), indices);
354
      }
355
    else if( variant==4 ) // corner type 1
356
      {
357
      int[][] indices =
358
          {
359
              {1,3,0},
360
              {3,2,0},
361
              {2,1,0},
362
              {3,1,4},
363
              {2,3,4},
364
              {1,2,4}
365
          };
366

    
367
      return new ObjectShape(getVertices(variant), indices);
368
      }
369
    else                 // corner type 2
370
      {
371
      int[][] indices =
372
          {
373
              {0,2,1},
374
              {0,3,2},
375
              {2,3,1},
376
              {1,3,0}
377
          };
378

    
379
      return new ObjectShape(getVertices(variant), indices);
380
      }
381
    }
382

    
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384

    
385
  public ObjectFaceShape getObjectFaceShape(int variant)
386
    {
387
    float height = isInIconMode() ? 0.001f : 0.025f;
388

    
389
    if( variant==0 )
390
      {
391
      float[][] bands   = { {height,20,0.2f,0.4f,5,1,0}, {0.001f,20,0.2f,0.4f,5,1,0} };
392
      int[] bandIndices = { 0,0,1,1,1,1,1 };
393
      return new ObjectFaceShape(bands,bandIndices,null);
394
      }
395
    else if( variant==1 )
396
      {
397
      float[][] bands   = { {height,20,0.2f,0.4f,5,1,0}, {0.001f,20,0.2f,0.4f,5,1,0} };
398
      int[] bandIndices = { 0,1,1,1,1 };
399
      return new ObjectFaceShape(bands,bandIndices,null);
400
      }
401
    else if( variant==2 )
402
      {
403
      float[][] bands   = { {height,20,0.2f,0.4f,5,1,0}, {0.001f,20,0.2f,0.4f,5,1,0} };
404
      int[] bandIndices = { 0,0,1,1,1,1 };
405
      return new ObjectFaceShape(bands,bandIndices,null);
406
      }
407
    else if( variant==3 )
408
      {
409
      float[][] bands   = { {height,20,0.2f,0.4f,5,1,0}, {0.001f,20,0.2f,0.4f,5,1,0} };
410
      int[] bandIndices = { 0,0,1,1,1,1 };
411
      return new ObjectFaceShape(bands,bandIndices,null);
412
      }
413
    else if( variant==4 )
414
      {
415
      float[][] bands   = { {height,20,0.2f,0.4f,5,1,0}, {0.001f,20,0.2f,0.4f,5,1,0} };
416
      int[] bandIndices = { 0,0,0,1,1,1 };
417
      return new ObjectFaceShape(bands,bandIndices,null);
418
      }
419
    else
420
      {
421
      float h1 = isInIconMode() ? 0.001f : 0.05f;
422
      float h2 = isInIconMode() ? 0.001f : 0.01f;
423
      float[][] bands   = { {h1,35,0.25f,0.7f,5,1,0}, {h2,35,0.25f,0.7f,5,1,0} };
424
      int[] bandIndices = { 0,1,1,1 };
425
      return new ObjectFaceShape(bands,bandIndices,null);
426
      }
427
    }
428

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

    
431
  public ObjectVertexEffects getVertexEffects(int variant)
432
    {
433
    if( variant==0 )
434
      {
435
      float[][] vertices= getVertices(variant);
436
      float[][] corners = { {0.04f,0.09f} };
437
      int[] indices     = { 0,0,0,0,-1,-1,-1,-1 };
438
      float[][] centers = { { -0.5f, -0.5f, 0.0f } };
439
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
440
      }
441
    else if( variant==1 )
442
      {
443
      float[][] vertices= getVertices(variant);
444
      float[][] corners = { {0.04f,0.09f} };
445
      int[] indices     = { 0,0,0,0,-1,-1 };
446
      float[][] centers = { { -5.0f/24, -5.0f/6, 5.0f/24} };
447
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
448
      }
449
    else if( variant==2 )
450
      {
451
      float[][] vertices= getVertices(variant);
452
      float[][] corners = { {0.04f,0.09f} };
453
      int[] indices     = { 0,0,0,0,-1,-1 };
454
      float[][] centers = { { 0.0f, -1.0f, -1.0f } };
455
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
456
      }
457
    else if( variant==3 )
458
      {
459
      float[][] vertices= getVertices(variant);
460
      float[][] corners = { {0.04f,0.09f} };
461
      int[] indices     = { 0,0,0,0,-1,-1 };
462
      float[][] centers = { { 1.0f, -1.0f, 0.0f } };
463
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
464
      }
465
    else if( variant==4 )
466
      {
467
      float[][] vertices= getVertices(variant);
468
      float[][] corners = { {0.03f,0.08f} };
469
      int[] indices     = { 0,0,0,0,-1 };
470
      float[][] centers = { { -1.0f, -1.0f, 1.0f } };
471
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
472
      }
473
    else
474
      {
475
      float[][] vertices= getVertices(variant);
476
      float[][] corners = { {0.04f,0.12f} };
477
      int[] indices     = { 0,0,0,-1 };
478
      float[][] centers = { { 1.0f/3, -2.0f/3,-1.0f/3 } };
479
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
480
      }
481
    }
482

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

    
485
  public int getNumCubitVariants(int[] numLayers)
486
    {
487
    return 6;
488
    }
489

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

    
492
  public int getCubitVariant(int cubit, int[] numLayers)
493
    {
494
    if( cubit<6 ) return 0;
495
    if( cubit<12) return 1;
496
    if( cubit<15) return 2;
497
    if( cubit<18) return 3;
498
    if( cubit<20) return 4;
499

    
500
    return 5;
501
    }
502

    
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

    
505
  public float getStickerRadius()
506
    {
507
    return 0.13f;
508
    }
509

    
510
///////////////////////////////////////////////////////////////////////////////////////////////////
511

    
512
  public float getStickerStroke()
513
    {
514
    return isInIconMode() ? 0.22f : 0.10f;
515
    }
516

    
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518

    
519
  public float[][] getStickerAngles()
520
    {
521
    return null;
522
    }
523

    
524
///////////////////////////////////////////////////////////////////////////////////////////////////
525
// PUBLIC API
526

    
527
  public Static3D[] getRotationAxis()
528
    {
529
    return ROT_AXIS;
530
    }
531

    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533

    
534
  public String getShortName()
535
    {
536
    return ObjectType.AXIS_3.name();
537
    }
538

    
539
///////////////////////////////////////////////////////////////////////////////////////////////////
540

    
541
  public ObjectSignature getSignature()
542
    {
543
    return new ObjectSignature(ObjectType.AXIS_3);
544
    }
545

    
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547

    
548
  public int[][] getBasicAngles()
549
    {
550
    if( mBasicAngle ==null )
551
      {
552
      int num = getNumLayers()[0];
553
      int[] tmp = new int[num];
554
      for(int i=0; i<num; i++) tmp[i] = 4;
555
      mBasicAngle = new int[][] { tmp,tmp,tmp };
556
      }
557

    
558
    return mBasicAngle;
559
    }
560

    
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562

    
563
  public String getObjectName()
564
    {
565
    return "Axis Cube";
566
    }
567

    
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569

    
570
  public String getInventor()
571
    {
572
    return "Aleh Hladzilin";
573
    }
574

    
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576

    
577
  public int getYearOfInvention()
578
    {
579
    return 2008;
580
    }
581

    
582
///////////////////////////////////////////////////////////////////////////////////////////////////
583

    
584
  public int getComplexity()
585
    {
586
    return 2;
587
    }
588

    
589
///////////////////////////////////////////////////////////////////////////////////////////////////
590

    
591
  public String[][] getTutorials()
592
    {
593
    return new String[][]{
594
                          {"gb","DdYBkV07WpM","How to Solve the Axis Cube","Z3"},
595
                          {"es","oLWCj8-6G4Q","Resolver Axis Cube","Cuby"},
596
                          {"ru","pgPtyD7DV7A","Как собрать Аксис Куб","Алексей Ярыгин"},
597
                          {"fr","4M7cOgjZHSY","Résolution de l'Axis Cube","asthalis"},
598
                          {"de","CVPII1-sEqw","Axis Cube Tutorial","Pezcraft"},
599
                          {"pl","Yrmq0m4vjfE","Axis Cube TUTORIAL PL","MrUk"},
600
                          {"br","5HoM4_fQOM8","Como resolver o axis cube ","Gabriel Sihnel"},
601
                          {"kr","8KjHoNOGWLE","엑시스 큐브 해법","듀나메스 큐브 해법연구소"},
602
                          {"vn","ESdOqn7Tikg","Tutorial N.17 - Axis Cube","Duy Thích Rubik"},
603
                         };
604
    }
605
}
(1-1/41)