Project

General

Profile

« Previous | Next » 

Revision d5380277

Added by Leszek Koltunski over 2 years ago

Remove statics from the Square classes.

View differences:

src/main/java/org/distorted/objects/TwistySquare.java
51 51
      new Static3D(0,-1,0),
52 52
    };
53 53

  
54
  static final int[] BASIC_ANGLE = new int[] { 12,2,12 };
55

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

  
63
  static final Static4D[] QUATS = new Static4D[]
61
  int mLastRot;
62
  int[] mBasicAngle;
63
  Static4D[] mQuats;
64
  int[][] mQuatMult;
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

  
68
  TwistySquare(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
69
               DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
64 70
    {
71
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
72
    }
73

  
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

  
76
  void initializeQuats()
77
    {
78
    mQuats = new Static4D[]
79
      {
65 80
      new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
66 81
      new Static4D(  0.0f, SIN15,  0.0f, COS15 ),
67 82
      new Static4D(  0.0f,  0.5f,  0.0f, SQ3/2 ),
......
87 102
      new Static4D(-SQ2/2,  0.0f, SQ2/2,  0.0f ),
88 103
      new Static4D(-SQ3/2,  0.0f,  0.5f,  0.0f ),
89 104
      new Static4D(-COS15,  0.0f, SIN15,  0.0f )
90
    };
91

  
92
  static final double[][] VERTICES_MIDDLE = new double[][]
93
    {
94
      { -1.5-X, 0.5, 1.5 },
95
      {    0.0, 0.5, 1.5 },
96
      {    0.0, 0.5,-1.5 },
97
      { -1.5+X, 0.5,-1.5 },
98
      { -1.5-X,-0.5, 1.5 },
99
      {    0.0,-0.5, 1.5 },
100
      {    0.0,-0.5,-1.5 },
101
      { -1.5+X,-0.5,-1.5 }
102
    };
103

  
104
  static final int[][] VERT_INDEXES_MIDDLE = new int[][]
105
    {
106
      {0,1,2,3},   // counterclockwise!
107
      {4,5,6,7},
108
      {4,5,1,0},
109
      {5,6,2,1},
110
      {6,7,3,2},
111
      {7,4,0,3}
112
    };
113

  
114
  static final double[][] VERTICES_EDGE = new double[][]
115
    {
116
      { -X, 0.5, 0.0 },
117
      { +X, 0.5, 0.0 },
118
      {0.0, 0.5,-1.5 },
119
      { -X,-0.5, 0.0 },
120
      { +X,-0.5, 0.0 },
121
      {0.0,-0.5,-1.5 },
122
    };
123

  
124
  static final int[][] VERT_INDEXES_EDGE = new int[][]
125
    {
126
      {0,1,2},   // counterclockwise!
127
      {3,4,5},
128
      {3,4,1,0},
129
      {4,5,2,1},
130
      {5,3,0,2}
131
    };
105
      };
106
    }
132 107

  
133
  // QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
134
  static final int[][] QUAT_MULT = new int[][]
135
    {
136
      {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
137
      {  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
138
      {  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
139
      {  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
140
      {  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
141
      {  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
142
      {  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
143
      {  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
144
      {  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
145
      {  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
146
      { 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
147
      { 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
148
      { 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,},
149
      { 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,},
150
      { 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,},
151
      { 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,},
152
      { 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,},
153
      { 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,},
154
      { 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,},
155
      { 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,},
156
      { 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,},
157
      { 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,},
158
      { 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11,},
159
      { 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0,}
160
    };
161 108

  
162
  int mLastRot;
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
// QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
111

  
112
  void initializeQuatMult()
113
    {
114
    mQuatMult = new int[][]
115
      {
116
        {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
117
        {  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
118
        {  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
119
        {  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
120
        {  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
121
        {  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
122
        {  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
123
        {  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
124
        {  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
125
        {  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
126
        { 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
127
        { 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
128
        { 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,},
129
        { 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,},
130
        { 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,},
131
        { 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,},
132
        { 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,},
133
        { 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,},
134
        { 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,},
135
        { 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,},
136
        { 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,},
137
        { 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,},
138
        { 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11,},
139
        { 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0,}
140
      };
141
    }
163 142

  
164 143
///////////////////////////////////////////////////////////////////////////////////////////////////
165 144

  
166
  TwistySquare(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
167
               DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
145
  void initializeBasicAngle()
168 146
    {
169
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
147
    mBasicAngle = new int[] {12,2,12};
170 148
    }
171 149

  
172 150
///////////////////////////////////////////////////////////////////////////////////////////////////
173 151

  
174 152
  Static4D[] getQuats()
175 153
    {
176
    return QUATS;
154
    if( mQuats==null ) initializeQuats();
155
    return mQuats;
177 156
    }
178 157

  
179 158
///////////////////////////////////////////////////////////////////////////////////////////////////
......
237 216

  
238 217
  public int[] getBasicAngle()
239 218
    {
240
    return BASIC_ANGLE;
219
    if( mBasicAngle ==null ) initializeBasicAngle();
220
    return mBasicAngle;
241 221
    }
242 222
}

Also available in: Unified diff