Project

General

Profile

« Previous | Next » 

Revision 48fec01e

Added by Leszek Koltunski about 3 years ago

Remove statics from the Pyraminx class.

View differences:

src/main/java/org/distorted/objects/TwistyJing.java
190 190

  
191 191
  float getScreenRatio()
192 192
    {
193
    return 2*TwistyPyraminx.SCREEN_RATIO;
193
    return 1.76f;
194 194
    }
195 195

  
196 196
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistyPyraminx.java
37 37

  
38 38
public class TwistyPyraminx extends TwistyObject
39 39
{
40
  static final float SCREEN_RATIO = 0.88f;
41

  
42 40
  static final Static3D[] ROT_AXIS = new Static3D[]
43 41
         {
44 42
           new Static3D(     0,-SQ3/3,-SQ6/3),
......
47 45
           new Static3D(-SQ6/3,+SQ3/3,     0),
48 46
         };
49 47

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

  
52 48
  private static final int[] FACE_COLORS = new int[]
53 49
         {
54 50
           COLOR_GREEN , COLOR_YELLOW,
55 51
           COLOR_BLUE  , COLOR_RED
56 52
         };
57 53

  
58
  // computed with res/raw/compute_quats.c
59
  private static final Static4D[] QUATS = new Static4D[]
60
         {
61
           new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
62
           new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
63
           new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
64
           new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
65
           new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
66
           new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
67
           new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
68
           new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
69
           new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
70
           new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
71
           new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
72
           new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
73
         };
74

  
75
  private static final double[][] VERTICES_TETRA = new double[][]
76
          {
77
             {-0.5, SQ2/4, 0.0},
78
             { 0.5, SQ2/4, 0.0},
79
             { 0.0,-SQ2/4, 0.5},
80
             { 0.0,-SQ2/4,-0.5}
81
          };
82

  
83
  private static final int[][] VERT_INDEXES_TETRA = new int[][]
84
          {
85
             {2,1,0},   // counterclockwise!
86
             {3,0,1},
87
             {3,2,0},
88
             {2,3,1}
89
          };
90

  
91
  private static final double[][] VERTICES_OCTA = new double[][]
92
          {
93
             { 0.5,   0.0, 0.5},
94
             { 0.5,   0.0,-0.5},
95
             {-0.5,   0.0,-0.5},
96
             {-0.5,   0.0, 0.5},
97
             { 0.0, SQ2/2, 0.0},
98
             { 0.0,-SQ2/2, 0.0}
99
          };
100

  
101
  private static final int[][] VERT_INDEXES_OCTA = new int[][]
102
          {
103
             {3,0,4},   // counterclockwise!
104
             {0,1,4},
105
             {1,2,4},
106
             {2,3,4},
107
             {5,0,3},
108
             {5,1,0},
109
             {5,2,1},
110
             {5,3,2}
111
          };
112

  
113
  private static final float[][] STICKERS = new float[][]
114
          {
115
             { -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f }
116
          };
117

  
118
  private static final ObjectSticker[] mStickers;
119

  
120
  static
121
    {
122
    mStickers = new ObjectSticker[STICKERS.length];
123
    final float stroke = 0.08f;
124
    final float radius = 0.06f;
125
    final float[] radii= {radius,radius,radius};
126
    mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
127
    }
128

  
129 54
  private int mCurrState;
130 55
  private int mIndexExcluded;
131 56
  private ScrambleState[] mStates;
132 57
  private int[][] mScrambleTable;
133 58
  private int[] mNumOccurences;
59
  private int[] mBasicAngle;
60
  private Static4D[] mQuats;
61
  private ObjectSticker[] mStickers;
134 62

  
135 63
///////////////////////////////////////////////////////////////////////////////////////////////////
136 64

  
......
142 70
    initializeScrambleStates(size);
143 71
    }
144 72

  
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

  
75
  private void initializeQuats()
76
    {
77
    mQuats = new Static4D[]
78
         {
79
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
80
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
81
         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
82
         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
83
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
84
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
85
         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
86
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
87
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
88
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
89
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
90
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
91
         };
92
    }
93

  
145 94
///////////////////////////////////////////////////////////////////////////////////////////////////
146 95

  
147 96
  private int[][] generateState(int start, int end)
......
182 131

  
183 132
  int[] getSolvedQuats(int cubit, int numLayers)
184 133
    {
134
    if( mQuats==null ) initializeQuats();
185 135
    int status = retCubitSolvedStatus(cubit,numLayers);
186
    return status<0 ? null : buildSolvedQuats(MovementPyraminx.FACE_AXIS[status],QUATS);
136
    return status<0 ? null : buildSolvedQuats(MovementPyraminx.FACE_AXIS[status],mQuats);
187 137
    }
188 138

  
189 139
///////////////////////////////////////////////////////////////////////////////////////////////////
......
242 192

  
243 193
  Static4D[] getQuats()
244 194
    {
245
    return QUATS;
195
    if( mQuats==null ) initializeQuats();
196
    return mQuats;
246 197
    }
247 198

  
248 199
///////////////////////////////////////////////////////////////////////////////////////////////////
......
263 214

  
264 215
  int getNumStickerTypes(int numLayers)
265 216
    {
266
    return STICKERS.length;
217
    return 1;
267 218
    }
268 219

  
269 220
///////////////////////////////////////////////////////////////////////////////////////////////////
......
295 246

  
296 247
  float getScreenRatio()
297 248
    {
298
    return SCREEN_RATIO;
249
    return 0.88f;
299 250
    }
300 251

  
301 252
///////////////////////////////////////////////////////////////////////////////////////////////////
......
348 299

  
349 300
    if( variant==0 )
350 301
      {
302
      double[][] vertices = new double[][] { { 0.5,0.0,0.5},{ 0.5,0.0,-0.5},{-0.5,0.0,-0.5},{-0.5,0.0,0.5},{ 0.0,SQ2/2,0.0},{ 0.0,-SQ2/2,0.0} };
303
      int[][] vert_indices = new int[][] { {3,0,4},{0,1,4},{1,2,4},{2,3,4},{5,0,3},{5,1,0},{5,2,1},{5,3,2} };
351 304
      int N = numLayers==3? 6 : 5;
352 305
      int E = numLayers==3? 2 : 1;
353 306
      float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
......
356 309
      int[] cornerIndices = new int[] { 0,0,0,0,0,0 };
357 310
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
358 311
      int[] centerIndices = new int[] { 0,0,0,0,0,0 };
359
      return new ObjectShape(VERTICES_OCTA,VERT_INDEXES_OCTA,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
312
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
360 313
      }
361 314
    else
362 315
      {
316
      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} };
317
      int[][] vert_indices = new int[][] { {2,1,0},{3,0,1},{3,2,0},{2,3,1} };
363 318
      int N = numLayers==3? 6 : 5;
364 319
      int E = numLayers==3? 2 : 1;
365 320
      float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
......
368 323
      int[] cornerIndices = new int[] { 0,0,0,0 };
369 324
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
370 325
      int[] centerIndices = new int[] { 0,0,0,0 };
371
      return new ObjectShape(VERTICES_TETRA,VERT_INDEXES_TETRA,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
326
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
372 327
      }
373 328
    }
374 329

  
......
376 331

  
377 332
  Static4D getQuat(int cubit, int numLayers)
378 333
    {
379
    return QUATS[0];
334
    if( mQuats==null ) initializeQuats();
335
    return mQuats[0];
380 336
    }
381 337

  
382 338
///////////////////////////////////////////////////////////////////////////////////////////////////
......
404 360

  
405 361
  ObjectSticker retSticker(int face)
406 362
    {
363
    if( mStickers==null )
364
      {
365
      float[][] STICKERS = new float[][] { { -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f } };
366
      final float stroke = 0.08f;
367
      final float radius = 0.06f;
368
      final float[] radii= {radius,radius,radius};
369
      mStickers = new ObjectSticker[STICKERS.length];
370
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
371
      }
372

  
407 373
    return mStickers[face/NUM_FACES];
408 374
    }
409 375

  
......
475 441

  
476 442
  public int[] getBasicAngle()
477 443
    {
478
    return BASIC_ANGLE;
444
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
445
    return mBasicAngle;
479 446
    }
480 447

  
481 448
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff