Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 Leszek Koltunski                                                               //
3
//                                                                                               //
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
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_TETRAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
14

    
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
import org.distorted.objectlib.bandaged.FactoryBandagedPyraminx;
20
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
import org.distorted.objectlib.shape.ShapeTetrahedron;
28
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
public class TwistyBandagedPyraminx extends ShapeTetrahedron
33
{
34
  public static final String OBJECT_NAME_PYRAMINX = "LOCAL_PYRAMINX";
35

    
36
  private static final Static3D[] ROT_AXIS = new Static3D[]
37
        {
38
                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
        };
43

    
44
  private static final int OCT_1 = 0;
45
  private static final int TET_1 = 1;
46
  private static final int OTHER = 2;
47

    
48
  private static final int NUM_TYPES = 2;  // OCT_1 and TET_1
49

    
50
  private int[] mCubitVariantMap;
51
  private int[] mTypeVariantMap;
52
  private ObjectShape[] mTmpShapes;
53
  private int mNumVariants;
54
  private float[][] mPosition;
55
  private ObjectSignature mSignature;
56
  private float[][] mCuts;
57
  private int[][] mBasicAngle;
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
  private float[][] getPositions()
62
    {
63
    if( mPosition==null ) mPosition = getInitData().getPos();
64
    return mPosition;
65
    }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  private int getType(float[] pos, int numLayers)
70
    {
71
    if( pos.length>3 ) return OTHER;
72
    int variant = FactoryBandagedPyraminx.getElementVariant(numLayers,pos[1]);
73
    return variant==0 ? OCT_1 : TET_1;
74
    }
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
  private int getType(int variant)
79
    {
80
    for(int t=0; t<NUM_TYPES; t++)
81
      if( mTypeVariantMap[t]==variant ) return t;
82

    
83
    return -1;
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  private void produceTmpShape(int variant)
89
    {
90
    float[][] positions = getPositions();
91
    int cubit,numCubits = positions.length;
92

    
93
    for(cubit=0; cubit<numCubits; cubit++)
94
      {
95
      if( mCubitVariantMap[cubit]==variant ) break;
96
      }
97

    
98
    if( cubit>=numCubits )
99
      {
100
      android.util.Log.e("D", "unknown variant: "+variant);
101
      }
102
    else
103
      {
104
      FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
105
      mTmpShapes[variant] = factory.createIrregularShape(variant,positions[cubit]);
106
      }
107
    }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
  private float[][] getVertices(int variant)
112
    {
113
    if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
114
    if( mTmpShapes[variant]==null ) produceTmpShape(variant);
115
    return mTmpShapes[variant].getVertices();
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119
// PUBLIC API
120

    
121
  public TwistyBandagedPyraminx(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
122
    {
123
    super(meshState, iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127
// Computing scramble states of many a bandaged cubes takes way too long time and too much space.
128
// Return null here and turn to construction of scramble tables just-in-time (scrambleType=2)
129

    
130
  public int[][] getScrambleEdges()
131
    {
132
    return null;
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  @Override
138
  public float[][] returnRotationFactor()
139
    {
140
    int numL= getNumLayers()[0];
141
    float[][] factor = new float[4][numL];
142

    
143
    for(int ax=0; ax<4; ax++)
144
      for(int la=0; la<numL; la++) factor[ax][la] = ((float)numL)/(numL-la);
145

    
146
    return factor;
147
    }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

    
151
  @Override
152
  public int[][] getScrambleAlgorithms()
153
    {
154
    return super.getScrambleAlgorithms();
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  @Override
160
  public int getScrambleType()
161
    {
162
    return ObjectScrambler.SCRAMBLING_BANDAGED;
163
    }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

    
167
  public ObjectShape getObjectShape(int variant)
168
    {
169
    if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
170
    if( mTmpShapes[variant]==null ) produceTmpShape(variant);
171
    return mTmpShapes[variant];
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  public ObjectFaceShape getObjectFaceShape(int variant)
177
    {
178
    int type = getType(variant);
179
    FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
180

    
181
    if( type>=0 )
182
      {
183
      boolean iconMode = isInIconMode();
184
      float[][] bands = factory.getBands(iconMode);
185
      int numFaces = type==TET_1 ? 4:8;
186
      int[] bandIndices= new int[numFaces];
187
      for(int i=0; i<numFaces; i++) bandIndices[i] = 1;
188
      return new ObjectFaceShape(bands,bandIndices,null);
189
      }
190

    
191
    return factory.createIrregularFaceShape(variant, isInIconMode() );
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

    
196
  public ObjectVertexEffects getVertexEffects(int variant)
197
    {
198
    int[] numLayers = getNumLayers();
199
    int size = numLayers[0];
200
    boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode());
201
    int type = getType(variant);
202

    
203
    if( type>=0 )
204
      {
205
      float[][] vertices = getVertices(variant);
206
      int numV = vertices.length;
207
      float S = -0.04f;
208

    
209
      String name = EffectName.DEFORM.name();
210
      float[] reg = {0,0,0,0.15f};
211

    
212
      float[][] variables = new float[numV][];
213
      String[] names      = new String[numV];
214
      float[][] regions   = new float[numV][];
215
      boolean[] uses      = new boolean[numV];
216

    
217
      for(int i=0; i<numV; i++)
218
        {
219
        float[] v    = vertices[i];
220
        variables[i] = new float[] { 0, S*v[0], S*v[1], S*v[2], 1 };
221
        names[i]     = name;
222
        regions[i]   = reg;
223
        uses[i]      = round;
224
        }
225

    
226
      return new ObjectVertexEffects(names,variables,vertices,regions,uses);
227
      }
228

    
229
    FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
230
    return factory.createVertexEffects(variant,round);
231
    }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
  public Static4D getCubitQuats(int cubit, int[] numLayers)
236
    {
237
    return new Static4D(0,0,0,1);
238
    }
239

    
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

    
242
  public int getNumCubitVariants(int[] numLayers)
243
    {
244
    if( mNumVariants==0 )
245
      {
246
      float[][] positions = getPositions();
247
      boolean T1=false;
248
      boolean O1=false;
249

    
250
      int numCubits = positions.length;
251
      mCubitVariantMap = new int[numCubits];
252

    
253
      mTypeVariantMap = new int[NUM_TYPES];
254
      for(int i=0; i<NUM_TYPES; i++) mTypeVariantMap[i] = -1;
255

    
256
      for (int cubit=0; cubit<numCubits; cubit++)
257
        {
258
        int type = getType(positions[cubit],numLayers[0]);
259

    
260
        switch (type)
261
          {
262
          case TET_1: if (!T1) { T1 = true; mTypeVariantMap[TET_1]=mNumVariants++; }
263
                      mCubitVariantMap[cubit] = mTypeVariantMap[TET_1];
264
                      break;
265
          case OCT_1: if (!O1) { O1 = true; mTypeVariantMap[OCT_1]=mNumVariants++; }
266
                      mCubitVariantMap[cubit] = mTypeVariantMap[OCT_1];
267
                      break;
268
          default   : mCubitVariantMap[cubit] = mNumVariants++;
269
          }
270
        }
271

    
272
      FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
273
      factory.prepare(mNumVariants,numLayers);
274
      }
275

    
276
    return mNumVariants;
277
    }
278

    
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280

    
281
  public float[][] getCubitPositions(int[] numLayers)
282
    {
283
    return getPositions();
284
    }
285

    
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287

    
288
  public boolean[][] getLayerRotatable(int[] numLayers)
289
    {
290
    int numAxis = ROT_AXIS.length;
291
    int size = numLayers[0];
292
    boolean[][] layerRotatable = new boolean[numAxis][size];
293

    
294
    for(int i=0; i<numAxis; i++)
295
      for(int j=0; j<size; j++) layerRotatable[i][j] = true;
296

    
297
    return layerRotatable;
298
    }
299

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

    
302
  public float[][] getCuts(int[] numLayers)
303
    {
304
    if( mCuts==null )
305
      {
306
      int numL = numLayers[0];
307
      mCuts = new float[4][numL-1];
308

    
309
      for(int i=0; i<numL-1; i++)
310
        {
311
        float cut = (1.0f+i-numL/4.0f)*(SQ6/3);
312
        mCuts[0][i] = cut;
313
        mCuts[1][i] = cut;
314
        mCuts[2][i] = cut;
315
        mCuts[3][i] = cut;
316
        }
317
      }
318

    
319
    return mCuts;
320
    }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
  public Static3D[] getFaceAxis()
325
    {
326
    return TouchControlTetrahedron.FACE_AXIS;
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

    
331
  public Static3D[] getRotationAxis()
332
    {
333
    return ROT_AXIS;
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  public int[][][] getEnabled()
339
    {
340
    return new int[][][] { {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}} };
341
    }
342

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344

    
345
  public int getTouchControlType()
346
    {
347
    return TC_TETRAHEDRON;
348
    }
349

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351

    
352
  public int getTouchControlSplit()
353
    {
354
    return TYPE_NOT_SPLIT;
355
    }
356

    
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358

    
359
  public int getCubitVariant(int cubit, int[] numLayers)
360
    {
361
    return mCubitVariantMap[cubit];
362
    }
363

    
364
///////////////////////////////////////////////////////////////////////////////////////////////////
365

    
366
  public float[] getDist3D(int[] numLayers)
367
    {
368
    return TouchControlTetrahedron.D3D;
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

    
373
  public int[][] getBasicAngles()
374
    {
375
    if( mBasicAngle ==null )
376
      {
377
      int num = getNumLayers()[0];
378
      int[] tmp = new int[num];
379
      for(int i=0; i<num; i++) tmp[i] = 3;
380
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
381
      }
382

    
383
    return mBasicAngle;
384
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

    
388
  public float getStickerRadius()
389
    {
390
    return 0.10f;
391
    }
392

    
393
///////////////////////////////////////////////////////////////////////////////////////////////////
394

    
395
  public float getStickerStroke()
396
    {
397
    return isInIconMode() ? 0.16f : 0.08f;
398
    }
399

    
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401

    
402
  public float[][] getStickerAngles()
403
    {
404
    return null;
405
    }
406

    
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408

    
409
  public String getShortName()
410
    {
411
    if( mSignature==null ) mSignature = getSignature();
412
    int[] numLayers = getNumLayers();
413
    return "P"+numLayers[0]+"_"+mSignature.getString();
414
    }
415

    
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417

    
418
  public ObjectSignature getSignature()
419
    {
420
    if( mSignature==null )
421
      {
422
      int[] numLayers = getNumLayers();
423
      mSignature = new ObjectSignature(numLayers[0],mPosition);
424
      }
425
    return mSignature;
426
    }
427

    
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429

    
430
  public String getObjectName()
431
    {
432
    return OBJECT_NAME_PYRAMINX;
433
    }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

    
437
  public String getInventor()
438
    {
439
    return "??";
440
    }
441

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

    
444
  public int getYearOfInvention()
445
    {
446
    return 0;
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450

    
451
  public int getComplexity()
452
    {
453
    return 4;
454
    }
455

    
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457

    
458
  public String[][] getTutorials()
459
    {
460
    return null;
461
    }
462
}
(4-4/47)