Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyVoid.java @ 9ba7f3f6

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.helpers.ObjectSignature;
18
import org.distorted.objectlib.helpers.ObjectVertexEffects;
19
import org.distorted.objectlib.main.InitData;
20
import org.distorted.objectlib.main.ObjectType;
21
import org.distorted.objectlib.shape.ShapeHexahedron;
22
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
23

    
24
import java.io.InputStream;
25

    
26
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
27
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

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

    
40
  private int[][] mEdges;
41
  private int[][] mBasicAngle;
42
  private float[][] mCuts;
43
  private float[][] mPositions;
44
  private int[] mQuatIndex;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
  public TwistyVoid(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
49
    {
50
    super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
51
    }
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
  @Override
56
  public void adjustStickerCoords()
57
    {
58
    final float A = 0.497f;
59
    final float B = 0.38950402f;
60
    final float C = 0.25900806f;
61
    final float D = 0.51f;
62

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

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

    
72
  @Override
73
  public int getInternalColor()
74
    {
75
    return 0xff222222;
76
    }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
  private void insertSection(int[] table, int startIndex, int size, int startAlg, int state)
81
    {
82
    for(int i=0; i<size; i++)
83
      {
84
      table[2*(i+startIndex)  ] = startAlg +i;
85
      table[2*(i+startIndex)+1] = state;
86
      }
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

    
91
  private int[] createEdge(int stateX, int stateY, int stateZ)
92
    {
93
    int size = 8;
94
    int num = 0;
95
    if( stateX>=0 ) num += size;
96
    if( stateY>=0 ) num += size;
97
    if( stateZ>=0 ) num += size;
98

    
99
    int[] ret = new int[2*num];
100

    
101
    if( stateX>=0 )
102
      {
103
      insertSection(ret,0,size,0,stateX);
104
      if( stateY>=0 )
105
        {
106
        insertSection(ret,size,size,size+1,stateY);
107
        if( stateZ>=0 ) insertSection(ret,2*size,size,2*size+2,stateZ);
108
        }
109
      else
110
        {
111
        if( stateZ>=0 ) insertSection(ret,size,size,2*size+2,stateZ);
112
        }
113
      }
114
    else
115
      {
116
      if( stateY>=0 )
117
        {
118
        insertSection(ret,0,size,size+1,stateY);
119
        if( stateZ>=0 ) insertSection(ret,size,size,2*size+2,stateZ);
120
        }
121
      else
122
        {
123
        if( stateZ>=0 ) insertSection(ret,0,size,2*size+2,stateZ);
124
        }
125
      }
126

    
127
    return ret;
128
    }
129

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

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

    
160
    return mEdges;
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  public float[][] getCuts(int[] numLayers)
166
    {
167
    if( mCuts==null )
168
      {
169
      float C = 0.5f;
170
      float[] cut = new float[] {-C,+C};
171
      mCuts = new float[][] { cut,cut,cut };
172
      }
173

    
174
    return mCuts;
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  public boolean[][] getLayerRotatable(int[] numLayers)
180
    {
181
    boolean[] tmp = new boolean[] {true,false,true};
182
    return new boolean[][] { tmp,tmp,tmp };
183
    }
184

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

    
187
  public int getTouchControlType()
188
    {
189
    return TC_HEXAHEDRON;
190
    }
191

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

    
194
  public int getTouchControlSplit()
195
    {
196
    return TYPE_NOT_SPLIT;
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
  public int[][][] getEnabled()
202
    {
203
    return new int[][][] { {{1,2}},{{1,2}},{{0,2}},{{0,2}},{{0,1}},{{0,1}} };
204
    }
205

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

    
208
  public float[] getDist3D(int[] numLayers)
209
    {
210
    return TouchControlHexahedron.D3D;
211
    }
212

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

    
215
  public Static3D[] getFaceAxis()
216
    {
217
    return TouchControlHexahedron.FACE_AXIS;
218
    }
219

    
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

    
222
  public float[][] getCubitPositions(int[] numLayers)
223
    {
224
    if( mPositions==null )
225
      {
226
      mPositions = new float[][]
227
         {
228
             { 1.0f, 1.0f, 1.0f},
229
             { 1.0f, 1.0f,-1.0f},
230
             { 1.0f,-1.0f, 1.0f},
231
             { 1.0f,-1.0f,-1.0f},
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

    
237
             { 1.0f, 1.0f, 0.0f},
238
             { 1.0f,-1.0f, 0.0f},
239
             { 1.0f, 0.0f, 1.0f},
240
             { 1.0f, 0.0f,-1.0f},
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
             { 0.0f, 1.0f, 1.0f},
246
             { 0.0f, 1.0f,-1.0f},
247
             { 0.0f,-1.0f, 1.0f},
248
             { 0.0f,-1.0f,-1.0f},
249
         };
250
      }
251

    
252
    return mPositions;
253
    }
254

    
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

    
257
  public Static4D getCubitQuats(int cubit, int[] numLayers)
258
    {
259
    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 };
260
    return mObjectQuats[mQuatIndex[cubit]];
261
    }
262

    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

    
265
  private float[][] getVertices(int variant)
266
    {
267
    if( variant==0 )
268
      {
269
      final float X = 0.3f;
270
      final double A = 54*Math.PI/180;
271
      final float COS = (float)Math.cos(A);
272
      final float SIN = (float)Math.sin(A);
273

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

    
300
      return new float[][]
301
          {
302
              {    C, 0.5f,    C},
303
              { 0.5f, 0.5f,-0.5f},
304
              {    C,-0.5f,    C},
305
              { 0.5f,-0.5f,-0.5f},
306
              {-0.5f, 0.5f, 0.5f},
307
              {-0.5f, 0.5f,-0.5f},
308
              {-0.5f,-0.5f, 0.5f},
309
              {-0.5f,-0.5f,-0.5f},
310

    
311
              {-0.5f+A, 0.25f, 0.5f},
312
              {-0.5f+B, 0.00f, 0.5f},
313
              {-0.5f+A,-0.25f, 0.5f},
314

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

    
319
              { 0.5f  , 0.25f,-0.5f+A},
320
              { 0.5f  , 0.00f,-0.5f+B},
321
              { 0.5f  ,-0.25f,-0.5f+A},
322
          };
323
      }
324
    }
325

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327

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

    
346
      return new ObjectShape(getVertices(variant), indices);
347
      }
348
    else                // edge
349
      {
350
      int[][] indices =
351
          {
352
              {6,2,0,4,8,9,10},
353
              {1,0,2,3,16,15,14},
354
              {4,0,1,5},
355
              {2,6,7,3},
356

    
357
              {11,8,4,5},
358
              {12,9,8,11},
359
              {13,10,9,12},
360
              {7,6,10,13},
361
              {13,16,3,7},
362
              {12,15,16,13},
363
              {11,14,15,12},
364
              {5,1,14,11}
365
          };
366

    
367
      return new ObjectShape(getVertices(variant), indices);
368
      }
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

    
373
  public ObjectFaceShape getObjectFaceShape(int variant)
374
    {
375
    if( variant==0 )
376
      {
377
      float h1 = isInIconMode() ? 0.001f : 0.015f;
378
      float h2 = isInIconMode() ? 0.001f : 0.010f;
379
      float h3 = isInIconMode() ? 0.001f : 0.030f;
380
      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} };
381
      int[] indices   = { 0,0,0,1,1,1,1,1,1,2 };
382
      return new ObjectFaceShape(bands,indices,null);
383
      }
384
    else
385
      {
386
      float h1 = isInIconMode() ? 0.001f : 0.01f;
387
      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} };
388
      int[] indices   = { 0,0,1,1,2,2,2,2,2,2,2,2 };
389
      return new ObjectFaceShape(bands,indices,null);
390
      }
391
    }
392

    
393
///////////////////////////////////////////////////////////////////////////////////////////////////
394

    
395
  public ObjectVertexEffects getVertexEffects(int variant)
396
    {
397
    if( variant==0 )
398
      {
399
      float[][] corners = { {0.02f,0.09f} };
400
      int[] indices     = { -1,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1 };
401
      float[][] centers = { { -0.5f, -0.5f, -0.5f } };
402
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
403
      }
404
    else
405
      {
406
      float[][] corners = { {0.02f,0.09f} };
407
      int[] indices     = { 0,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 };
408
      float[][] centers = { { 0.0f, 0.0f, 0.0f } };
409
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
410
      }
411
    }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

    
415
  public int getNumCubitVariants(int[] numLayers)
416
    {
417
    return 2;
418
    }
419

    
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421

    
422
  public int getCubitVariant(int cubit, int[] numLayers)
423
    {
424
    return cubit<8 ? 0:1;
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  public float getStickerRadius()
430
    {
431
    return 0.05f;
432
    }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
  public float getStickerStroke()
437
    {
438
    return isInIconMode() ? 0.22f : 0.12f;
439
    }
440

    
441
///////////////////////////////////////////////////////////////////////////////////////////////////
442

    
443
  public float[][] getStickerAngles()
444
    {
445
    float D = (float)(Math.PI/6);
446
    return new float[][] { { 0,D,0 },{ 0,0,0,-D } };
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450
// PUBLIC API
451

    
452
  public Static3D[] getRotationAxis()
453
    {
454
    return ROT_AXIS;
455
    }
456

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

    
459
  public int[][] getBasicAngles()
460
    {
461
    if( mBasicAngle ==null )
462
      {
463
      int num = getNumLayers()[0];
464
      int[] tmp = new int[num];
465
      for(int i=0; i<num; i++) tmp[i] = 4;
466
      mBasicAngle = new int[][] { tmp,tmp,tmp };
467
      }
468

    
469
    return mBasicAngle;
470
    }
471

    
472
///////////////////////////////////////////////////////////////////////////////////////////////////
473

    
474
  public String getShortName()
475
    {
476
    return ObjectType.VOID_3.name();
477
    }
478

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

    
481
  public ObjectSignature getSignature()
482
    {
483
    return new ObjectSignature(ObjectType.VOID_3);
484
    }
485

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

    
488
  public String getObjectName()
489
    {
490
    return "Void Cube";
491
    }
492

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

    
495
  public String getInventor()
496
    {
497
    return "Katsuhiko Okamoto";
498
    }
499

    
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501

    
502
  public int getYearOfInvention()
503
    {
504
    return 2012;
505
    }
506

    
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508

    
509
  public int getComplexity()
510
    {
511
    return 2;
512
    }
513

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

    
516
  public String[][] getTutorials()
517
    {
518
    return new String[][]{
519
                          {"gb","3sLMpQrX_dU","How to Solve the Void Cube","Z3"},
520
                          {"gb","EB0bmcI1RnM","aVOIDing parity: Void Cube","SuperAntoniovivaldi"},
521
                          {"es","tDV4vmo7Qz4","Resolver 3x3 Void (Hueco)","Cuby"},
522
                          {"ru","BCa6Zh8-I_g","Как собрать Войд-Куб","RBcuber"},
523
                          {"fr","yqSyPu5ciAc","Résoudre le Void Cube","TwinsCuber"},
524
                          {"de","1mh-jRrcP0w","Void Cube: Parity intuitiv lösen","rofrisch"},
525
                          {"br","uTC01oMGBJ8","3x3 Void cube Tutorial","Cubo vicio"},
526
                          {"kr","eCfepw1gVBA","보이드 큐브(홀큐브)","듀나메스 큐브 해법연구소"},
527
                         };
528
    }
529
}
(40-40/41)