Project

General

Profile

« Previous | Next » 

Revision 2a495bdb

Added by Leszek Koltunski about 2 years ago

Simplifications for the Factory of Bandaged Puzzles.

View differences:

src/main/java/org/distorted/objectlib/bandaged/BandagedElement.java
13 13

  
14 14
public class BandagedElement
15 15
  {
16
  private final float[][] mCuts;
17
  private final int[] mNumCuts;
18
  private final float[][] mRotAxis;
19
  private final int[] mRotationRow;
20 16
  private final float[] mPos;
21 17
  private final int mVariant;
22 18

  
23 19
///////////////////////////////////////////////////////////////////////////////////////////////////
24 20

  
25
  BandagedElement(float[] pos, int index, float[][] rotAxis, float[][] cuts, int variant)
21
  BandagedElement(float[] pos, int index, int variant)
26 22
    {
27 23
    mPos = new float[] { pos[index], pos[index+1], pos[index+2] };
28

  
29
    int numAxis = rotAxis.length;
30
    mRotAxis = rotAxis;
31
    mRotationRow = new int[numAxis];
32
    mNumCuts = new int[numAxis];
33
    mCuts = cuts;
34 24
    mVariant = variant;
35

  
36
    for(int i=0; i<numAxis; i++)
37
      {
38
      mNumCuts[i] = (mCuts==null || mCuts[i]==null ? 0 : mCuts[i].length);
39
      mRotationRow[i] = computeRow(i);
40
      }
41
    }
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

  
45
  private int computeRow(int rotAx)
46
    {
47
    float[] ax = mRotAxis[rotAx];
48
    float casted = mPos[0]*ax[0] + mPos[1]*ax[1] + mPos[2]*ax[2];
49
    int num = mNumCuts[rotAx];
50
    float[] cuts = mCuts[rotAx];
51

  
52
    for(int i=0; i<num; i++)
53
      if( casted<cuts[i] ) return i;
54

  
55
    return num;
56
    }
57

  
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

  
60
  int[] getRotRow()
61
    {
62
    return mRotationRow;
63 25
    }
64 26

  
65 27
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/bandaged/FactoryBandaged.java
114 114
  private ArrayList<float[]> mTmpArray;
115 115
  private float[] mDist3D;
116 116
  private int[][] mFaceBelongsBitmap;
117
  private float[][] mCuts;
118
  private float[][] mRotAxis;
119 117
  private float[][] mDiaAxis;
120 118
  private float[][] mMinMax;
121 119

  
......
143 141
///////////////////////////////////////////////////////////////////////////////////////////////////
144 142

  
145 143
  abstract Static3D[] getNormals();
146
  abstract float[][] getRotAxis();
147 144
  abstract float[][] getDiameterAxis();
148 145
  abstract float[] getDist3D();
149 146
  abstract float[][] getBands(boolean iconMode);
150
  abstract float[][] getCuts(int[] numLayers);
151 147
  abstract int getElementVariant(float x, float y, float z);
152 148
  abstract int diameterMap(float diameter);
153 149
  abstract float[][] getVertices(int variant);
154 150
  abstract int[][] getIndices(int variant);
151
  abstract int getNumAxis();
155 152

  
156 153
///////////////////////////////////////////////////////////////////////////////////////////////////
157 154

  
......
811 808
    mNormals   = getNormals();
812 809
    mNumFaces  = mNormals.length;
813 810
    mDist3D    = getDist3D();
814
    mCuts      = getCuts(numLayers);
815
    mRotAxis   = getRotAxis();
816
    mNumAxis   = mRotAxis.length;
811
    mNumAxis   = getNumAxis();
817 812
    mDiaAxis   = getDiameterAxis();
818 813
    mMinMax    = new float[mDiaAxis.length][2];
819 814
    }
......
829 824
    for(int i=0; i<mNumElements; i++)
830 825
      {
831 826
      int elementVariant = getElementVariant(pos[3*i],pos[3*i+1],pos[3*i+2]);
832
      mElements[i] = new BandagedElement(pos, 3*i, mRotAxis, mCuts,elementVariant);
827
      mElements[i] = new BandagedElement(pos, 3*i, elementVariant);
833 828
      }
834 829

  
835 830
    fillUpVertexArray();
src/main/java/org/distorted/objectlib/bandaged/FactoryBandagedCuboid.java
17 17
public class FactoryBandagedCuboid extends FactoryBandaged
18 18
  {
19 19
  private static FactoryBandagedCuboid mThis;
20
  private float[][] mVertices;
21
  private int[][] mIndices;
20 22

  
21 23
///////////////////////////////////////////////////////////////////////////////////////////////////
22 24

  
......
37 39

  
38 40
  public float[][] getVertices(int variant)
39 41
    {
40
    return new float[][]
41
      {
42
    if( mVertices==null )
43
      mVertices = new float[][]
44
       {
42 45
        { 0.5f, 0.5f, 0.5f },
43 46
        { 0.5f, 0.5f,-0.5f },
44 47
        { 0.5f,-0.5f, 0.5f },
......
47 50
        {-0.5f, 0.5f,-0.5f },
48 51
        {-0.5f,-0.5f, 0.5f },
49 52
        {-0.5f,-0.5f,-0.5f },
50
      };
53
       };
54

  
55
    return mVertices;
51 56
    }
52 57

  
53 58
///////////////////////////////////////////////////////////////////////////////////////////////////
54 59

  
55 60
  public int[][] getIndices(int variant)
56 61
    {
57
    return new int[][]
58
      {
62
    if( mIndices==null )
63
      mIndices = new int[][]
64
       {
59 65
        {2,3,1,0},
60 66
        {7,6,4,5},
61 67
        {4,0,1,5},
62 68
        {7,3,2,6},
63 69
        {6,2,0,4},
64 70
        {3,7,5,1}
65
      };
71
       };
72

  
73
    return mIndices;
66 74
    }
67 75

  
68 76
///////////////////////////////////////////////////////////////////////////////////////////////////
......
72 80
     return 0;
73 81
     }
74 82

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

  
77
  public float[][] getCuts(int[] numLayers)
78
    {
79
    int numAxis = numLayers.length;
80
    float[][] cuts = new float[numAxis][];
81

  
82
    for(int axis=0; axis<numAxis; axis++)
83
      {
84
      int len = numLayers[axis];
85
      float start = 1-len*0.5f;
86

  
87
      if( len>=2 )
88
        {
89
        cuts[axis] = new float[len-1];
90
        for(int i=0; i<len-1; i++) cuts[axis][i] = start+i;
91
        }
92
      }
93

  
94
    return cuts;
95
    }
96

  
97 83
///////////////////////////////////////////////////////////////////////////////////////////////////
98 84

  
99 85
  public Static3D[] getNormals()
......
103 89

  
104 90
///////////////////////////////////////////////////////////////////////////////////////////////////
105 91

  
106
  public float[][] getRotAxis()
92
  public int getNumAxis()
107 93
    {
108
    return new float[][] { {-1,0,0},{0,-1,0},{0,0,-1} };
94
    return 3;
109 95
    }
110 96

  
111 97
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/bandaged/FactoryBandagedMegaminx.java
9 9

  
10 10
package org.distorted.objectlib.bandaged;
11 11

  
12
import static org.distorted.objectlib.bandaged.BandagedObjectMegaminx.COS18;
12 13
import static org.distorted.objectlib.bandaged.BandagedObjectMegaminx.MEGA_D;
13 14
import static org.distorted.objectlib.bandaged.BandagedObjectMegaminx.SIN18;
14 15
import static org.distorted.objectlib.main.TwistyObject.SQ5;
15
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.C2;
16
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.LEN;
16
import static org.distorted.objectlib.objects.TwistyDodecahedron.COS_HALFD;
17
import static org.distorted.objectlib.objects.TwistyDodecahedron.SIN_HALFD;
18
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.COS54;
17 19
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.SIN54;
18 20

  
19 21
import org.distorted.library.type.Static3D;
......
28 30

  
29 31
  private int[][] mEdgeMap;
30 32
  private float[][] mCorners;
33
  private float[][][] mVertices;
34
  private int[][][] mIndices;
31 35

  
32 36
///////////////////////////////////////////////////////////////////////////////////////////////////
33 37

  
......
38 42

  
39 43
///////////////////////////////////////////////////////////////////////////////////////////////////
40 44

  
41
  private float[][] genericGetCuts(int numLayers, float dist)
45
  public static FactoryBandagedMegaminx getInstance()
46
    {
47
    if( mThis==null ) mThis = new FactoryBandagedMegaminx();
48
    return mThis;
49
    }
50

  
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

  
53
  private float[][] retCornerKilominx(int numL)
54
    {
55
    float width = (1+0.5f*(numL-3)*SIN18)*numL/(numL-1);
56
    float X = width*COS18*SIN_HALFD;
57
    float Y = width*SIN18;
58
    float Z = width*COS18*COS_HALFD;
59
    float H = width*(SIN54/COS54);
60
    float H3 = H/COS_HALFD;
61
    float X3 = H*SIN_HALFD;
62
    float Z3 = H*COS_HALFD;
63
    float C = 1/(COS54*(float) Math.sqrt(2-2*SIN18));
64

  
65
    return new float[][]
66
      {
67
       {  0,      0,      0 },
68
       {  X,      Y,     -Z },
69
       {  0,  C*2*Y, -2*C*Z },
70
       { -X,      Y,     -Z },
71
       {  0, -width,      0 },
72
       { X3, -width,    -Z3 },
73
       {  0, -width,    -H3 },
74
       {-X3, -width,    -Z3 }
75
      };
76
    }
77

  
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

  
80
  private float[][] retEdgeKilominx(int numL, int variant)
42 81
    {
43
    float[][] cuts = new float[6][numLayers-1];
44
    float D = numLayers* TouchControlDodecahedron.DIST3D;
45
    float X = 2*D/(2+SIN18);  // height of the 'upper' part of a dodecahedron, i.e. put it on a table,
46
                              // its height is then 2D, it has one 'lower' part of height X, one
47
                              // 'middle' part of height Y and one upper part of height X again.
48
    int num = (numLayers-1)/2;
49
    float G = X*dist/num;     // height of one Layer
50

  
51
    for(int i=0; i<num; i++)
82
    int type = variant-1;
83
    float tmpVal= numL/(numL-1.0f);
84
    float height= tmpVal*COS18;
85
    float width = tmpVal + (type/2)*tmpVal*SIN18;
86
    boolean left = (type%2)==0;
87

  
88
    float X = height*SIN_HALFD;
89
    float Y = height*SIN18/COS18;
90
    float Z = height*COS_HALFD;
91

  
92
    float[][] vertices =
52 93
      {
53
      float cut = -D + (i+0.85f)*G;  // 0.85? not fully correct; attempt to make it
54
                                     // easier to rotate the outer layers
55
      int j = 2*num-1-i;
56
      cuts[0][i] =  cut;
57
      cuts[0][j] = -cut;
58
      cuts[1][i] =  cut;
59
      cuts[1][j] = -cut;
60
      cuts[2][i] =  cut;
61
      cuts[2][j] = -cut;
62
      cuts[3][i] =  cut;
63
      cuts[3][j] = -cut;
64
      cuts[4][i] =  cut;
65
      cuts[4][j] = -cut;
66
      cuts[5][i] =  cut;
67
      cuts[5][j] = -cut;
94
        {   0,   0   ,   0 },
95
        {   X,   Y   ,  -Z },
96
        {   0, 2*Y   ,-2*Z },
97
        {  -X,   Y   ,  -Z },
98
        {   0, -width,   0 },
99
        {   X, -width,  -Z },
100
        {   0, -width,-2*Z },
101
        {  -X, -width,  -Z },
102
      };
103

  
104
    if( !left )
105
      {
106
      int len = vertices.length;
107
      for(int i=0; i<len; i++) vertices[i][1] = -vertices[i][1];
68 108
      }
69 109

  
70
    return cuts;
110
    return vertices;
71 111
    }
72 112

  
73 113
///////////////////////////////////////////////////////////////////////////////////////////////////
74 114

  
75
  public static FactoryBandagedMegaminx getInstance()
115
  private float[][] retCenterKilominx(int numL)
76 116
    {
77
    if( mThis==null ) mThis = new FactoryBandagedMegaminx();
78
    return mThis;
117
    float width = (1+0.5f*(numL-3)*SIN18)*numL/(numL-1);
118
    float X = width*COS18*SIN_HALFD;
119
    float Y = width*SIN18;
120
    float Z = width*COS18*COS_HALFD;
121
    float H = width*(SIN54/COS54);
122
    float H3= H/COS_HALFD;
123
    float X3= H*SIN_HALFD;
124
    float Z3= H*COS_HALFD;
125
    float C = 1/(COS54*(float)Math.sqrt(2-2*SIN18));
126

  
127
    return new float[][]
128
      {
129
        {   0,   0  ,     0 },
130
        {   X,   Y  ,    -Z },
131
        {   0,C*2*Y ,-2*C*Z },
132
        {  -X,   Y  ,    -Z },
133
        {   0,-width,     0 },
134
        {  X3,-width,   -Z3 },
135
        {   0,-width,   -H3 },
136
        { -X3,-width,   -Z3 }
137
      };
138
    }
139

  
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

  
142
  private float[][] retCornerMegaminx(int numL)
143
    {
144
    float width = numL*(0.5f-MEGA_D)/(0.5f*(numL-1));
145
    float X = width*COS18*SIN_HALFD;
146
    float Y = width*SIN18;
147
    float Z = width*COS18*COS_HALFD;
148

  
149
    return new float[][]
150
      {
151
        {   0,   0      ,   0 },
152
        {   X,   Y      ,  -Z },
153
        {   0, 2*Y      ,-2*Z },
154
        {  -X,   Y      ,  -Z },
155
        {   0,   0-width,   0 },
156
        {   X,   Y-width,  -Z },
157
        {   0, 2*Y-width,-2*Z },
158
        {  -X,   Y-width,  -Z },
159
      };
160
    }
161

  
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

  
164
  private float[][] retEdgeMegaminx(int numL, int variant)
165
    {
166
    int type = variant-1;
167
    float height= numL*(0.5f-MEGA_D)*COS18/((numL-1)*0.5f);
168
    float width = numL*2*MEGA_D + 2*type*height*SIN18/COS18;
169

  
170
    float W = width/2;
171
    float X = height*SIN_HALFD;
172
    float Y = height*SIN18/COS18;
173
    float Z = height*COS_HALFD;
174

  
175
    return new float[][]
176
      {
177
        {   0,   W   ,   0 },
178
        {   X, W+Y   ,  -Z },
179
        {   0, W+2*Y ,-2*Z },
180
        {  -X, W+Y   ,  -Z },
181
        {   0,  -W   ,   0 },
182
        {   X,-W-Y   ,  -Z },
183
        {   0,-W-2*Y ,-2*Z },
184
        {  -X,-W-Y   ,  -Z },
185
      };
186
    }
187

  
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

  
190
  private float[][] retCenterMegaminx(int numL)
191
    {
192
    float width = 2*numL*(MEGA_D+(0.5f-MEGA_D)*SIN18);
193
    final double ANGLE = 0.825f*Math.PI;
194
    final float cosA  = (float)Math.cos(ANGLE);
195
    final float sinA  = (float)Math.sin(ANGLE);
196

  
197
    float R  = 0.5f*width/COS54;
198
    float X1 = R*COS54;
199
    float Y1 = R*SIN54;
200
    float X2 = R*COS18;
201
    float Y2 = R*SIN18;
202

  
203
    return new float[][]
204
      {
205
       {-X1, Y1*sinA, Y1*cosA},
206
       {-X2,-Y2*sinA,-Y2*cosA},
207
       { 0 ,-R*sinA ,-R*cosA },
208
       {+X2,-Y2*sinA,-Y2*cosA},
209
       {+X1, Y1*sinA, Y1*cosA},
210
       { 0 , R*cosA ,-R*sinA }
211
      };
212
    }
213

  
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

  
216
  private float[][] verticesKilominx(int variant)
217
    {
218
    if( mVertices[0]==null ) mVertices[0] = retCornerKilominx(3);
219
    return mVertices[0];
220
    }
221

  
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

  
224
  private float[][] verticesMegaminx(int variant)
225
    {
226
    switch(variant)
227
      {
228
      case 0: if( mVertices[1]==null ) mVertices[1] = retCornerMegaminx(3);
229
              break;
230
      case 1: if( mVertices[2]==null ) mVertices[2] = retEdgeMegaminx(3,variant);
231
              break;
232
      case 2: if( mVertices[3]==null ) mVertices[3] = retCenterMegaminx(3);
233
              break;
234
      }
235

  
236
    return mVertices[variant+1];
237
    }
238

  
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

  
241
  private float[][] verticesMasterKilominx(int variant)
242
    {
243
    switch(variant)
244
      {
245
      case 0: if( mVertices[4]==null ) mVertices[4] = retCornerKilominx(5);
246
              break;
247
      case 1: if( mVertices[5]==null ) mVertices[5] = retEdgeKilominx(5,variant);
248
              break;
249
      case 2: if( mVertices[6]==null ) mVertices[6] = retEdgeKilominx(5,variant);
250
              break;
251
      case 3: if( mVertices[7]==null ) mVertices[7] = retCenterKilominx(5);
252
              break;
253
      }
254

  
255
    return mVertices[variant+1+3];
256
    }
257

  
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

  
260
  private float[][] verticesGigaminx(int variant)
261
    {
262
    switch(variant)
263
      {
264
      case 0: if( mVertices[ 8]==null ) mVertices[ 8] = retCornerMegaminx(5);
265
              break;
266
      case 1: if( mVertices[ 9]==null ) mVertices[ 9] = retEdgeMegaminx(5,variant);
267
              break;
268
      case 2: if( mVertices[10]==null ) mVertices[10] = retEdgeMegaminx(5,variant);
269
              break;
270
      case 3: if( mVertices[11]==null ) mVertices[11] = retCenterMegaminx(5);
271
              break;
272
      }
273

  
274
    return mVertices[variant+1+3+4];
79 275
    }
80 276

  
81 277
///////////////////////////////////////////////////////////////////////////////////////////////////
82 278

  
83 279
  public float[][] getVertices(int variant)
84 280
    {
281
    if( mVertices==null ) mVertices = new float[1+3+4+4][][];
282

  
283
    switch( mNumLayers[0] )
284
      {
285
      case 0: return verticesKilominx(variant);
286
      case 1: return verticesMegaminx(variant);
287
      case 2: return verticesMasterKilominx(variant);
288
      case 3: return verticesGigaminx(variant);
289
      }
290

  
85 291
    return null;
86 292
    }
87 293

  
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

  
296
  private int[][] cornerIndices()
297
    {
298
    return new int[][]
299
      {
300
        {4,5,1,0},
301
        {7,4,0,3},
302
        {0,1,2,3},
303
        {7,6,5,4},
304
        {2,1,5,6},
305
        {3,2,6,7}
306
      };
307
    }
308

  
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

  
311
  private int[][] centerIndices()
312
    {
313
    return new int[][]
314
      {
315
        {0,1,2,3,4},
316
        {5,1,0},
317
        {5,2,1},
318
        {5,3,2},
319
        {5,4,3},
320
        {5,0,4}
321
      };
322
    }
323

  
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

  
326
  private int[][] indicesKilominx(int variant)
327
    {
328
    if( mIndices[0]==null ) mIndices[0] = cornerIndices();
329
    return mIndices[0];
330
    }
331

  
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

  
334
  private int[][] indicesMegaminx(int variant)
335
    {
336
    switch( variant )
337
      {
338
      case 0: if( mIndices[1]==null ) mIndices[1] = cornerIndices(); break;
339
      case 1: if( mIndices[2]==null ) mIndices[2] = cornerIndices(); break;
340
      case 2: if( mIndices[3]==null ) mIndices[3] = centerIndices(); break;
341
      }
342

  
343
    return mIndices[variant+1];
344
    }
345

  
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

  
348
  private int[][] indicesMasterKilominx(int variant)
349
    {
350
    switch( variant )
351
      {
352
      case 0: if( mIndices[4]==null ) mIndices[4] = cornerIndices(); break;
353
      case 1: if( mIndices[5]==null )
354
                {
355
                mIndices[5] = cornerIndices();
356

  
357
                int[][] indices = mIndices[5];
358
                int tmp, len = indices.length;
359

  
360
                for(int i=0; i<len; i++)
361
                  {
362
                  tmp = indices[i][0];
363
                  indices[i][0] = indices[i][3];
364
                  indices[i][3] = tmp;
365
                  tmp = indices[i][1];
366
                  indices[i][1] = indices[i][2];
367
                  indices[i][2] = tmp;
368
                  }
369
                }
370
              break;
371
      case 2: if( mIndices[6]==null ) mIndices[6] = cornerIndices(); break;
372
      case 3: if( mIndices[7]==null ) mIndices[7] = cornerIndices(); break;
373
      }
374

  
375
    return mIndices[variant+1+3];
376
    }
377

  
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

  
380
  private int[][] indicesGigaminx(int variant)
381
    {
382
    switch( variant )
383
      {
384
      case 0: if( mIndices[ 8]==null ) mIndices[ 8] = cornerIndices(); break;
385
      case 1: if( mIndices[ 9]==null ) mIndices[ 9] = cornerIndices(); break;
386
      case 2: if( mIndices[10]==null ) mIndices[10] = cornerIndices(); break;
387
      case 3: if( mIndices[11]==null ) mIndices[11] = centerIndices(); break;
388
      }
389

  
390
    return mIndices[variant+1+3+4];
391
    }
392

  
88 393
///////////////////////////////////////////////////////////////////////////////////////////////////
89 394

  
90 395
  public int[][] getIndices(int variant)
91 396
    {
397
    if( mIndices==null ) mIndices = new int[1+3+4+4][][];
398

  
399
    switch( mNumLayers[0] )
400
      {
401
      case 0: return indicesKilominx(variant);
402
      case 1: return indicesMegaminx(variant);
403
      case 2: return indicesMasterKilominx(variant);
404
      case 3: return indicesGigaminx(variant);
405
      }
406

  
92 407
    return null;
93 408
    }
94 409

  
......
197 512
    return 0;
198 513
    }
199 514

  
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

  
202
  public float[][] getCuts(int[] numLayers)
203
    {
204
    int size = numLayers[0];
205

  
206
    if( (size%2)==1 ) return genericGetCuts(size  ,0.5f-MEGA_D);
207
    else              return genericGetCuts(size+1,0.5f);
208
    }
209

  
210 515
///////////////////////////////////////////////////////////////////////////////////////////////////
211 516

  
212 517
  public Static3D[] getNormals()
......
216 521

  
217 522
///////////////////////////////////////////////////////////////////////////////////////////////////
218 523

  
219
  public float[][] getRotAxis()
524
  public int getNumAxis()
220 525
    {
221
    return new float[][]
222
            {
223
                    {    C2/LEN, SIN54/LEN,    0      },
224
                    {   -C2/LEN, SIN54/LEN,    0      },
225
                    { 0        ,    C2/LEN, SIN54/LEN },
226
                    { 0        ,   -C2/LEN, SIN54/LEN },
227
                    { SIN54/LEN,    0     ,    C2/LEN },
228
                    { SIN54/LEN,    0     ,   -C2/LEN }
229
            };
526
    return 6;
230 527
    }
231 528

  
232 529
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/bandaged/FactoryBandagedPyraminx.java
10 10
package org.distorted.objectlib.bandaged;
11 11

  
12 12
import static org.distorted.objectlib.main.TwistyObject.SQ2;
13
import static org.distorted.objectlib.main.TwistyObject.SQ3;
14
import static org.distorted.objectlib.main.TwistyObject.SQ6;
15 13

  
16 14
import org.distorted.library.type.Static3D;
17 15
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
......
21 19
public class FactoryBandagedPyraminx extends FactoryBandaged
22 20
  {
23 21
  private static FactoryBandagedPyraminx mThis;
22
  private float[][][] mVertices;
23
  private int[][][] mIndices;
24 24

  
25 25
///////////////////////////////////////////////////////////////////////////////////////////////////
26 26

  
......
41 41

  
42 42
  public float[][] getVertices(int variant)
43 43
    {
44
    if( mVertices==null ) mVertices = new float[2][][];
45

  
44 46
    if( variant==0 )
45 47
      {
46
      return new float[][] { { 0.5f,0.0f,0.5f},{ 0.5f,0.0f,-0.5f},{-0.5f,0.0f,-0.5f},{-0.5f,0.0f,0.5f},{ 0.0f,SQ2/2,0.0f},{ 0.0f,-SQ2/2,0.0f} };
48
      if( mVertices[0]==null )
49
        mVertices[0] = new float[][] { { 0.5f,0.0f,0.5f},{ 0.5f,0.0f,-0.5f},{-0.5f,0.0f,-0.5f},{-0.5f,0.0f,0.5f},{ 0.0f,SQ2/2,0.0f},{ 0.0f,-SQ2/2,0.0f} };
50

  
51
      return mVertices[0];
47 52
      }
48 53
    else
49 54
      {
50
      return new float[][] { {-0.5f, SQ2/4, 0.0f},{ 0.5f, SQ2/4, 0.0f},{ 0.0f,-SQ2/4, 0.5f},{ 0.0f,-SQ2/4,-0.5f} };
55
      if( mVertices[1]==null )
56
        mVertices[1] = new float[][] { {-0.5f, SQ2/4, 0.0f},{ 0.5f, SQ2/4, 0.0f},{ 0.0f,-SQ2/4, 0.5f},{ 0.0f,-SQ2/4,-0.5f} };
57

  
58
      return mVertices[1];
51 59
      }
52 60
    }
53 61

  
......
55 63

  
56 64
  public int[][] getIndices(int variant)
57 65
    {
66
    if( mIndices==null ) mIndices = new int[2][][];
67

  
58 68
    if( variant==0 )
59 69
      {
60
      return 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} };
70
      if( mIndices[0]==null )
71
        mIndices[0] = 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} };
72

  
73
      return mIndices[0];
61 74
      }
62 75
    else
63 76
      {
64
      return new int[][] { {2,1,0},{3,0,1},{3,2,0},{2,3,1} };
77
      if( mIndices[1]==null )
78
        mIndices[1] = new int[][] { {2,1,0},{3,0,1},{3,2,0},{2,3,1} };
79

  
80
      return mIndices[1];
65 81
      }
66 82
    }
67 83

  
......
84 100
    return isOctahedron(mNumLayers[0],y) ? 0 : 1;
85 101
    }
86 102

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

  
89
  public float[][] getCuts(int[] numLayers)
90
    {
91
    int numL = numLayers[0];
92
    float[][] ret = new float[4][numL-1];
93

  
94
    for(int i=0; i<numL-1; i++)
95
      {
96
      float cut = (1.0f+i-numL/4.0f)*(SQ6/3);
97
      ret[0][i] = cut;
98
      ret[1][i] = cut;
99
      ret[2][i] = cut;
100
      ret[3][i] = cut;
101
      }
102

  
103
    return ret;
104
    }
105

  
106 103
///////////////////////////////////////////////////////////////////////////////////////////////////
107 104

  
108 105
  public Static3D[] getNormals()
......
112 109

  
113 110
///////////////////////////////////////////////////////////////////////////////////////////////////
114 111

  
115
  public float[][] getRotAxis()
112
  public int getNumAxis()
116 113
    {
117
    return new float[][]
118
            {
119
                    {     0,-SQ3/3,-SQ6/3 },
120
                    {     0,-SQ3/3, SQ6/3 },
121
                    { SQ6/3, SQ3/3,     0 },
122
                    {-SQ6/3, SQ3/3,     0 },
123
            };
114
    return 4;
124 115
    }
125 116

  
126 117
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyDodecahedron.java
26 26

  
27 27
public abstract class TwistyDodecahedron extends ShapeDodecahedron
28 28
{
29
  public static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
30
  public static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
31

  
29 32
  static final int NUM_CORNERS = 20;
30 33
  static final int NUM_CENTERS = 12;
31 34
  static final int NUM_EDGES   = 30;
32 35

  
33 36
  static final float SIN18    = (SQ5-1)/4;
34 37
  static final float COS18    = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
35
  static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
36
  static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
37 38

  
38 39
  // the six rotation axis of a Minx. Must be normalized.
39 40
  static final Static3D[] ROT_AXIS = new Static3D[]
src/main/java/org/distorted/objectlib/objects/TwistyKilominx.java
384 384
    int[] numLayers = getNumLayers();
385 385
    int numVariants = getNumCubitVariants(numLayers);
386 386
    int numL        = numLayers[0];
387
    boolean small   = numL<=3;
388 387

  
389
    if( variant==0 && !small )
388
    int[][] indices =
390 389
      {
391
      int[][] indices =
392
        {
393
            {4,5,1,0},
394
            {7,4,0,3},
395
            {0,1,2,3},
396
            {7,6,5,4},
397
            {2,1,5,6},
398
            {3,2,6,7}
399
        };
390
       {4,5,1,0},
391
       {7,4,0,3},
392
       {0,1,2,3},
393
       {7,6,5,4},
394
       {2,1,5,6},
395
       {3,2,6,7}
396
      };
400 397

  
401
      return new ObjectShape(getVertices(variant), indices);
402
      }
403
    if( variant<numVariants-1 )
398
    if( (variant!=0 || numL<=3) && (variant<numVariants-1) && (variant%2)!=1 )
404 399
      {
405
      boolean left = (variant%2)==1;
400
      int tmp, len = indices.length;
406 401

  
407
      int[][] indices =
402
      for(int i=0; i<len; i++)
408 403
        {
409
            {4,5,1,0},
410
            {7,4,0,3},
411
            {3,2,6,7},
412
            {2,1,5,6},
413
            {0,1,2,3},
414
            {7,6,5,4}
415
        };
416

  
417
      if( !left )
418
        {
419
        int tmp, len = indices.length;
420

  
421
        for(int i=0; i<len; i++)
422
          {
423
          tmp = indices[i][0];
424
          indices[i][0] = indices[i][3];
425
          indices[i][3] = tmp;
426
          tmp = indices[i][1];
427
          indices[i][1] = indices[i][2];
428
          indices[i][2] = tmp;
429
          }
404
        tmp = indices[i][0];
405
        indices[i][0] = indices[i][3];
406
        indices[i][3] = tmp;
407
        tmp = indices[i][1];
408
        indices[i][1] = indices[i][2];
409
        indices[i][2] = tmp;
430 410
        }
431

  
432
      return new ObjectShape(getVertices(variant), indices);
433 411
      }
434
    else
435
      {
436
      int[][] indices =
437
        {
438
            {4,5,1,0},
439
            {7,4,0,3},
440
            {0,1,2,3},
441
            {3,2,6,7},
442
            {2,1,5,6},
443
            {7,6,5,4}
444
        };
445 412

  
446
      return new ObjectShape(getVertices(variant), indices);
447
      }
413
    return new ObjectShape(getVertices(variant), indices);
448 414
    }
449 415

  
450 416
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyMegaminx.java
328 328
    int[] numLayers = getNumLayers();
329 329
    int numVariants = getNumCubitVariants(numLayers);
330 330

  
331
    if( variant==0 )
332
      {
333
      int[][] indices =
334
        {
335
            {4,5,1,0},
336
            {7,4,0,3},
337
            {0,1,2,3},
338
            {7,6,5,4},
339
            {2,1,5,6},
340
            {3,2,6,7}
341
        };
342

  
343
      return new ObjectShape(getVertices(variant), indices);
344
      }
345 331
    if( variant<numVariants-1 )
346 332
      {
347 333
      int[][] indices =
348 334
        {
349
            {4,5,1,0},
350
            {7,4,0,3},
351
            {3,2,6,7},
352
            {2,1,5,6},
353
            {0,1,2,3},
354
            {7,6,5,4}
335
          {4,5,1,0},
336
          {7,4,0,3},
337
          {0,1,2,3},
338
          {7,6,5,4},
339
          {2,1,5,6},
340
          {3,2,6,7}
355 341
        };
356 342

  
357 343
      return new ObjectShape(getVertices(variant), indices);

Also available in: Unified diff