Project

General

Profile

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

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

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.ObjectShape;
25
import org.distorted.objectlib.helpers.ScrambleState;
26
import org.distorted.objectlib.main.ObjectControl;
27
import org.distorted.objectlib.main.ObjectType;
28
import org.distorted.objectlib.main.ShapeOctahedron;
29
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
30

    
31
import java.io.InputStream;
32

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

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
public class TwistyTrajber extends ShapeOctahedron
39
{
40
  // each cut is at 1/5 of the length of the segment from the center to a vertex.
41
  private static final float CUT = 0.2f;
42
  private static final float LEN = 1.5f;
43

    
44
  // the three rotation axis of a 3x3x3 cube. Must be normalized.
45
  static final Static3D[] ROT_AXIS = new Static3D[]
46
         {
47
         new Static3D(SQ2/2, 0, SQ2/2),
48
         new Static3D(    0, 1,     0),
49
         new Static3D(SQ2/2, 0,-SQ2/2)
50
         };
51

    
52
  private static final int[] mQuatIndices = new int[] {13,12,8,9,0,1, 15,10,14,11, 0,1,3,2, 8,9,5,4, 0,8,9,1,15,2,3,6};
53

    
54
  private int[][] mFaceColorMap, mEdgeColorMap, mCornerColorMap;
55
  private ScrambleState[] mStates;
56
  private int[] mBasicAngle;
57
  private int[] mFaceMap;
58
  private float[][] mCuts;
59
  private Static4D[] mQuats;
60
  private float[][] mCenters;
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

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

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

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

    
77
      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};
78

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

    
100
    return mStates;
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  private void initializeQuats()
106
    {
107
    mQuats = new Static4D[]
108
         {
109
         new Static4D(  0.0f,   0.0f,   0.0f,   1.0f),  // 0  nothing
110
         new Static4D( SQ2/2,   0.0f,  SQ2/2,   0.0f),  // 1  ( 1, 0,-1) 180
111
         new Static4D(  0.0f,   1.0f,   0.0f,   0.0f),  // 2  ( 0, 1, 0) 180
112
         new Static4D( SQ2/2,   0.0f, -SQ2/2,   0.0f),  // 3  ( 1, 0, 1) 180
113

    
114
         new Static4D(  0.5f,  SQ2/2,  -0.5f,   0.0f),  // 4 (0.5,SQ2/2,0.5) 180
115
         new Static4D(  0.5f, -SQ2/2,  -0.5f,   0.0f),  // 5 (0.5,-SQ2/2,-0.5) 180
116
         new Static4D(  1.0f,   0.0f,   0.0f,   0.0f),  // 6 (1,0,0) 180
117
         new Static4D(  0.0f,   0.0f,   1.0f,   0.0f),  // 7 (0,0,1) 180
118
         new Static4D(  0.5f,   0.0f,   0.5f,  SQ2/2),  // 8  ( 1, 0, 1) +-90
119
         new Static4D(  0.5f,   0.0f,   0.5f, -SQ2/2),  // 9  ( 1, 0, 1) -+90
120
         new Static4D(  0.5f,  SQ2/2,   0.5f,   0.0f),  // 10 (-0.5,-SQ2/2,-0.5) 180
121
         new Static4D(  0.5f, -SQ2/2,   0.5f,   0.0f),  // 11 (0.5,-SQ2/2,0.5) 180
122
         new Static4D(  0.0f,  SQ2/2,   0.0f,  SQ2/2),  // 12  ( 0, 1, 0) +-90
123
         new Static4D(  0.0f,  SQ2/2,   0.0f, -SQ2/2),  // 13  ( 0, 1, 0) -+90
124
         new Static4D(  0.5f,   0.0f,  -0.5f, -SQ2/2),  // 15  ( 1, 0,-1) -+90
125
         new Static4D(  0.5f,   0.0f,  -0.5f,  SQ2/2),  // 14  ( 1, 0,-1) +-90
126

    
127
         new Static4D( SQ2/2,   0.5f,   0.0f,   0.5f),  // 16 (+,+,0) +
128
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  -0.5f),  // 17 (0,-,+) -
129
         new Static4D(  0.0f,   0.5f, -SQ2/2,  -0.5f),  // 18 (0,+,-) -
130
         new Static4D( SQ2/2,  -0.5f,   0.0f,  -0.5f),  // 19 (+,-,0) -
131
         new Static4D(-SQ2/2,  -0.5f,   0.0f,   0.5f),  // 20 (-,-,0) +
132
         new Static4D( SQ2/2,  -0.5f,   0.0f,   0.5f),  // 21 (+,-,0) +
133
         new Static4D(  0.0f,  -0.5f, -SQ2/2,   0.5f),  // 22 (0,-,-) +
134
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  -0.5f),  // 23 (0,-,-) -
135
         };
136
    }
137

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

    
140
  public int[] getSolvedQuats(int cubit, int[] numLayers)
141
    {
142
    if( mQuats==null ) initializeQuats();
143
    if( mFaceMap==null ) mFaceMap = new int[] {4,0,6,2,7,3,5,1};
144
    int status = retCubitSolvedStatus(cubit,numLayers);
145
    return status<0 ? null : buildSolvedQuats(TouchControlOctahedron.FACE_AXIS[mFaceMap[status]],mQuats);
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  public Static4D[] getQuats()
151
    {
152
    if( mQuats==null ) initializeQuats();
153
    return mQuats;
154
    }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

    
158
  public int getSolvedFunctionIndex()
159
    {
160
    return 0;
161
    }
162

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

    
165
  public float[][] getCuts(int[] numLayers)
166
    {
167
    if( mCuts==null )
168
      {
169
      final float cut= CUT*LEN*SQ2;
170
      mCuts = new float[][] { {-cut,+cut},{-cut,+cut},{-cut,+cut} };
171
      }
172

    
173
    return mCuts;
174
    }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

    
178
  public boolean[][] getLayerRotatable(int[] numLayers)
179
    {
180
    int numAxis = ROT_AXIS.length;
181
    boolean[][] layerRotatable = new boolean[numAxis][];
182

    
183
    for(int i=0; i<numAxis; i++)
184
      {
185
      layerRotatable[i] = new boolean[numLayers[i]];
186
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
187
      }
188

    
189
    return layerRotatable;
190
    }
191

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

    
194
  public int getTouchControlType()
195
    {
196
    return TC_OCTAHEDRON;
197
    }
198

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

    
201
  public int getTouchControlSplit()
202
    {
203
    return TYPE_NOT_SPLIT;
204
    }
205

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

    
208
  public int[][][] getEnabled()
209
    {
210
    return new int[][][]
211
      {
212
          {{0,1,2}},{{0,1,2}},{{0,1,2}},{{0,1,2}},{{0,1,2}},{{0,1,2}},{{0,1,2}},{{0,1,2}}
213
      };
214
    }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
  public float[] getDist3D(int[] numLayers)
219
    {
220
    return null;
221
    }
222

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

    
225
  public int getNumCubitFaces()
226
    {
227
    return 9;
228
    }
229

    
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

    
232
  public float[][] getCubitPositions(int[] numLayers)
233
    {
234
    if( mCenters==null )
235
      {
236
      mCenters = new float[][]
237
          {
238
              {   LEN,       0,   LEN},
239
              {  -LEN,       0,  -LEN},
240
              {     0, SQ2*LEN,     0},
241
              {     0,-SQ2*LEN,     0},
242
              {  -LEN,       0,   LEN},
243
              {   LEN,       0,  -LEN},
244

    
245
              {-LEN/2, (SQ2/2)*LEN, LEN/2},
246
              { LEN/2, (SQ2/2)*LEN,-LEN/2},
247
              {-LEN/2,-(SQ2/2)*LEN, LEN/2},
248
              { LEN/2,-(SQ2/2)*LEN,-LEN/2},
249
              {     0,     0,   LEN},
250
              {   LEN,     0,     0},
251
              {  -LEN,     0,     0},
252
              {     0,     0,  -LEN},
253
              { LEN/2, (SQ2/2)*LEN, LEN/2},
254
              { LEN/2,-(SQ2/2)*LEN, LEN/2},
255
              {-LEN/2, (SQ2/2)*LEN,-LEN/2},
256
              {-LEN/2,-(SQ2/2)*LEN,-LEN/2},
257

    
258
              {       0, SQ2*LEN/3, 2*LEN/3},
259
              { 2*LEN/3, SQ2*LEN/3,       0},
260
              {       0,-SQ2*LEN/3, 2*LEN/3},
261
              { 2*LEN/3,-SQ2*LEN/3,       0},
262
              {-2*LEN/3, SQ2*LEN/3,       0},
263
              {       0, SQ2*LEN/3,-2*LEN/3},
264
              {-2*LEN/3,-SQ2*LEN/3,       0},
265
              {       0,-SQ2*LEN/3,-2*LEN/3},
266
          };
267
      }
268

    
269
    return mCenters;
270
    }
271

    
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

    
274
  public ObjectShape getObjectShape(int variant)
275
    {
276
    if( variant==0 )
277
      {
278
      final float A = SQ2*CUT*LEN;
279
      final float B =     CUT*LEN;
280

    
281
      float[][] vertices = new float[][]
282
          {
283
             {    0,    0,    0},
284
             {    B,    A,   -B},
285
             {    B,   -A,   -B},
286
             {  2*B,    0,    0},
287
             {    0,    0, -2*B},
288
             {  3*B,    A,   -B},
289
             {  3*B,   -A,   -B},
290
             {    B,    A, -3*B},
291
             {    B,   -A, -3*B},
292

    
293
             {  LEN      ,    A, SQ2*A-LEN},
294
             {  LEN      ,   -A, SQ2*A-LEN},
295
             {  LEN-SQ2*A,    A,      -LEN},
296
             {  LEN-SQ2*A,   -A,      -LEN}
297
          };
298

    
299
      int[][] vert_indices = new int[][]
300
          {
301
             {0,3,5,1},
302
             {0,2,6,3},
303
             {0,4,8,2},
304
             {0,1,7,4},
305
             {3,6,10,9,5},
306
             {2,8,12,10,6},
307
             {4,7,11,12,8},
308
             {1,5,9,11,7},
309
             {9,10,12,11}
310
          };
311

    
312
      float[][] bands     = new float[][] { {0.05f,35,0.15f,0.3f,4,1,1},{0.00f,35,0.15f,0.3f,4,1,1} };
313
      int[] bandIndices   = new int[] { 0,0,0,0,1,1,1,1,1 };
314
      float[][] corners   = new float[][] { {0.03f,0.10f} };
315
      int[] cornerIndices = new int[] { 0,-1,-1,-1,-1,0,0,0,0,-1,-1,-1,-1 };
316
      float[][] centers   = new float[][] { { LEN/2, 0.0f, -LEN/2} };
317
      int[] centerIndices = new int[] { 0,-1,-1,-1,-1,0,0,0,0,-1,-1,-1,-1 };
318
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null,4);
319
      }
320
    if( variant==1 )
321
      {
322
      final float A = SQ2*CUT*LEN;
323
      final float B = LEN-2*LEN*CUT;
324
      final float C = (SQ2/2)*A;
325

    
326
      float[][] vertices = new float[][]
327
          {
328
             {    -B, 0,  0 },
329
             {  -B+C, A, -C },
330
             {  -B+C,-A, -C },
331
             {     B, 0,  0 },
332
             {   B-C, A, -C },
333
             {   B-C,-A, -C },
334
             {     0, A, -B },
335
             {     0,-A, -B },
336
          };
337

    
338
      int[][] vert_indices = new int[][]
339
          {
340
             {0,3,4,1},
341
             {0,2,5,3},
342
             {1,4,6},
343
             {2,7,5},
344
             {0,1,6,7,2},
345
             {3,5,7,6,4}
346
          };
347

    
348
      float[][] bands     = new float[][] { {0.03f,35,0.15f,0.3f,3,1,1},{0.00f,35,0.15f,0.3f,3,1,1} };
349
      int[] bandIndices   = new int[] { 0,0,1,1,1,1 };
350
      float[][] corners   = new float[][] { {0.02f,0.10f} };
351
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,-1,-1 };
352
      float[][] centers   = new float[][] { { 0, 0, -B} };
353
      int[] centerIndices = new int[] { 0,0,0,0,0,0,-1,-1 };
354
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null,2);
355
      }
356
    else
357
      {
358
      final float L = LEN-3*LEN*CUT;
359

    
360
      float[][] vertices = new float[][]
361
          {
362
             { -L, -(SQ2/3)*L,   L/3 },
363
             {  L, -(SQ2/3)*L,   L/3 },
364
             {  0,(2*SQ2/3)*L,-2*L/3 },
365
             {  0, -(SQ2/3)*L,-2*L/3 },
366
          };
367

    
368
      int[][] vert_indices = new int[][]
369
          {
370
             {0,1,2},
371
             {0,1,3},
372
             {0,2,3},
373
             {1,3,2},
374
          };
375

    
376
      float[][] bands     = new float[][] { {0.03f,35,0.15f,0.3f,4,1,1},{0.00f,35,0.15f,0.3f,4,0,0} };
377
      int[] bandIndices   = new int[] { 0,1,1,1 };
378
      float[][] corners   = new float[][] { {0.02f,0.10f} };
379
      int[] cornerIndices = new int[] { 0,0,0,-1 };
380
      float[][] centers   = new float[][] { {0, -(SQ2/3)*L,-2*L/3} };
381
      int[] centerIndices = new int[] { 0,0,0,-1 };
382
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null,1);
383
      }
384
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

    
388
  public Static4D getQuat(int cubit, int[] numLayers)
389
    {
390
    if( mQuats==null ) initializeQuats();
391
    return mQuats[mQuatIndices[cubit]];
392
    }
393

    
394
///////////////////////////////////////////////////////////////////////////////////////////////////
395

    
396
  public int getNumCubitVariants(int[] numLayers)
397
    {
398
    return 3;
399
    }
400

    
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402

    
403
  public int getCubitVariant(int cubit, int[] numLayers)
404
    {
405
    return cubit<6 ? 0 : cubit<18 ? 1 : 2;
406
    }
407

    
408
///////////////////////////////////////////////////////////////////////////////////////////////////
409

    
410
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
411
    {
412
    int variant = getCubitVariant(cubit,numLayers);
413

    
414
    if( mFaceColorMap==null)
415
      {
416
      mFaceColorMap = new int[][] { {1,5,4,0},{3,7,6,2},{1,0,3,2},{4,5,6,7},{0,4,7,3},{5,1,2,6} };
417
      }
418

    
419
    if( mEdgeColorMap==null)
420
      {
421
      mEdgeColorMap = new int[][] { {3,0},{1,2},{4,7},{6,5}, {0,4},{5,1},{7,3},{2,6}, {1,0},{4,5},{3,2},{6,7} };
422
      }
423

    
424
    if( mCornerColorMap==null)
425
      {
426
      mCornerColorMap = new int[][] { {0},{1},{4},{5},{3},{2},{7},{6} };
427
      }
428

    
429
    switch(variant)
430
      {
431
      case 0: return face<4 ? mFaceColorMap[cubit][face]     :-1;
432
      case 1: return face<2 ? mEdgeColorMap[cubit-6][face]   :-1;
433
      case 2: return face<1 ? mCornerColorMap[cubit-18][face]:-1;
434
      }
435

    
436
    return 0;
437
    }
438

    
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

    
441
  public float getStickerRadius()
442
    {
443
    return 0.12f;
444
    }
445

    
446
///////////////////////////////////////////////////////////////////////////////////////////////////
447

    
448
  public float getStickerStroke()
449
    {
450
    return ObjectControl.isInIconMode() ? 0.20f : 0.10f;
451
    }
452

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

    
455
  public float[][] getStickerAngles()
456
    {
457
    return null;
458
    }
459

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461
// PUBLIC API
462

    
463
  public Static3D[] getRotationAxis()
464
    {
465
    return ROT_AXIS;
466
    }
467

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469

    
470
  public int[] getBasicAngle()
471
    {
472
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 4,4,4 };
473
    return mBasicAngle;
474
    }
475

    
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477

    
478
  public ObjectType intGetObjectType(int[] numLayers)
479
    {
480
    return ObjectType.TRAJ_3;
481
    }
482

    
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484

    
485
  public String getObjectName()
486
    {
487
    return "Trajber's Octahedron";
488
    }
489

    
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491

    
492
  public String getInventor()
493
    {
494
    return "Josef Trajber";
495
    }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498

    
499
  public int getYearOfInvention()
500
    {
501
    return 1982;
502
    }
503

    
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505

    
506
  public int getComplexity()
507
    {
508
    return 2;
509
    }
510
}
(25-25/26)