Project

General

Profile

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

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

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

    
32
import java.io.InputStream;
33

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

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

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

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

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

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

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

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

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

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

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

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

    
101
    return mStates;
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

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

    
115
    return mCuts;
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

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

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

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

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

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

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

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

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

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

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

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

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

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

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

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

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

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

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

    
203
    return mCenters;
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

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

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
372
///////////////////////////////////////////////////////////////////////////////////////////////////
373

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

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

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

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

    
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444

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

    
453
    return 5;
454
    }
455

    
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457

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

    
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464

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

    
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471

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

    
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478
// PUBLIC API
479

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

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486

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

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493

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

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

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

    
511
    return mBasicAngle;
512
    }
513

    
514
///////////////////////////////////////////////////////////////////////////////////////////////////
515

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

    
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522

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

    
528
///////////////////////////////////////////////////////////////////////////////////////////////////
529

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

    
535
///////////////////////////////////////////////////////////////////////////////////////////////////
536

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

    
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543

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