Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyTrajber.java @ 8d96b92f

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objectlib.objects;
21

    
22
import org.distorted.library.type.Static3D;
23
import org.distorted.library.type.Static4D;
24
import org.distorted.objectlib.helpers.ObjectFaceShape;
25
import org.distorted.objectlib.helpers.ObjectShape;
26
import org.distorted.objectlib.scrambling.ScrambleState;
27
import org.distorted.objectlib.main.ObjectControl;
28
import org.distorted.objectlib.main.ObjectType;
29
import org.distorted.objectlib.main.ShapeOctahedron;
30
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
31

    
32
import java.io.InputStream;
33

    
34
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_OCTAHEDRON;
35
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
public class TwistyTrajber extends ShapeOctahedron
40
{
41
  // Trajber 3x3: each cut is at 1/5 of the length of the segment from the center to a vertex.
42
  private static final float CUT3 = 0.20f;
43
  // Trajber 4x4: each cut is at 1/4 of the length of the segment from the center to a vertex.
44
  private static final float CUT4 = 0.25f;
45

    
46
  static final Static3D[] ROT_AXIS = new Static3D[]
47
         {
48
         new Static3D(SQ2/2, 0, SQ2/2),
49
         new Static3D(    0, 1,     0),
50
         new Static3D(SQ2/2, 0,-SQ2/2)
51
         };
52

    
53
  private ScrambleState[] mStates;
54
  private int[] mBasicAngle;
55
  private float[][] mCuts;
56
  private float[][] mCenters;
57
  private int[] mQuatIndex;
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
  public TwistyTrajber(int[] numL, int meshState, Static4D quat, Static3D move, float scale, InputStream stream)
62
    {
63
    super(numL, meshState, numL[0], quat, move, scale, stream);
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
// TODO: override of the getSolvedQuats() - notice the 4x4 has multiple solved states!
68

    
69
  public ScrambleState[] getScrambleStates()
70
    {
71
    if( mStates==null )
72
      {
73
      int[][] m = new int[16][];
74

    
75
      for(int i=0; i<16; i++) m[i] = new int[] { 0,-1,i,0,1,i,0,2,i, 1,-1,i,1,1,i,1,2,i, 2,-1,i,2,1,i,2,2,i};
76

    
77
      mStates = new ScrambleState[]
78
          {
79
          new ScrambleState( new int[][] { m[ 1], m[ 2], m[ 3] } ),  //  0 0
80
          new ScrambleState( new int[][] {  null, m[ 4], m[ 5] } ),  //  1 x
81
          new ScrambleState( new int[][] { m[ 6],  null, m[ 7] } ),  //  2 y
82
          new ScrambleState( new int[][] { m[ 8], m[ 9],  null } ),  //  3 z
83
          new ScrambleState( new int[][] { m[10],  null, m[ 7] } ),  //  4 xy
84
          new ScrambleState( new int[][] { m[11], m[ 9],  null } ),  //  5 xz
85
          new ScrambleState( new int[][] {  null, m[12], m[ 5] } ),  //  6 yx
86
          new ScrambleState( new int[][] { m[ 8], m[13],  null } ),  //  7 yz
87
          new ScrambleState( new int[][] {  null, m[ 4], m[14] } ),  //  8 zx
88
          new ScrambleState( new int[][] { m[ 6],  null, m[15] } ),  //  9 zy
89
          new ScrambleState( new int[][] {  null,  null, m[ 5] } ),  // 10 xyx
90
          new ScrambleState( new int[][] {  null, m[ 4],  null } ),  // 11 xzx
91
          new ScrambleState( new int[][] {  null,  null, m[ 7] } ),  // 12 yxy
92
          new ScrambleState( new int[][] { m[ 6],  null,  null } ),  // 13 yzy
93
          new ScrambleState( new int[][] {  null, m[ 9],  null } ),  // 14 zxz
94
          new ScrambleState( new int[][] { m[ 8],  null,  null } ),  // 15 zyz
95
          };
96
      }
97

    
98
    return mStates;
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  public float[][] getCuts(int[] numLayers)
104
    {
105
    if( mCuts==null )
106
      {
107
      float[] tmp;
108

    
109
      if( numLayers[0]==3 )
110
        {
111
        final float cut= CUT3*numLayers[0]*SQ2/2;
112
        tmp = new float[] {-cut,+cut};
113
        }
114
      else
115
        {
116
        final float cut= CUT4*numLayers[0]*SQ2/2;
117
        tmp = new float[] {-cut,0,+cut};
118
        }
119

    
120
      mCuts = new float[][] { tmp,tmp,tmp };
121
      }
122

    
123
    return mCuts;
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
  public boolean[][] getLayerRotatable(int[] numLayers)
129
    {
130
    int numL = numLayers[0];
131
    boolean[] tmp = new boolean[numL];
132
    for(int i=0; i<numL; i++) tmp[i] = true;
133
    return new boolean[][] { tmp,tmp,tmp };
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  public int getTouchControlType()
139
    {
140
    return TC_OCTAHEDRON;
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  public int getTouchControlSplit()
146
    {
147
    return TYPE_NOT_SPLIT;
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  public int[][][] getEnabled()
153
    {
154
    return new int[][][]
155
      {
156
          {{0,1,2}},{{0,1,2}},{{0,1,2}},{{0,1,2}},{{0,1,2}},{{0,1,2}},{{0,1,2}},{{0,1,2}}
157
      };
158
    }
159

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

    
162
  public float[] getDist3D(int[] numLayers)
163
    {
164
    return TouchControlOctahedron.D3D;
165
    }
166

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

    
169
  public Static3D[] getFaceAxis()
170
    {
171
    return TouchControlOctahedron.FACE_AXIS;
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175
// TODO: support numLayers=4
176

    
177
  public float[][] getCubitPositions(int[] numLayers)
178
    {
179
    if( mCenters==null )
180
      {
181
      float LEN = numLayers[0]*0.5f;
182

    
183
      mCenters = new float[][]
184
          {
185
              {   LEN,       0,   LEN},
186
              {  -LEN,       0,  -LEN},
187
              {     0, SQ2*LEN,     0},
188
              {     0,-SQ2*LEN,     0},
189
              {  -LEN,       0,   LEN},
190
              {   LEN,       0,  -LEN},
191

    
192
              {-LEN/2, (SQ2/2)*LEN, LEN/2},
193
              { LEN/2, (SQ2/2)*LEN,-LEN/2},
194
              {-LEN/2,-(SQ2/2)*LEN, LEN/2},
195
              { LEN/2,-(SQ2/2)*LEN,-LEN/2},
196
              {     0,     0,   LEN},
197
              {   LEN,     0,     0},
198
              {  -LEN,     0,     0},
199
              {     0,     0,  -LEN},
200
              { LEN/2, (SQ2/2)*LEN, LEN/2},
201
              { LEN/2,-(SQ2/2)*LEN, LEN/2},
202
              {-LEN/2, (SQ2/2)*LEN,-LEN/2},
203
              {-LEN/2,-(SQ2/2)*LEN,-LEN/2},
204

    
205
              {       0, SQ2*LEN/3, 2*LEN/3},
206
              { 2*LEN/3, SQ2*LEN/3,       0},
207
              {       0,-SQ2*LEN/3, 2*LEN/3},
208
              { 2*LEN/3,-SQ2*LEN/3,       0},
209
              {-2*LEN/3, SQ2*LEN/3,       0},
210
              {       0, SQ2*LEN/3,-2*LEN/3},
211
              {-2*LEN/3,-SQ2*LEN/3,       0},
212
              {       0,-SQ2*LEN/3,-2*LEN/3},
213
          };
214
      }
215

    
216
    return mCenters;
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220
// TODO: support numLayers=4
221

    
222
  public Static4D getCubitQuats(int cubit, int[] numLayers)
223
    {
224
    if( mQuatIndex==null ) mQuatIndex = new int[] {6,4,1,3,0,2, 7,19,9,18, 0,2,8,5, 1,3,14,11, 0,1,3,2,7,5,8,16 };
225
    return mObjectQuats[mQuatIndex[cubit]];
226
    }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
// TODO: support numLayers=4
230

    
231
  public ObjectShape getObjectShape(int variant)
232
    {
233
    if( variant==0 )
234
      {
235
      final float LEN = getNumLayers()[0]*0.5f;
236
      final float A = SQ2*CUT3*LEN;
237
      final float B =     CUT3*LEN;
238

    
239
      float[][] vertices =
240
          {
241
             {    0,    0,    0},
242
             {    B,    A,   -B},
243
             {    B,   -A,   -B},
244
             {  2*B,    0,    0},
245
             {    0,    0, -2*B},
246
             {  3*B,    A,   -B},
247
             {  3*B,   -A,   -B},
248
             {    B,    A, -3*B},
249
             {    B,   -A, -3*B},
250

    
251
             {  LEN      ,    A, SQ2*A-LEN},
252
             {  LEN      ,   -A, SQ2*A-LEN},
253
             {  LEN-SQ2*A,    A,      -LEN},
254
             {  LEN-SQ2*A,   -A,      -LEN}
255
          };
256

    
257
      int[][] indices =
258
          {
259
             {0,3,5,1},
260
             {0,2,6,3},
261
             {0,4,8,2},
262
             {0,1,7,4},
263
             {3,6,10,9,5},
264
             {2,8,12,10,6},
265
             {4,7,11,12,8},
266
             {1,5,9,11,7},
267
             {9,10,12,11}
268
          };
269

    
270
      return new ObjectShape(vertices, indices);
271
      }
272
    if( variant==1 )
273
      {
274
      final float LEN = getNumLayers()[0]*0.5f;
275
      final float A = SQ2*CUT3*LEN;
276
      final float B = LEN*(1-2*CUT3);
277
      final float C = (SQ2/2)*A;
278

    
279
      float[][] vertices =
280
          {
281
             {    -B, 0,  0 },
282
             {  -B+C, A, -C },
283
             {  -B+C,-A, -C },
284
             {     B, 0,  0 },
285
             {   B-C, A, -C },
286
             {   B-C,-A, -C },
287
             {     0, A, -B },
288
             {     0,-A, -B },
289
          };
290

    
291
      int[][] indices =
292
          {
293
             {0,3,4,1},
294
             {0,2,5,3},
295
             {1,4,6},
296
             {2,7,5},
297
             {0,1,6,7,2},
298
             {3,5,7,6,4}
299
          };
300

    
301
      return new ObjectShape(vertices, indices);
302
      }
303
    else
304
      {
305
      final float LEN = getNumLayers()[0]*0.5f;
306
      final float L = LEN*(1-3*CUT3);
307

    
308
      float[][] vertices =
309
          {
310
             { -L, -(SQ2/3)*L,   L/3 },
311
             {  L, -(SQ2/3)*L,   L/3 },
312
             {  0,(2*SQ2/3)*L,-2*L/3 },
313
             {  0, -(SQ2/3)*L,-2*L/3 },
314
          };
315

    
316
      int[][] indices =
317
          {
318
             {0,1,2},
319
             {3,1,0},
320
             {0,2,3},
321
             {1,3,2},
322
          };
323

    
324
      return new ObjectShape(vertices, indices);
325
      }
326
    }
327

    
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329
// TODO: support numLayers=4
330

    
331
  public ObjectFaceShape getObjectFaceShape(int variant)
332
    {
333
    final float LEN = getNumLayers()[0]*0.5f;
334

    
335
    if( variant==0 )
336
      {
337
      float[][] bands     = { {0.05f,35,0.15f,0.3f,4,1,1},{0.00f,35,0.15f,0.3f,4,1,1} };
338
      int[] bandIndices   = { 0,0,0,0,1,1,1,1,1 };
339
      float[][] corners   = { {0.03f,0.10f} };
340
      int[] cornerIndices = { 0,-1,-1,-1,-1,0,0,0,0,-1,-1,-1,-1 };
341
      float[][] centers   = { { LEN/2, 0.0f, -LEN/2} };
342
      int[] centerIndices = { 0,-1,-1,-1,-1,0,0,0,0,-1,-1,-1,-1 };
343
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
344
      }
345
    if( variant==1 )
346
      {
347
      final float B = LEN*(1-2*CUT3);
348
      float[][] bands     = { {0.03f,35,0.15f,0.3f,3,1,1},{0.00f,35,0.15f,0.3f,3,1,1} };
349
      int[] bandIndices   = { 0,0,1,1,1,1 };
350
      float[][] corners   = { {0.02f,0.10f} };
351
      int[] cornerIndices = { 0,0,0,0,0,0,-1,-1 };
352
      float[][] centers   = { { 0, 0, -B} };
353
      int[] centerIndices = { 0,0,0,0,0,0,-1,-1 };
354
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
355
      }
356
    else
357
      {
358
      final float L = LEN*(1-3*CUT3);
359
      float[][] bands     = { {0.03f,35,0.15f,0.3f,4,1,1},{0.00f,35,0.15f,0.3f,4,0,0} };
360
      int[] bandIndices   = { 0,1,1,1 };
361
      float[][] corners   = { {0.02f,0.10f} };
362
      int[] cornerIndices = { 0,0,0,-1 };
363
      float[][] centers   = { {0, -(SQ2/3)*L,-2*L/3} };
364
      int[] centerIndices = { 0,0,0,-1 };
365
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
366
      }
367
    }
368

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

    
371
  public int getNumCubitVariants(int[] numLayers)
372
    {
373
    return 3;
374
    }
375

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

    
378
  public int getCubitVariant(int cubit, int[] numLayers)
379
    {
380
    if( numLayers[0]==3 ) return cubit< 6 ? 0 : cubit<18 ? 1 : 2;
381
    else                  return cubit<24 ? 0 : cubit<48 ? 1 : 2;
382
    }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

    
386
  public float getStickerRadius()
387
    {
388
    return 0.12f;
389
    }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

    
393
  public float getStickerStroke()
394
    {
395
    return ObjectControl.isInIconMode() ? 0.20f : 0.10f;
396
    }
397

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

    
400
  public float[][] getStickerAngles()
401
    {
402
    return null;
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406
// PUBLIC API
407

    
408
  public Static3D[] getRotationAxis()
409
    {
410
    return ROT_AXIS;
411
    }
412

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

    
415
  public int[] getBasicAngles()
416
    {
417
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 4,4,4 };
418
    return mBasicAngle;
419
    }
420

    
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422

    
423
  public String getShortName()
424
    {
425
    int[] numLayers = getNumLayers();
426
    return numLayers[0]==3 ? ObjectType.TRAJ_3.name() : ObjectType.TRAJ_4.name();
427
    }
428

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

    
431
  public long getSignature()
432
    {
433
    int[] numLayers = getNumLayers();
434
    return numLayers[0]==3 ? ObjectType.TRAJ_3.ordinal() : ObjectType.TRAJ_4.ordinal();
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

    
439
  public String getObjectName()
440
    {
441
    int[] numLayers = getNumLayers();
442
    return numLayers[0]==3 ? "Trajber's Octahedron" : "Trajber 4x4";
443
    }
444

    
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446

    
447
  public String getInventor()
448
    {
449
    int[] numLayers = getNumLayers();
450
    return numLayers[0]==3 ? "Josef Trajber" : "Jürgen Brandt";
451
    }
452

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

    
455
  public int getYearOfInvention()
456
    {
457
    int[] numLayers = getNumLayers();
458
    return numLayers[0]==3 ? 1982 : 2001;
459
    }
460

    
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462

    
463
  public int getComplexity()
464
    {
465
    int[] numLayers = getNumLayers();
466
    return numLayers[0]==3 ? 2 : 3;
467
    }
468

    
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470

    
471
  public String[][] getTutorials()
472
    {
473
    int[] numLayers = getNumLayers();
474

    
475
    switch(numLayers[0])
476
      {
477
      case 3: return new String[][] {
478
                                     {"gb","Q2NSiuJWVvk","Trajber and UFO Tutorial","SuperAntoniovivaldi"},
479
                                     {"es","FPBirEJ8ZfY","Resolver Octaedro 3x3","Solución Rubik"},
480
                                     {"de","FjQXlwJGniQ","Trajbers Octahedron Tutorial","GerCubing"},
481
                                     {"br","kO3nMpZKv3Q","Resolver Octaedro Trajber","Rafael Cinoto"},
482
                                    };
483
      case 4: return new String[][] {
484
                                     {"gb","FZlw68I7snM","4x4 Trajber's Tutorial (1/3)","SuperAntoniovivaldi"},
485
                                     {"gb","VM0XFu7gAII","4x4 Trajber's Tutorial (2/3)","SuperAntoniovivaldi"},
486
                                     {"es","Q8ljV-feLpU","Tutorial Octaedro 4x4 (1/2)","Dany Cuber"},
487
                                     {"es","QyWpDLa1eZQ","Tutorial Octaedro 4x4 (2/2)","Dany Cuber"},
488
                                     {"ru","ikUogVow-58","Как собрать Октаэдр 4х4","RBcuber"},
489
                                     {"fr","4hxZyMVGiTA","Résolution de l'Octaèdre 4x4","asthalis"},
490
                                     {"pl","oPBvAT9lwt4","Octahedron 4x4 TUTORIAL PL","MrUK"},
491
                                     {"br","0ZgaoQ6IS2w","Resolver o octaedro Trajber 4x4 (1/3)","Rafael Cinoto"},
492
                                     {"br","TjxTx3IJy6M","Resolver o octaedro Trajber 4x4 (2/3)","Rafael Cinoto"},
493
                                     {"br","E8k2TXfUS8g","Resolver o octaedro Trajber 4x4 (3/3)","Rafael Cinoto"},
494
                                     {"vn","yorULpIm6Yw","Tutorial N.22 - Octahedron 4x4","Duy Thích Rubik"},
495
                                    };
496
      }
497

    
498
    return null;
499
    }
500
}
(31-31/34)