Project

General

Profile

« Previous | Next » 

Revision e01fa67a

Added by Leszek Koltunski about 3 years ago

Remove statics from the Ivy class.

View differences:

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

  
38 38
public class TwistyIvy extends TwistyObject
39 39
{
40
  public static final float IVY_D = 0.003f;
41
  private static final int  IVY_N = 8;
42

  
43
  private static final int FACES_PER_CUBIT =6;
44

  
45 40
  // the four rotation axis of a RubikIvy. Must be normalized.
46 41
  static final Static3D[] ROT_AXIS = new Static3D[]
47 42
         {
......
51 46
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
52 47
         };
53 48

  
54
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
55

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

  
63
  // All legal rotation quats of a RubikIvy
64
  private static final Static4D[] QUATS = new Static4D[]
65
         {
66
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
67
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
68
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
69
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
70

  
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
           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
         };
80

  
81
  private static final int[][] mFaceMap =
82
         {
83
           {  4, 0, 2, 12,12,12 },
84
           {  5, 1, 2, 12,12,12 },
85
           {  4, 1, 3, 12,12,12 },
86
           {  5, 0, 3, 12,12,12 },
87

  
88
           {  6, 12,12,12,12,12 },
89
           {  7, 12,12,12,12,12 },
90
           {  8, 12,12,12,12,12 },
91
           {  9, 12,12,12,12,12 },
92
           { 10, 12,12,12,12,12 },
93
           { 11, 12,12,12,12,12 },
94
         };
95

  
96
  private static final ObjectSticker[] mStickers;
97

  
98
  private static final float[][] STICKERS = new float[][]
99
          {
100
             { 0.29258922f, -0.5f, 0.29258922f, 0.29258922f, -0.5f, 0.29258922f },
101
             { -0.5f, 0.5f, 0.5f, -0.5f }
102
          };
103
  private static final int NUM_STICKERS = STICKERS.length;
104

  
105
  static
106
    {
107
    mStickers = new ObjectSticker[NUM_STICKERS];
108

  
109
    float D = (float)(Math.PI/4);
110
    final float[][] angles = { { 0,0,D },{ D,D } };
111
    final float[][] radii  = { { 0,0.04f,0 },{ 0.06f,0.06f } };
112
    final float[] strokes = { 0.03f, 0.08f };
113

  
114
    for(int s=0; s<NUM_STICKERS; s++)
115
      {
116
      mStickers[s] = new ObjectSticker(STICKERS[s], angles[s],radii[s],strokes[s]);
117
      }
118
    }
56
  private static final int NUM_STICKERS = 2;
57
  public static final float IVY_D = 0.003f;
58
  private static final int  IVY_N = 8;
59
  private static final int FACES_PER_CUBIT =6;
119 60

  
120 61
  private int mCurrState;
121 62
  private int mIndexExcluded;
122 63
  private final ScrambleState[] mStates;
123 64
  private int[][] mScrambleTable;
124 65
  private int[] mNumOccurences;
66
  private int[] mBasicAngle;
67
  private Static4D[] mQuats;
68
  private int[][] mFaceMap;
69
  private ObjectSticker[] mStickers;
125 70

  
126 71
///////////////////////////////////////////////////////////////////////////////////////////////////
127 72

  
......
138 83
      };
139 84
    }
140 85

  
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

  
88
  private void initializeQuats()
89
    {
90
    mQuats = new Static4D[]
91
         {
92
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
93
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
94
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
95
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
96

  
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
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
101
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
102
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
103
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
104
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
105
         };
106
    }
107

  
141 108
///////////////////////////////////////////////////////////////////////////////////////////////////
142 109

  
143 110
  int[] getSolvedQuats(int cubit, int numLayers)
144 111
    {
112
    if( mQuats==null ) initializeQuats();
145 113
    int status = retCubitSolvedStatus(cubit,numLayers);
146
    return status<0 ? null : buildSolvedQuats(MovementIvy.FACE_AXIS[status],QUATS);
114
    return status<0 ? null : buildSolvedQuats(MovementIvy.FACE_AXIS[status],mQuats);
147 115
    }
148 116

  
149 117
///////////////////////////////////////////////////////////////////////////////////////////////////
......
157 125

  
158 126
  Static4D[] getQuats()
159 127
    {
160
    return QUATS;
128
    if( mQuats==null ) initializeQuats();
129
    return mQuats;
161 130
    }
162 131

  
163 132
///////////////////////////////////////////////////////////////////////////////////////////////////
......
387 356

  
388 357
  Static4D getQuat(int cubit, int numLayers)
389 358
    {
359
    if( mQuats==null ) initializeQuats();
360

  
390 361
    switch(cubit)
391 362
      {
392
      case  0: return QUATS[0];
393
      case  1: return QUATS[2];
394
      case  2: return QUATS[3];
395
      case  3: return QUATS[1];
396

  
397
      case  4: return QUATS[8];
398
      case  5: return QUATS[11];
399
      case  6: return QUATS[10];
400
      case  7: return QUATS[9];
401
      case  8: return QUATS[0];
402
      case  9: return QUATS[2];
363
      case  0: return mQuats[0];
364
      case  1: return mQuats[2];
365
      case  2: return mQuats[3];
366
      case  3: return mQuats[1];
367

  
368
      case  4: return mQuats[8];
369
      case  5: return mQuats[11];
370
      case  6: return mQuats[10];
371
      case  7: return mQuats[9];
372
      case  8: return mQuats[0];
373
      case  9: return mQuats[2];
403 374
      }
404 375

  
405
    return QUATS[0];
376
    return mQuats[0];
406 377
    }
407 378

  
408 379
///////////////////////////////////////////////////////////////////////////////////////////////////
......
423 394

  
424 395
  int getFaceColor(int cubit, int cubitface, int numLayers)
425 396
    {
397
    if( mFaceMap==null )
398
      {
399
      mFaceMap = new int[][]
400
         {
401
           {  4, 0, 2, 12,12,12 },
402
           {  5, 1, 2, 12,12,12 },
403
           {  4, 1, 3, 12,12,12 },
404
           {  5, 0, 3, 12,12,12 },
405

  
406
           {  6, 12,12,12,12,12 },
407
           {  7, 12,12,12,12,12 },
408
           {  8, 12,12,12,12,12 },
409
           {  9, 12,12,12,12,12 },
410
           { 10, 12,12,12,12,12 },
411
           { 11, 12,12,12,12,12 },
412
         };
413
      }
414

  
426 415
    return mFaceMap[cubit][cubitface];
427 416
    }
428 417

  
......
437 426

  
438 427
  ObjectSticker retSticker(int face)
439 428
    {
429
    if( mStickers==null )
430
      {
431
      float[][] STICKERS = new float[][] { { 0.29258922f, -0.5f, 0.29258922f, 0.29258922f, -0.5f, 0.29258922f }, { -0.5f, 0.5f, 0.5f, -0.5f } };
432
      mStickers = new ObjectSticker[NUM_STICKERS];
433
      float D = (float)(Math.PI/4);
434
      final float[][] angles = { { 0,0,D },{ D,D } };
435
      final float[][] radii  = { { 0,0.04f,0 },{ 0.06f,0.06f } };
436
      final float[] strokes = { 0.03f, 0.08f };
437
      for(int s=0; s<NUM_STICKERS; s++) mStickers[s] = new ObjectSticker(STICKERS[s], angles[s],radii[s],strokes[s]);
438
      }
439

  
440 440
    return mStickers[face/NUM_FACES];
441 441
    }
442 442

  
......
507 507

  
508 508
  public int[] getBasicAngle()
509 509
    {
510
    return BASIC_ANGLE;
510
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
511
    return mBasicAngle;
511 512
    }
512 513

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

Also available in: Unified diff