Project

General

Profile

« Previous | Next » 

Revision 8c3148e2

Added by Leszek Koltunski over 3 years ago

Remove statics from the Skewb class.

View differences:

src/main/java/org/distorted/objects/TwistySkewb.java
37 37

  
38 38
public class TwistySkewb extends TwistyObject
39 39
{
40
  private static final int FACES_PER_CUBIT =6;
41

  
42 40
  // the four rotation axis of a RubikSkewb. Must be normalized.
43 41
  static final Static3D[] ROT_AXIS = new Static3D[]
44 42
         {
......
48 46
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
49 47
         };
50 48

  
51
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
52

  
53 49
  private static final int[] FACE_COLORS = new int[]
54 50
         {
55 51
           COLOR_YELLOW, COLOR_WHITE,
......
57 53
           COLOR_RED   , COLOR_ORANGE
58 54
         };
59 55

  
60
  // All legal rotation quats of a RubikSkewb
61
  private static final Static4D[] QUATS = new Static4D[]
62
         {
63
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
64
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
65
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
66
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
67

  
68
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
69
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
70
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
71
           new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
72
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
73
           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
74
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
75
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
76
         };
77

  
78
  private static final int[][] mCornerMap =
79
         {
80
           {  4, 2, 0, 18,18,18 },
81
           {  2, 5, 0, 18,18,18 },
82
           {  3, 4, 0, 18,18,18 },
83
           {  5, 3, 0, 18,18,18 },
84
           {  1, 2, 4, 18,18,18 },
85
           {  5, 2, 1, 18,18,18 },
86
           {  4, 3, 1, 18,18,18 },
87
           {  1, 3, 5, 18,18,18 },
88
         };
89

  
90
  private static final int[][] mEdgeMap =
91
         {
92
           { 10, 8, 18,18,18,18 },
93
           {  6,10, 18,18,18,18 },
94
           { 10, 9, 18,18,18,18 },
95
           {  7,10, 18,18,18,18 },
96
           {  8, 6, 18,18,18,18 },
97
           {  9, 6, 18,18,18,18 },
98
           {  9, 7, 18,18,18,18 },
99
           {  8, 7, 18,18,18,18 },
100
           { 11, 8, 18,18,18,18 },
101
           {  6,11, 18,18,18,18 },
102
           { 11, 9, 18,18,18,18 },
103
           {  7,11, 18,18,18,18 }
104
         };
105

  
106
  private static final int[][] mCenterMap =
107
         {
108
           { 12, 18,18,18,18,18 },
109
           { 13, 18,18,18,18,18 },
110
           { 14, 18,18,18,18,18 },
111
           { 15, 18,18,18,18,18 },
112
           { 16, 18,18,18,18,18 },
113
           { 17, 18,18,18,18,18 },
114
         };
115

  
116
  private static final double[][] VERTICES_CORNER = new double[][]
117
          {
118
              {-0.5f, 0.0f, 0.0f},
119
              { 0.0f,-0.5f, 0.0f},
120
              { 0.0f, 0.0f,-0.5f},
121
              {-0.5f,-0.5f,-0.5f},
122
              { 0.0f, 0.0f, 0.0f}
123
          };
124

  
125
  private static final int[][] VERT_INDEXES_CORNER = new int[][]
126
          {
127
              {0,1,4},
128
              {2,0,4},
129
              {1,2,4},
130
              {3,1,0},
131
              {3,2,1},
132
              {3,0,2}
133
          };
134

  
135
  private static final double[][] VERTICES_EDGE = new double[][]
136
          {
137
             {-0.5, 0.0, 0.0},
138
             { 0.5, 0.0, 0.0},
139
             { 0.0,-0.5, 0.0},
140
             { 0.0, 0.0,-0.5}
141
          };
142

  
143
  private static final int[][] VERT_INDEXES_EDGE = new int[][]
144
          {
145
             {2,1,0},   // counterclockwise!
146
             {3,0,1},
147
             {2,3,1},
148
             {3,2,0},
149
          };
150

  
151
  private static final double[][] VERTICES_FACE = new double[][]
152
          {
153
             {-0.5f, 0.0f, 0.0f },
154
             { 0.0f,-0.5f, 0.0f },
155
             { 0.5f, 0.0f, 0.0f },
156
             { 0.0f, 0.5f, 0.0f },
157
             { 0.0f, 0.0f,-0.5f }
158
          };
159

  
160
  private static final int[][] VERT_INDEXES_FACE = new int[][]
161
          {
162
             {0,1,2,3},
163
             {4,1,0},
164
             {4,2,1},
165
             {4,3,2},
166
             {4,0,3}
167
          };
168

  
169
  private static final float[][] STICKERS = new float[][]
170
          {
171
             { -0.5f, 0.25f, 0.25f,  -0.5f, 0.25f, 0.25f  },
172
             { -0.5f, 0.00f, 0.00f,  -0.5f, 0.50f, 0.0f, 0.0f, 0.5f }
173
          };
174

  
175
  private static final ObjectSticker[] mStickers;
176

  
177
  static
178
    {
179
    mStickers = new ObjectSticker[STICKERS.length+1];
180
    final float R1 = 0.025f;
181
    final float R2 = 0.025f;
182
    final float R3 = 0.055f;
183
    final float[][] radii  = { { R1,R1,R1 },{ R2,R2,R2 },{ R3,R3,R3,R3 } };
184
    final float[] strokes = { 0.045f, 0.035f, 0.035f };
185

  
186
    for(int s=0; s<STICKERS.length+1; s++)
187
      {
188
      int index = s<2 ? 0:1;
189
      mStickers[s] = new ObjectSticker(STICKERS[index],null,radii[s],strokes[s]);
190
      }
191
    }
192

  
193 56
  private int mCurrState;
194 57
  private int mIndexExcluded;
195 58
  private final ScrambleState[] mStates;
196 59
  private int[][] mScrambleTable;
197 60
  private int[] mNumOccurences;
61
  private int[] mBasicAngle;
62
  private Static4D[] mQuats;
63
  private int[][] mCornerMap,mEdgeMap,mCenterMap;
64
  private ObjectSticker[] mStickers;
198 65

  
199 66
///////////////////////////////////////////////////////////////////////////////////////////////////
200 67

  
......
211 78
      };
212 79
    }
213 80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

  
83
  private void initializeQuats()
84
    {
85
    mQuats = new Static4D[]
86
         {
87
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
88
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
89
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
90
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
91

  
92
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
93
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
94
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
95
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
96
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
97
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
98
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
99
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
100
         };
101
    }
102

  
214 103
///////////////////////////////////////////////////////////////////////////////////////////////////
215 104

  
216 105
  int[] getSolvedQuats(int cubit, int numLayers)
217 106
    {
107
    if( mQuats==null ) initializeQuats();
218 108
    int status = retCubitSolvedStatus(cubit,numLayers);
219
    return status<0 ? null : buildSolvedQuats(MovementSkewb.FACE_AXIS[status],QUATS);
109
    return status<0 ? null : buildSolvedQuats(MovementSkewb.FACE_AXIS[status],mQuats);
220 110
    }
221 111

  
222 112
///////////////////////////////////////////////////////////////////////////////////////////////////
......
251 141

  
252 142
  Static4D[] getQuats()
253 143
    {
254
    return QUATS;
144
    if( mQuats==null ) initializeQuats();
145
    return mQuats;
255 146
    }
256 147

  
257 148
///////////////////////////////////////////////////////////////////////////////////////////////////
......
300 191

  
301 192
  int getNumCubitFaces()
302 193
    {
303
    return FACES_PER_CUBIT;
194
    return 6;
304 195
    }
305 196

  
306 197
///////////////////////////////////////////////////////////////////////////////////////////////////
......
435 326

  
436 327
  Static4D getQuat(int cubit, int numLayers)
437 328
    {
329
    if( mQuats==null ) initializeQuats();
438 330
    int numCorners = getNumCorners();
439 331
    int numEdges   = getNumEdges(numLayers);
440 332

  
......
442 334
      {
443 335
      switch(cubit)
444 336
        {
445
        case  0: return QUATS[0];                          //  unit quat
337
        case  0: return mQuats[0];                         //  unit quat
446 338
        case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
447 339
        case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
448
        case  3: return QUATS[1];                          // 180 along X
340
        case  3: return mQuats[1];                         // 180 along X
449 341
        case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
450
        case  5: return QUATS[2];                          // 180 along Y
451
        case  6: return QUATS[3];                          // 180 along Z
342
        case  5: return mQuats[2];                         // 180 along Y
343
        case  6: return mQuats[3];                         // 180 along Z
452 344
        case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
453 345
        }
454 346
      }
......
458 350

  
459 351
      switch(edge)
460 352
        {
461
        case  0: return QUATS[ 0];
462
        case  1: return QUATS[ 5];
463
        case  2: return QUATS[ 3];
464
        case  3: return QUATS[11];
465
        case  4: return QUATS[ 4];
466
        case  5: return QUATS[ 7];
467
        case  6: return QUATS[ 9];
468
        case  7: return QUATS[10];
469
        case  8: return QUATS[ 2];
470
        case  9: return QUATS[ 8];
471
        case 10: return QUATS[ 1];
472
        case 11: return QUATS[ 6];
353
        case  0: return mQuats[ 0];
354
        case  1: return mQuats[ 5];
355
        case  2: return mQuats[ 3];
356
        case  3: return mQuats[11];
357
        case  4: return mQuats[ 4];
358
        case  5: return mQuats[ 7];
359
        case  6: return mQuats[ 9];
360
        case  7: return mQuats[10];
361
        case  8: return mQuats[ 2];
362
        case  9: return mQuats[ 8];
363
        case 10: return mQuats[ 1];
364
        case 11: return mQuats[ 6];
473 365
        }
474 366
      }
475 367
    else
......
482 374
        case 1: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
483 375
        case 2: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
484 376
        case 3: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
485
        case 4: return QUATS[0];                          //  unit quaternion
486
        case 5: return QUATS[1];                          // 180 along X
377
        case 4: return mQuats[0];                         //  unit quaternion
378
        case 5: return mQuats[1];                         // 180 along X
487 379
        }
488 380
      }
489 381

  
......
498 390

  
499 391
    if( variant==0 )
500 392
      {
393
      double[][] vertices = new double[][] { {-0.5f, 0.0f, 0.0f},{ 0.0f,-0.5f, 0.0f},{ 0.0f, 0.0f,-0.5f},{-0.5f,-0.5f,-0.5f},{ 0.0f, 0.0f, 0.0f} };
394
      int[][] vert_indices = new int[][] { {0,1,4},{2,0,4},{1,2,4},{3,1,0},{3,2,1},{3,0,2} };
501 395
      int N = numLayers==2 ? 7:5;
502 396
      int E1= numLayers==2 ? 3:2;
503 397
      int E2= numLayers==2 ? 5:3;
......
507 401
      int[] cornerIndices = new int[] { 1,1,1,0,0 };
508 402
      float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.25f} };
509 403
      int[] centerIndices = new int[] { 0,0,0,-1,0 };
510
      return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
404
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
511 405
      }
512 406
    else if( variant==1 )
513 407
      {
408
      double[][] vertices = new double[][] { {-0.5, 0.0, 0.0},{ 0.5, 0.0, 0.0},{ 0.0,-0.5, 0.0},{ 0.0, 0.0,-0.5} };
409
      int[][] vert_indices = new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
514 410
      int N = numLayers==2 ? 7:5;
515 411
      int E = numLayers==2 ? 5:2;
516 412
      float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,N,2,E}, {0.020f,45,0.16f,0.2f,3,1,2} };
......
519 415
      int[] cornerIndices = new int[] { 0,0,1,1 };
520 416
      float[][] centers   = new float[][] { {0.0f, -0.25f, -0.25f} };
521 417
      int[] centerIndices = new int[] { 0,0,0,0 };
522
      return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
418
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
523 419
      }
524 420
    else
525 421
      {
422
      double[][] vertices = new double[][] { {-0.5f, 0.0f, 0.0f },{ 0.0f,-0.5f, 0.0f },{ 0.5f, 0.0f, 0.0f },{ 0.0f, 0.5f, 0.0f },{ 0.0f, 0.0f,-0.5f } };
423
      int[][] vert_indices = new int[][] { {0,1,2,3},{4,1,0},{4,2,1},{4,3,2},{4,0,3} };
526 424
      int N = numLayers==2 ? 7:6;
527 425
      int E = numLayers==2 ? 3:1;
528 426
      float[][] bands     = new float[][] { {0.051f,35,SQ2/8,0.9f,N,E,E}, {0.000f,0,1,0.0f,3,0,0} };
......
531 429
      int[] cornerIndices = new int[] { 0,0,0,0,0 };
532 430
      float[][] centers   = new float[][] { {0,0,-0.2f} };
533 431
      int[] centerIndices = new int[] { 0,0,0,0,-1 };
534
      return new ObjectShape(VERTICES_FACE,VERT_INDEXES_FACE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
432
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
535 433
      }
536 434
    }
537 435

  
......
556 454

  
557 455
  int getFaceColor(int cubit, int cubitface, int numLayers)
558 456
    {
457
    if( mCornerMap==null || mEdgeMap==null || mCenterMap==null )
458
      {
459
      mCornerMap = new int[][]
460
         {
461
           {  4, 2, 0, 18,18,18 },
462
           {  2, 5, 0, 18,18,18 },
463
           {  3, 4, 0, 18,18,18 },
464
           {  5, 3, 0, 18,18,18 },
465
           {  1, 2, 4, 18,18,18 },
466
           {  5, 2, 1, 18,18,18 },
467
           {  4, 3, 1, 18,18,18 },
468
           {  1, 3, 5, 18,18,18 },
469
         };
470

  
471
      mEdgeMap = new int[][]
472
         {
473
           { 10, 8, 18,18,18,18 },
474
           {  6,10, 18,18,18,18 },
475
           { 10, 9, 18,18,18,18 },
476
           {  7,10, 18,18,18,18 },
477
           {  8, 6, 18,18,18,18 },
478
           {  9, 6, 18,18,18,18 },
479
           {  9, 7, 18,18,18,18 },
480
           {  8, 7, 18,18,18,18 },
481
           { 11, 8, 18,18,18,18 },
482
           {  6,11, 18,18,18,18 },
483
           { 11, 9, 18,18,18,18 },
484
           {  7,11, 18,18,18,18 }
485
         };
486

  
487
      mCenterMap = new int[][]
488
         {
489
           { 12, 18,18,18,18,18 },
490
           { 13, 18,18,18,18,18 },
491
           { 14, 18,18,18,18,18 },
492
           { 15, 18,18,18,18,18 },
493
           { 16, 18,18,18,18,18 },
494
           { 17, 18,18,18,18,18 },
495
         };
496
      }
497

  
559 498
    int numCorners = getNumCorners();
560 499
    int numEdges   = getNumEdges(numLayers);
561 500

  
......
586 525

  
587 526
  ObjectSticker retSticker(int face)
588 527
    {
528
    if( mStickers==null )
529
      {
530
      float[][] STICKERS = new float[][]
531
          {
532
             { -0.5f, 0.25f, 0.25f,  -0.5f, 0.25f, 0.25f  },
533
             { -0.5f, 0.00f, 0.00f,  -0.5f, 0.50f, 0.0f, 0.0f, 0.5f }
534
          };
535

  
536
      final float R1 = 0.025f;
537
      final float R2 = 0.025f;
538
      final float R3 = 0.055f;
539
      final float[][] radii  = { { R1,R1,R1 },{ R2,R2,R2 },{ R3,R3,R3,R3 } };
540
      final float[] strokes = { 0.045f, 0.035f, 0.035f };
541

  
542
      mStickers = new ObjectSticker[STICKERS.length+1];
543

  
544
      for(int s=0; s<STICKERS.length+1; s++)
545
        {
546
        int index = s<2 ? 0:1;
547
        mStickers[s] = new ObjectSticker(STICKERS[index],null,radii[s],strokes[s]);
548
        }
549
      }
550

  
589 551
    return mStickers[face/NUM_FACES];
590 552
    }
591 553

  
......
656 618

  
657 619
  public int[] getBasicAngle()
658 620
    {
659
    return BASIC_ANGLE;
621
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
622
    return mBasicAngle;
660 623
    }
661 624

  
662 625
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff