Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyDiamond.java @ 4c9ca251

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 static org.distorted.objectlib.touchcontrol.TouchControl.TC_OCTAHEDRON;
23
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
24

    
25
import java.io.InputStream;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.helpers.ObjectFaceShape;
31
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
32
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
33
import org.distorted.objectlib.main.ObjectControl;
34
import org.distorted.objectlib.main.ObjectType;
35
import org.distorted.objectlib.helpers.ObjectShape;
36
import org.distorted.objectlib.helpers.ScrambleState;
37
import org.distorted.objectlib.main.ShapeOctahedron;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
public class TwistyDiamond extends ShapeOctahedron
42
{
43
  // the four rotation axis of a Diamond. Must be normalized.
44
  static final Static3D[] ROT_AXIS = new Static3D[]
45
         {
46
           new Static3D(+SQ6/3,+SQ3/3,     0),
47
           new Static3D(-SQ6/3,+SQ3/3,     0),
48
           new Static3D(     0,-SQ3/3,-SQ6/3),
49
           new Static3D(     0,-SQ3/3,+SQ6/3)
50
         };
51

    
52
  private ScrambleState[] mStates;
53
  private int[] mBasicAngle;
54
  private int[] mFaceMap;
55
  private float[][] mCuts;
56
  private Static4D[] mQuats;
57
  private int[] mTetraToFaceMap;
58

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

    
61
  public TwistyDiamond(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

    
68
  public ScrambleState[] getScrambleStates()
69
    {
70
    if( mStates==null )
71
      {
72
      int[] numLayers = getNumLayers();
73
      int numL = numLayers[0];
74
      int[] tmp = new int[3*2*numL];
75

    
76
      for(int i=0; i<2*numL; i++)
77
        {
78
        tmp[3*i  ] = (i<numL) ?  i:i-numL;
79
        tmp[3*i+1] = (i%2==0) ? -1:1;
80
        tmp[3*i+2] = 0;
81
        }
82

    
83
      mStates = new ScrambleState[]
84
        {
85
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
86
        };
87
      }
88

    
89
    return mStates;
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  private void initializeQuats()
95
    {
96
    mQuats = new Static4D[]
97
         {
98
          new Static4D(  0.0f,  0.0f,   0.0f,  1.0f ),
99
          new Static4D(  0.0f,  1.0f,   0.0f,  0.0f ),
100
          new Static4D(+SQ2/2,  0.0f, -SQ2/2,  0.0f ),
101
          new Static4D(-SQ2/2,  0.0f, -SQ2/2,  0.0f ),
102

    
103
          new Static4D(+SQ2/2,  0.5f,   0.0f,  0.5f ),
104
          new Static4D(-SQ2/2,  0.5f,   0.0f,  0.5f ),
105
          new Static4D(  0.0f,  0.5f, +SQ2/2,  0.5f ),
106
          new Static4D(  0.0f,  0.5f, -SQ2/2,  0.5f ),
107
          new Static4D(+SQ2/2,  0.5f,   0.0f, -0.5f ),
108
          new Static4D(-SQ2/2,  0.5f,   0.0f, -0.5f ),
109
          new Static4D(  0.0f,  0.5f, +SQ2/2, -0.5f ),
110
          new Static4D(  0.0f,  0.5f, -SQ2/2, -0.5f )
111
         };
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  public int[] getSolvedQuats(int cubit, int[] numLayers)
117
    {
118
    if( mQuats==null ) initializeQuats();
119
    if( mFaceMap==null ) mFaceMap = new int[] {4,0,6,2,7,3,5,1};
120
    int status = retCubitSolvedStatus(cubit,numLayers);
121
    return status<0 ? null : buildSolvedQuats(TouchControlOctahedron.FACE_AXIS[mFaceMap[status]],mQuats);
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  public Static4D[] getQuats()
127
    {
128
    if( mQuats==null ) initializeQuats();
129
    return mQuats;
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  public int getSolvedFunctionIndex()
135
    {
136
    return 0;
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  public float[][] getCuts(int[] numLayers)
142
    {
143
    int numL = numLayers[0];
144
    if( numL<2 ) return null;
145

    
146
    if( mCuts==null )
147
      {
148
      mCuts = new float[4][numL-1];
149
      float cut = (SQ6/6)*(2-numL);
150

    
151
      for(int i=0; i<numL-1; i++)
152
        {
153
        mCuts[0][i] = cut;
154
        mCuts[1][i] = cut;
155
        mCuts[2][i] = cut;
156
        mCuts[3][i] = cut;
157
        cut += SQ6/3;
158
        }
159
      }
160

    
161
    return mCuts;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

    
166
  public boolean[][] getLayerRotatable(int[] numLayers)
167
    {
168
    int numAxis = ROT_AXIS.length;
169
    boolean[][] layerRotatable = new boolean[numAxis][];
170

    
171
    for(int i=0; i<numAxis; i++)
172
      {
173
      layerRotatable[i] = new boolean[numLayers[i]];
174
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
175
      }
176

    
177
    return layerRotatable;
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

    
182
  public int getTouchControlType()
183
    {
184
    return TC_OCTAHEDRON;
185
    }
186

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

    
189
  public int getTouchControlSplit()
190
    {
191
    return TYPE_NOT_SPLIT;
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

    
196
  public int[][][] getEnabled()
197
    {
198
    return new int[][][]
199
      {
200
          {{1,2,3}},{{1,2,3}},{{0,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,3}},{{0,1,2}},{{0,1,2}}
201
      };
202
    }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
  public float[] getDist3D(int[] numLayers)
207
    {
208
    return TouchControlOctahedron.D3D;
209
    }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

    
213
  public Static3D[] getFaceAxis()
214
    {
215
    return TouchControlOctahedron.FACE_AXIS;
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

    
220
  private int getNumOctahedrons(int layers)
221
    {
222
    return layers==1 ? 1 : 4*(layers-1)*(layers-1) + 2;
223
    }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
  private int getNumTetrahedrons(int layers)
228
    {
229
    return 4*layers*(layers-1);
230
    }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
  private int createOctaPositions(float[][] centers, int index, int layers, float height)
235
    {
236
    float x = (layers-1)*0.5f;
237
    float z = (layers+1)*0.5f;
238

    
239
    for(int i=0; i<layers; i++, index++)
240
      {
241
      z -= 1;
242
      centers[index][0] = x;
243
      centers[index][1] = height;
244
      centers[index][2] = z;
245
      }
246

    
247
    for(int i=0; i<layers-1; i++, index++)
248
      {
249
      x -= 1;
250
      centers[index][0] = x;
251
      centers[index][1] = height;
252
      centers[index][2] = z;
253
      }
254

    
255
    for(int i=0; i<layers-1; i++, index++)
256
      {
257
      z += 1;
258
      centers[index][0] = x;
259
      centers[index][1] = height;
260
      centers[index][2] = z;
261
      }
262

    
263
    for(int i=0; i<layers-2; i++, index++)
264
      {
265
      x += 1;
266
      centers[index][0] = x;
267
      centers[index][1] = height;
268
      centers[index][2] = z;
269
      }
270

    
271
    return index;
272
    }
273

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

    
276
  private int createTetraPositions(float[][] centers, int index, int layers, float height)
277
    {
278
    float x = (layers-1)*0.5f;
279
    float z =  layers*0.5f;
280

    
281
    for(int i=0; i<layers-1; i++, index++)
282
      {
283
      z -= 1;
284
      centers[index][0] = x;
285
      centers[index][1] = height;
286
      centers[index][2] = z;
287
      }
288

    
289
    x += 0.5f;
290
    z -= 0.5f;
291

    
292
    for(int i=0; i<layers-1; i++, index++)
293
      {
294
      x -= 1;
295
      centers[index][0] = x;
296
      centers[index][1] = height;
297
      centers[index][2] = z;
298
      }
299

    
300
    x -= 0.5f;
301
    z -= 0.5f;
302

    
303
    for(int i=0; i<layers-1; i++, index++)
304
      {
305
      z += 1;
306
      centers[index][0] = x;
307
      centers[index][1] = height;
308
      centers[index][2] = z;
309
      }
310

    
311
    x -= 0.5f;
312
    z += 0.5f;
313

    
314
    for(int i=0; i<layers-1; i++, index++)
315
      {
316
      x += 1;
317
      centers[index][0] = x;
318
      centers[index][1] = height;
319
      centers[index][2] = z;
320
      }
321

    
322
    return index;
323
    }
324

    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326

    
327
  public float[][] getCubitPositions(int[] numLayers)
328
    {
329
    int layers = numLayers[0];
330
    int numO = getNumOctahedrons(layers);
331
    int numT = getNumTetrahedrons(layers);
332
    int index = 0;
333
    float height = 0.0f;
334

    
335
    float[][] CENTERS = new float[numO+numT][3];
336

    
337
    index = createOctaPositions(CENTERS,index,layers,height);
338

    
339
    for(int i=layers-1; i>0; i--)
340
      {
341
      height += SQ2/2;
342
      index = createOctaPositions(CENTERS,index,i,+height);
343
      index = createOctaPositions(CENTERS,index,i,-height);
344
      }
345

    
346
    height = SQ2/4;
347

    
348
    for(int i=layers; i>1; i--)
349
      {
350
      index = createTetraPositions(CENTERS,index,i,+height);
351
      index = createTetraPositions(CENTERS,index,i,-height);
352
      height += SQ2/2;
353
      }
354

    
355
    return CENTERS;
356
    }
357

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

    
360
  private int retFaceTetraBelongsTo(int tetra, int numLayers)
361
    {
362
    if( mTetraToFaceMap==null ) mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4};
363

    
364
    for(int i=numLayers-1; i>0; i--)
365
      {
366
      if( tetra < 8*i ) return mTetraToFaceMap[tetra/i];
367
      tetra -= 8*i;
368
      }
369

    
370
    return -1;
371
    }
372

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

    
375
  public ObjectShape getObjectShape(int variant)
376
    {
377
    if( variant==0 )
378
      {
379
      float[][] vertices =
380
          {
381
             { 0.5f,  0.0f, 0.5f},
382
             { 0.5f,  0.0f,-0.5f},
383
             {-0.5f,  0.0f,-0.5f},
384
             {-0.5f,  0.0f, 0.5f},
385
             { 0.0f, SQ2/2, 0.0f},
386
             { 0.0f,-SQ2/2, 0.0f}
387
          };
388

    
389
      int[][] indices =
390
          {
391
             {3,0,4},
392
             {0,1,4},
393
             {1,2,4},
394
             {2,3,4},
395
             {5,0,3},
396
             {5,1,0},
397
             {5,2,1},
398
             {5,3,2}
399
          };
400

    
401
      return new ObjectShape(vertices, indices, 1);
402
      }
403
    else
404
      {
405
      float[][] vertices= { {-0.5f, SQ2/4, 0.0f}, { 0.5f, SQ2/4, 0.0f}, { 0.0f,-SQ2/4, 0.5f}, { 0.0f,-SQ2/4,-0.5f} };
406
      int[][] indices   = { {2,1,0}, {2,3,1}, {3,2,0}, {3,0,1} };
407
      return new ObjectShape(vertices, indices, 1);
408
      }
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

    
413
  public ObjectFaceShape getObjectFaceShape(int variant)
414
    {
415
    int numL = getNumLayers()[0];
416
    int N = numL>3 ? 5:6;
417
    int E = numL>2 ? (numL>3 ? 0:1) : 2;
418

    
419
    if( variant==0 )
420
      {
421
      float[][] bands     = { {0.05f,35,0.5f,0.8f,N,E,E} };
422
      int[] bandIndices   = { 0,0,0,0,0,0,0,0 };
423
      float[][] corners   = { {0.04f,0.20f} };
424
      int[] cornerIndices = { 0,0,0,0,0,0 };
425
      float[][] centers   = { {0.0f, 0.0f, 0.0f} };
426
      int[] centerIndices = { 0,0,0,0,0,0 };
427
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
428
      }
429
    else
430
      {
431
      float[][] bands     = { {0.05f,35,0.5f,0.8f,N,E,E} };
432
      int[] bandIndices   = { 0,0,0,0 };
433
      float[][] corners   = { {0.08f,0.15f} };
434
      int[] cornerIndices = { 0,0,0,0 };
435
      float[][] centers   = { {0.0f, 0.0f, 0.0f} };
436
      int[] centerIndices = { 0,0,0,0 };
437
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
438
      }
439
    }
440

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

    
443
  public Static4D getQuat(int cubit, int[] numLayers)
444
    {
445
    if( mQuats==null ) initializeQuats();
446

    
447
    int numL = numLayers[0];
448
    int numO = getNumOctahedrons(numL);
449

    
450
    if( cubit<numO ) return mQuats[0];
451

    
452
    switch( retFaceTetraBelongsTo(cubit-numO, numL) )
453
      {
454
      case 0: return mQuats[0];                         // unit quat
455
      case 1: return new Static4D(0,-SQ2/2,0,SQ2/2);    //  90 along Y
456
      case 2: return mQuats[1];                         // 180 along Y
457
      case 3: return new Static4D(0,+SQ2/2,0,SQ2/2);    //  90 along
458
      case 4: return new Static4D(0,     0,1,    0);    // 180 along Z
459
      case 5: return new Static4D(SQ2/2, 0,SQ2/2,0);    //
460
      case 6: return new Static4D(     1,0,0,    0);    // 180 along X
461
      case 7: return new Static4D(-SQ2/2,0,SQ2/2,0);    //
462
      }
463

    
464
    return null;
465
    }
466

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

    
469
  public int getNumCubitVariants(int[] numLayers)
470
    {
471
    return 2;
472
    }
473

    
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475

    
476
  public int getCubitVariant(int cubit, int[] numLayers)
477
    {
478
    return cubit<getNumOctahedrons(numLayers[0]) ? 0 : 1;
479
    }
480

    
481
///////////////////////////////////////////////////////////////////////////////////////////////////
482

    
483
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
484
    {
485
    int numL = numLayers[0];
486
    int numO = getNumOctahedrons(numL);
487

    
488
    if( cubit<numO )
489
      {
490
      int axis = 0;
491
      int layer= 1;
492

    
493
      switch(face)
494
        {
495
        case 0: axis = 2; layer =             1; break;
496
        case 1: axis = 0; layer = (1<<(numL-1)); break;
497
        case 2: axis = 3; layer =             1; break;
498
        case 3: axis = 1; layer = (1<<(numL-1)); break;
499
        case 4: axis = 3; layer = (1<<(numL-1)); break;
500
        case 5: axis = 1; layer =             1; break;
501
        case 6: axis = 2; layer = (1<<(numL-1)); break;
502
        case 7: axis = 0; layer =             1; break;
503
        }
504

    
505
      return CUBITS[cubit].getRotRow(axis) == layer ? face : -1;
506
      }
507
    else
508
      {
509
      return face>0 ? -1 : retFaceTetraBelongsTo(cubit-numO, numL);
510
      }
511
    }
512

    
513
///////////////////////////////////////////////////////////////////////////////////////////////////
514

    
515
  public float getStickerRadius()
516
    {
517
    return 0.08f;
518
    }
519

    
520
///////////////////////////////////////////////////////////////////////////////////////////////////
521

    
522
  public float getStickerStroke()
523
    {
524
    float stroke = 0.08f;
525

    
526
    if( ObjectControl.isInIconMode() )
527
      {
528
      int[] numLayers = getNumLayers();
529

    
530
      switch(numLayers[0])
531
        {
532
        case 2: stroke*=1.4f; break;
533
        case 3: stroke*=2.0f; break;
534
        case 4: stroke*=2.1f; break;
535
        default:stroke*=2.2f; break;
536
        }
537
      }
538

    
539
    return stroke;
540
    }
541

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

    
544
  public float[][] getStickerAngles()
545
    {
546
    return null;
547
    }
548

    
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550
// PUBLIC API
551

    
552
  public Static3D[] getRotationAxis()
553
    {
554
    return ROT_AXIS;
555
    }
556

    
557
///////////////////////////////////////////////////////////////////////////////////////////////////
558

    
559
  public int[] getBasicAngle()
560
    {
561
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
562
    return mBasicAngle;
563
    }
564

    
565
///////////////////////////////////////////////////////////////////////////////////////////////////
566

    
567
  public ObjectType intGetObjectType(int[] numLayers)
568
    {
569
    switch(numLayers[0])
570
      {
571
      case 2: return ObjectType.DIAM_2;
572
      case 3: return ObjectType.DIAM_3;
573
      case 4: return ObjectType.DIAM_4;
574
      }
575

    
576
    return ObjectType.DIAM_2;
577
    }
578

    
579
///////////////////////////////////////////////////////////////////////////////////////////////////
580

    
581
  public String getObjectName()
582
    {
583
    switch(getNumLayers()[0])
584
      {
585
      case 2: return "Skewb Diamond";
586
      case 3: return "Face Turning Octahedron";
587
      case 4: return "Master Face Turning Octahedron";
588
      }
589

    
590
    return "Skewb Diamond";
591
    }
592

    
593
///////////////////////////////////////////////////////////////////////////////////////////////////
594

    
595
  public String getInventor()
596
    {
597
    switch(getNumLayers()[0])
598
      {
599
      case 2: return "Uwe Meffert";
600
      case 3: return "David Pitcher";
601
      case 4: return "Timur Evbatyrov";
602
      }
603

    
604
    return "Uwe Meffert";
605
    }
606

    
607
///////////////////////////////////////////////////////////////////////////////////////////////////
608

    
609
  public int getYearOfInvention()
610
    {
611
    switch(getNumLayers()[0])
612
      {
613
      case 2: return 1984;
614
      case 3: return 2003;
615
      case 4: return 2011;
616
      }
617
    return 1984;
618
    }
619

    
620
///////////////////////////////////////////////////////////////////////////////////////////////////
621

    
622
  public int getComplexity()
623
    {
624
    switch(getNumLayers()[0])
625
      {
626
      case 2: return 1;
627
      case 3: return 2;
628
      case 4: return 3;
629
      }
630

    
631
    return 0;
632
    }
633
}
(7-7/26)