Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyVoid.java @ 8f5116ec

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.metadata.ListObjects;
21
import org.distorted.objectlib.shape.ShapeHexahedron;
22
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
23

    
24
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
25
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
26

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

    
29
public class TwistyVoid extends ShapeHexahedron
30
{
31
  static final Static3D[] ROT_AXIS = new Static3D[]
32
         {
33
           new Static3D(1,0,0),
34
           new Static3D(0,1,0),
35
           new Static3D(0,0,1)
36
         };
37

    
38
  private int[][] mEdges;
39
  private int[][] mBasicAngle;
40
  private float[][] mCuts;
41
  private float[][] mPositions;
42
  private int[] mQuatIndex;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

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

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  @Override
54
  public void adjustStickerCoords()
55
    {
56
    final float A = 0.507f;
57
    final float B = 0.38950402f;
58
    final float C = 0.25900806f;
59
    final float D = 0.50f;
60
    final float E = 0.50f;
61

    
62
    mStickerCoords = new float[][][][]
63
          {
64
             { { {-E,-E}, { A,-E}, {-E, A} } },
65
             { { {-C,-B}, { D,-B}, { D, B}, {-C, B} } }
66
          };
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  @Override
72
  protected float[][][] getStickerRadii()
73
    {
74
    float R1 = 0.12f;
75
    float R2 = 0.00f;
76
    float R3 = 0.10f;
77
    return new float[][][] { {{ R1,R1,R1 }} , {{ R2,R3,R3,R2 }} };
78
    }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
  @Override
83
  public int getInternalColor()
84
    {
85
    return 0xff222222;
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89
// +5 missing - it is the 180 deg rotation of the middle layer which we don't want.
90

    
91
  private void insertSection(int[] table, int index, int alg, int state)
92
    {
93
    table[index   ] = alg;
94
    table[index+ 1] = state;
95
    table[index+ 2] = alg+1;
96
    table[index+ 3] = state;
97
    table[index+ 4] = alg+2;
98
    table[index+ 5] = state;
99
    table[index+ 6] = alg+3;
100
    table[index+ 7] = state;
101
    table[index+ 8] = alg+4;
102
    table[index+ 9] = state;
103
    table[index+10] = alg+6;
104
    table[index+11] = state;
105
    table[index+12] = alg+7;
106
    table[index+13] = state;
107
    table[index+14] = alg+8;
108
    table[index+15] = state;
109
    }
110

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

    
113
  private int[] createEdge(int stateX, int stateY, int stateZ)
114
    {
115
    int size= 8;
116
    int num = 0;
117
    if( stateX>=0 ) num += 2*size;
118
    if( stateY>=0 ) num += 2*size;
119
    if( stateZ>=0 ) num += 2*size;
120

    
121
    int[] ret = new int[num];
122

    
123
    int index = 0;
124
    int alg = 0;
125
    if( stateX>=0 ) { insertSection(ret,index,alg,stateX); index+= (2*size);}
126
    alg += (size+1);
127
    if( stateY>=0 ) { insertSection(ret,index,alg,stateY); index+= (2*size);}
128
    alg += (size+1);
129
    if( stateZ>=0 ) { insertSection(ret,index,alg,stateZ); }
130

    
131
    return ret;
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135
// Normal 3x3, but without the 180 deg move of the middle layer.
136
// We need to rotate the middle layer here (by swiping it is not possible) because otherwise the
137
// phantom centers would always stay at their initial positions which would defeat the point here.
138

    
139
  public int[][] getScrambleEdges()
140
    {
141
    if( mEdges==null )
142
      {
143
      mEdges = new int[][]
144
        {
145
        createEdge( 1, 2, 3), // 0 0
146
        createEdge(-1, 4, 5), // 1 x
147
        createEdge( 6,-1, 7), // 2 y
148
        createEdge( 8, 9,-1), // 3 z
149
        createEdge(10,-1, 7), // 4 xy
150
        createEdge(11, 9,-1), // 5 xz
151
        createEdge(-1,12, 5), // 6 yx
152
        createEdge( 8,13,-1), // 7 yz
153
        createEdge(-1, 4,14), // 8 zx
154
        createEdge( 6,-1,15), // 9 zy
155
        createEdge(-1,-1, 5), // 10 xyx
156
        createEdge(-1, 4,-1), // 11 xzx
157
        createEdge(-1,-1, 7), // 12 yxy
158
        createEdge( 6,-1,-1), // 13 yzy
159
        createEdge(-1, 9,-1), // 14 zxz
160
        createEdge( 8,-1,-1), // 15 zyz
161
        };
162
      }
163

    
164
    return mEdges;
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  public float[][] getCuts(int[] numLayers)
170
    {
171
    if( mCuts==null )
172
      {
173
      float C = 0.5f;
174
      float[] cut = new float[] {-C,+C};
175
      mCuts = new float[][] { cut,cut,cut };
176
      }
177

    
178
    return mCuts;
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  public boolean[][] getLayerRotatable(int[] numLayers)
184
    {
185
    boolean[] tmp = new boolean[] {true,false,true};
186
    return new boolean[][] { tmp,tmp,tmp };
187
    }
188

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

    
191
  public int getTouchControlType()
192
    {
193
    return TC_HEXAHEDRON;
194
    }
195

    
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197

    
198
  public int getTouchControlSplit()
199
    {
200
    return TYPE_NOT_SPLIT;
201
    }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

    
205
  public int[][][] getEnabled()
206
    {
207
    return new int[][][] { {{1,2}},{{1,2}},{{0,2}},{{0,2}},{{0,1}},{{0,1}} };
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

    
212
  public float[] getDist3D(int[] numLayers)
213
    {
214
    return TouchControlHexahedron.D3D;
215
    }
216

    
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

    
219
  public Static3D[] getFaceAxis()
220
    {
221
    return TouchControlHexahedron.FACE_AXIS;
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  public float[][] getCubitPositions(int[] numLayers)
227
    {
228
    if( mPositions==null )
229
      {
230
      mPositions = new float[][]
231
         {
232
             { 1.0f, 1.0f, 1.0f},
233
             { 1.0f, 1.0f,-1.0f},
234
             { 1.0f,-1.0f, 1.0f},
235
             { 1.0f,-1.0f,-1.0f},
236
             {-1.0f, 1.0f, 1.0f},
237
             {-1.0f, 1.0f,-1.0f},
238
             {-1.0f,-1.0f, 1.0f},
239
             {-1.0f,-1.0f,-1.0f},
240

    
241
             { 1.0f, 1.0f, 0.0f},
242
             { 1.0f,-1.0f, 0.0f},
243
             { 1.0f, 0.0f, 1.0f},
244
             { 1.0f, 0.0f,-1.0f},
245
             {-1.0f, 1.0f, 0.0f},
246
             {-1.0f,-1.0f, 0.0f},
247
             {-1.0f, 0.0f, 1.0f},
248
             {-1.0f, 0.0f,-1.0f},
249
             { 0.0f, 1.0f, 1.0f},
250
             { 0.0f, 1.0f,-1.0f},
251
             { 0.0f,-1.0f, 1.0f},
252
             { 0.0f,-1.0f,-1.0f},
253
         };
254
      }
255

    
256
    return mPositions;
257
    }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

    
261
  public Static4D getCubitQuats(int cubit, int[] numLayers)
262
    {
263
    if( mQuatIndex==null ) mQuatIndex = new int[] {0,1,17,22,4,5,8,19,  1,3,0,2,10,11,4,5,9,15,7,19 };
264
    return mObjectQuats[mQuatIndex[cubit]];
265
    }
266

    
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

    
269
  private float[][] getVertices(int variant)
270
    {
271
    if( variant==0 )
272
      {
273
      final float X = 0.1f;
274
      final float D = 0.9f;
275
      final double A = 54*Math.PI/180;
276
      final float COS = (float)(D*Math.cos(A));
277
      final float SIN = (float)(D*Math.sin(A));
278

    
279
      return new float[][]
280
          {
281
              { -0.5f, -0.5f, -0.5f },
282
              { -0.5f, -0.5f, +0.5f },
283
              { -0.5f, +0.5f, -0.5f },
284
              { +0.5f, -0.5f, -0.5f },
285
              { +0.5f, +0.5f, -0.5f },
286
              { +0.5f, -0.5f, +0.5f },
287
              { -0.5f, +0.5f, +0.5f },
288
              { +0.5f, +0.5f, -0.5f+X },
289
              { +0.5f, -0.5f+X, +0.5f },
290
              { -0.5f+X, +0.5f, +0.5f },
291
              { SIN-0.5f, 0.5f, COS-0.5f },
292
              { COS-0.5f, 0.5f, SIN-0.5f },
293
              { COS-0.5f, SIN-0.5f, 0.5f },
294
              { SIN-0.5f, COS-0.5f, 0.5f },
295
              { 0.5f, COS-0.5f, SIN-0.5f },
296
              { 0.5f, SIN-0.5f, COS-0.5f },
297
          };
298
      }
299
    else
300
      {
301
      final float A = 0.13f;
302
      final float B = 0.18f;
303
      final float C = 0.52f;
304

    
305
      return new float[][]
306
          {
307
              {    C, 0.5f,    C},
308
              { 0.5f, 0.5f,-0.5f},
309
              {    C,-0.5f,    C},
310
              { 0.5f,-0.5f,-0.5f},
311
              {-0.5f, 0.5f, 0.5f},
312
              {-0.5f, 0.5f,-0.5f},
313
              {-0.5f,-0.5f, 0.5f},
314
              {-0.5f,-0.5f,-0.5f},
315

    
316
              {-0.5f+A, 0.25f, 0.5f},
317
              {-0.5f+B, 0.00f, 0.5f},
318
              {-0.5f+A,-0.25f, 0.5f},
319

    
320
              {-0.5f+A, 0.25f,-0.5f+A},
321
              {-0.5f+B, 0.00f,-0.5f+B},
322
              {-0.5f+A,-0.25f,-0.5f+A},
323

    
324
              { 0.5f  , 0.25f,-0.5f+A},
325
              { 0.5f  , 0.00f,-0.5f+B},
326
              { 0.5f  ,-0.25f,-0.5f+A},
327
          };
328
      }
329
    }
330

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

    
333
  public ObjectShape getObjectShape(int variant)
334
    {
335
    if( variant==0 )  // corner
336
      {
337
      int[][] indices =
338
          {
339
              {6,1,5,8,13,12,9},
340
              {5,3,4,7,15,14,8},
341
              {4,2,6,9,11,10,7},
342
              {0,1,6,2},
343
              {0,3,5,1},
344
              {0,2,4,3},
345
              {9,12,11},
346
              {8,14,13},
347
              {7,10,15},
348
              {10,11,12,13,14,15}
349
          };
350

    
351
      return new ObjectShape(getVertices(variant), indices);
352
      }
353
    else                // edge
354
      {
355
      int[][] indices =
356
          {
357
              {6,2,0,4,8,9,10},
358
              {1,0,2,3,16,15,14},
359
              {4,0,1,5},
360
              {2,6,7,3},
361

    
362
              {11,8,4,5},
363
              {12,9,8,11},
364
              {13,10,9,12},
365
              {7,6,10,13},
366
              {13,16,3,7},
367
              {12,15,16,13},
368
              {11,14,15,12},
369
              {5,1,14,11}
370
          };
371

    
372
      return new ObjectShape(getVertices(variant), indices);
373
      }
374
    }
375

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

    
378
  public ObjectFaceShape getObjectFaceShape(int variant)
379
    {
380
    if( variant==0 )
381
      {
382
      float h1 = isInIconMode() ? 0.001f : 0.015f;
383
      float h2 = isInIconMode() ? 0.001f : 0.010f;
384
      float h3 = isInIconMode() ? 0.001f : 0.030f;
385
      float[][] bands = { {h1,20,0.2f,0.4f,5,1,0}, {h2,5,0.3f,0.2f,5,0,0}, {h3,8,0.3f,0.2f,6,0,0} };
386
      int[] indices   = { 0,0,0,1,1,1,1,1,1,2 };
387
      return new ObjectFaceShape(bands,indices,null);
388
      }
389
    else
390
      {
391
      float h1 = isInIconMode() ? 0.001f : 0.01f;
392
      float[][] bands = { {h1,5,0.2f,0.4f,5,1,0}, {0.001f,1,0.3f,0.5f,5,0,0}, {0.001f,1,0.3f,0.5f,5,0,0} };
393
      int[] indices   = { 0,0,1,1,2,2,2,2,2,2,2,2 };
394
      return new ObjectFaceShape(bands,indices,null);
395
      }
396
    }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

    
400
  public ObjectVertexEffects getVertexEffects(int variant)
401
    {
402
    if( variant==0 )
403
      {
404
      float[][] corners = { {0.01f,0.05f} };
405
      int[] indices     = { -1,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1 };
406
      float[][] centers = { { -0.5f, -0.5f, -0.5f } };
407
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
408
      }
409
    else
410
      {
411
      float[][] corners = { {0.05f,0.09f} };
412
      int[] indices     = { 0,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 };
413
      float[][] centers = { { 0.0f, 0.0f, 0.0f } };
414
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
415
      }
416
    }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419

    
420
  public int getNumCubitVariants(int[] numLayers)
421
    {
422
    return 2;
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

    
427
  public int getCubitVariant(int cubit, int[] numLayers)
428
    {
429
    return cubit<8 ? 0:1;
430
    }
431

    
432
///////////////////////////////////////////////////////////////////////////////////////////////////
433
// doesn't matter = we're overriding the 'getStickerRadii()' anyway
434

    
435
  public float getStickerRadius()
436
    {
437
    return 0;
438
    }
439

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

    
442
  public float getStickerStroke()
443
    {
444
    return isInIconMode() ? 0.22f : 0.12f;
445
    }
446

    
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448

    
449
  public float[][][] getStickerAngles()
450
    {
451
    float D = (float)(Math.PI/3);
452
    return new float[][][] { {{ 0,D,0 }} , {{ 0,0,0,-D }} };
453
    }
454

    
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456
// PUBLIC API
457

    
458
  public Static3D[] getRotationAxis()
459
    {
460
    return ROT_AXIS;
461
    }
462

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

    
465
  public int[][] getBasicAngles()
466
    {
467
    if( mBasicAngle ==null )
468
      {
469
      int num = getNumLayers()[0];
470
      int[] tmp = new int[num];
471
      for(int i=0; i<num; i++) tmp[i] = 4;
472
      mBasicAngle = new int[][] { tmp,tmp,tmp };
473
      }
474

    
475
    return mBasicAngle;
476
    }
477

    
478
///////////////////////////////////////////////////////////////////////////////////////////////////
479

    
480
  public String getShortName()
481
    {
482
    return ListObjects.VOID_3.name();
483
    }
484

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

    
487
  public String[][] getTutorials()
488
    {
489
    return new String[][]{
490
                          {"gb","3sLMpQrX_dU","How to Solve the Void Cube","Z3"},
491
                          {"gb","EB0bmcI1RnM","aVOIDing parity: Void Cube","SuperAntoniovivaldi"},
492
                          {"es","tDV4vmo7Qz4","Resolver 3x3 Void (Hueco)","Cuby"},
493
                          {"ru","BCa6Zh8-I_g","Как собрать Войд-Куб","RBcuber"},
494
                          {"fr","yqSyPu5ciAc","Résoudre le Void Cube","TwinsCuber"},
495
                          {"de","1mh-jRrcP0w","Void Cube: Parity intuitiv lösen","rofrisch"},
496
                          {"br","uTC01oMGBJ8","3x3 Void cube Tutorial","Cubo vicio"},
497
                          {"kr","eCfepw1gVBA","보이드 큐브(홀큐브)","듀나메스 큐브 해법연구소"},
498
                          {"tw","rb6GyuOBUNE","空心方塊 教學","不正常魔術方塊研究中心"},
499
                         };
500
    }
501
}
(58-58/59)