Project

General

Profile

« Previous | Next » 

Revision aec5cc91

Added by Leszek Koltunski about 3 years ago

Remove statics from the Diamond classes.

View differences:

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

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

  
42 40
  // the four rotation axis of a Diamond. Must be normalized.
43 41
  static final Static3D[] ROT_AXIS = new Static3D[]
44 42
         {
......
48 46
           new Static3D(     0,-SQ3/3,+SQ6/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_ORANGE, COLOR_VIOLET,
......
58 54
           COLOR_GREEN , COLOR_GREY
59 55
         };
60 56

  
61
  private static final int[] mFaceMap = new int[] {4,0,6,2,7,3,5,1};
62

  
63
  // All legal rotation quats of a Diamond: unit + three 180 deg turns + 8 generators
64
  private static final Static4D[] QUATS = new Static4D[]
65
         {
66
           new Static4D(  0.0f,  0.0f,   0.0f,  1.0f ),
67
           new Static4D(  0.0f,  1.0f,   0.0f,  0.0f ),
68
           new Static4D(+SQ2/2,  0.0f, -SQ2/2,  0.0f ),
69
           new Static4D(-SQ2/2,  0.0f, -SQ2/2,  0.0f ),
70

  
71
           new Static4D(+SQ2/2,  0.5f,   0.0f,  0.5f ),
72
           new Static4D(-SQ2/2,  0.5f,   0.0f,  0.5f ),
73
           new Static4D(  0.0f,  0.5f, +SQ2/2,  0.5f ),
74
           new Static4D(  0.0f,  0.5f, -SQ2/2,  0.5f ),
75
           new Static4D(+SQ2/2,  0.5f,   0.0f, -0.5f ),
76
           new Static4D(-SQ2/2,  0.5f,   0.0f, -0.5f ),
77
           new Static4D(  0.0f,  0.5f, +SQ2/2, -0.5f ),
78
           new Static4D(  0.0f,  0.5f, -SQ2/2, -0.5f )
79
         };
80

  
81 57
  private static final float DIST = 0.50f;
82

  
83
  private static final int[] mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4};
84

  
85
  private static final double[][] VERTICES_TETRA = new double[][]
86
          {
87
             {-0.5, SQ2/4, 0.0},
88
             { 0.5, SQ2/4, 0.0},
89
             { 0.0,-SQ2/4, 0.5},
90
             { 0.0,-SQ2/4,-0.5}
91
          };
92

  
93
  private static final int[][] VERT_INDEXES_TETRA = new int[][]
94
          {
95
             {2,1,0},   // counterclockwise!
96
             {2,3,1},
97
             {3,2,0},
98
             {3,0,1}
99
          };
100

  
101
  private static final double[][] VERTICES_OCTA = new double[][]
102
          {
103
             { 0.5,   0.0, 0.5},
104
             { 0.5,   0.0,-0.5},
105
             {-0.5,   0.0,-0.5},
106
             {-0.5,   0.0, 0.5},
107
             { 0.0, SQ2/2, 0.0},
108
             { 0.0,-SQ2/2, 0.0}
109
          };
110

  
111
  private static final int[][] VERT_INDEXES_OCTA = new int[][]
112
          {
113
             {3,0,4},   // counterclockwise!
114
             {0,1,4},
115
             {1,2,4},
116
             {2,3,4},
117
             {5,0,3},
118
             {5,1,0},
119
             {5,2,1},
120
             {5,3,2}
121
          };
122

  
123
  private static final float[][] STICKERS = new float[][]
124
          {
125
             { -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f }
126
          };
127

  
128
  private static final ObjectSticker[] mStickers;
129

  
130
  static
131
    {
132
    float radius = 0.06f;
133
    float stroke = 0.07f;
134
    float[] radii = new float[] {radius,radius,radius};
135
    mStickers = new ObjectSticker[STICKERS.length];
136
    mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
137
    }
58
  private static final int FACES_PER_CUBIT =8;
138 59

  
139 60
  private int mCurrState;
140 61
  private int mIndexExcluded;
141 62
  private final ScrambleState[] mStates;
142 63
  private int[][] mScrambleTable;
143 64
  private int[] mNumOccurences;
65
  private int[] mBasicAngle;
66
  private int[] mFaceMap;
67
  private Static4D[] mQuats;
68
  private int[] mTetraToFaceMap;
69
  private ObjectSticker[] mStickers;
144 70

  
145 71
///////////////////////////////////////////////////////////////////////////////////////////////////
146 72

  
......
164 90
      };
165 91
    }
166 92

  
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

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

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

  
167 115
///////////////////////////////////////////////////////////////////////////////////////////////////
168 116

  
169 117
  int[] getSolvedQuats(int cubit, int numLayers)
170 118
    {
119
    if( mQuats==null ) initializeQuats();
120
    if( mFaceMap==null ) mFaceMap = new int[] {4,0,6,2,7,3,5,1};
171 121
    int status = retCubitSolvedStatus(cubit,numLayers);
172
    return status<0 ? null : buildSolvedQuats(MovementDiamond.FACE_AXIS[mFaceMap[status]],QUATS);
122
    return status<0 ? null : buildSolvedQuats(MovementDiamond.FACE_AXIS[mFaceMap[status]],mQuats);
173 123
    }
174 124

  
175 125
///////////////////////////////////////////////////////////////////////////////////////////////////
......
183 133

  
184 134
  Static4D[] getQuats()
185 135
    {
186
    return QUATS;
136
    if( mQuats==null ) initializeQuats();
137
    return mQuats;
187 138
    }
188 139

  
189 140
///////////////////////////////////////////////////////////////////////////////////////////////////
......
211 162

  
212 163
  int getNumStickerTypes(int numLayers)
213 164
    {
214
    return STICKERS.length;
165
    return 1;
215 166
    }
216 167

  
217 168
///////////////////////////////////////////////////////////////////////////////////////////////////
......
391 342

  
392 343
  private int retFaceTetraBelongsTo(int tetra, int numLayers)
393 344
    {
345
    if( mTetraToFaceMap==null ) mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4};
346

  
394 347
    for(int i=numLayers-1; i>0; i--)
395 348
      {
396 349
      if( tetra < 8*i ) return mTetraToFaceMap[tetra/i];
......
410 363

  
411 364
    if( variant==0 )
412 365
      {
366
      double[][] vertices = new double[][]
367
          {
368
             { 0.5,   0.0, 0.5},
369
             { 0.5,   0.0,-0.5},
370
             {-0.5,   0.0,-0.5},
371
             {-0.5,   0.0, 0.5},
372
             { 0.0, SQ2/2, 0.0},
373
             { 0.0,-SQ2/2, 0.0}
374
          };
375

  
376
      int[][] vert_indices = new int[][]
377
          {
378
             {3,0,4},
379
             {0,1,4},
380
             {1,2,4},
381
             {2,3,4},
382
             {5,0,3},
383
             {5,1,0},
384
             {5,2,1},
385
             {5,3,2}
386
          };
387

  
413 388
      float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
414 389
      int[] bandIndices   = new int[] { 0,0,0,0,0,0,0,0 };
415 390
      float[][] corners   = new float[][] { {0.04f,0.20f} };
416 391
      int[] cornerIndices = new int[] { 0,0,0,0,0,0 };
417 392
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
418 393
      int[] centerIndices = new int[] { 0,0,0,0,0,0 };
419
      return new ObjectShape(VERTICES_OCTA,VERT_INDEXES_OCTA,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
394
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
420 395
      }
421 396
    else
422 397
      {
398
      double[][] vertices = new double[][] { {-0.5, SQ2/4, 0.0}, { 0.5, SQ2/4, 0.0}, { 0.0,-SQ2/4, 0.5}, { 0.0,-SQ2/4,-0.5} };
399
      int[][] vert_indices = new int[][]  { {2,1,0}, {2,3,1}, {3,2,0}, {3,0,1} };
423 400
      float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
424 401
      int[] bandIndices   = new int[] { 0,0,0,0 };
425 402
      float[][] corners   = new float[][] { {0.08f,0.15f} };
426 403
      int[] cornerIndices = new int[] { 0,0,0,0 };
427 404
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
428 405
      int[] centerIndices = new int[] { 0,0,0,0 };
429
      return new ObjectShape(VERTICES_TETRA,VERT_INDEXES_TETRA,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
406
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
430 407
      }
431 408
    }
432 409

  
......
434 411

  
435 412
  Static4D getQuat(int cubit, int numLayers)
436 413
    {
414
    if( mQuats==null ) initializeQuats();
437 415
    int numO = getNumOctahedrons(numLayers);
438 416

  
439
    if( cubit<numO ) return QUATS[0];
417
    if( cubit<numO ) return mQuats[0];
440 418

  
441 419
    switch( retFaceTetraBelongsTo(cubit-numO, numLayers) )
442 420
      {
443
      case 0: return QUATS[0];                          // unit quat
421
      case 0: return mQuats[0];                         // unit quat
444 422
      case 1: return new Static4D(0,-SQ2/2,0,SQ2/2);    //  90 along Y
445
      case 2: return QUATS[1];                          // 180 along Y
423
      case 2: return mQuats[1];                         // 180 along Y
446 424
      case 3: return new Static4D(0,+SQ2/2,0,SQ2/2);    //  90 along
447 425
      case 4: return new Static4D(0,     0,1,    0);    // 180 along Z
448 426
      case 5: return new Static4D(SQ2/2, 0,SQ2/2,0);    //
......
509 487

  
510 488
  ObjectSticker retSticker(int face)
511 489
    {
490
    if( mStickers==null )
491
      {
492
      float[][] STICKERS = new float[][] { { -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f } };
493
      float radius = 0.06f;
494
      float stroke = 0.07f;
495
      float[] radii = new float[] {radius,radius,radius};
496
      mStickers     = new ObjectSticker[STICKERS.length];
497
      mStickers[0]  = new ObjectSticker(STICKERS[0],null,radii,stroke);
498
      }
499

  
512 500
    return mStickers[face/NUM_FACES];
513 501
    }
514 502

  
......
579 567

  
580 568
  public int[] getBasicAngle()
581 569
    {
582
    return BASIC_ANGLE;
570
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
571
    return mBasicAngle;
583 572
    }
584 573

  
585 574
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff