Project

General

Profile

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

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

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 = "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)
70
    {
71
    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

    
77

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

    
80
  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
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

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

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

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

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

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

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
// PUBLIC API
122

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

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
// 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

    
132
  public int[][] getScrambleEdges()
133
    {
134
    return null;
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  @Override
140
  public float[][] returnRotationFactor()
141
    {
142
    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
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

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

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  @Override
162
  public int getScrambleType()
163
    {
164
    return ObjectScrambler.SCRAMBLING_BANDAGED;
165
    }
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
    int type = getType(variant);
181
    FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
182

    
183
    if( type>=0 )
184
      {
185
      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
      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
    int size = numLayers[0];
202
    boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode());
203
    int type = getType(variant);
204

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

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

    
214
      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

    
228
      return new ObjectVertexEffects(names,variables,vertices,regions,uses);
229
      }
230

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

    
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

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

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

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

    
252
      int numCubits = positions.length;
253
      mCubitVariantMap = new int[numCubits];
254

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

    
258
      for (int cubit=0; cubit<numCubits; cubit++)
259
        {
260
        int type = getType(positions[cubit]);
261

    
262
        switch (type)
263
          {
264
          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
          }
272
        }
273

    
274
      FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
275
      factory.prepare(mNumVariants,numLayers);
276
      }
277

    
278
    return mNumVariants;
279
    }
280

    
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

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

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

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

    
296
    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
      {
308
      int numL = numLayers[0];
309
      mCuts = new float[4][numL-1];
310

    
311
      for(int i=0; i<numL-1; i++)
312
        {
313
        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
      }
320

    
321
    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
    }
365

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

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

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
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
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

    
390
  public float getStickerRadius()
391
    {
392
    return 0.10f;
393
    }
394

    
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396

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

    
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403

    
404
  public float[][] getStickerAngles()
405
    {
406
    return null;
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410

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

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419
// TODO
420

    
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
}
(4-4/47)