Project

General

Profile

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

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

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 ) mQuatIndex = new int[] {0,22,10,17,14,19, 0,22,10,17,14,19, 0,22,10, 0,22,10, 0,14, 0,14,10,19,17,22 };
210
    return mObjectQuats[mQuatIndex[cubit]];
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

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

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

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

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

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

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

    
443
    return 5;
444
    }
445

    
446
///////////////////////////////////////////////////////////////////////////////////////////////////
447

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

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

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

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

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

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468
// PUBLIC API
469

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

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

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

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483

    
484
  public long getSignature()
485
    {
486
    return ObjectType.AXIS_3.ordinal();
487
    }
488

    
489
///////////////////////////////////////////////////////////////////////////////////////////////////
490

    
491
  public int[] getBasicAngles()
492
    {
493
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 4,4,4 };
494
    return mBasicAngle;
495
    }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498

    
499
  public String getObjectName()
500
    {
501
    return "Axis Cube";
502
    }
503

    
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505

    
506
  public String getInventor()
507
    {
508
    return "Aleh Hladzilin";
509
    }
510

    
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512

    
513
  public int getYearOfInvention()
514
    {
515
    return 2008;
516
    }
517

    
518
///////////////////////////////////////////////////////////////////////////////////////////////////
519

    
520
  public int getComplexity()
521
    {
522
    return 2;
523
    }
524

    
525
///////////////////////////////////////////////////////////////////////////////////////////////////
526

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