Project

General

Profile

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

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

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.metadata.Metadata;
18
import org.distorted.objectlib.signature.ObjectSignature;
19
import org.distorted.objectlib.helpers.ObjectVertexEffects;
20
import org.distorted.objectlib.main.InitAssets;
21
import org.distorted.objectlib.signature.ObjectConstants;
22
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
23
import org.distorted.objectlib.main.ObjectType;
24
import org.distorted.objectlib.shape.ShapeHexahedron;
25
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
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 int[][] mEdges;
42
  private int[][] mBasicAngle;
43
  private float[][] mCuts;
44
  private float[][] mCenters;
45
  private int[] mQuatIndex;
46

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

    
49
  public TwistyAxis(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
50
    {
51
    super(iconMode, meta.getNumLayers()[0], quat, move, scale, meta, asset);
52
    }
53

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

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

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

    
64
  public int[][] getScrambleEdges()
65
    {
66
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesCuboid(3,3,3);
67
    return mEdges;
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  public float[][] getCuts(int[] numLayers)
73
    {
74
    if( mCuts==null )
75
      {
76
      float C = 0.5f;
77
      float[] cut = new float[] {-C,+C};
78
      mCuts = new float[][] { cut,cut,cut };
79
      }
80

    
81
    return mCuts;
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
  public boolean[][] getLayerRotatable(int[] numLayers)
87
    {
88
    boolean[] tmp = new boolean[] {true,true,true};
89
    return new boolean[][] { tmp,tmp,tmp };
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  public int getTouchControlType()
95
    {
96
    return TC_CHANGING_SHAPEMOD;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  public int getTouchControlSplit()
102
    {
103
    return TYPE_NOT_SPLIT;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public int[][][] getEnabled()
109
    {
110
    return null;
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  public float[] getDist3D(int[] numLayers)
116
    {
117
    return TouchControlHexahedron.D3D;
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  public Static3D[] getFaceAxis()
123
    {
124
    return TouchControlHexahedron.FACE_AXIS;
125
    }
126

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

    
129
  public float[][] getCubitPositions(int[] numLayers)
130
    {
131
    if( mCenters==null )
132
      {
133
      mCenters = new float[][]
134
         {
135
             { 1.50f, 1.50f, 0.75f},
136
             {-0.75f, 1.50f,-1.50f},
137
             { 1.50f,-0.75f,-1.50f},
138
             {-1.50f, 0.75f, 1.50f},
139
             { 0.75f,-1.50f, 1.50f},
140
             {-1.50f,-1.50f,-0.75f},
141

    
142
             {0.375f, 1.50f,-0.375f},
143
             {0.375f,0.375f,-1.50f },
144
             { 1.50f,0.375f,-0.375f},
145
             {-0.375f,-0.375f,1.50f},
146
             {-0.375f,-1.50f,0.375f},
147
             {-1.50f,-0.375f,0.375f},
148

    
149
             { 0.00f, 1.50f, 1.50f},
150
             {-1.50f, 0.00f,-1.50f},
151
             { 1.50f,-1.50f, 0.00f},
152

    
153
             {-1.50f, 1.50f, 0.00f},
154
             { 0.00f,-1.50f,-1.50f},
155
             { 1.50f, 0.00f, 1.50f},
156

    
157
             { 1.50f, 1.50f,-1.50f},
158
             {-1.50f,-1.50f, 1.50f},
159

    
160
             {-0.5f, 1.5f, 0.5f},
161
             { 0.5f,-1.5f,-0.5f},
162
             { 1.5f,-0.5f, 0.5f},
163
             {-1.5f, 0.5f,-0.5f},
164
             { 0.5f, 0.5f, 1.5f},
165
             {-0.5f,-0.5f,-1.5f},
166
         };
167
      }
168

    
169
    return mCenters;
170
    }
171

    
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

    
174
  public Static4D getCubitQuats(int cubit, int[] numLayers)
175
    {
176
    if( mQuatIndex==null )
177
      {
178
      mQuatIndex = new int[] { 0,22,10,17,14,19,
179
                               0,22,10,17,14,19,
180
                               0,22,10,
181
                               0,22,10,
182
                               0,14,
183
                               0,14,10,19,17,22
184
                             };
185
      }
186
    return mObjectQuats[mQuatIndex[cubit]];
187
    }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

    
191
  private float[][] getVertices(int variant)
192
    {
193
    final float T = 1.0f/3;
194

    
195
    if( variant==0 )
196
      {
197
      return new float[][]
198
          {
199
              { -1.0f, 0.0f, -0.25f  },
200
              {  0.0f, 0.0f, -0.75f  },
201
              {  0.0f, 0.0f,  0.75f  },
202
              {  0.0f,-1.0f, -0.25f  },
203
              {  -5*T, -2*T, -1.75f*T},
204
              { -1.0f,-1.0f, -1.25f  },
205
              {  -4*T, -4*T,  0.25f*T},
206
              {  -2*T, -5*T, -1.75f*T}
207
          };
208
      }
209
    else if( variant==1 )
210
      {
211
      return new float[][]
212
          {
213
              {-0.375f  , 0.0f, -1.125f  },
214
              { 1.125f  , 0.0f,  0.375f  },
215
              {-0.875f  , 0.0f, -0.125f  },
216
              { 0.125f  , 0.0f,  0.875f  },
217
              {-1.625f*T, -2*T,  1.625f*T},
218
              { 0.125f  ,-1.0f, -0.125f  }
219
          };
220
      }
221
    else if( variant==2 )
222
      {
223
      return new float[][]
224
          {
225
              {-1.5f  , 0.0f, 0.0f},
226
              { 0.5f  , 0.0f,-1.0f},
227
              { 1.5f  , 0.0f, 0.0f},
228
              {-0.5f  ,-1.0f, 0.0f},
229
              {-0.5f*T, -2*T, -4*T},
230
              { 0.5f*T, -4*T, -2*T},
231
          };
232
      }
233
    else if( variant==3 )
234
      {
235
      return new float[][]
236
          {
237
              {0.0f, 0.0f, -1.5f  },
238
              {1.0f, 0.0f, -0.5f  },
239
              {0.0f, 0.0f,  1.5f  },
240
              {0.0f,-1.0f,  0.5f  },
241
              { 4*T, -2*T,  0.5f*T},
242
              { 2*T, -4*T, -0.5f*T}
243
          };
244
      }
245
    else if( variant==4 )
246
      {
247
      return new float[][]
248
          {
249
              { 0.0f, 0.0f, 0.0f},
250
              {-1.5f, 0.0f, 0.0f},
251
              { 0.0f,-1.5f, 0.0f},
252
              { 0.0f, 0.0f, 1.5f},
253
              {-1.0f,-1.0f, 1.0f}
254
          };
255
      }
256
    else
257
      {
258
      return new float[][]
259
          {
260
              {-1.0f, 0.0f, 1.0f},
261
              { 0.0f, 0.0f,-1.0f},
262
              { 1.0f, 0.0f, 0.0f},
263
              {    T, -2*T,   -T}
264
          };
265
      }
266
    }
267

    
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269

    
270
  public ObjectShape getObjectShape(int variant)
271
    {
272
    if( variant==0 )  // center
273
      {
274
      int[][] indices =
275
          {
276
              {2,1,0},
277
              {2,3,1},
278
              {4,6,2,0},
279
              {6,7,3,2},
280
              {7,5,1,3},
281
              {5,4,0,1},
282
              {7,6,4,5}
283
          };
284

    
285
      return new ObjectShape(getVertices(variant), indices);
286
      }
287
    else if( variant==1 ) // edge type 1
288
      {
289
      int[][] indices =
290
          {
291
              {2,3,1,0},
292
              {2,4,3},
293
              {4,5,1,3},
294
              {5,0,1},
295
              {5,4,2,0}
296
          };
297

    
298
      return new ObjectShape(getVertices(variant), indices);
299
      }
300
    else if( variant==2 ) // edge type 2
301
      {
302
      int[][] indices =
303
          {
304
              {0,2,1},
305
              {0,3,2},
306
              {3,5,2},
307
              {1,4,0},
308
              {4,5,3,0},
309
              {5,4,1,2}
310
          };
311

    
312
      return new ObjectShape(getVertices(variant), indices);
313
      }
314
    else if( variant==3 ) // edge type 3
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(getVertices(variant), indices);
327
      }
328
    else if( variant==4 ) // corner type 1
329
      {
330
      int[][] indices =
331
          {
332
              {1,3,0},
333
              {3,2,0},
334
              {2,1,0},
335
              {3,1,4},
336
              {2,3,4},
337
              {1,2,4}
338
          };
339

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

    
352
      return new ObjectShape(getVertices(variant), indices);
353
      }
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

    
358
  public ObjectFaceShape getObjectFaceShape(int variant)
359
    {
360
    float height = isInIconMode() ? 0.001f : 0.025f;
361
    int angle = 15;
362
    float R = 0.9f;
363
    float S = 0.5f;
364

    
365
    if( variant==0 )
366
      {
367
      float[][] bands   = { {height,angle,R,S,5,1,0}, {0.001f,angle,R,S,5,1,0} };
368
      int[] bandIndices = { 0,0,1,1,1,1,1 };
369
      return new ObjectFaceShape(bands,bandIndices,null);
370
      }
371
    else if( variant==1 )
372
      {
373
      float[][] bands   = { {height,angle,R,S,5,1,0}, {0.001f,angle,R,S,5,1,0} };
374
      int[] bandIndices = { 0,1,1,1,1 };
375
      return new ObjectFaceShape(bands,bandIndices,null);
376
      }
377
    else if( variant==2 )
378
      {
379
      float[][] bands   = { {height,angle,R,S,5,1,0}, {0.001f,angle,R,S,5,1,0} };
380
      int[] bandIndices = { 0,0,1,1,1,1 };
381
      return new ObjectFaceShape(bands,bandIndices,null);
382
      }
383
    else if( variant==3 )
384
      {
385
      float[][] bands   = { {height,angle,R,S,5,1,0}, {0.001f,angle,R,S,5,1,0} };
386
      int[] bandIndices = { 0,0,1,1,1,1 };
387
      return new ObjectFaceShape(bands,bandIndices,null);
388
      }
389
    else if( variant==4 )
390
      {
391
      float[][] bands   = { {height,angle,R,S,5,1,0}, {0.001f,angle,R,S,5,1,0} };
392
      int[] bandIndices = { 0,0,0,1,1,1 };
393
      return new ObjectFaceShape(bands,bandIndices,null);
394
      }
395
    else
396
      {
397
      float h1 = isInIconMode() ? 0.001f : 0.05f;
398
      float h2 = isInIconMode() ? 0.001f : 0.01f;
399
      float[][] bands   = { {h1,angle,R,S,5,1,0}, {h2,angle,R,S,5,1,0} };
400
      int[] bandIndices = { 0,1,1,1 };
401
      return new ObjectFaceShape(bands,bandIndices,null);
402
      }
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

    
407
  public ObjectVertexEffects getVertexEffects(int variant)
408
    {
409
    if( variant==0 )
410
      {
411
      float[][] vertices= getVertices(variant);
412
      float[][] corners = { {0.04f,0.09f} };
413
      int[] indices     = { 0,0,0,0,-1,-1,-1,-1 };
414
      float[][] centers = { { -0.5f, -0.5f, 0.0f } };
415
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
416
      }
417
    else if( variant==1 )
418
      {
419
      float[][] vertices= getVertices(variant);
420
      float[][] corners = { {0.04f,0.09f} };
421
      int[] indices     = { 0,0,0,0,-1,-1 };
422
      float[][] centers = { { -5.0f/24, -5.0f/6, 5.0f/24} };
423
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
424
      }
425
    else if( variant==2 )
426
      {
427
      float[][] vertices= getVertices(variant);
428
      float[][] corners = { {0.04f,0.09f} };
429
      int[] indices     = { 0,0,0,0,-1,-1 };
430
      float[][] centers = { { 0.0f, -1.0f, -1.0f } };
431
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
432
      }
433
    else if( variant==3 )
434
      {
435
      float[][] vertices= getVertices(variant);
436
      float[][] corners = { {0.04f,0.09f} };
437
      int[] indices     = { 0,0,0,0,-1,-1 };
438
      float[][] centers = { { 1.0f, -1.0f, 0.0f } };
439
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
440
      }
441
    else if( variant==4 )
442
      {
443
      float[][] vertices= getVertices(variant);
444
      float[][] corners = { {0.03f,0.08f} };
445
      int[] indices     = { 0,0,0,0,-1 };
446
      float[][] centers = { { -1.0f, -1.0f, 1.0f } };
447
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
448
      }
449
    else
450
      {
451
      float[][] vertices= getVertices(variant);
452
      float[][] corners = { {0.04f,0.12f} };
453
      int[] indices     = { 0,0,0,-1 };
454
      float[][] centers = { { 1.0f/3, -2.0f/3,-1.0f/3 } };
455
      return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
456
      }
457
    }
458

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

    
461
  public int getNumCubitVariants(int[] numLayers)
462
    {
463
    return 6;
464
    }
465

    
466
///////////////////////////////////////////////////////////////////////////////////////////////////
467

    
468
  public int getCubitVariant(int cubit, int[] numLayers)
469
    {
470
    if( cubit<6 ) return 0;
471
    if( cubit<12) return 1;
472
    if( cubit<15) return 2;
473
    if( cubit<18) return 3;
474
    if( cubit<20) return 4;
475

    
476
    return 5;
477
    }
478

    
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480

    
481
  public float getStickerRadius()
482
    {
483
    return 0.13f;
484
    }
485

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

    
488
  public float getStickerStroke()
489
    {
490
    return isInIconMode() ? 0.22f : 0.10f;
491
    }
492

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

    
495
  public float[][][] getStickerAngles()
496
    {
497
    return null;
498
    }
499

    
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501
// PUBLIC API
502

    
503
  public Static3D[] getRotationAxis()
504
    {
505
    return ROT_AXIS;
506
    }
507

    
508
///////////////////////////////////////////////////////////////////////////////////////////////////
509

    
510
  public String getShortName()
511
    {
512
    return ObjectType.AXIS_3.name();
513
    }
514

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

    
517
  public ObjectSignature getSignature()
518
    {
519
    return new ObjectSignature(ObjectConstants.AXIS_3);
520
    }
521

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

    
524
  public int[][] getBasicAngles()
525
    {
526
    if( mBasicAngle ==null )
527
      {
528
      int num = getNumLayers()[0];
529
      int[] tmp = new int[num];
530
      for(int i=0; i<num; i++) tmp[i] = 4;
531
      mBasicAngle = new int[][] { tmp,tmp,tmp };
532
      }
533

    
534
    return mBasicAngle;
535
    }
536

    
537
///////////////////////////////////////////////////////////////////////////////////////////////////
538

    
539
  public String getObjectName()
540
    {
541
    return "Axis Cube";
542
    }
543

    
544
///////////////////////////////////////////////////////////////////////////////////////////////////
545

    
546
  public String getInventor()
547
    {
548
    return "Aleh Hladzilin";
549
    }
550

    
551
///////////////////////////////////////////////////////////////////////////////////////////////////
552

    
553
  public int getYearOfInvention()
554
    {
555
    return 2008;
556
    }
557

    
558
///////////////////////////////////////////////////////////////////////////////////////////////////
559

    
560
  public float getComplexity()
561
    {
562
    return 2.8f;
563
    }
564

    
565
///////////////////////////////////////////////////////////////////////////////////////////////////
566

    
567
  public String[][] getTutorials()
568
    {
569
    return new String[][]{
570
                          {"gb","DdYBkV07WpM","How to Solve the Axis Cube","Z3"},
571
                          {"es","oLWCj8-6G4Q","Resolver Axis Cube","Cuby"},
572
                          {"ru","pgPtyD7DV7A","Как собрать Аксис Куб","Алексей Ярыгин"},
573
                          {"fr","4M7cOgjZHSY","Résolution de l'Axis Cube","asthalis"},
574
                          {"de","CVPII1-sEqw","Axis Cube Tutorial","Pezcraft"},
575
                          {"pl","Yrmq0m4vjfE","Axis Cube TUTORIAL PL","MrUk"},
576
                          {"br","5HoM4_fQOM8","Como resolver o axis cube ","Gabriel Sihnel"},
577
                          {"kr","8KjHoNOGWLE","엑시스 큐브 해법","듀나메스 큐브 해법연구소"},
578
                          {"vn","ESdOqn7Tikg","Tutorial N.17 - Axis Cube","Duy Thích Rubik"},
579
                          {"tw","2ANall515_E","變幻金剛 教學","不正常魔術方塊研究中心"},
580
                         };
581
    }
582
}
(1-1/57)