Project

General

Profile

« Previous | Next » 

Revision 9ba7f3f6

Added by Leszek Koltunski over 1 year ago

Move scrambling to a new model where there are spearete scrambling 'algorithms' and 'edges' of the scrambling graph.
Now each edge can contain a whole algorithm, i.e. a sequence of moves leading from state to state, which permits construction of scrambling for more complicated bandaged objects such as the AI cube.

Unchecked as of yet, probably still a lot of bugs.

View differences:

src/main/java/org/distorted/objectlib/json/JsonReader.java
34 34

  
35 35
import org.distorted.objectlib.helpers.ObjectShape;
36 36
import org.distorted.objectlib.helpers.ObjectSticker;
37
import org.distorted.objectlib.scrambling.ScrambleState;
38 37
import org.distorted.objectlib.main.ObjectType;
39 38

  
40 39
///////////////////////////////////////////////////////////////////////////////////////////////////
41 40

  
42 41
public class JsonReader
43 42
{
44
  private ScrambleState[] mStates;
43
  private int[][] mAlgorithms;
44
  private int[][] mEdges;
45 45
  private int[][] mSolvedQuats;
46 46
  private Static4D[] mQuats;
47 47
  private int mSolvedFuncIndex;
......
441 441

  
442 442
    if( mScrambleType==0 )
443 443
      {
444
      JSONArray jsonStates = object.getJSONArray("scrambleStates");
445
      int numStates = jsonStates.length();
446
      mStates = new ScrambleState[numStates];
444
      JSONArray jsonAlgorithms = object.getJSONArray("algorithms");
445
      int numAlgs = jsonAlgorithms.length();
446
      mAlgorithms = new int[numAlgs][];
447 447

  
448
      for(int i=0; i<numStates; i++)
448
      for(int i=0; i<numAlgs; i++)
449 449
        {
450
        JSONArray jsonState = jsonStates.getJSONArray(i);
451
        int numAxis = jsonState.length();
452
        int[][] scramblingData = new int[numAxis][];
450
        JSONArray jsonAlg = jsonAlgorithms.getJSONArray(i);
451
        int numEntries = jsonAlg.length();
452
        for(int j=0; j<numEntries; j++) mAlgorithms[i][j] = jsonAlg.getInt(j);
453
        }
453 454

  
454
        for(int j=0; j<numAxis; j++)
455
          {
456
          JSONArray jsonData = jsonState.getJSONArray(j);
457
          int numData = jsonData.length();
458
          scramblingData[j] = new int[numData];
459
          for(int k=0; k<numData; k++) scramblingData[j][k] = jsonData.getInt(k);
460
          }
455
      JSONArray jsonEdges = object.getJSONArray("edges");
456
      int numEdges = jsonEdges.length();
457
      mEdges = new int[numEdges][];
461 458

  
462
        mStates[i] = new ScrambleState(scramblingData);
459
      for(int i=0; i<numEdges; i++)
460
        {
461
        JSONArray jsonEdge = jsonEdges.getJSONArray(i);
462
        int numEntries = jsonEdge.length();
463
        for(int j=0; j<numEntries; j++) mEdges[i][j] = jsonEdge.getInt(j);
463 464
        }
464 465
      }
465 466
    }
......
694 695

  
695 696
///////////////////////////////////////////////////////////////////////////////////////////////////
696 697

  
697
  public ScrambleState[] getScrambleStates()
698
  public int getScrambleType()
699
    {
700
    return mScrambleType;
701
    }
702

  
703
///////////////////////////////////////////////////////////////////////////////////////////////////
704

  
705
  public int[][] getScrambleEdges()
698 706
    {
699
    return mStates;
707
    return mEdges;
708
    }
709

  
710
///////////////////////////////////////////////////////////////////////////////////////////////////
711

  
712
  public int[][] getScrambleAlgorithms()
713
    {
714
    return mAlgorithms;
700 715
    }
701 716

  
702 717
///////////////////////////////////////////////////////////////////////////////////////////////////
......
980 995
    return mSize;
981 996
    }
982 997

  
983
///////////////////////////////////////////////////////////////////////////////////////////////////
984

  
985
  public int getScrambleType()
986
    {
987
    return mScrambleType;
988
    }
989

  
990 998
///////////////////////////////////////////////////////////////////////////////////////////////////
991 999

  
992 1000
  public int getColor(int face)
src/main/java/org/distorted/objectlib/json/JsonWriter.java
486 486
    {
487 487
    JSONObject scrambling = new JSONObject();
488 488

  
489
    ScrambleState[] states = object.getScrambleStates();
490 489
    int scrambleType = object.getScrambleType();
491 490
    scrambling.put("scrambleType",scrambleType );
491
    int[][] algorithms = object.getScrambleAlgorithms();
492 492

  
493
    if( states!=null )
493
    if( algorithms!=null )
494 494
      {
495
      JSONArray scrambleStates = new JSONArray();
495
      JSONArray scrambleAlgorithms = new JSONArray();
496 496

  
497
      for(ScrambleState state : states)
497
      for(int[] algorithm : algorithms)
498 498
        {
499
        JSONArray axisArray = new JSONArray();
500
        int numAxis = state.getNumAxis();
499
        JSONArray algArray = new JSONArray();
500
        for (int entry : algorithm) algArray.put(entry);
501
        scrambleAlgorithms.put(algArray);
502
        }
501 503

  
502
        for(int ax=0; ax<numAxis; ax++)
503
          {
504
          JSONArray axArray = new JSONArray();
505
          int[] axData = state.getAx(ax);
504
      scrambling.put("algorithms", scrambleAlgorithms);
505
      }
506 506

  
507
          if( axData!=null )
508
            for(int data : axData) axArray.put(data);
507
    int[][] edges = object.getScrambleEdges();
509 508

  
510
          axisArray.put(axArray);
511
          }
509
    if( edges!=null )
510
      {
511
      JSONArray scrambleEdges = new JSONArray();
512 512

  
513
        scrambleStates.put(axisArray);
513
      for(int[] edge : edges)
514
        {
515
        JSONArray edgeArray = new JSONArray();
516
        for (int entry : edge) edgeArray.put(entry);
517
        scrambleEdges.put(edgeArray);
514 518
        }
515 519

  
516
      scrambling.put("scrambleStates", scrambleStates);
520
      scrambling.put("edges", scrambleEdges);
517 521
      }
518 522

  
519 523
    return scrambling;
src/main/java/org/distorted/objectlib/main/ObjectType.java
186 186

  
187 187
  public static TwistyObject create(int ordinal, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream meshStream)
188 188
    {
189
    /*
190
    if( ordinal==CRA1_3.ordinal() )
189

  
190
    if( ordinal==CUBE_2.ordinal() )
191 191
      {
192
      return new TwistyCrazy3x3(objects[ordinal].mInitData,meshState,iconMode,quat,move,scale,meshStream);
192
      return new TwistyCuboid(objects[ordinal].mInitData,meshState,iconMode,quat,move,scale,meshStream);
193 193
      }
194
    */
194

  
195 195
    Class<? extends TwistyObject> clazz = objects[ordinal].mClass;
196 196

  
197 197
    try
src/main/java/org/distorted/objectlib/main/TwistyJson.java
159 159
    return mReader.getScrambleType();
160 160
    }
161 161

  
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

  
164
  @Override
165
  public int[][] getScrambleAlgorithms()
166
    {
167
    return mReader.getScrambleAlgorithms();
168
    }
169

  
162 170
///////////////////////////////////////////////////////////////////////////////////////////////////
163 171

  
164 172
  @Override
......
184 192

  
185 193
///////////////////////////////////////////////////////////////////////////////////////////////////
186 194

  
187
  public ScrambleState[] getScrambleStates()
195
  public int[][] getScrambleEdges()
188 196
    {
189
    return mReader.getScrambleStates();
197
    return mReader.getScrambleEdges();
190 198
    }
191 199

  
192 200
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/main/TwistyObject.java
239 239
    mBelongs = new boolean[mNumCubits];
240 240

  
241 241
    int scramblingType = getScrambleType();
242
    ScrambleState[] states = getScrambleStates();
243
    mScrambler = new ObjectScrambler(scramblingType, mNumAxis,mNumLayers,states);
242
    int[][] edges = getScrambleEdges();
243
    int[][] algorithms = getScrambleAlgorithms();
244

  
245
print_table("EDGES", edges);
246
print_table("ALGOS", algorithms);
247

  
248
    mScrambler = new ObjectScrambler(scramblingType,mNumAxis,mNumLayers,algorithms,edges);
244 249

  
245 250
    boolean bandaged=false;
246 251

  
......
287 292
    mNode = new DistortedNode(mTexture,mEffects,mMesh);
288 293
    }
289 294

  
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296

  
297
  private static void print_table(String mess, int[][] table)
298
    {
299
    android.util.Log.e("D", mess);
300

  
301
    int len = table.length;
302

  
303
    for(int i=0; i<len; i++)
304
      {
305
      String m = "";
306
      int l = table[i].length;
307
      for(int j=0; j<l; j++) m += (" "+table[i][j]);
308
      android.util.Log.e("D", m);
309
      }
310
    }
311

  
290 312
///////////////////////////////////////////////////////////////////////////////////////////////////
291 313

  
292 314
  private void createQuaternionEffects()
......
561 583
    return false;
562 584
    }
563 585

  
586
///////////////////////////////////////////////////////////////////////////////////////////////////
587

  
588
  public int[][] getScrambleAlgorithms()
589
    {
590
    int num=0;
591

  
592
    for (int[] basic : mBasicAngles)
593
      for (int i : basic) num += (i-1);
594

  
595
    int[][] ret = new int[num][3];
596
    int index = 0;
597

  
598
    for(int i=0; i<mNumAxis; i++)
599
      for(int j=0; j<mNumLayers[i]; j++)
600
        {
601
        int N = mBasicAngles[i][j];
602
        int NEG = (1-N)/2;
603
        int POS = N/2;
604

  
605
        for(int k=NEG; k<=-1; k++)
606
          {
607
          ret[index][0] = i;
608
          ret[index][1] = j;
609
          ret[index][2] = k;
610
          index++;
611
          }
612

  
613
        for(int k=1; k<=POS; k++)
614
          {
615
          ret[index][0] = i;
616
          ret[index][1] = j;
617
          ret[index][2] = k;
618
          index++;
619
          }
620
        }
621

  
622
    return ret;
623
    }
624

  
564 625
///////////////////////////////////////////////////////////////////////////////////////////////////
565 626

  
566 627
  private void createDataStructuresForSolved()
......
2184 2245
  public abstract int[][][] getEnabled();
2185 2246
  public abstract float[] getDist3D(int[] numLayers);
2186 2247
  public abstract Static3D[] getFaceAxis();
2187
  public abstract ScrambleState[] getScrambleStates();
2248
  public abstract int[][] getScrambleEdges();
2188 2249
  public abstract float[][] getCuts(int[] numLayers);
2189 2250
  public abstract float getStickerRadius();
2190 2251
  public abstract float getStickerStroke();
src/main/java/org/distorted/objectlib/objects/TwistyAxis.java
16 16
import org.distorted.objectlib.helpers.ObjectShape;
17 17
import org.distorted.objectlib.helpers.ObjectSignature;
18 18
import org.distorted.objectlib.helpers.ObjectVertexEffects;
19
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
19 20
import org.distorted.objectlib.main.InitData;
20
import org.distorted.objectlib.scrambling.ScrambleState;
21 21
import org.distorted.objectlib.main.ObjectType;
22 22
import org.distorted.objectlib.shape.ShapeHexahedron;
23 23
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
......
38 38
           new Static3D( 2.0f/3, 2.0f/3, 1.0f/3),
39 39
         };
40 40

  
41
  private ScrambleState[] mStates;
41
  private int[][] mEdges;
42 42
  private int[][] mBasicAngle;
43 43
  private float[][] mCuts;
44 44
  private float[][] mCenters;
......
60 60
    }
61 61

  
62 62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
// same as in a 3x3
64 63

  
65
  public ScrambleState[] getScrambleStates()
64
  public int[][] getScrambleEdges()
66 65
    {
67
    if( mStates==null )
68
      {
69
      int[][] m = new int[16][];
70

  
71
      for(int i=0; i<16; i++) m[i] = new int[] { 0,-1,i,0,1,i,0,2,i, 1,-1,i,1,1,i,1,2,i, 2,-1,i,2,1,i,2,2,i};
72

  
73
      mStates = new ScrambleState[]
74
          {
75
          new ScrambleState( new int[][] { m[ 1], m[ 2], m[ 3] } ),  //  0 0
76
          new ScrambleState( new int[][] {  null, m[ 4], m[ 5] } ),  //  1 x
77
          new ScrambleState( new int[][] { m[ 6],  null, m[ 7] } ),  //  2 y
78
          new ScrambleState( new int[][] { m[ 8], m[ 9],  null } ),  //  3 z
79
          new ScrambleState( new int[][] { m[10],  null, m[ 7] } ),  //  4 xy
80
          new ScrambleState( new int[][] { m[11], m[ 9],  null } ),  //  5 xz
81
          new ScrambleState( new int[][] {  null, m[12], m[ 5] } ),  //  6 yx
82
          new ScrambleState( new int[][] { m[ 8], m[13],  null } ),  //  7 yz
83
          new ScrambleState( new int[][] {  null, m[ 4], m[14] } ),  //  8 zx
84
          new ScrambleState( new int[][] { m[ 6],  null, m[15] } ),  //  9 zy
85
          new ScrambleState( new int[][] {  null,  null, m[ 5] } ),  // 10 xyx
86
          new ScrambleState( new int[][] {  null, m[ 4],  null } ),  // 11 xzx
87
          new ScrambleState( new int[][] {  null,  null, m[ 7] } ),  // 12 yxy
88
          new ScrambleState( new int[][] { m[ 6],  null,  null } ),  // 13 yzy
89
          new ScrambleState( new int[][] {  null, m[ 9],  null } ),  // 14 zxz
90
          new ScrambleState( new int[][] { m[ 8],  null,  null } ),  // 15 zyz
91
          };
92
      }
93

  
94
    return mStates;
66
    if( mEdges==null ) ScrambleEdgeGenerator.getScrambleEdgesCuboid(3,3,3);
67
    return mEdges;
95 68
    }
96 69

  
97 70
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyBandagedAbstract.java
16 16
import org.distorted.objectlib.helpers.ObjectShape;
17 17
import org.distorted.objectlib.helpers.ObjectSignature;
18 18
import org.distorted.objectlib.main.InitData;
19
import org.distorted.objectlib.scrambling.ScrambleState;
20 19
import org.distorted.objectlib.shape.ShapeHexahedron;
21 20
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
22 21

  
......
168 167
// Computing scramble states of many a bandaged cubes takes way too long time and too much space.
169 168
// Return null here and turn to construction of scramble tables just-in-time.
170 169

  
171
  @Override
172
  public ScrambleState[] getScrambleStates()
170
  public int[][] getScrambleEdges()
173 171
    {
174 172
    return null;
175 173
    }
src/main/java/org/distorted/objectlib/objects/TwistyCamouflage.java
367 367

  
368 368
  public String getObjectName()
369 369
    {
370
    int[] nL = getNumLayers();
371
    return "Camouflage "+nL[0]+"x"+nL[1]+"x"+nL[2];
370
    if( mPosition==null ) mPosition = getInitData().getPos();
371

  
372
    if( mPosition==CAM_333 ) return "Camouflage 3x3x3";
373

  
374
    return "Camouflage";
372 375
    }
373 376

  
374 377
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyContainer.java
18 18
import org.distorted.objectlib.helpers.ObjectShape;
19 19
import org.distorted.objectlib.helpers.ObjectSignature;
20 20
import org.distorted.objectlib.helpers.ObjectVertexEffects;
21
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
21 22
import org.distorted.objectlib.main.InitData;
22
import org.distorted.objectlib.scrambling.ScrambleState;
23 23
import org.distorted.objectlib.main.ObjectType;
24 24
import org.distorted.objectlib.shape.ShapeHexahedron;
25 25
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
......
39 39
           new Static3D(  0.0f, SQ3/3, SQ6/3)
40 40
         };
41 41

  
42
  private ScrambleState[] mStates;
42
  private int[][] mEdges;
43 43
  private int[][] mBasicAngle;
44 44
  private float[][] mCuts;
45 45
  private int[][] mFaceMap;
......
85 85

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

  
88
  public ScrambleState[] getScrambleStates()
88
  public int[][] getScrambleEdges()
89 89
    {
90
    if( mStates==null )
91
      {
92
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
93

  
94
      mStates = new ScrambleState[]
95
        {
96
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
97
        };
98
      }
99

  
100
    return mStates;
90
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
91
    return mEdges;
101 92
    }
102 93

  
103 94
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyCrazy2x2.java
18 18
import org.distorted.objectlib.helpers.ObjectShape;
19 19
import org.distorted.objectlib.helpers.ObjectSignature;
20 20
import org.distorted.objectlib.helpers.ObjectVertexEffects;
21
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
21 22
import org.distorted.objectlib.main.Cubit;
22 23
import org.distorted.objectlib.main.InitData;
23 24
import org.distorted.objectlib.main.ObjectType;
24 25
import org.distorted.objectlib.shape.ShapeHexahedron;
25
import org.distorted.objectlib.scrambling.ScrambleState;
26 26
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
27 27

  
28 28
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
......
43 43
           new Static3D(0,0,1)
44 44
         };
45 45

  
46
  private ScrambleState[] mStates;
46
  private int[][] mEdges;
47 47
  private int[][] mBasicAngle;
48 48
  private float[][] mCuts;
49 49
  private float[][] mPositions;
......
108 108
    }
109 109

  
110 110
///////////////////////////////////////////////////////////////////////////////////////////////////
111
// Normal 2x2
112 111

  
113
  public ScrambleState[] getScrambleStates()
112
  public int[][] getScrambleEdges()
114 113
    {
115
    if( mStates==null )
116
      {
117
      int[] m = new int[] { 0,-1,0,0,1,0,0,2,0, 1,-1,0,1,1,0,1,2,0 };
118

  
119
      mStates = new ScrambleState[]
120
          {
121
          new ScrambleState( new int[][] { m,m,m } )
122
          };
123
      }
124

  
125
    return mStates;
114
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
115
    return mEdges;
126 116
    }
127 117

  
128 118
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyCrazy3x3.java
20 20
import org.distorted.objectlib.helpers.ObjectSignature;
21 21
import org.distorted.objectlib.helpers.ObjectStickerOverride;
22 22
import org.distorted.objectlib.helpers.ObjectVertexEffects;
23
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
23 24
import org.distorted.objectlib.main.Cubit;
24 25
import org.distorted.objectlib.main.InitData;
25 26
import org.distorted.objectlib.main.ObjectType;
26 27
import org.distorted.objectlib.shape.ShapeHexahedron;
27
import org.distorted.objectlib.scrambling.ScrambleState;
28 28
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
29 29

  
30 30
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
......
56 56
           new Static3D(0,0,1)
57 57
         };
58 58

  
59
  private ScrambleState[] mStates;
59
  private int[][] mEdges;
60 60
  private int[][] mBasicAngle;
61 61
  private float[][] mCuts;
62 62
  private float[][] mPositions;
......
185 185
    }
186 186

  
187 187
///////////////////////////////////////////////////////////////////////////////////////////////////
188
// Normal 3x3
189 188

  
190
  public ScrambleState[] getScrambleStates()
189
  public int[][] getScrambleEdges()
191 190
    {
192
    if( mStates==null )
193
      {
194
      int[][] m = new int[16][];
195

  
196
      for(int i=0; i<16; i++) m[i] = new int[] { 0,-1,i,0,1,i,0,2,i, 1,-1,i,1,1,i,1,2,i, 2,-1,i,2,1,i,2,2,i};
197

  
198
      mStates = new ScrambleState[]
199
          {
200
          new ScrambleState( new int[][] { m[ 1], m[ 2], m[ 3] } ),  //  0 0
201
          new ScrambleState( new int[][] {  null, m[ 4], m[ 5] } ),  //  1 x
202
          new ScrambleState( new int[][] { m[ 6],  null, m[ 7] } ),  //  2 y
203
          new ScrambleState( new int[][] { m[ 8], m[ 9],  null } ),  //  3 z
204
          new ScrambleState( new int[][] { m[10],  null, m[ 7] } ),  //  4 xy
205
          new ScrambleState( new int[][] { m[11], m[ 9],  null } ),  //  5 xz
206
          new ScrambleState( new int[][] {  null, m[12], m[ 5] } ),  //  6 yx
207
          new ScrambleState( new int[][] { m[ 8], m[13],  null } ),  //  7 yz
208
          new ScrambleState( new int[][] {  null, m[ 4], m[14] } ),  //  8 zx
209
          new ScrambleState( new int[][] { m[ 6],  null, m[15] } ),  //  9 zy
210
          new ScrambleState( new int[][] {  null,  null, m[ 5] } ),  // 10 xyx
211
          new ScrambleState( new int[][] {  null, m[ 4],  null } ),  // 11 xzx
212
          new ScrambleState( new int[][] {  null,  null, m[ 7] } ),  // 12 yxy
213
          new ScrambleState( new int[][] { m[ 6],  null,  null } ),  // 13 yzy
214
          new ScrambleState( new int[][] {  null, m[ 9],  null } ),  // 14 zxz
215
          new ScrambleState( new int[][] { m[ 8],  null,  null } ),  // 15 zyz
216
          };
217
      }
218

  
219
    return mStates;
191
    if( mEdges==null ) ScrambleEdgeGenerator.getScrambleEdgesCuboid(3,3,3);
192
    return mEdges;
220 193
    }
221 194

  
222 195
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyCrystal.java
23 23

  
24 24
///////////////////////////////////////////////////////////////////////////////////////////////////
25 25

  
26
public class TwistyCrystal extends TwistyMinx
26
public class TwistyCrystal extends TwistyDodecahedron
27 27
{
28 28
  private static final float A = (SQ5+5)/10;
29 29

  
src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java
21 21
import org.distorted.objectlib.helpers.ObjectFaceShape;
22 22
import org.distorted.objectlib.helpers.ObjectSignature;
23 23
import org.distorted.objectlib.helpers.ObjectVertexEffects;
24
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
24 25
import org.distorted.objectlib.main.InitData;
25 26
import org.distorted.objectlib.touchcontrol.TouchControlCuboids;
26 27
import org.distorted.objectlib.main.ObjectType;
27 28
import org.distorted.objectlib.helpers.ObjectShape;
28
import org.distorted.objectlib.scrambling.ScrambleState;
29 29
import org.distorted.objectlib.shape.ShapeHexahedron;
30 30

  
31 31
///////////////////////////////////////////////////////////////////////////////////////////////////
......
39 39
           new Static3D(0,0,1)
40 40
         };
41 41

  
42
  private ScrambleState[] mStates;
42
  private int[][] mEdges;
43 43
  private float[][] mCuts;
44 44
  private int[][] mBasicAngle;
45 45

  
......
88 88

  
89 89
///////////////////////////////////////////////////////////////////////////////////////////////////
90 90

  
91
  private int[] createEdges(int size, boolean full, int vertex)
91
  public int[][] getScrambleEdges()
92 92
    {
93
    if( size==1 ) return null;
94

  
95
    if( full )
96
      {
97
      int[] ret = new int[9*size];
98

  
99
      for(int l=0; l<size; l++)
100
        {
101
        ret[9*l  ] = l;
102
        ret[9*l+1] =-1;
103
        ret[9*l+2] = vertex;
104
        ret[9*l+3] = l;
105
        ret[9*l+4] = 1;
106
        ret[9*l+5] = vertex;
107
        ret[9*l+6] = l;
108
        ret[9*l+7] = 2;
109
        ret[9*l+8] = vertex;
110
        }
111

  
112
      return ret;
113
      }
114
    else
115
      {
116
      int[] ret = new int[6*size];
117

  
118
      for(int l=0; l<size; l++)
119
        {
120
        ret[6*l  ] = l;
121
        ret[6*l+1] = 1;
122
        ret[6*l+2] = vertex;
123
        ret[6*l+3] = l;
124
        ret[6*l+4] =-1;
125
        ret[6*l+5] = vertex;
126
        }
127

  
128
      return ret;
129
      }
130
    }
131

  
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

  
134
  public ScrambleState[] getScrambleStates()
135
    {
136
    if( mStates==null )
93
    if( mEdges==null )
137 94
      {
138 95
      int[] numLayers = getNumLayers();
139 96

  
......
141 98
      int Y = numLayers[1];
142 99
      int Z = numLayers[2];
143 100

  
144
      int[][] mX = new int[16][];
145
      int[][] mY = new int[16][];
146
      int[][] mZ = new int[16][];
147

  
148
      for(int i=0; i<16; i++)
149
        {
150
        mX[i] = createEdges(X,Y==Z,i);
151
        mY[i] = createEdges(Y,X==Z,i);
152
        mZ[i] = createEdges(Z,X==Y,i);
153
        }
154

  
155 101
      if( X>1 && Y>1 && Z>1 )
156 102
        {
157
        mStates = new ScrambleState[]
158
          {
159
          new ScrambleState( new int[][] { mX[ 1], mY[ 2], mZ[ 3] } ),  //  0 0
160
          new ScrambleState( new int[][] {   null, mY[ 4], mZ[ 5] } ),  //  1 x
161
          new ScrambleState( new int[][] { mX[ 6],   null, mZ[ 7] } ),  //  2 y
162
          new ScrambleState( new int[][] { mX[ 8], mY[ 9],   null } ),  //  3 z
163
          new ScrambleState( new int[][] { mX[10],   null, mZ[ 7] } ),  //  4 xy
164
          new ScrambleState( new int[][] { mX[11], mY[ 9],   null } ),  //  5 xz
165
          new ScrambleState( new int[][] {   null, mY[12], mZ[ 5] } ),  //  6 yx
166
          new ScrambleState( new int[][] { mX[ 8], mY[13],   null } ),  //  7 yz
167
          new ScrambleState( new int[][] {   null, mY[ 4], mZ[14] } ),  //  8 zx
168
          new ScrambleState( new int[][] { mX[ 6],   null, mZ[15] } ),  //  9 zy
169
          new ScrambleState( new int[][] {   null,   null, mZ[ 5] } ),  // 10 xyx
170
          new ScrambleState( new int[][] {   null, mY[ 4],   null } ),  // 11 xzx
171
          new ScrambleState( new int[][] {   null,   null, mZ[ 7] } ),  // 12 yxy
172
          new ScrambleState( new int[][] { mX[ 6],   null,   null } ),  // 13 yzy
173
          new ScrambleState( new int[][] {   null, mY[ 9],   null } ),  // 14 zxz
174
          new ScrambleState( new int[][] { mX[ 8],   null,   null } ),  // 15 zyz
175
          };
176
        }
177
      else if( X==1 && Y==1 && Z==1 )
178
        {
179
        int[] state = new int[] {0,-1,0,0,1,0,0,2,0};
180

  
181
        mStates = new ScrambleState[]
182
          {
183
          new ScrambleState( new int[][] { state, state, state } )
184
          };
103
        mEdges = ScrambleEdgeGenerator.getScrambleEdgesCuboid(X,Y,Z);
185 104
        }
186 105
      else
187 106
        {
188
        mStates = new ScrambleState[]
107
        int size = 3*(X+Y+Z);
108
        int[] edge = new int[2*size];
109

  
110
        for(int i=0; i<size; i++)
189 111
          {
190
          new ScrambleState( new int[][] { mX[ 0], mY[ 0], mZ[ 0] } )
191
          };
192
        }
112
          edge[2*i  ] = i;
113
          edge[2*i+1] = 0;
114
          }
193 115

  
116
        mEdges = new int[][] { edge };
117
        }
194 118
      }
195 119

  
196
    return mStates;
120
    return mEdges;
197 121
    }
198 122

  
199 123
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyDiamond.java
21 21
import org.distorted.objectlib.helpers.ObjectFaceShape;
22 22
import org.distorted.objectlib.helpers.ObjectSignature;
23 23
import org.distorted.objectlib.helpers.ObjectVertexEffects;
24
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
24 25
import org.distorted.objectlib.main.InitData;
25 26
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
26 27
import org.distorted.objectlib.main.ObjectType;
27 28
import org.distorted.objectlib.helpers.ObjectShape;
28
import org.distorted.objectlib.scrambling.ScrambleState;
29 29
import org.distorted.objectlib.shape.ShapeOctahedron;
30 30

  
31 31
///////////////////////////////////////////////////////////////////////////////////////////////////
......
41 41
           new Static3D(     0,-SQ3/3, SQ6/3)
42 42
         };
43 43

  
44
  private ScrambleState[] mStates;
44
  private int[][] mEdges;
45 45
  private int[][] mBasicAngle;
46 46
  private float[][] mCuts;
47 47
  private int[] mTetraToFaceMap;
......
56 56

  
57 57
///////////////////////////////////////////////////////////////////////////////////////////////////
58 58

  
59
  public ScrambleState[] getScrambleStates()
59
  public int[][] getScrambleEdges()
60 60
    {
61
    if( mStates==null )
62
      {
63
      int[] numLayers = getNumLayers();
64
      int numL = numLayers[0];
65
      int[] tmp = new int[3*2*numL];
66

  
67
      for(int i=0; i<2*numL; i++)
68
        {
69
        tmp[3*i  ] = (i<numL) ?  i:i-numL;
70
        tmp[3*i+1] = (i%2==0) ? -1:1;
71
        tmp[3*i+2] = 0;
72
        }
73

  
74
      mStates = new ScrambleState[]
75
        {
76
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
77
        };
78
      }
79

  
80
    return mStates;
61
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
62
    return mEdges;
81 63
    }
82 64

  
83 65
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyDino.java
22 22
import org.distorted.objectlib.helpers.ObjectShape;
23 23
import org.distorted.objectlib.helpers.ObjectVertexEffects;
24 24
import org.distorted.objectlib.main.InitData;
25
import org.distorted.objectlib.scrambling.ScrambleState;
26 25
import org.distorted.objectlib.shape.ShapeHexahedron;
27 26
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
28 27

  
......
41 40
  private int[][] mBasicAngle;
42 41
  private float[][] mCuts;
43 42
  private float[][] mCenters;
44
  ScrambleState[] mStates;
45 43
  private int[] mQuatIndex;
44
  int[][] mEdges;
46 45

  
47 46
///////////////////////////////////////////////////////////////////////////////////////////////////
48 47

  
src/main/java/org/distorted/objectlib/objects/TwistyDino4.java
67 67

  
68 68
///////////////////////////////////////////////////////////////////////////////////////////////////
69 69

  
70
  public ScrambleState[] getScrambleStates()
70
  public int[][] getScrambleEdges()
71 71
    {
72
    if( mStates==null )
72
    if( mEdges==null )
73 73
      {
74
      mStates = new ScrambleState[]
74
      mEdges = new int[][]
75 75
        {
76
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5              },{              2,1,8,2,-1,8} } ),
77
        new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
78
        new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
79
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
80
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
81
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
82
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
83
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
84
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
76
          {          2,1,3,1, 4,7,5,7,          8,6,9,6,                      14,4,15,4 },  // 0
77
          {                            6,2,7,2,          10,3,11,3, 12,5,13,5           },  // 1
78
          {          2,1,3,1,                   8,6,9,6,                      14,4,15,4 },  // 2
79
          {          2,1,3,1, 4,7,5,7,                                        14,4,15,4 },  // 3
80
          { 0,8,1,8,                   6,2,7,2,          10,3,11,3                      },  // 4
81
          {          2,1,3,1, 4,7,5,7,          8,6,9,6                                 },  // 5
82
          { 0,8,1,8,                   6,2,7,2,                     12,5,13,5           },  // 6
83
          { 0,8,1,8,                                     10,3,11,3, 12,5,13,5           },  // 7
84
          {                   4,7,5,7,          8,6,9,6,                      14,4,15,4 },  // 8
85 85
        };
86 86
      }
87 87

  
88
    return mStates;
88
    return mEdges;
89 89
    }
90 90

  
91 91
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyDino6.java
43 43

  
44 44
///////////////////////////////////////////////////////////////////////////////////////////////////
45 45

  
46
  public ScrambleState[] getScrambleStates()
46
  public int[][] getScrambleEdges()
47 47
    {
48
    if( mStates==null )
48
    if( mEdges==null )
49 49
      {
50
      mStates = new ScrambleState[]
50
      mEdges = new int[][]
51 51
        {
52
        new ScrambleState( new int[][] { {0,1,1,0,-1,1, 2,1,2,2,-1,2},{0,1,3,0,-1,3, 2,1,4,2,-1,4},{0,1,5,0,-1,5, 2,1,6,2,-1,6},{0,1,7,0,-1,7, 2,1,8,2,-1,8} } ),
53
        new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
54
        new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
55
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
56
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
57
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
58
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
59
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
60
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
52
          { 0,8,1,8, 2,1,3,1, 4,7,5,7, 6,2,7,2, 8,6,9,6, 10,3,11,3, 12,5,13,5, 14,4,15,4 },  // 0
53
          {                            6,2,7,2,          10,3,11,3, 12,5,13,5            },  // 1
54
          {          2,1,3,1,                   8,6,9,6,                       14,4,15,4 },  // 2
55
          {          2,1,3,1, 4,7,5,7,                                         14,4,15,4 },  // 3
56
          { 0,8,1,8,                   6,2,7,2,          10,3,11,3                       },  // 4
57
          {          2,1,3,1, 4,7,5,7,          8,6,9,6                                  },  // 5
58
          { 0,8,1,8,                   6,2,7,2,                     12,5,13,5            },  // 6
59
          { 0,8,1,8,                                     10,3,11,3, 12,5,13,5            },  // 7
60
          {                   4,7,5,7,          8,6,9,6,                       14,4,15,4 },  // 8
61 61
        };
62 62
      }
63 63

  
64
    return mStates;
64
    return mEdges;
65 65
    }
66 66

  
67 67
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyDodecahedron.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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_DODECAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_EDGE;
14
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.C2;
15
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.LEN;
16
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.SIN54;
17

  
18
import java.io.InputStream;
19

  
20
import org.distorted.library.type.Static3D;
21
import org.distorted.library.type.Static4D;
22
import org.distorted.objectlib.main.InitData;
23
import org.distorted.objectlib.touchcontrol.TouchControlDodecahedron;
24
import org.distorted.objectlib.shape.ShapeDodecahedron;
25

  
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

  
28
abstract class TwistyDodecahedron extends ShapeDodecahedron
29
{
30
  static final int NUM_CORNERS = 20;
31
  static final int NUM_CENTERS = 12;
32
  static final int NUM_EDGES   = 30;
33

  
34
  static final float SIN18    = (SQ5-1)/4;
35
  static final float COS18    = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
36
  static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
37
  static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
38

  
39
  // the six rotation axis of a Minx. Must be normalized.
40
  static final Static3D[] ROT_AXIS = new Static3D[]
41
         {
42
           new Static3D(    C2/LEN, SIN54/LEN,    0      ),
43
           new Static3D(   -C2/LEN, SIN54/LEN,    0      ),
44
           new Static3D( 0        ,    C2/LEN, SIN54/LEN ),
45
           new Static3D( 0        ,   -C2/LEN, SIN54/LEN ),
46
           new Static3D( SIN54/LEN,    0     ,    C2/LEN ),
47
           new Static3D( SIN54/LEN,    0     ,   -C2/LEN )
48
         };
49

  
50
  private int[][] mBasicAngle;
51
  private float[][] mCuts;
52
  float[][] mCenterCoords,mCorners;
53
  int[] mQuatEdgeIndices,mQuatCornerIndices;
54
  int[][] mEdgeMap,mCenterMap;
55
  Static4D[] mBasicCornerV, mCurrCornerV;
56
  int[][] mEdges;
57

  
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

  
60
  TwistyDodecahedron(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
61
    {
62
    super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
63
    }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
  public int[][] getScrambleEdges()
68
    {
69
    if( mEdges==null )
70
      {
71
      int[] numLayers = getNumLayers();
72
      initializeScrambleEdges(numLayers[0]);
73
      }
74

  
75
    return mEdges;
76
    }
77

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

  
80
  void initializeCornerV()
81
    {
82
    mBasicCornerV = new Static4D[3];
83
    mCurrCornerV  = new Static4D[3];
84

  
85
    mBasicCornerV[0] = new Static4D( (SQ5+1)*0.375f, (SQ5-1)*0.375f, -0.750f, 0.0f );
86
    mBasicCornerV[1] = new Static4D(-(SQ5+1)*0.375f, (SQ5-1)*0.375f, -0.750f, 0.0f );
87
    mBasicCornerV[2] = new Static4D(              0,        -1.500f,    0.0f, 0.0f );
88
    }
89

  
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91
// the five vertices that form a given face. Order: the same as colors of the faces in TwistyMinx.
92

  
93
  void initializeCenterMap()
94
    {
95
    mCenterMap = new int[][]
96
         {
97
           { 0, 12,  8, 10, 16},
98
           { 0, 12,  4, 14,  2},
99
           { 0,  2, 18,  6, 16},
100
           { 6, 18, 11, 19,  7},
101
           { 3, 15,  9, 11, 19},
102
           { 4,  5, 15,  9, 14},
103
           { 1, 13,  5, 15,  3},
104
           { 1,  3, 19,  7, 17},
105
           {10, 16,  6,  7, 17},
106
           { 8, 13,  5,  4, 12},
107
           { 1, 13,  8, 10, 17},
108
           { 2, 14,  9, 11, 18},
109
         };
110
    }
111

  
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
// the quadruple ( corner1, corner2, face1, face2 ) defining an edge.
114
// In fact the 2 corners already define it, the faces only provide easy
115
// way to get to know the colors. Order: arbitrary. Face1 arbitrarily on
116
// the 'left' or right of vector corner1 --> corner2, according to Quat.
117

  
118
  void initializeEdgeMap()
119
    {
120
    mEdgeMap = new int[][]
121
         {
122
           {  2,  0,  1,  2}, //0
123
           {  0, 12,  1,  0},
124
           { 12,  4,  1,  9},
125
           {  4, 14,  1,  5},
126
           { 14,  2,  1, 11},
127
           { 14,  9, 11,  5}, //5
128
           {  9, 11, 11,  4},
129
           { 11, 18, 11,  3},
130
           { 18,  2, 11,  2},
131
           { 18,  6,  2,  3},
132
           {  6, 16,  2,  8}, //10
133
           { 16,  0,  2,  0},
134
           { 16, 10,  0,  8},
135
           { 10,  8,  0, 10},
136
           {  8, 12,  0,  9},
137
           {  8, 13,  9, 10}, //15
138
           { 13,  5,  9,  6},
139
           {  5,  4,  9,  5},
140
           {  5, 15,  5,  6},
141
           { 15,  9,  5,  4},
142
           { 11, 19,  3,  4}, //20
143
           { 19,  7,  3,  7},
144
           {  7,  6,  3,  8},
145
           {  7, 17,  8,  7},
146
           { 17, 10,  8, 10},
147
           { 17,  1, 10,  7}, //25
148
           {  1,  3,  6,  7},
149
           {  3, 19,  4,  7},
150
           {  1, 13, 10,  6},
151
           {  3, 15,  6,  4},
152
         };
153
    }
154

  
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

  
157
  void initializeQuatIndices()
158
    {
159
    mQuatEdgeIndices = new int[]
160
      {
161
         0, 17, 18, 19, 20, 56, 25,  5, 24, 16,
162
         9, 44,  1, 34, 35, 27, 41, 50, 26, 54,
163
        15, 49, 39, 28, 10,  2, 48,  6, 46,  3
164
      };
165
    mQuatCornerIndices = new int[]
166
      {
167
         0, 29, 59, 48, 18, 53, 22, 49, 11, 54,
168
        10, 52, 17, 27, 19, 26,  9, 28, 23, 45
169
      };
170
    }
171

  
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173
// Coordinates of all 20 corners of a Minx
174

  
175
  void initializeCorners()
176
    {
177
    float cA = 1.5f;
178
    float cB = 3*C2;
179
    float cC = 3*SIN54;
180

  
181
    mCorners = new float[][]
182
         {
183
             {  0, cA, cB},
184
             {  0, cA,-cB},
185
             {  0,-cA, cB},
186
             {  0,-cA,-cB},
187
             { cB,  0, cA},
188
             { cB,  0,-cA},
189
             {-cB,  0, cA},
190
             {-cB,  0,-cA},
191
             { cA, cB,  0},
192
             { cA,-cB,  0},
193
             {-cA, cB,  0},
194
             {-cA,-cB,  0},
195
             { cC, cC, cC},
196
             { cC, cC,-cC},
197
             { cC,-cC, cC},
198
             { cC,-cC,-cC},
199
             {-cC, cC, cC},
200
             {-cC, cC,-cC},
201
             {-cC,-cC, cC},
202
             {-cC,-cC,-cC},
203
         };
204
    }
205

  
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

  
208
  void initializeCenterCoords()
209
    {
210
    if( mCorners==null ) initializeCorners();
211
    if( mCenterMap==null ) initializeCenterMap();
212

  
213
    mCenterCoords = new float[NUM_CENTERS][3];
214

  
215
    for(int center=0; center<NUM_CENTERS; center++)
216
      {
217
      int[] map = mCenterMap[center];
218

  
219
      float x = mCorners[map[0]][0] +
220
                mCorners[map[1]][0] +
221
                mCorners[map[2]][0] +
222
                mCorners[map[3]][0] +
223
                mCorners[map[4]][0] ;
224

  
225
      float y = mCorners[map[0]][1] +
226
                mCorners[map[1]][1] +
227
                mCorners[map[2]][1] +
228
                mCorners[map[3]][1] +
229
                mCorners[map[4]][1] ;
230

  
231
      float z = mCorners[map[0]][2] +
232
                mCorners[map[1]][2] +
233
                mCorners[map[2]][2] +
234
                mCorners[map[3]][2] +
235
                mCorners[map[4]][2] ;
236

  
237
      mCenterCoords[center][0] = x/5;
238
      mCenterCoords[center][1] = y/5;
239
      mCenterCoords[center][2] = z/5;
240
      }
241
    }
242

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
  private void fillRet(int[] table, int index, int count, int startMove, int graphVertex)
246
    {
247
    int num = count/2;
248
    int move= startMove*num;
249

  
250
    for(int i=0; i<num; i++)
251
      {
252
      table[index+2*i  ] = move++;
253
      table[index+2*i+1] = graphVertex;
254
      }
255
    }
256

  
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

  
259
  private int[] genEdge(int numLayers, int x0, int x1, int x2, int x3, int x4, int x5,
260
                                       int x6, int x7, int x8, int x9, int x10,int x11)
261
    {
262
    int layers = (numLayers-1)/2;
263
    int num = 8*layers;
264
    int size = 0;
265

  
266
    if( x0 >=0 ) size += num;
267
    if( x1 >=0 ) size += num;
268
    if( x2 >=0 ) size += num;
269
    if( x3 >=0 ) size += num;
270
    if( x4 >=0 ) size += num;
271
    if( x5 >=0 ) size += num;
272
    if( x6 >=0 ) size += num;
273
    if( x7 >=0 ) size += num;
274
    if( x8 >=0 ) size += num;
275
    if( x9 >=0 ) size += num;
276
    if( x10>=0 ) size += num;
277
    if( x11>=0 ) size += num;
278

  
279
    int[] ret = new int[size];
280
    int index = 0;
281

  
282
    if( x0 >=0 ) { fillRet(ret,index,num,0 ,x0 ); index+=num; }
283
    if( x1 >=0 ) { fillRet(ret,index,num,1 ,x1 ); index+=num; }
284
    if( x2 >=0 ) { fillRet(ret,index,num,2 ,x2 ); index+=num; }
285
    if( x3 >=0 ) { fillRet(ret,index,num,3 ,x3 ); index+=num; }
286
    if( x4 >=0 ) { fillRet(ret,index,num,4 ,x4 ); index+=num; }
287
    if( x5 >=0 ) { fillRet(ret,index,num,5 ,x5 ); index+=num; }
288
    if( x6 >=0 ) { fillRet(ret,index,num,6 ,x6 ); index+=num; }
289
    if( x7 >=0 ) { fillRet(ret,index,num,7 ,x7 ); index+=num; }
290
    if( x8 >=0 ) { fillRet(ret,index,num,8 ,x8 ); index+=num; }
291
    if( x9 >=0 ) { fillRet(ret,index,num,9 ,x9 ); index+=num; }
292
    if( x10>=0 ) { fillRet(ret,index,num,10,x10); index+=num; }
293
    if( x11>=0 ) { fillRet(ret,index,num,11,x11);             }
294

  
295
    return ret;
296
    }
297

  
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

  
300
  private void initializeScrambleEdges(int numLayers)
301
    {
302
    mEdges = new int[][]
303
      {
304
      genEdge(numLayers, 1, 2,  3, 4,  5, 6,  7, 8,  9,10, 11,12),  // 0
305
      genEdge(numLayers,-1,-1, -1, 4,  5,-1, -1, 8,  9,-1, 11,-1),  // 0L
306
      genEdge(numLayers,-1,-1,  3,-1, -1, 6,  7,-1, -1,10, -1,12),  // 0R
307
      genEdge(numLayers,-1, 2, -1,-1,  5,-1, -1, 8, -1,10, -1,12),  // 1L
308
      genEdge(numLayers, 1,-1, -1,-1, -1, 6,  7,-1,  9,-1, 11,-1),  // 1R
309
      genEdge(numLayers, 1,-1,  3,-1, -1,-1, -1, 8,  9,-1, -1,12),  // 2L
310
      genEdge(numLayers,-1, 2, -1, 4, -1,-1,  7,-1, -1,10, 11,-1),  // 2R
311
      genEdge(numLayers,-1, 2, -1, 4, -1, 6, -1,-1,  9,-1, -1,12),  // 3L
312
      genEdge(numLayers, 1,-1,  3,-1,  5,-1, -1,-1, -1,10, 11,-1),  // 3R
313
      genEdge(numLayers, 1,-1, -1, 4,  5,-1,  7,-1, -1,-1, -1,12),  // 4L
314
      genEdge(numLayers,-1, 2,  3,-1,  5,-1, -1, 8, -1,-1, 11,-1),  // 4R
315
      genEdge(numLayers, 1,-1, -1, 4, -1, 6, -1, 8, -1,10, -1,-1),  // 5L
316
      genEdge(numLayers,-1, 2,  3,-1,  5,-1,  7,-1,  9,-1, -1,-1),  // 5R
317
      };
318
    }
319

  
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321

  
322
  float[][] genericGetCuts(int numLayers, float dist)
323
    {
324
    if( mCuts==null )
325
      {
326
      mCuts = new float[6][numLayers-1];
327
      float D = numLayers* TouchControlDodecahedron.DIST3D;
328
      float X = 2*D/(2+SIN18);  // height of the 'upper' part of a dodecahedron, i.e. put it on a table,
329
                                // its height is then 2D, it has one 'lower' part of height X, one
330
                                // 'middle' part of height Y and one upper part of height X again.
331
      int num = (numLayers-1)/2;
332
      float G = X*dist/num;     // height of one Layer
333

  
334
      for(int i=0; i<num; i++)
335
        {
336
        float cut = -D + (i+0.85f)*G;  // 0.85? not fully correct; attempt to make it
337
                                       // easier to rotate the outer layers
338
        int j = 2*num-1-i;
339
        mCuts[0][i] =  cut;
340
        mCuts[0][j] = -cut;
341
        mCuts[1][i] =  cut;
342
        mCuts[1][j] = -cut;
343
        mCuts[2][i] =  cut;
344
        mCuts[2][j] = -cut;
345
        mCuts[3][i] =  cut;
346
        mCuts[3][j] = -cut;
347
        mCuts[4][i] =  cut;
348
        mCuts[4][j] = -cut;
349
        mCuts[5][i] =  cut;
350
        mCuts[5][j] = -cut;
351
        }
352
      }
353

  
354
    return mCuts;
355
    }
356

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

  
359
  public boolean[][] getLayerRotatable(int[] numLayers)
360
    {
361
    int numAxis = ROT_AXIS.length;
362
    boolean[][] layerRotatable = new boolean[numAxis][];
363

  
364
    for(int i=0; i<numAxis; i++)
365
      {
366
      layerRotatable[i] = new boolean[numLayers[i]];
367
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
368
      layerRotatable[i][numLayers[i]/2] = false;
369
      }
370

  
371
    return layerRotatable;
372
    }
373

  
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

  
376
  public int getTouchControlType()
377
    {
378
    return TC_DODECAHEDRON;
379
    }
380

  
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382

  
383
  public int getTouchControlSplit()
384
    {
385
    return TYPE_SPLIT_EDGE;
386
    }
387

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

  
390
  public int[][][] getEnabled()
391
    {
392
    return new int[][][]
393
      {
394
          {{2,3},{3,5},{1,5},{1,4},{2,4}},
395
          {{0,5},{2,5},{2,3},{3,4},{0,4}},
396
          {{2,3},{2,5},{0,5},{0,4},{3,4}},
397
          {{1,5},{3,5},{2,3},{2,4},{1,4}},
398
          {{0,3},{0,4},{4,5},{1,5},{1,3}},
399
          {{1,2},{1,4},{4,5},{0,5},{0,2}},
400
          {{4,5},{1,4},{1,2},{0,2},{0,5}},
401
          {{4,5},{0,4},{0,3},{1,3},{1,5}},
402
          {{0,2},{0,1},{1,3},{3,5},{2,5}},
403
          {{3,4},{2,4},{1,2},{0,1},{0,3}},
404
          {{2,4},{3,4},{0,3},{0,1},{1,2}},
405
          {{1,3},{0,1},{0,2},{2,5},{3,5}},
406
      };
407
    }
408

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

  
411
  public float[] getDist3D(int[] numLayers)
412
    {
413
    return TouchControlDodecahedron.D3D;
414
    }
415

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

  
418
  public Static3D[] getFaceAxis()
419
    {
420
    return TouchControlDodecahedron.FACE_AXIS;
421
    }
422

  
423
///////////////////////////////////////////////////////////////////////////////////////////////////
424
// PUBLIC API
425

  
426
  public Static3D[] getRotationAxis()
427
    {
428
    return ROT_AXIS;
429
    }
430

  
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432

  
433
  public int[][] getBasicAngles()
434
    {
435
    if( mBasicAngle ==null )
436
      {
437
      int num = getNumLayers()[0];
438
      int[] tmp = new int[num];
439
      for(int i=0; i<num; i++) tmp[i] = 5;
440
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp,tmp,tmp };
441
      }
442

  
443
    return mBasicAngle;
444
    }
445
}
src/main/java/org/distorted/objectlib/objects/TwistyFisher.java
16 16
import org.distorted.objectlib.helpers.ObjectShape;
17 17
import org.distorted.objectlib.helpers.ObjectSignature;
18 18
import org.distorted.objectlib.helpers.ObjectVertexEffects;
19
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
19 20
import org.distorted.objectlib.main.InitData;
20
import org.distorted.objectlib.scrambling.ScrambleState;
21 21
import org.distorted.objectlib.main.ObjectType;
22 22
import org.distorted.objectlib.shape.ShapeHexahedron;
23 23
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
......
38 38
           new Static3D( SQ2/2, 0.0f,-SQ2/2),
39 39
         };
40 40

  
41
  private ScrambleState[] mStates;
41
  private int[][] mEdges;
42 42
  private int[][] mBasicAngle;
43 43
  private float[][] mCuts;
44 44
  private float[][] mCenters;
......
60 60
    }
61 61

  
62 62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
// same as in a 3x3
64 63

  
65
  public ScrambleState[] getScrambleStates()
64
  public int[][] getScrambleEdges()
66 65
    {
67
    if( mStates==null )
68
      {
69
      int[][] m = new int[16][];
70

  
71
      for(int i=0; i<16; i++) m[i] = new int[] { 0,-1,i,0,1,i,0,2,i, 1,-1,i,1,1,i,1,2,i, 2,-1,i,2,1,i,2,2,i};
72

  
73
      mStates = new ScrambleState[]
74
          {
75
          new ScrambleState( new int[][] { m[ 1], m[ 2], m[ 3] } ),  //  0 0
76
          new ScrambleState( new int[][] {  null, m[ 4], m[ 5] } ),  //  1 x
77
          new ScrambleState( new int[][] { m[ 6],  null, m[ 7] } ),  //  2 y
78
          new ScrambleState( new int[][] { m[ 8], m[ 9],  null } ),  //  3 z
79
          new ScrambleState( new int[][] { m[10],  null, m[ 7] } ),  //  4 xy
80
          new ScrambleState( new int[][] { m[11], m[ 9],  null } ),  //  5 xz
81
          new ScrambleState( new int[][] {  null, m[12], m[ 5] } ),  //  6 yx
82
          new ScrambleState( new int[][] { m[ 8], m[13],  null } ),  //  7 yz
83
          new ScrambleState( new int[][] {  null, m[ 4], m[14] } ),  //  8 zx
84
          new ScrambleState( new int[][] { m[ 6],  null, m[15] } ),  //  9 zy
85
          new ScrambleState( new int[][] {  null,  null, m[ 5] } ),  // 10 xyx
86
          new ScrambleState( new int[][] {  null, m[ 4],  null } ),  // 11 xzx
87
          new ScrambleState( new int[][] {  null,  null, m[ 7] } ),  // 12 yxy
88
          new ScrambleState( new int[][] { m[ 6],  null,  null } ),  // 13 yzy
89
          new ScrambleState( new int[][] {  null, m[ 9],  null } ),  // 14 zxz
90
          new ScrambleState( new int[][] { m[ 8],  null,  null } ),  // 15 zyz
91
          };
92
      }
93

  
94
    return mStates;
66
    if( mEdges==null ) ScrambleEdgeGenerator.getScrambleEdgesCuboid(3,3,3);
67
    return mEdges;
95 68
    }
96 69

  
97 70
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/objects/TwistyHelicopter.java
25 25
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
26 26
import org.distorted.objectlib.main.ObjectType;
27 27
import org.distorted.objectlib.helpers.ObjectShape;
28
import org.distorted.objectlib.scrambling.ScrambleState;
29 28
import org.distorted.objectlib.shape.ShapeHexahedron;
30 29

  
31 30
///////////////////////////////////////////////////////////////////////////////////////////////////
......
42 41
           new Static3D(-SQ2/2, -SQ2/2,      0)
43 42
         };
44 43

  
45
  private ScrambleState[] mStates;
44
  private int[][] mEdges;
46 45
  private int[][] mBasicAngle;
47 46
  private float[][] mCuts;
48 47
  private float[][] mCenters;
......
57 56

  
58 57
///////////////////////////////////////////////////////////////////////////////////////////////////
59 58

  
60
  public ScrambleState[] getScrambleStates()
59
  public int[][] getScrambleEdges()
61 60
    {
62
    if( mStates==null )
61
    if( mEdges==null )
63 62
      {
64
      mStates = new ScrambleState[]
63
      mEdges = new int[][]
65 64
        {
66
        new ScrambleState( new int[][] { {0,1,1,2,1,2},{0,1,3,2,1,4},{0,1,5,2,1,6},{0,1,7,2,1,8},{0,1,9,2,1,10},{0,1,11,2,1,12} } ),
67
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{      2,1,10},{       2,1,12} } ),
68
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{0,1,9       },{0,1,11       } } ),
69
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{0,1,9       },{0,1,11       } } ),
70
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{      2,1,10},{       2,1,12} } ),
71
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{0,1,9       },{       2,1,12} } ),
72
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{      2,1,10},{0,1,11       } } ),
73
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{      2,1,10},{0,1,11       } } ),
74
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{0,1,9       },{       2,1,12} } ),
75
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{0,1,5      },{      2,1,8},{            },{             } } ),
76
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{      2,1,6},{0,1,7      },{            },{             } } ),
77
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{      2,1,6},{0,1,7      },{            },{             } } ),
78
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{0,1,5      },{      2,1,8},{            },{             } } ),
65
            {0,1, 2,2, 3,3, 5,4, 6,5, 8,6, 9,7, 11,8, 12,9, 14,10, 15,11, 17,12},  // 0
66
            {                    6,5,      9,7,             14,10,        17,12},  // 1
67
            {                         8,6,      11,8, 12,9,        15,11       },  // 2
68
            {                    6,5,      9,7,       12,9,        15,11       },  // 3
69
            {                         8,6,      11,8,       14,10,        17,12},  // 4
70
            {0,1,      3,3,                           12,9,               17,12},  // 5
71
            {     2,2,      5,4,                            14,10, 15,11       },  // 6
72
            {0,1,      3,3,                                 14,10, 15,11       },  // 7
73
            {     2,2,      5,4,                      12,9,               17,12},  // 8
74
            {     2,2, 3,3,      6,5,           11,8                           },  // 9
75
            {0,1,           5,4,      8,6, 9,7,                                },  // 10
76
            {     2,2, 3,3,           8,6, 9,7                                 },  // 11
77
            {0,1,           5,4, 6,5,           11,8                           }   // 12
79 78
        };
80 79
      }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff