Project

General

Profile

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

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

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.helpers.ObjectVertexEffects;
19
import org.distorted.objectlib.main.InitAssets;
20
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
21
import org.distorted.objectlib.metadata.ListObjects;
22
import org.distorted.objectlib.shape.ShapeHexahedron;
23
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
24

    
25
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD;
26
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

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

    
39
  private int[][] mEdges;
40
  private int[][] mBasicAngle;
41
  private float[][] mCuts;
42
  private float[][] mCenters;
43
  private int[] mQuatIndex;
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

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

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

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

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

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

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

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

    
79
    return mCuts;
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

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

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  public int getTouchControlType()
93
    {
94
    return TC_CHANGING_SHAPEMOD;
95
    }
96

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

    
99
  public int getTouchControlSplit()
100
    {
101
    return TYPE_NOT_SPLIT;
102
    }
103

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

    
106
  public int[][][] getEnabled()
107
    {
108
    return null;
109
    }
110

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

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

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

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

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

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

    
140
             {0.375f, 1.50f,-0.375f},
141
             {0.375f,0.375f,-1.50f },
142
             { 1.50f,0.375f,-0.375f},
143
             {-0.375f,-0.375f,1.50f},
144
             {-0.375f,-1.50f,0.375f},
145
             {-1.50f,-0.375f,0.375f},
146

    
147
             { 0.00f, 1.50f, 1.50f},
148
             {-1.50f, 0.00f,-1.50f},
149
             { 1.50f,-1.50f, 0.00f},
150

    
151
             {-1.50f, 1.50f, 0.00f},
152
             { 0.00f,-1.50f,-1.50f},
153
             { 1.50f, 0.00f, 1.50f},
154

    
155
             { 1.50f, 1.50f,-1.50f},
156
             {-1.50f,-1.50f, 1.50f},
157

    
158
             {-0.5f, 1.5f, 0.5f},
159
             { 0.5f,-1.5f,-0.5f},
160
             { 1.5f,-0.5f, 0.5f},
161
             {-1.5f, 0.5f,-0.5f},
162
             { 0.5f, 0.5f, 1.5f},
163
             {-0.5f,-0.5f,-1.5f},
164
         };
165
      }
166

    
167
    return mCenters;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

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

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

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

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

    
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

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

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

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

    
310
      return new ObjectShape(getVertices(variant), indices);
311
      }
312
    else if( variant==3 ) // edge type 3
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(getVertices(variant), indices);
325
      }
326
    else if( variant==4 ) // corner type 1
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(getVertices(variant), indices);
339
      }
340
    else                 // corner type 2
341
      {
342
      int[][] indices =
343
          {
344
              {0,2,1},
345
              {0,3,2},
346
              {2,3,1},
347
              {1,3,0}
348
          };
349

    
350
      return new ObjectShape(getVertices(variant), indices);
351
      }
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

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

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

    
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404

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

    
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458

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

    
464
///////////////////////////////////////////////////////////////////////////////////////////////////
465

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

    
474
    return 5;
475
    }
476

    
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478

    
479
  public float getStickerRadius()
480
    {
481
    return 0.13f;
482
    }
483

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

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

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

    
493
  public float[][][] getStickerAngles()
494
    {
495
    return null;
496
    }
497

    
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499
// PUBLIC API
500

    
501
  public Static3D[] getRotationAxis()
502
    {
503
    return ROT_AXIS;
504
    }
505

    
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507

    
508
  public String getShortName()
509
    {
510
    return ListObjects.AXIS_3.name();
511
    }
512

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

    
515
  public int[][] getBasicAngles()
516
    {
517
    if( mBasicAngle ==null )
518
      {
519
      int num = getNumLayers()[0];
520
      int[] tmp = new int[num];
521
      for(int i=0; i<num; i++) tmp[i] = 4;
522
      mBasicAngle = new int[][] { tmp,tmp,tmp };
523
      }
524

    
525
    return mBasicAngle;
526
    }
527

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

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