Project

General

Profile

Download (14.2 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyBandagedPyraminx.java @ bb85236a

1 c18507d9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 bb85236a leszek
// Copyright 2023 Leszek Koltunski                                                               //
3 c18507d9 Leszek Koltunski
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.objectlib.objects;
11
12 bb85236a leszek
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_TETRAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
14 c18507d9 Leszek Koltunski
15
import org.distorted.library.effect.EffectName;
16
import org.distorted.library.main.DistortedLibrary;
17
import org.distorted.library.type.Static3D;
18
import org.distorted.library.type.Static4D;
19 bb85236a leszek
import org.distorted.objectlib.bandaged.FactoryBandagedPyraminx;
20 c18507d9 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectFaceShape;
21
import org.distorted.objectlib.helpers.ObjectShape;
22
import org.distorted.objectlib.helpers.ObjectSignature;
23
import org.distorted.objectlib.helpers.ObjectVertexEffects;
24
import org.distorted.objectlib.main.InitAssets;
25
import org.distorted.objectlib.main.InitData;
26
import org.distorted.objectlib.scrambling.ObjectScrambler;
27 bb85236a leszek
import org.distorted.objectlib.shape.ShapeTetrahedron;
28
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
29 c18507d9 Leszek Koltunski
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31
32 bb85236a leszek
public class TwistyBandagedPyraminx extends ShapeTetrahedron
33 c18507d9 Leszek Koltunski
{
34 bb85236a leszek
  public static final String OBJECT_NAME = "LOCAL_PYRAMINX";
35 c18507d9 Leszek Koltunski
36 bb85236a leszek
  private static final Static3D[] ROT_AXIS = new Static3D[]
37 c18507d9 Leszek Koltunski
        {
38 bb85236a leszek
                new Static3D(     0,-SQ3/3,-SQ6/3),
39
                new Static3D(     0,-SQ3/3, SQ6/3),
40
                new Static3D( SQ6/3, SQ3/3,     0),
41
                new Static3D(-SQ6/3, SQ3/3,     0),
42 c18507d9 Leszek Koltunski
        };
43
44 bb85236a leszek
  private static final int OCT_1 = 0;
45
  private static final int TET_1 = 1;
46
  private static final int OTHER = 2;
47 c18507d9 Leszek Koltunski
48 bb85236a leszek
  private static final int NUM_TYPES = 2;  // OCT_1 and TET_1
49 c18507d9 Leszek Koltunski
50
  private int[] mCubitVariantMap;
51
  private int[] mTypeVariantMap;
52 bb85236a leszek
  private ObjectShape[] mTmpShapes;
53
  private int mNumVariants;
54
  private float[][] mPosition;
55
  private ObjectSignature mSignature;
56
  private float[][] mCuts;
57
  private int[][] mBasicAngle;
58 c18507d9 Leszek Koltunski
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61 bb85236a leszek
  private float[][] getPositions()
62 c18507d9 Leszek Koltunski
    {
63 bb85236a leszek
    if( mPosition==null ) mPosition = getInitData().getPos();
64
    return mPosition;
65 c18507d9 Leszek Koltunski
    }
66
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69 bb85236a leszek
  private int getType(float[] pos)
70 c18507d9 Leszek Koltunski
    {
71 bb85236a leszek
    if( pos.length>3 ) return OTHER;
72
    int[] numLayers = getNumLayers();
73
    int variant = FactoryBandagedPyraminx.getElementVariant(numLayers[0],pos[1]);
74
    return variant==0 ? OCT_1 : TET_1;
75
    }
76 c18507d9 Leszek Koltunski
77
78 bb85236a leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
79 c18507d9 Leszek Koltunski
80 bb85236a leszek
  private int getType(int variant)
81
    {
82
    for(int t=0; t<NUM_TYPES; t++)
83
      if( mTypeVariantMap[t]==variant ) return t;
84
85
    return -1;
86 c18507d9 Leszek Koltunski
    }
87
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89
90 bb85236a leszek
  private void produceTmpShape(int variant)
91 c18507d9 Leszek Koltunski
    {
92 bb85236a leszek
    float[][] positions = getPositions();
93
    int cubit,numCubits = positions.length;
94 c18507d9 Leszek Koltunski
95 bb85236a leszek
    for(cubit=0; cubit<numCubits; cubit++)
96 c18507d9 Leszek Koltunski
      {
97 bb85236a leszek
      if( mCubitVariantMap[cubit]==variant ) break;
98
      }
99
100
    if( cubit>=numCubits )
101
      {
102
      android.util.Log.e("D", "unknown variant: "+variant);
103 c18507d9 Leszek Koltunski
      }
104
    else
105
      {
106 bb85236a leszek
      FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
107
      mTmpShapes[variant] = factory.createIrregularShape(variant,positions[cubit]);
108 c18507d9 Leszek Koltunski
      }
109
    }
110
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112
113 bb85236a leszek
  private float[][] getVertices(int variant)
114 c18507d9 Leszek Koltunski
    {
115 bb85236a leszek
    if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
116
    if( mTmpShapes[variant]==null ) produceTmpShape(variant);
117
    return mTmpShapes[variant].getVertices();
118 c18507d9 Leszek Koltunski
    }
119
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121 bb85236a leszek
// PUBLIC API
122 c18507d9 Leszek Koltunski
123 bb85236a leszek
  public TwistyBandagedPyraminx(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
124 c18507d9 Leszek Koltunski
    {
125 bb85236a leszek
    super(meshState, iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
126 c18507d9 Leszek Koltunski
    }
127
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129 bb85236a leszek
// Computing scramble states of many a bandaged cubes takes way too long time and too much space.
130
// Return null here and turn to construction of scramble tables just-in-time (scrambleType=2)
131 c18507d9 Leszek Koltunski
132 bb85236a leszek
  public int[][] getScrambleEdges()
133 c18507d9 Leszek Koltunski
    {
134 bb85236a leszek
    return null;
135 c18507d9 Leszek Koltunski
    }
136
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138
139 bb85236a leszek
  @Override
140
  public float[][] returnRotationFactor()
141 c18507d9 Leszek Koltunski
    {
142 bb85236a leszek
    int numL= getNumLayers()[0];
143
    float[][] factor = new float[4][numL];
144
145
    for(int ax=0; ax<4; ax++)
146
      for(int la=0; la<numL; la++) factor[ax][la] = ((float)numL)/(numL-la);
147
148
    return factor;
149 c18507d9 Leszek Koltunski
    }
150
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152
153 bb85236a leszek
  @Override
154
  public int[][] getScrambleAlgorithms()
155 c18507d9 Leszek Koltunski
    {
156 bb85236a leszek
    return super.getScrambleAlgorithms();
157 c18507d9 Leszek Koltunski
    }
158
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
161 bb85236a leszek
  @Override
162
  public int getScrambleType()
163 c18507d9 Leszek Koltunski
    {
164 bb85236a leszek
    return ObjectScrambler.SCRAMBLING_BANDAGED;
165 c18507d9 Leszek Koltunski
    }
166
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168
169
  public ObjectShape getObjectShape(int variant)
170
    {
171
    if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
172
    if( mTmpShapes[variant]==null ) produceTmpShape(variant);
173
    return mTmpShapes[variant];
174
    }
175
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177
178
  public ObjectFaceShape getObjectFaceShape(int variant)
179
    {
180 bb85236a leszek
    int type = getType(variant);
181
    FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
182 c18507d9 Leszek Koltunski
183 bb85236a leszek
    if( type>=0 )
184 c18507d9 Leszek Koltunski
      {
185 bb85236a leszek
      boolean iconMode = isInIconMode();
186
      float[][] bands = factory.getBands(iconMode);
187
      int numFaces = type==TET_1 ? 4:8;
188
      int[] bandIndices= new int[numFaces];
189
      for(int i=0; i<numFaces; i++) bandIndices[i] = 1;
190 c18507d9 Leszek Koltunski
      return new ObjectFaceShape(bands,bandIndices,null);
191
      }
192
193
    return factory.createIrregularFaceShape(variant, isInIconMode() );
194
    }
195
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197
198
  public ObjectVertexEffects getVertexEffects(int variant)
199
    {
200
    int[] numLayers = getNumLayers();
201 bb85236a leszek
    int size = numLayers[0];
202 c18507d9 Leszek Koltunski
    boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode());
203 bb85236a leszek
    int type = getType(variant);
204 c18507d9 Leszek Koltunski
205 bb85236a leszek
    if( type>=0 )
206 c18507d9 Leszek Koltunski
      {
207
      float[][] vertices = getVertices(variant);
208 bb85236a leszek
      int numV = vertices.length;
209
      float S = -0.04f;
210 c18507d9 Leszek Koltunski
211
      String name = EffectName.DEFORM.name();
212
      float[] reg = {0,0,0,0.15f};
213
214 bb85236a leszek
      float[][] variables = new float[numV][];
215
      String[] names      = new String[numV];
216
      float[][] regions   = new float[numV][];
217
      boolean[] uses      = new boolean[numV];
218
219
      for(int i=0; i<numV; i++)
220
        {
221
        float[] v    = vertices[i];
222
        variables[i] = new float[] { 0, S*v[0], S*v[1], S*v[2], 1 };
223
        names[i]     = name;
224
        regions[i]   = reg;
225
        uses[i]      = round;
226
        }
227 c18507d9 Leszek Koltunski
228
      return new ObjectVertexEffects(names,variables,vertices,regions,uses);
229
      }
230
231 bb85236a leszek
    FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
232 c18507d9 Leszek Koltunski
    return factory.createVertexEffects(variant,round);
233
    }
234
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236
237
  public Static4D getCubitQuats(int cubit, int[] numLayers)
238
    {
239 bb85236a leszek
    return new Static4D(0,0,0,1);
240 c18507d9 Leszek Koltunski
    }
241
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243
244
  public int getNumCubitVariants(int[] numLayers)
245
    {
246
    if( mNumVariants==0 )
247
      {
248
      float[][] positions = getPositions();
249 bb85236a leszek
      boolean T1=false;
250
      boolean O1=false;
251 c18507d9 Leszek Koltunski
252
      int numCubits = positions.length;
253
      mCubitVariantMap = new int[numCubits];
254
255 bb85236a leszek
      mTypeVariantMap = new int[NUM_TYPES];
256
      for(int i=0; i<NUM_TYPES; i++) mTypeVariantMap[i] = -1;
257 c18507d9 Leszek Koltunski
258
      for (int cubit=0; cubit<numCubits; cubit++)
259
        {
260
        int type = getType(positions[cubit]);
261
262
        switch (type)
263
          {
264 bb85236a leszek
          case TET_1: if (!T1) { T1 = true; mTypeVariantMap[TET_1]=mNumVariants++; }
265
                      mCubitVariantMap[cubit] = mTypeVariantMap[TET_1];
266
                      break;
267
          case OCT_1: if (!O1) { O1 = true; mTypeVariantMap[OCT_1]=mNumVariants++; }
268
                      mCubitVariantMap[cubit] = mTypeVariantMap[OCT_1];
269
                      break;
270
          default   : mCubitVariantMap[cubit] = mNumVariants++;
271 c18507d9 Leszek Koltunski
          }
272
        }
273
274 bb85236a leszek
      FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
275 c65d5889 Leszek Koltunski
      factory.prepare(mNumVariants,numLayers);
276 c18507d9 Leszek Koltunski
      }
277
278
    return mNumVariants;
279
    }
280
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282
283 bb85236a leszek
  public float[][] getCubitPositions(int[] numLayers)
284 c18507d9 Leszek Koltunski
    {
285 bb85236a leszek
    return getPositions();
286 c18507d9 Leszek Koltunski
    }
287
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289
290 bb85236a leszek
  public boolean[][] getLayerRotatable(int[] numLayers)
291 c18507d9 Leszek Koltunski
    {
292 bb85236a leszek
    int numAxis = ROT_AXIS.length;
293
    int size = numLayers[0];
294
    boolean[][] layerRotatable = new boolean[numAxis][size];
295 c18507d9 Leszek Koltunski
296 bb85236a leszek
    for(int i=0; i<numAxis; i++)
297
      for(int j=0; j<size; j++) layerRotatable[i][j] = true;
298
299
    return layerRotatable;
300
    }
301
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303
304
  public float[][] getCuts(int[] numLayers)
305
    {
306
    if( mCuts==null )
307 c18507d9 Leszek Koltunski
      {
308 bb85236a leszek
      int numL = numLayers[0];
309
      mCuts = new float[4][numL-1];
310 c18507d9 Leszek Koltunski
311 bb85236a leszek
      for(int i=0; i<numL-1; i++)
312 c18507d9 Leszek Koltunski
        {
313 bb85236a leszek
        float cut = (1.0f+i-numL/4.0f)*(SQ6/3);
314
        mCuts[0][i] = cut;
315
        mCuts[1][i] = cut;
316
        mCuts[2][i] = cut;
317
        mCuts[3][i] = cut;
318
        }
319 c18507d9 Leszek Koltunski
      }
320
321 bb85236a leszek
    return mCuts;
322
    }
323
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325
326
  public Static3D[] getFaceAxis()
327
    {
328
    return TouchControlTetrahedron.FACE_AXIS;
329
    }
330
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332
333
  public Static3D[] getRotationAxis()
334
    {
335
    return ROT_AXIS;
336
    }
337
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339
340
  public int[][][] getEnabled()
341
    {
342
    return new int[][][] { {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}} };
343
    }
344
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346
347
  public int getTouchControlType()
348
    {
349
    return TC_TETRAHEDRON;
350
    }
351
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353
354
  public int getTouchControlSplit()
355
    {
356
    return TYPE_NOT_SPLIT;
357
    }
358
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360
361
  public int getCubitVariant(int cubit, int[] numLayers)
362
    {
363
    return mCubitVariantMap[cubit];
364 c18507d9 Leszek Koltunski
    }
365
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367
368
  public float[] getDist3D(int[] numLayers)
369
    {
370 bb85236a leszek
    return TouchControlTetrahedron.D3D;
371
    }
372 c18507d9 Leszek Koltunski
373 bb85236a leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
374
375
  public int[][] getBasicAngles()
376
    {
377
    if( mBasicAngle ==null )
378
      {
379
      int num = getNumLayers()[0];
380
      int[] tmp = new int[num];
381
      for(int i=0; i<num; i++) tmp[i] = 3;
382
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
383
      }
384
385
    return mBasicAngle;
386 c18507d9 Leszek Koltunski
    }
387
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389
390
  public float getStickerRadius()
391
    {
392
    return 0.10f;
393
    }
394
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396
397
  public float getStickerStroke()
398
    {
399 bb85236a leszek
    return isInIconMode() ? 0.16f : 0.08f;
400
    }
401 c18507d9 Leszek Koltunski
402 bb85236a leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
403 c18507d9 Leszek Koltunski
404 bb85236a leszek
  public float[][] getStickerAngles()
405
    {
406
    return null;
407 c18507d9 Leszek Koltunski
    }
408
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410
411
  public String getShortName()
412
    {
413
    if( mSignature==null ) mSignature = getSignature();
414
    int[] numLayers = getNumLayers();
415 bb85236a leszek
    return "P"+numLayers[0]+"_"+mSignature.getString();
416 c18507d9 Leszek Koltunski
    }
417
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419 bb85236a leszek
// TODO
420 c18507d9 Leszek Koltunski
421
  public ObjectSignature getSignature()
422
    {
423
    if( mSignature==null )
424
      {
425
      int[] numLayers = getNumLayers();
426
      mSignature = new ObjectSignature(numLayers[0],numLayers[1],numLayers[2],mPosition);
427
      }
428
    return mSignature;
429
    }
430
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432
433
  public String getObjectName()
434
    {
435
    return OBJECT_NAME;
436
    }
437
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439
440
  public String getInventor()
441
    {
442
    return "??";
443
    }
444
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446
447
  public int getYearOfInvention()
448
    {
449
    return 0;
450
    }
451
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453
454
  public int getComplexity()
455
    {
456
    return 4;
457
    }
458
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460
461
  public String[][] getTutorials()
462
    {
463
    return null;
464
    }
465
}