Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
14

    
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17
import org.distorted.objectlib.helpers.FactoryCubit;
18
import org.distorted.objectlib.helpers.ObjectFaceShape;
19
import org.distorted.objectlib.helpers.ObjectShape;
20
import org.distorted.objectlib.metadata.Metadata;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitAssets;
23
import org.distorted.objectlib.metadata.ListObjects;
24
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
25
import org.distorted.objectlib.shape.ShapeHexahedron;
26
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
27

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

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

    
40
  private int[][] mEdges;
41
  private int[][] mBasicAngle;
42
  private float[][] mCuts;
43
  private float[][] mPosition;
44
  private int[] mQuatIndex;
45
  private boolean[][] mRotatable;
46

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

    
49
  public TwistyTins(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
50
    {
51
    super(iconMode, 4, quat, move, scale, meta, asset);
52
    }
53

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

    
56
  public int[][] getScrambleEdges()
57
    {
58
    if( mEdges==null )
59
      {
60
      mEdges = new int[][]
61
        {
62
          { 0,16,1,16,2,8,3,8,  4,1,5,1,6,9,7,9,  8,15,9,15,10,7,11,7,  12,2,13,2,14,10,15,10,  16,14,17,14,18,6,19,6,  20,3,21,3,22,11,23,11,  24,13,25,13,26,5,27,5,  28,4,29,4,30,12,31,12 },  // 0
63

    
64
          {                                                             12,2,13,2,14,10,15,10,                          20,3,21,3,22,11,23,11,  24,13,25,13,26,5,27,5,                        },  // 1
65
          {                     4,1,5,1,6,9,7,9,                                                16,14,17,14,18,6,19,6,                                                  28,4,29,4,30,12,31,12 },  // 2
66
          {                     4,1,5,1,6,9,7,9,  8,15,9,15,10,7,11,7,                                                                                                  28,4,29,4,30,12,31,12 },  // 3
67
          { 0,16,1,16,2,8,3,8,                                          12,2,13,2,14,10,15,10,                          20,3,21,3,22,11,23,11,                                                },  // 4
68
          {                     4,1,5,1,6,9,7,9,  8,15,9,15,10,7,11,7,                          16,14,17,14,18,6,19,6,                                                                        },  // 5
69
          { 0,16,1,16,2,8,3,8,                                          12,2,13,2,14,10,15,10,                                                  24,13,25,13,26,5,27,5,                        },  // 6
70
          { 0,16,1,16,2,8,3,8,                                                                                          20,3,21,3,22,11,23,11,  24,13,25,13,26,5,27,5,                        },  // 7
71
          {                                       8,15,9,15,10,7,11,7,                          16,14,17,14,18,6,19,6,                                                  28,4,29,4,30,12,31,12 },  // 8
72

    
73
          {                                                             12,2,13,2,                                      20,3,21,3,                          26,5,27,5,                        },  // 9
74
          {                     4,1,5,1,                                                                    18,6,19,6,                                                  28,4,29,4,            },  // 10
75
          {                     4,1,5,1,                    10,7,11,7,                                                                                                  28,4,29,4,            },  // 11
76
          {           2,8,3,8,                                          12,2,13,2,                                      20,3,21,3,                                                            },  // 12
77
          {                     4,1,5,1,                    10,7,11,7,                                      18,6,19,6,                                                                        },  // 13
78
          {           2,8,3,8,                                          12,2,13,2,                                                                          26,5,27,5,                        },  // 14
79
          {           2,8,3,8,                                                                                          20,3,21,3,                          26,5,27,5,                        },  // 15
80
          {                                                 10,7,11,7,                                      18,6,19,6,                                                  28,4,29,4,            },  // 16
81
        };
82
      }
83

    
84
    return mEdges;
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  @Override
90
  public int[][] getScrambleAlgorithms()
91
    {
92
    setUpRotatable();
93
    return ScrambleEdgeGenerator.getScramblingAlgorithms(mBasicAngle, mRotatable);
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
  @Override
99
  public float[][] returnRotationFactor()
100
    {
101
    float C1 = 1.7f;
102
    float C2 = 2.5f;
103
    float[] f = new float[] { C2,C1,C1,C1,C2 };
104
    return new float[][] { f,f,f,f };
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  public float[][] getCuts(int[] numLayers)
110
    {
111
    if( mCuts==null )
112
      {
113
      float C1 = -4*SQ3/3;
114
      float C2 = -2*SQ3/3;
115
      float C3 =  2*SQ3/3;
116
      float C4 =    SQ3+0.01f;
117

    
118
      float[] cut1 = new float[] { C1, C2, C3, C4 };
119
      float[] cut2 = new float[] {-C4,-C3,-C2,-C1 };
120

    
121
      mCuts = new float[][] { cut1,cut2,cut2,cut1 };
122
      }
123

    
124
    return mCuts;
125
    }
126

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

    
129
  private void setUpRotatable()
130
    {
131
    if( mRotatable==null )
132
      {
133
      boolean[] tmp = new boolean[] {true,true,false,true,true};
134
      mRotatable = new boolean[][] { tmp,tmp,tmp,tmp };
135
      }
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  public boolean[][] getLayerRotatable(int[] numLayers)
141
    {
142
    setUpRotatable();
143
    return mRotatable;
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  public int getTouchControlType()
149
    {
150
    return TC_HEXAHEDRON;
151
    }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

    
155
  public int getTouchControlSplit()
156
    {
157
    return TYPE_SPLIT_CORNER;
158
    }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

    
162
  public int[][][] getEnabled()
163
    {
164
    return new int[][][]
165
      {
166
          {{0,1},{3,1},{2,3},{0,2}},
167
          {{2,3},{3,1},{0,1},{0,2}},
168
          {{1,2},{0,1},{0,3},{2,3}},
169
          {{1,2},{2,3},{0,3},{0,1}},
170
          {{0,3},{0,2},{1,2},{1,3}},
171
          {{1,2},{0,2},{0,3},{1,3}},
172
      };
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

    
177
  public float[] getDist3D(int[] numLayers)
178
    {
179
    return TouchControlHexahedron.D3D;
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
  public Static3D[] getFaceAxis()
185
    {
186
    return TouchControlHexahedron.FACE_AXIS;
187
    }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190
// corner cubes, corner 'dino' , edges, centers.
191

    
192
  public float[][] getCubitPositions(int[] numLayers)
193
    {
194
    if( mPosition==null )
195
      {
196
      float C1 = 1.5f;
197
      float C2 = 1.0f;
198
      float C3 = 2.0f;
199
      float C4 = 0.5f;
200
      float C5 = 0.25f;
201
      float C6 = 0.75f;
202

    
203
      mPosition = new float[][]
204
         {
205
             { C1, C1, C1},
206
             {-C1, C1,-C1},
207
             { C1,-C1,-C1},
208
             {-C1,-C1, C1},
209

    
210
             {-C2, C3, C3},
211
             {-C3, C2, C3},
212
             {-C3, C3, C2},
213
             { C2, C3,-C3},
214
             { C3, C2,-C3},
215
             { C3, C3,-C2},
216
             { C2,-C3, C3},
217
             { C3,-C2, C3},
218
             { C3,-C3, C2},
219
             {-C2,-C3,-C3},
220
             {-C3,-C2,-C3},
221
             {-C3,-C3,-C2},
222

    
223
             { C4, C3, C3},
224
             { C3, C4, C3},
225
             {-C4,-C3, C3},
226
             {-C3,-C4, C3},
227
             { C3, C3, C4},
228
             { C3,-C3,-C4},
229
             {-C3,-C3, C4},
230
             {-C3, C3,-C4},
231
             {-C4, C3,-C3},
232
             { C3,-C4,-C3},
233
             { C4,-C3,-C3},
234
             {-C3, C4,-C3},
235

    
236
             {-C5, C6, C3}, // F
237
             { C5,-C6, C3},
238
             { C5, C6,-C3}, // B
239
             {-C5,-C6,-C3},
240
             { C3, C5,-C6}, // R
241
             { C3,-C5, C6},
242
             {-C3,-C5,-C6}, // L
243
             {-C3, C5, C6},
244
             {-C6, C3, C5}, // T
245
             { C6, C3,-C5},
246
             {-C6,-C3,-C5}, // D
247
             { C6,-C3, C5},
248

    
249
             { C6,-C5, C3},
250
             {-C6, C5, C3},
251
             {-C6,-C5,-C3},
252
             { C6, C5,-C3},
253
             { C3,-C6, C5},
254
             { C3, C6,-C5},
255
             {-C3, C6, C5},
256
             {-C3,-C6,-C5},
257
             { C5, C3,-C6},
258
             {-C5, C3, C6},
259
             { C5,-C3, C6},
260
             {-C5,-C3,-C6},
261
         };
262
      }
263

    
264
    return mPosition;
265
    }
266

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

    
269
  public Static4D getCubitQuats(int cubit, int[] numLayers)
270
    {
271
    if( mQuatIndex==null ) mQuatIndex = new int[] { 0, 3, 4, 6,
272
                                                    0, 8, 7,11, 5, 1,10, 2, 4, 9, 3, 6,
273
                                                    0, 2,10, 8, 1, 4, 6, 7,11, 5, 9, 3,
274
                                                    0,10,11, 9, 5, 2, 3, 8, 7, 1, 6, 4,
275
                                                    0,10,11, 9, 5, 2, 3, 8, 7, 1, 6, 4,
276
                                                  };
277
    return mObjectQuats[mQuatIndex[cubit]];
278
    }
279

    
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

    
282
  private float[][] getVertices(int variant)
283
    {
284
    if( variant==0 )
285
      {
286
      return new float[][]
287
          {
288
             { 0.0f, 0.0f, 0.0f },
289
             {-0.5f, 0.5f, 0.5f },
290
             {-0.5f,-0.5f, 0.5f },
291
             { 0.5f, 0.5f, 0.5f },
292
             { 0.5f,-0.5f, 0.5f },
293
             { 0.5f, 0.5f,-0.5f },
294
             { 0.5f,-0.5f,-0.5f },
295
             {-0.5f, 0.5f,-0.5f },
296
          };
297
      }
298
    else if( variant==1 )
299
      {
300
      return new float[][]
301
          {
302
             {-1.0f, 0.0f, 0.0f},
303
             { 1.0f, 0.0f, 0.0f},
304
             { 0.0f,-1.0f, 0.0f},
305
             { 0.0f, 0.0f,-1.0f}
306
          };
307
      }
308
    else if( variant==2 )
309
      {
310
      return new float[][]
311
          {
312
             {-0.5f, 0.0f, 0.0f},
313
             { 0.5f, 0.0f, 0.0f},
314
             { 0.5f,-1.0f, 0.0f},
315
             { 0.0f,-1.5f, 0.0f},
316
             {-1.0f,-0.5f, 0.0f},
317
             {-1.0f, 0.0f,-0.5f},
318
             { 0.0f, 0.0f,-1.5f},
319
             { 0.5f, 0.0f,-1.0f}
320
          };
321
      }
322
    else if( variant==3 )
323
      {
324
      return new float[][]
325
          {
326
             {-0.25f, 0.75f, 0.00f},
327
             { 0.75f,-0.25f, 0.00f},
328
             { 0.25f,-0.75f, 0.00f},
329
             {-0.75f, 0.25f, 0.00f},
330
             {-0.25f, 1.00f,-0.25f},
331
             { 0.75f, 0.50f,-0.75f},
332
             { 0.25f, 0.25f,-1.00f},
333
             {-0.75f, 0.75f,-0.50f}
334
          };
335
      }
336
    else
337
      {
338
      return new float[][]
339
          {
340
             {-0.25f, 0.75f, 0.00f},
341
             { 0.75f,-0.25f, 0.00f},
342
             { 0.25f,-0.75f, 0.00f},
343
             {-0.75f, 0.25f, 0.00f},
344
             { 0.50f, 0.75f,-0.75f},
345
             { 1.00f,-0.25f,-0.25f},
346
             { 0.75f,-0.75f,-0.50f},
347
             { 0.25f, 0.25f,-1.00f}
348
          };
349
      }
350
    }
351

    
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

    
354
  public ObjectShape getObjectShape(int variant)
355
    {
356
    if( variant==0 )
357
      {
358
      int[][] indices =
359
          {
360
             { 2,4,3,1 },
361
             { 1,3,5,7 },
362
             { 4,6,5,3 },
363
             { 0,4,2 },
364
             { 0,7,5 },
365
             { 0,6,4 },
366
             { 0,1,7 },
367
             { 0,2,1 },
368
             { 0,5,6 }
369
          };
370

    
371
      return new ObjectShape(getVertices(variant), indices);
372
      }
373
    else if( variant==1 )
374
      {
375
      int[][] indices =
376
          {
377
             {2,1,0},
378
             {3,0,1},
379
             {2,3,1},
380
             {3,2,0}
381
          };
382

    
383
      return new ObjectShape(getVertices(variant), indices);
384
      }
385
    else if( variant==2 )
386
      {
387
      int[][] indices =
388
          {
389
             {4,3,2,1,0},
390
             {0,1,7,6,5},
391
             {1,2,7},
392
             {2,3,6,7},
393
             {3,4,5,6},
394
             {0,5,4}
395
          };
396

    
397
      return new ObjectShape(getVertices(variant), indices);
398
      }
399
    else
400
      {
401
      int[][] indices =
402
          {
403
             {3,2,1,0},
404
             {6,5,1,2},
405
             {5,4,0,1},
406
             {4,7,3,0},
407
             {7,6,2,3},
408
             {4,5,6,7}
409
          };
410

    
411
      return new ObjectShape(getVertices(variant), indices);
412
      }
413
    }
414

    
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416

    
417
  public ObjectFaceShape getObjectFaceShape(int variant)
418
    {
419
    if( variant==0 )
420
      {
421
      float h1 = isInIconMode() ? 0.001f : 0.06f;
422
      float h2 = isInIconMode() ? 0.001f : 0.01f;
423
      float[][] bands = { {h1,35,0.5f,0.7f,5,1,0}, {h2,35,0.2f,0.4f,5,1,0} };
424
      int[] indices   = { 0,0,0,1,1,1,1,1,1 };
425
      return new ObjectFaceShape(bands,indices,null);
426
      }
427
    else if( variant==1 )
428
      {
429
      float h1 = isInIconMode() ? 0.001f : 0.035f;
430
      float h2 = isInIconMode() ? 0.001f : 0.010f;
431
      float[][] bands  = { {h1,30,0.16f,0.8f,5,0,0}, {h2,30,0.16f,0.2f,5,0,0} };
432
      int[] bandIndices= { 0,0,1,1 };
433
      return new ObjectFaceShape(bands,bandIndices,null);
434
      }
435
    else if( variant==2 )
436
      {
437
      float h1 = isInIconMode() ? 0.001f : 0.035f;
438
      float h2 = isInIconMode() ? 0.001f : 0.010f;
439
      float[][] bands  = { {h1,30,0.16f,0.8f,5,1,0}, {h2,30,0.16f,0.2f,5,0,0} };
440
      int[] bandIndices= { 0,0,1,1,1,1 };
441
      return new ObjectFaceShape(bands,bandIndices,null);
442
      }
443
    else
444
      {
445
      float h1 = isInIconMode() ? 0.001f : 0.040f;
446
      float h2 = isInIconMode() ? 0.001f : 0.002f;
447
      float[][] bands  = { {h1,30,0.3f,0.5f,5,0,0}, {h2,30,0.1f,0.2f,3,0,0} };
448
      int[] bandIndices= { 0,1,1,1,1,1,1,1 };
449
      return new ObjectFaceShape(bands,bandIndices,null);
450
      }
451
    }
452

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

    
455
  public ObjectVertexEffects getVertexEffects(int variant)
456
    {
457
    if( variant==0 )
458
      {
459
      float[][] corners = { {0.06f,0.12f} };
460
      int[] indices     = { -1,0,-1,0,0,0,-1,-1 };
461
      float[][] centers = { { 0.0f, 0.0f, 0.0f} };
462
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
463
      }
464
    else if( variant==1 )
465
      {
466
      float[][] corners   = { {0.05f,0.30f}, {0.05f,0.20f} };
467
      int[] cornerIndices = { 0,0,1,1 };
468
      float[][] centers   = { {0.0f, -0.75f, -0.75f} };
469
      int[] centerIndices = { 0,0,0,0 };
470
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,cornerIndices,centers,centerIndices);
471
      }
472
    else if( variant==2 )
473
      {
474
      float[][] corners   = { {0.05f,0.20f}, {0.05f,0.15f} };
475
      int[] cornerIndices = { 0,0,1,1,1,1,1,1 };
476
      float[][] centers   = { {0.0f, -0.5f, -0.5f} };
477
      int[] centerIndices = { 0,0,0,0,0,0,0,0 };
478
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,cornerIndices,centers,centerIndices);
479
      }
480
    else
481
      {
482
      return null;
483
      }
484
    }
485

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

    
488
  public int getNumCubitVariants(int[] numLayers)
489
    {
490
    return 5;
491
    }
492

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

    
495
  public int getCubitVariant(int cubit, int[] numLayers)
496
    {
497
    return cubit<4 ? 0: (cubit<16 ? 1: (cubit<28 ? 2: (cubit<40 ? 3:4)));
498
    }
499

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

    
502
  public float getStickerRadius()
503
    {
504
    return 0.09f;
505
    }
506

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

    
509
  public float getStickerStroke()
510
    {
511
    return isInIconMode() ? 0.24f : 0.10f;
512
    }
513

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

    
516
  public float[][][] getStickerAngles()
517
    {
518
    return null;
519
    }
520

    
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522
// PUBLIC API
523

    
524
  public Static3D[] getRotationAxis()
525
    {
526
    return ROT_AXIS;
527
    }
528

    
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530

    
531
  public int[][] getBasicAngles()
532
    {
533
    if( mBasicAngle ==null )
534
      {
535
      int[] tmp = {3,3,3,3,3};
536
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
537
      }
538

    
539
    return mBasicAngle;
540
    }
541

    
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543

    
544
  public String getShortName()
545
    {
546
    return ListObjects.TINS_5.name();
547
    }
548

    
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550

    
551
  public String[][] getTutorials()
552
    {
553
    return null;
554
    }
555
}
(55-55/59)