Project

General

Profile

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

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

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.scrambling.ScrambleState;
27
import org.distorted.objectlib.main.ObjectType;
28
import org.distorted.objectlib.main.ShapeHexahedron;
29
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
30

    
31
import java.io.InputStream;
32

    
33
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD;
34
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

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

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

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
  public TwistyAxis(int[] numL, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
56
    {
57
    super(numL, meshState, iconMode, numL[0], quat, move, scale, stream);
58
    }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

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

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
// same as in a 3x3
70

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

    
77
      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};
78

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

    
100
    return mStates;
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

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

    
114
    return mCuts;
115
    }
116

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

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

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
  public int getTouchControlType()
128
    {
129
    return TC_CHANGING_SHAPEMOD;
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  public int getTouchControlSplit()
135
    {
136
    return TYPE_NOT_SPLIT;
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  public int[][][] getEnabled()
142
    {
143
    return null;
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

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

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

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

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

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

    
175
             {0.375f, 1.50f,-0.375f},
176
             {0.375f,0.375f,-1.50f },
177
             { 1.50f,0.375f,-0.375f},
178
             {-0.375f,-0.375f,1.50f},
179
             {-0.375f,-1.50f,0.375f},
180
             {-1.50f,-0.375f,0.375f},
181

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

    
186
             {-1.50f, 1.50f, 0.00f},
187
             { 0.00f,-1.50f,-1.50f},
188
             { 1.50f, 0.00f, 1.50f},
189

    
190
             { 1.50f, 1.50f,-1.50f},
191
             {-1.50f,-1.50f, 1.50f},
192

    
193
             {-0.5f, 1.5f, 0.5f},
194
             { 0.5f,-1.5f,-0.5f},
195
             { 1.5f,-0.5f, 0.5f},
196
             {-1.5f, 0.5f,-0.5f},
197
             { 0.5f, 0.5f, 1.5f},
198
             {-0.5f,-0.5f,-1.5f},
199
         };
200
      }
201

    
202
    return mCenters;
203
    }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

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

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

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

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

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

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

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

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

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

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

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

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

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

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

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

    
367
      return new ObjectShape(vertices, indices);
368
      }
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

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

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

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

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

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

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

    
452
    return 5;
453
    }
454

    
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456

    
457
  public float getStickerRadius()
458
    {
459
    return 0.13f;
460
    }
461

    
462
///////////////////////////////////////////////////////////////////////////////////////////////////
463

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

    
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470

    
471
  public float[][] getStickerAngles()
472
    {
473
    return null;
474
    }
475

    
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477
// PUBLIC API
478

    
479
  public Static3D[] getRotationAxis()
480
    {
481
    return ROT_AXIS;
482
    }
483

    
484
///////////////////////////////////////////////////////////////////////////////////////////////////
485

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

    
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492

    
493
  public long getSignature()
494
    {
495
    return ObjectType.AXIS_3.ordinal();
496
    }
497

    
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499

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

    
510
    return mBasicAngle;
511
    }
512

    
513
///////////////////////////////////////////////////////////////////////////////////////////////////
514

    
515
  public String getObjectName()
516
    {
517
    return "Axis Cube";
518
    }
519

    
520
///////////////////////////////////////////////////////////////////////////////////////////////////
521

    
522
  public String getInventor()
523
    {
524
    return "Aleh Hladzilin";
525
    }
526

    
527
///////////////////////////////////////////////////////////////////////////////////////////////////
528

    
529
  public int getYearOfInvention()
530
    {
531
    return 2008;
532
    }
533

    
534
///////////////////////////////////////////////////////////////////////////////////////////////////
535

    
536
  public int getComplexity()
537
    {
538
    return 2;
539
    }
540

    
541
///////////////////////////////////////////////////////////////////////////////////////////////////
542

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