Project

General

Profile

« Previous | Next » 

Revision 97eb0852

Added by Leszek Koltunski about 3 years ago

Remove more statics from the Bandaged Cube classes.

View differences:

src/main/java/org/distorted/objects/TwistyBandagedAbstract.java
44 44
           new Static3D(0,0,1)
45 45
         };
46 46

  
47
  private static final int[] BASIC_ANGLE = new int[] { 4,4,4 };
48

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

  
56
  private static final Static4D[] QUATS = new Static4D[]
57
         {
58
         new Static4D(  0.0f,   0.0f,   0.0f,   1.0f),
59
         new Static4D(  1.0f,   0.0f,   0.0f,   0.0f),
60
         new Static4D(  0.0f,   1.0f,   0.0f,   0.0f),
61
         new Static4D(  0.0f,   0.0f,   1.0f,   0.0f),
62

  
63
         new Static4D( SQ2/2,  SQ2/2,  0.0f ,   0.0f),
64
         new Static4D( SQ2/2, -SQ2/2,  0.0f ,   0.0f),
65
         new Static4D( SQ2/2,   0.0f,  SQ2/2,   0.0f),
66
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,   0.0f),
67
         new Static4D( SQ2/2,   0.0f,   0.0f,  SQ2/2),
68
         new Static4D( SQ2/2,   0.0f,   0.0f, -SQ2/2),
69
         new Static4D(  0.0f,  SQ2/2,  SQ2/2,   0.0f),
70
         new Static4D(  0.0f,  SQ2/2, -SQ2/2,   0.0f),
71
         new Static4D(  0.0f,  SQ2/2,   0.0f,  SQ2/2),
72
         new Static4D(  0.0f,  SQ2/2,   0.0f, -SQ2/2),
73
         new Static4D(  0.0f,   0.0f,  SQ2/2,  SQ2/2),
74
         new Static4D(  0.0f,   0.0f,  SQ2/2, -SQ2/2),
75

  
76
         new Static4D(  0.5f,   0.5f,   0.5f,   0.5f),
77
         new Static4D(  0.5f,   0.5f,  -0.5f,   0.5f),
78
         new Static4D(  0.5f,   0.5f,  -0.5f,  -0.5f),
79
         new Static4D(  0.5f,  -0.5f,   0.5f,  -0.5f),
80
         new Static4D( -0.5f,  -0.5f,  -0.5f,   0.5f),
81
         new Static4D( -0.5f,   0.5f,  -0.5f,  -0.5f),
82
         new Static4D( -0.5f,   0.5f,   0.5f,  -0.5f),
83
         new Static4D( -0.5f,   0.5f,   0.5f,   0.5f)
84
         };
85

  
86
  private static final Static4D[] INIT_QUATS = new Static4D[]
87
        {
88
        new Static4D(  0.0f,   0.0f,   0.0f,   1.0f),  // NULL
89
        new Static4D( SQ2/2,   0.0f,   0.0f, -SQ2/2),  // X
90
        new Static4D(  0.0f,  SQ2/2,   0.0f, -SQ2/2),  // Y
91
        new Static4D(  0.0f,   0.0f,  SQ2/2, -SQ2/2),  // Z
92
        new Static4D( -0.5f,  +0.5f,  -0.5f,  +0.5f),  // ZX
93
        new Static4D( +0.5f,  +0.5f,  +0.5f,  -0.5f),  // YX
94
        };
95

  
96 54
  private static final int[][] mDimensions = new int[][]
97 55
        {
98 56
         {1,1,1},  // has to be X>=Z>=Y so that all
......
102 60
         {2,2,2}
103 61
        };
104 62

  
105
  private static final int[][] mStickerDimensions = new int[][]
106
        {
107
         {1,1},  // dimensions of the faces of
108
         {2,1},  // the cuboids defined above
109
         {3,1},
110
         {2,2}
111
        };
112

  
113
  private static final int[][] mFaceMap = new int[][] // cubitface=2 when rotated by
114
    {                                                 // quatIndex=1 gets moved to
115
        {0,0,5,2,4,2},                                // position mFaceMap[2][1]
116
        {1,1,4,3,5,3},
117
        {2,4,2,1,1,4},
118
        {3,5,3,0,0,5},
119
        {4,3,0,4,3,0},
120
        {5,2,1,5,2,1}
121
    };
122

  
123
  private static final int[][] mAxisMap = new int[][] // axis=1 when rotated by
124
    {                                                 // quatIndex=2 gets moved to
125
        {0,0,2,1,2,1},                                // axis mAxisMap[1][2]
126
        {1,2,1,0,0,2},
127
        {2,1,0,2,1,0}
128
    };
129

  
130
  private static final int NUM_STICKERS = mStickerDimensions.length;
131

  
132
  private static final ObjectSticker[] mStickers;
133

  
134
  static
135
    {
136
    mStickers = new ObjectSticker[NUM_STICKERS];
137

  
138
    for(int s=0; s<NUM_STICKERS; s++)
139
      {
140
      float X = mStickerDimensions[s][0];
141
      float Y = mStickerDimensions[s][1];
142
      float MAX = Math.max(X,Y);
143
      X /= (2*MAX);
144
      Y /= (2*MAX);
145

  
146
      float R = 0.10f / MAX;
147
      float S = 0.08f / MAX;
148
      float[] coords = { -X,-Y, +X,-Y, +X,+Y, -X,+Y};
149
      float[] radii = new float[] {R,R,R,R};
150
      mStickers[s] = new ObjectSticker(coords,null,radii,S);
151
      }
152
    }
63
  private static final int NUM_STICKERS = 4;
153 64

  
65
  private int[] mBasicAngle;
154 66
  private int mCurrState;
155 67
  private int mIndexExcluded;
156 68
  private int[][] mScrambleTable;
157 69
  private int[] mNumOccurences;
70
  private Static4D[] mQuats;
71
  private ObjectSticker[] mStickers;
72
  private Static4D[] mInitQuats;
73
  private int[][] mAxisMap;
74
  private int[][] mFaceMap;
158 75
  ScrambleState[] mStates;
159 76
  float[][] POSITIONS;
160 77
  int[] QUAT_INDICES;
......
172 89
  abstract float[][] getPositions();
173 90
  abstract int[] getQuatIndices();
174 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(  1.0f,   0.0f,   0.0f,   0.0f),
100
         new Static4D(  0.0f,   1.0f,   0.0f,   0.0f),
101
         new Static4D(  0.0f,   0.0f,   1.0f,   0.0f),
102

  
103
         new Static4D( SQ2/2,  SQ2/2,  0.0f ,   0.0f),
104
         new Static4D( SQ2/2, -SQ2/2,  0.0f ,   0.0f),
105
         new Static4D( SQ2/2,   0.0f,  SQ2/2,   0.0f),
106
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,   0.0f),
107
         new Static4D( SQ2/2,   0.0f,   0.0f,  SQ2/2),
108
         new Static4D( SQ2/2,   0.0f,   0.0f, -SQ2/2),
109
         new Static4D(  0.0f,  SQ2/2,  SQ2/2,   0.0f),
110
         new Static4D(  0.0f,  SQ2/2, -SQ2/2,   0.0f),
111
         new Static4D(  0.0f,  SQ2/2,   0.0f,  SQ2/2),
112
         new Static4D(  0.0f,  SQ2/2,   0.0f, -SQ2/2),
113
         new Static4D(  0.0f,   0.0f,  SQ2/2,  SQ2/2),
114
         new Static4D(  0.0f,   0.0f,  SQ2/2, -SQ2/2),
115

  
116
         new Static4D(  0.5f,   0.5f,   0.5f,   0.5f),
117
         new Static4D(  0.5f,   0.5f,  -0.5f,   0.5f),
118
         new Static4D(  0.5f,   0.5f,  -0.5f,  -0.5f),
119
         new Static4D(  0.5f,  -0.5f,   0.5f,  -0.5f),
120
         new Static4D( -0.5f,  -0.5f,  -0.5f,   0.5f),
121
         new Static4D( -0.5f,   0.5f,  -0.5f,  -0.5f),
122
         new Static4D( -0.5f,   0.5f,   0.5f,  -0.5f),
123
         new Static4D( -0.5f,   0.5f,   0.5f,   0.5f)
124
         };
125
    }
126

  
175 127
///////////////////////////////////////////////////////////////////////////////////////////////////
176 128

  
177 129
  int[] getSolvedQuats(int cubit, int numLayers)
178 130
    {
131
    if( mQuats==null ) initializeQuats();
179 132
    int status = retCubitSolvedStatus(cubit,numLayers);
180
    return status<0 ? null : buildSolvedQuats(MovementCube.FACE_AXIS[status],QUATS);
133
    return status<0 ? null : buildSolvedQuats(MovementCube.FACE_AXIS[status],mQuats);
181 134
    }
182 135

  
183 136
///////////////////////////////////////////////////////////////////////////////////////////////////
......
272 225

  
273 226
  Static4D getQuat(int cubit, int numLayers)
274 227
    {
275
    return INIT_QUATS[getQuatIndex(cubit)];
228
    if( mInitQuats ==null )
229
      {
230
      mInitQuats = new Static4D[]
231
        {
232
        new Static4D(  0.0f,   0.0f,   0.0f,   1.0f),  // NULL
233
        new Static4D( SQ2/2,   0.0f,   0.0f, -SQ2/2),  // X
234
        new Static4D(  0.0f,  SQ2/2,   0.0f, -SQ2/2),  // Y
235
        new Static4D(  0.0f,   0.0f,  SQ2/2, -SQ2/2),  // Z
236
        new Static4D( -0.5f,  +0.5f,  -0.5f,  +0.5f),  // ZX
237
        new Static4D( +0.5f,  +0.5f,  +0.5f,  -0.5f),  // YX
238
        };
239
      }
240

  
241
    return mInitQuats[getQuatIndex(cubit)];
276 242
    }
277 243

  
278 244
///////////////////////////////////////////////////////////////////////////////////////////////////
......
308 274

  
309 275
  ObjectSticker retSticker(int face)
310 276
    {
277
    if( mStickers==null )
278
      {
279
      mStickers = new ObjectSticker[NUM_STICKERS];
280

  
281
      int[][] stickerDimensions = new int[][]
282
        {
283
         {1,1},  // dimensions of the faces of
284
         {2,1},  // the cuboids defined in mDimensions
285
         {3,1},
286
         {2,2}
287
        };
288

  
289
      for(int s=0; s<NUM_STICKERS; s++)
290
        {
291
        float X = stickerDimensions[s][0];
292
        float Y = stickerDimensions[s][1];
293
        float MAX = Math.max(X,Y);
294
        X /= (2*MAX);
295
        Y /= (2*MAX);
296

  
297
        float R = 0.10f / MAX;
298
        float S = 0.08f / MAX;
299
        float[] coords = { -X,-Y, +X,-Y, +X,+Y, -X,+Y};
300
        float[] radii = new float[] {R,R,R,R};
301
        mStickers[s] = new ObjectSticker(coords,null,radii,S);
302
        }
303
      }
304

  
311 305
    return mStickers[face/NUM_FACES];
312 306
    }
313 307

  
......
330 324

  
331 325
  Static4D[] getQuats()
332 326
    {
333
    return QUATS;
327
    if( mQuats==null ) initializeQuats();
328
    return mQuats;
334 329
    }
335 330

  
336 331
///////////////////////////////////////////////////////////////////////////////////////////////////
......
424 419

  
425 420
  int getFaceColor(int cubit, int cubitface, int numLayers)
426 421
    {
422
    if( mFaceMap==null )
423
      {
424
      // cubitface=2 when rotated by quatIndex=1 gets moved to position mFaceMap[2][1]
425
      mFaceMap = new int[][]
426
          {
427
              {0,0,5,2,4,2},
428
              {1,1,4,3,5,3},
429
              {2,4,2,1,1,4},
430
              {3,5,3,0,0,5},
431
              {4,3,0,4,3,0},
432
              {5,2,1,5,2,1}
433
          };
434
      }
435

  
436
    if( mAxisMap==null )
437
      {
438
      // axis=1 when rotated by quatIndex=2 gets moved to axis mAxisMap[1][2]
439
      mAxisMap = new int[][] { {0,0,2,1,2,1}, {1,2,1,0,0,2}, {2,1,0,2,1,0} };
440
      }
441

  
427 442
    int variant      = getCubitVariant(cubit,numLayers);
428 443
    int[] dim        = mDimensions[variant];
429 444
    float[] pos      = getCubitPosition(cubit);
......
441 456

  
442 457
    boolean reaches  = multiplier*position + dim[dimIndex]*0.5f > (numLayers-1)*0.5f;
443 458

  
444
    return reaches ? stickerIndex*NUM_FACES + face : NUM_STICKERS*NUM_FACES;
459
    return reaches ? stickerIndex*NUM_FACES + face : NUM_TEXTURES;
445 460
    }
446 461

  
447 462
///////////////////////////////////////////////////////////////////////////////////////////////////
......
511 526

  
512 527
  public int[] getBasicAngle()
513 528
    {
514
    return BASIC_ANGLE;
529
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 4,4,4 };
530
    return mBasicAngle;
515 531
    }
516 532
}

Also available in: Unified diff