Project

General

Profile

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

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

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 ae9d9227 leszek
import org.distorted.objectlib.metadata.Metadata;
23 97a75106 leszek
import org.distorted.objectlib.signature.ObjectSignature;
24 c18507d9 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectVertexEffects;
25
import org.distorted.objectlib.main.InitAssets;
26
import org.distorted.objectlib.scrambling.ObjectScrambler;
27 bb85236a leszek
import org.distorted.objectlib.shape.ShapeTetrahedron;
28 97a75106 leszek
import org.distorted.objectlib.signature.ObjectSignaturePyraminx;
29 bb85236a leszek
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
30 c18507d9 Leszek Koltunski
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 bb85236a leszek
public class TwistyBandagedPyraminx extends ShapeTetrahedron
34 c18507d9 Leszek Koltunski
{
35 6612cbb4 leszek
  public static final String OBJECT_NAME_PYRAMINX = "LOCAL_PYRAMINX";
36 9e79b20f leszek
  public static final char MARKER = 'p'; // keep lowercase
37 c18507d9 Leszek Koltunski
38 bb85236a leszek
  private static final Static3D[] ROT_AXIS = new Static3D[]
39 c18507d9 Leszek Koltunski
        {
40 bb85236a leszek
                new Static3D(     0,-SQ3/3,-SQ6/3),
41
                new Static3D(     0,-SQ3/3, SQ6/3),
42
                new Static3D( SQ6/3, SQ3/3,     0),
43
                new Static3D(-SQ6/3, SQ3/3,     0),
44 c18507d9 Leszek Koltunski
        };
45
46 bb85236a leszek
  private static final int OCT_1 = 0;
47
  private static final int TET_1 = 1;
48
  private static final int OTHER = 2;
49 c18507d9 Leszek Koltunski
50 bb85236a leszek
  private static final int NUM_TYPES = 2;  // OCT_1 and TET_1
51 c18507d9 Leszek Koltunski
52
  private int[] mCubitVariantMap;
53
  private int[] mTypeVariantMap;
54 bb85236a leszek
  private ObjectShape[] mTmpShapes;
55
  private int mNumVariants;
56
  private float[][] mPosition;
57
  private ObjectSignature mSignature;
58
  private float[][] mCuts;
59
  private int[][] mBasicAngle;
60 c18507d9 Leszek Koltunski
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
63 bb85236a leszek
  private float[][] getPositions()
64 c18507d9 Leszek Koltunski
    {
65 ae9d9227 leszek
    if( mPosition==null ) mPosition = getMetadata().getPos();
66 bb85236a leszek
    return mPosition;
67 c18507d9 Leszek Koltunski
    }
68
69 3d4cd65e leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
70
71 6612cbb4 leszek
  private int getType(float[] pos, int numLayers)
72 c18507d9 Leszek Koltunski
    {
73 bb85236a leszek
    if( pos.length>3 ) return OTHER;
74 3e6133f0 leszek
    boolean octa = FactoryBandagedPyraminx.isOctahedron(numLayers,pos[1]);
75
    return octa ? OCT_1 : TET_1;
76 bb85236a leszek
    }
77 c18507d9 Leszek Koltunski
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 ae9d9227 leszek
  public TwistyBandagedPyraminx(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
124 c18507d9 Leszek Koltunski
    {
125 ae9d9227 leszek
    super(iconMode, meta.getNumLayers()[0], quat, move, scale, meta, asset);
126 c18507d9 Leszek Koltunski
    }
127
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129 3e6133f0 leszek
// Computing scramble states of many a bandaged objects takes way too long time and too much space.
130 bb85236a leszek
// 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 5e1b47f8 leszek
    return null;
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 6155e738 leszek
      int[] numLayers = getNumLayers();
186 bb85236a leszek
      boolean iconMode = isInIconMode();
187 6155e738 leszek
      float[][] bands = factory.getBands(iconMode,numLayers);
188 bb85236a leszek
      int numFaces = type==TET_1 ? 4:8;
189
      int[] bandIndices= new int[numFaces];
190
      for(int i=0; i<numFaces; i++) bandIndices[i] = 1;
191 c18507d9 Leszek Koltunski
      return new ObjectFaceShape(bands,bandIndices,null);
192
      }
193
194
    return factory.createIrregularFaceShape(variant, isInIconMode() );
195
    }
196
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198
199
  public ObjectVertexEffects getVertexEffects(int variant)
200
    {
201
    int[] numLayers = getNumLayers();
202 bb85236a leszek
    int size = numLayers[0];
203 c18507d9 Leszek Koltunski
    boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode());
204 bb85236a leszek
    int type = getType(variant);
205 c18507d9 Leszek Koltunski
206 bb85236a leszek
    if( type>=0 )
207 c18507d9 Leszek Koltunski
      {
208
      float[][] vertices = getVertices(variant);
209 bb85236a leszek
      int numV = vertices.length;
210
      float S = -0.04f;
211 c18507d9 Leszek Koltunski
212
      String name = EffectName.DEFORM.name();
213
      float[] reg = {0,0,0,0.15f};
214
215 bb85236a leszek
      float[][] variables = new float[numV][];
216
      String[] names      = new String[numV];
217
      float[][] regions   = new float[numV][];
218
      boolean[] uses      = new boolean[numV];
219
220
      for(int i=0; i<numV; i++)
221
        {
222
        float[] v    = vertices[i];
223
        variables[i] = new float[] { 0, S*v[0], S*v[1], S*v[2], 1 };
224
        names[i]     = name;
225
        regions[i]   = reg;
226
        uses[i]      = round;
227
        }
228 c18507d9 Leszek Koltunski
229
      return new ObjectVertexEffects(names,variables,vertices,regions,uses);
230
      }
231
232 bb85236a leszek
    FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
233 c18507d9 Leszek Koltunski
    return factory.createVertexEffects(variant,round);
234
    }
235
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237
238
  public Static4D getCubitQuats(int cubit, int[] numLayers)
239
    {
240 bb85236a leszek
    return new Static4D(0,0,0,1);
241 c18507d9 Leszek Koltunski
    }
242
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244
245
  public int getNumCubitVariants(int[] numLayers)
246
    {
247
    if( mNumVariants==0 )
248
      {
249
      float[][] positions = getPositions();
250 bb85236a leszek
      boolean T1=false;
251
      boolean O1=false;
252 c18507d9 Leszek Koltunski
253
      int numCubits = positions.length;
254
      mCubitVariantMap = new int[numCubits];
255
256 bb85236a leszek
      mTypeVariantMap = new int[NUM_TYPES];
257
      for(int i=0; i<NUM_TYPES; i++) mTypeVariantMap[i] = -1;
258 c18507d9 Leszek Koltunski
259
      for (int cubit=0; cubit<numCubits; cubit++)
260
        {
261 6612cbb4 leszek
        int type = getType(positions[cubit],numLayers[0]);
262 c18507d9 Leszek Koltunski
263
        switch (type)
264
          {
265 bb85236a leszek
          case TET_1: if (!T1) { T1 = true; mTypeVariantMap[TET_1]=mNumVariants++; }
266
                      mCubitVariantMap[cubit] = mTypeVariantMap[TET_1];
267
                      break;
268
          case OCT_1: if (!O1) { O1 = true; mTypeVariantMap[OCT_1]=mNumVariants++; }
269
                      mCubitVariantMap[cubit] = mTypeVariantMap[OCT_1];
270
                      break;
271
          default   : mCubitVariantMap[cubit] = mNumVariants++;
272 c18507d9 Leszek Koltunski
          }
273
        }
274
275 bb85236a leszek
      FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
276 c65d5889 Leszek Koltunski
      factory.prepare(mNumVariants,numLayers);
277 c18507d9 Leszek Koltunski
      }
278
279
    return mNumVariants;
280
    }
281
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283
284 bb85236a leszek
  public float[][] getCubitPositions(int[] numLayers)
285 c18507d9 Leszek Koltunski
    {
286 bb85236a leszek
    return getPositions();
287 c18507d9 Leszek Koltunski
    }
288
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290
291 bb85236a leszek
  public boolean[][] getLayerRotatable(int[] numLayers)
292 c18507d9 Leszek Koltunski
    {
293 bb85236a leszek
    int numAxis = ROT_AXIS.length;
294
    int size = numLayers[0];
295
    boolean[][] layerRotatable = new boolean[numAxis][size];
296 c18507d9 Leszek Koltunski
297 bb85236a leszek
    for(int i=0; i<numAxis; i++)
298
      for(int j=0; j<size; j++) layerRotatable[i][j] = true;
299
300
    return layerRotatable;
301
    }
302
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304
305
  public float[][] getCuts(int[] numLayers)
306
    {
307
    if( mCuts==null )
308 c18507d9 Leszek Koltunski
      {
309 bb85236a leszek
      int numL = numLayers[0];
310
      mCuts = new float[4][numL-1];
311 c18507d9 Leszek Koltunski
312 bb85236a leszek
      for(int i=0; i<numL-1; i++)
313 c18507d9 Leszek Koltunski
        {
314 bb85236a leszek
        float cut = (1.0f+i-numL/4.0f)*(SQ6/3);
315
        mCuts[0][i] = cut;
316
        mCuts[1][i] = cut;
317
        mCuts[2][i] = cut;
318
        mCuts[3][i] = cut;
319
        }
320 c18507d9 Leszek Koltunski
      }
321
322 bb85236a leszek
    return mCuts;
323
    }
324
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326
327
  public Static3D[] getFaceAxis()
328
    {
329
    return TouchControlTetrahedron.FACE_AXIS;
330
    }
331
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333
334
  public Static3D[] getRotationAxis()
335
    {
336
    return ROT_AXIS;
337
    }
338
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340
341
  public int[][][] getEnabled()
342
    {
343
    return new int[][][] { {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}} };
344
    }
345
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347
348
  public int getTouchControlType()
349
    {
350
    return TC_TETRAHEDRON;
351
    }
352
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354
355
  public int getTouchControlSplit()
356
    {
357
    return TYPE_NOT_SPLIT;
358
    }
359
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361
362
  public int getCubitVariant(int cubit, int[] numLayers)
363
    {
364
    return mCubitVariantMap[cubit];
365 c18507d9 Leszek Koltunski
    }
366
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368
369
  public float[] getDist3D(int[] numLayers)
370
    {
371 bb85236a leszek
    return TouchControlTetrahedron.D3D;
372
    }
373 c18507d9 Leszek Koltunski
374 bb85236a leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
375
376
  public int[][] getBasicAngles()
377
    {
378
    if( mBasicAngle ==null )
379
      {
380
      int num = getNumLayers()[0];
381
      int[] tmp = new int[num];
382
      for(int i=0; i<num; i++) tmp[i] = 3;
383
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
384
      }
385
386
    return mBasicAngle;
387 c18507d9 Leszek Koltunski
    }
388
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390
391
  public float getStickerRadius()
392
    {
393
    return 0.10f;
394
    }
395
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
398
  public float getStickerStroke()
399
    {
400 bb85236a leszek
    return isInIconMode() ? 0.16f : 0.08f;
401
    }
402 c18507d9 Leszek Koltunski
403 bb85236a leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
404 c18507d9 Leszek Koltunski
405 ebe8c08e leszek
  public float[][][] getStickerAngles()
406 bb85236a leszek
    {
407
    return null;
408 c18507d9 Leszek Koltunski
    }
409
410
///////////////////////////////////////////////////////////////////////////////////////////////////
411
412
  public String getShortName()
413
    {
414
    if( mSignature==null ) mSignature = getSignature();
415
    int[] numLayers = getNumLayers();
416 9e79b20f leszek
    return MARKER+(numLayers[0]+"_"+mSignature.getString());
417 c18507d9 Leszek Koltunski
    }
418
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420
421
  public ObjectSignature getSignature()
422
    {
423
    if( mSignature==null )
424
      {
425
      int[] numLayers = getNumLayers();
426 97a75106 leszek
      mSignature = new ObjectSignaturePyraminx(numLayers[0],mPosition);
427 c18507d9 Leszek Koltunski
      }
428
    return mSignature;
429
    }
430
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432
433
  public String getObjectName()
434
    {
435 6612cbb4 leszek
    return OBJECT_NAME_PYRAMINX;
436 c18507d9 Leszek Koltunski
    }
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 da5551f4 leszek
  public float getComplexity()
455 c18507d9 Leszek Koltunski
    {
456
    return 4;
457
    }
458
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460
461
  public String[][] getTutorials()
462
    {
463
    return null;
464
    }
465
}