Project

General

Profile

« Previous | Next » 

Revision 5829e661

Added by Leszek Koltunski 10 months ago

progress with TwistyBandagedMegaminx.

View differences:

src/main/java/org/distorted/objectlib/objects/TwistyBandagedMegaminx.java
28 28

  
29 29
public class TwistyBandagedMegaminx extends TwistyDodecahedron
30 30
{
31
  public static final int KILOMINX3 = 2;
32
  public static final int MEGAMINX3 = 3;
33
  public static final int KILOMINX5 = 4;
34
  public static final int MEGAMINX5 = 5;
35

  
31 36
  public static final String OBJECT_NAME_MEGAMINX = "LOCAL_MEGAMINX";
32 37

  
33 38
  // TODO
......
42 47
  private ObjectShape[] mTmpShapes;
43 48
  private int mNumVariants;
44 49
  private float[][] mPosition;
50
  private float[][] mOrigPosition;  // again problem with the (2,3,4,5) numLayersFormat vs the (3,3,5,5) format:
51
                                    // for FactoryBandagedMegaminx we have to keep the original, 'uncorrected' positions;
45 52
  private ObjectSignature mSignature;
46 53

  
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

  
56
  private float[][] correctPos(float corr, float[][] pos)
57
    {
58
    int numPos = pos.length;
59
    float[][] ret = new float[numPos][];
60

  
61
    for(int p=0; p<numPos; p++)
62
      {
63
      float[] po = pos[p];
64
      int len = po.length/3;
65
      ret[p] = new float[3*len];
66
      float[] re = ret[p];
67

  
68
      for(int i=0; i<len; i++)
69
        {
70
        re[3*i  ] = corr * po[3*i  ];
71
        re[3*i+1] = corr * po[3*i+1];
72
        re[3*i+2] = corr * po[3*i+2];
73
        }
74
      }
75

  
76
    return ret;
77
    }
78

  
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

  
81
  private void correctVerts(float corr, float[][] verts)
82
    {
83
    for(float[] ve : verts)
84
      {
85
      ve[0] *= corr;
86
      ve[1] *= corr;
87
      ve[2] *= corr;
88
      }
89
    }
90

  
47 91
///////////////////////////////////////////////////////////////////////////////////////////////////
48 92

  
49 93
  private float[][] getPositions()
50 94
    {
51
    if( mPosition==null ) mPosition = getInitData().getPos();
95
    if( mPosition==null )
96
      {
97
      InitData data = getInitData();
98
      mOrigPosition = data.getPos();
99
      int param = data.getParam();
100

  
101
      switch(param)
102
        {
103
        case KILOMINX3: mPosition = correctPos(1.50f,mOrigPosition); break;
104
        case KILOMINX5: mPosition = correctPos(1.25f,mOrigPosition); break;
105
        case MEGAMINX3:
106
        case MEGAMINX5: mPosition = mOrigPosition;
107
        }
108
      }
109

  
52 110
    return mPosition;
53 111
    }
54 112

  
......
60 118
    return OTHER;
61 119
    }
62 120

  
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
// numLayers that we get here from BandagedObjectMegaminx are in the format (3,3,5,5) - i.e. one
123
// that agrees with the format in the previous TwistyKilominx/TwistyMegaminx classes (and in
124
// TwistyDodecahedron!). But FactoryBandagedMegaminx requires the unified (2,3,4,5) format -
125
// translate here.
126

  
127
  private int[] correctNumLayers(int param)
128
    {
129
    switch(param)
130
      {
131
      case KILOMINX3: return new int[] {2,2,2,2,2,2};
132
      case MEGAMINX3: return new int[] {3,3,3,3,3,3};
133
      case KILOMINX5: return new int[] {4,4,4,4,4,4};
134
      case MEGAMINX5: return new int[] {5,5,5,5,5,5};
135
      }
136

  
137
    return null;
138
    }
139

  
63 140
///////////////////////////////////////////////////////////////////////////////////////////////////
64 141

  
65 142
  private int getType(int variant)
......
74 151

  
75 152
  private void produceTmpShape(int variant)
76 153
    {
77
    float[][] positions = getPositions();
78
    int cubit,numCubits = positions.length;
154
    int cubit,numCubits = mPosition.length;
79 155

  
80 156
    for(cubit=0; cubit<numCubits; cubit++)
81 157
      {
......
89 165
    else
90 166
      {
91 167
      FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance();
92
      mTmpShapes[variant] = factory.createIrregularShape(variant,positions[cubit]);
168
      mTmpShapes[variant] = factory.createIrregularShape(variant,mOrigPosition[cubit]);
169

  
170
      InitData data = getInitData();
171
      int param = data.getParam();
172

  
173
      switch(param)
174
        {
175
        case KILOMINX3: correctVerts(1.50f,mTmpShapes[variant].getVertices()); break;
176
        case KILOMINX5: correctVerts(1.25f,mTmpShapes[variant].getVertices()); break;
177
        }
93 178
      }
94 179
    }
95 180

  
......
153 238

  
154 239
    if( type>=0 )
155 240
      {
156
      int[] numLayers = getNumLayers();
157
      boolean iconMode = isInIconMode();
158
      float[][] bands = factory.getBands(iconMode,numLayers);
241
      int param = getInitData().getParam();
242
      int[] numLayers = correctNumLayers(param);
159 243

  
160
      int numFaces = type==TET_1 ? 4:8;  // TODO
244
      if( numLayers!=null )
245
        {
246
        boolean iconMode = isInIconMode();
247
        float[][] bands = factory.getBands(iconMode,numLayers);
248

  
249
        int numFaces = type==TET_1 ? 4 : 8;  // TODO
161 250

  
162
      int[] bandIndices= new int[numFaces];
163
      for(int i=0; i<numFaces; i++) bandIndices[i] = 1;
164
      return new ObjectFaceShape(bands,bandIndices,null);
251
        int[] bandIndices = new int[numFaces];
252
        for(int i = 0; i<numFaces; i++) bandIndices[i] = 1;
253
        return new ObjectFaceShape(bands, bandIndices, null);
254
        }
165 255
      }
166 256

  
167 257
    return factory.createIrregularFaceShape(variant, isInIconMode() );
......
220 310
    {
221 311
    if( mNumVariants==0 )
222 312
      {
313
      int param = getInitData().getParam();
314
      int[] numL= correctNumLayers(param);
315
      int size = numL!=null ? numL[0] : -1;
223 316
      float[][] positions = getPositions();
224 317
      boolean T1=false;
225 318
      boolean O1=false;
......
232 325

  
233 326
      for (int cubit=0; cubit<numCubits; cubit++)
234 327
        {
235
        int type = getType(positions[cubit],numLayers[0]);
328
        int type = getType(positions[cubit],size);
236 329

  
237 330
        switch (type)
238 331
          {
......
247 340
        }
248 341

  
249 342
      FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance();
250
      factory.prepare(mNumVariants,numLayers);
343
      factory.prepare(mNumVariants,numL);
251 344
      }
252 345

  
253 346
    return mNumVariants;
......
264 357

  
265 358
  public float[][] getCuts(int[] numLayers)
266 359
    {
360
    int param = getInitData().getParam();
267 361
    int size = numLayers[0];
268
    float dist = (size%2==0) ? 0.5f : 0.5f-MEGA_D;
362
    float dist = (param==KILOMINX3 || param==KILOMINX5) ? 0.5f : 0.5f-MEGA_D;
269 363
    return genericGetCuts(size,dist);
270 364
    }
271 365

  
......
287 381

  
288 382
  public float getStickerStroke()
289 383
    {
290
    int[] numLayers = getNumLayers();
384
    int param = getInitData().getParam();
291 385

  
292
    switch(numLayers[0])
386
    switch(param)
293 387
      {
294
      case 2: return isInIconMode() ? 0.37f : 0.25f;
295
      case 3: return isInIconMode() ? 0.27f : 0.18f;
296
      case 4: return isInIconMode() ? 0.38f : 0.26f;
297
      case 5: return isInIconMode() ? 0.40f : 0.18f;
388
      case KILOMINX3: return isInIconMode() ? 0.38f : 0.27f;
389
      case MEGAMINX3: return isInIconMode() ? 0.27f : 0.18f;
390
      case KILOMINX5: return isInIconMode() ? 0.38f : 0.26f;
391
      case MEGAMINX5: return isInIconMode() ? 0.40f : 0.18f;
298 392
      }
299 393

  
300 394
    return 0.0f;
......
312 406
  public String getShortName()
313 407
    {
314 408
    if( mSignature==null ) mSignature = getSignature();
315
    int[] numLayers = getNumLayers();
316
    return "M"+numLayers[0]+"_"+mSignature.getString();
409
    int param = getInitData().getParam();
410
    return "M"+param+"_"+mSignature.getString();
317 411
    }
318 412

  
319 413
///////////////////////////////////////////////////////////////////////////////////////////////////
......
323 417
    {
324 418
    if( mSignature==null )
325 419
      {
326
      int[] numLayers = getNumLayers();
327
      mSignature = new ObjectSignature(numLayers[0],mPosition);
420
      int param = getInitData().getParam();
421
      mSignature = new ObjectSignature(param,mPosition);
328 422
      }
329 423
    return mSignature;
330 424
    }

Also available in: Unified diff