Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyBandagedCuboid.java @ 850e5074

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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_CUBOID;
13

    
14
import org.distorted.library.effect.EffectName;
15
import org.distorted.library.main.DistortedLibrary;
16
import org.distorted.library.type.Static3D;
17
import org.distorted.library.type.Static4D;
18

    
19
import org.distorted.objectlib.helpers.FactoryBandagedCuboid;
20
import org.distorted.objectlib.helpers.ObjectFaceShape;
21
import org.distorted.objectlib.helpers.ObjectSignature;
22
import org.distorted.objectlib.helpers.ObjectVertexEffects;
23
import org.distorted.objectlib.main.InitAssets;
24
import org.distorted.objectlib.main.InitData;
25
import org.distorted.objectlib.helpers.ObjectShape;
26
import org.distorted.objectlib.main.ObjectType;
27
import org.distorted.objectlib.scrambling.ObjectScrambler;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class TwistyBandagedCuboid extends TwistyBandagedAbstract
32
{
33
  public static final String OBJECT_NAME = "LOCAL_BANDAGED";
34

    
35
  public static final float STRENGTH = 0.04f;
36
  public static final float REGION_SIZE = 0.15f;
37

    
38
  private static final int CUBIT_111 = 0;
39
  private static final int CUBIT_211 = 1;
40
  private static final int CUBIT_311 = 2;
41
  private static final int CUBIT_221 = 3;
42
  private static final int CUBIT_222 = 4;
43
  private static final int CUBIT_OTH = 5;
44

    
45
  private static final int[][] mDims = new int[][]
46
        {
47
         {1,1,1},  // has to be X>=Z>=Y so that all
48
         {2,1,1},  // the faces are horizontal
49
         {3,1,1},
50
         {2,1,2},
51
         {2,2,2},
52
        };
53

    
54
  // Fused Cube
55
  public static final float[][] POS_1 = new float[][]
56
        {
57
          {-1.0f, -1.0f, +0.0f, -1.0f, -1.0f, +1.0f, -1.0f,  0.0f, +0.0f, -1.0f,  0.0f, +1.0f,
58
            0.0f, -1.0f, +0.0f,  0.0f, -1.0f, +1.0f,  0.0f,  0.0f, +0.0f,  0.0f,  0.0f, +1.0f },
59
          {-1.0f, +1.0f, +1.0f},
60
          {-1.0f, +1.0f, +0.0f},
61
          {-1.0f, +1.0f, -1.0f},
62
          { 0.0f, +1.0f, +1.0f},
63
          { 0.0f, +1.0f, +0.0f},
64
          { 0.0f, +1.0f, -1.0f},
65
          { 1.0f, +1.0f, +1.0f},
66
          { 1.0f, +1.0f, +0.0f},
67
          { 1.0f, +1.0f, -1.0f},
68
          { 1.0f,  0.0f, +1.0f},
69
          { 1.0f,  0.0f, +0.0f},
70
          { 1.0f,  0.0f, -1.0f},
71
          { 1.0f, -1.0f, +1.0f},
72
          { 1.0f, -1.0f, +0.0f},
73
          { 1.0f, -1.0f, -1.0f},
74
          {-1.0f, -1.0f, -1.0f},
75
          {-1.0f,  0.0f, -1.0f},
76
          { 0.0f, -1.0f, -1.0f},
77
          { 0.0f,  0.0f, -1.0f}
78
        };
79

    
80
  // 2-bar cube
81
  public static final float[][] POS_2 = new float[][]
82
        {
83
          { 0.0f, +1.0f,  1.0f, 0.0f, +1.0f,  0.0f, 0.0f, +1.0f, -1.0f},
84
          {-1.0f, -1.0f,  0.0f, 0.0f, -1.0f,  0.0f, 1.0f, -1.0f,  0.0f},
85
          {-1.0f, +1.0f, +1.0f},
86
          {-1.0f, +1.0f,  0.0f},
87
          {-1.0f, +1.0f, -1.0f},
88
          {-1.0f,  0.0f, +1.0f},
89
          {-1.0f,  0.0f,  0.0f},
90
          {-1.0f,  0.0f, -1.0f},
91
          {-1.0f, -1.0f, +1.0f},
92
          {-1.0f, -1.0f, -1.0f},
93
          {+1.0f, +1.0f, +1.0f},
94
          {+1.0f, +1.0f,  0.0f},
95
          {+1.0f, +1.0f, -1.0f},
96
          {+1.0f,  0.0f, +1.0f},
97
          {+1.0f,  0.0f,  0.0f},
98
          {+1.0f,  0.0f, -1.0f},
99
          {+1.0f, -1.0f, +1.0f},
100
          {+1.0f, -1.0f, -1.0f},
101
          { 0.0f,  0.0f, +1.0f},
102
          { 0.0f, -1.0f, +1.0f},
103
          { 0.0f,  0.0f, -1.0f},
104
          { 0.0f, -1.0f, -1.0f}
105
        };
106

    
107
  // 3-plate cube
108
  public static final float[][] POS_3 = new float[][]
109
        {
110
          {-1.0f,  1.0f,  1.0f, -1.0f,  0.0f,  1.0f,  0.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f},
111
          { 1.0f,  0.0f, -1.0f,  1.0f,  0.0f,  0.0f,  1.0f,  1.0f, -1.0f,  1.0f,  1.0f,  0.0f},
112
          {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f,  0.0f,  0.0f, -1.0f, -1.0f,  0.0f, -1.0f,  0.0f},
113
          { 1.0f,  1.0f,  1.0f},
114
          { 1.0f,  0.0f,  1.0f},
115
          { 1.0f, -1.0f,  1.0f},
116
          {-1.0f, -1.0f,  1.0f},
117
          { 0.0f, -1.0f,  1.0f},
118
          { 1.0f, -1.0f,  0.0f},
119
          { 1.0f, -1.0f, -1.0f},
120
          {-1.0f,  1.0f, -1.0f},
121
          {-1.0f,  1.0f,  0.0f},
122
          { 0.0f,  1.0f, -1.0f},
123
          { 0.0f,  1.0f,  0.0f},
124
          {-1.0f,  0.0f, -1.0f},
125
          {-1.0f,  0.0f,  0.0f},
126
          { 0.0f,  0.0f, -1.0f}
127
        };
128

    
129
  // BiCube
130
  public static final float[][] POS_4 = new float[][]
131
        {
132
          { 1.0f,  1.0f, -1.0f},
133
          {-1.0f, -1.0f,  0.0f, -1.0f,  0.0f,  0.0f, 0.0f, -1.0f,  0.0f,  0.0f,  0.0f,  0.0f},
134
          {-1.0f,  1.0f, -1.0f,  0.0f,  1.0f, -1.0f},
135
          {-1.0f,  0.0f, -1.0f,  0.0f,  0.0f, -1.0f},
136
          {-1.0f, -1.0f, -1.0f,  0.0f, -1.0f, -1.0f},
137
          {-1.0f,  1.0f,  0.0f, -1.0f,  1.0f,  1.0f},
138
          { 0.0f,  1.0f,  0.0f,  0.0f,  1.0f,  1.0f},
139
          { 1.0f,  1.0f,  0.0f,  1.0f,  1.0f,  1.0f},
140
          {-1.0f, -1.0f,  1.0f, -1.0f,  0.0f,  1.0f},
141
          { 0.0f, -1.0f,  1.0f,  0.0f,  0.0f,  1.0f},
142
          { 1.0f, -1.0f,  1.0f,  1.0f,  0.0f,  1.0f},
143
          { 1.0f, -1.0f,  0.0f,  1.0f,  0.0f,  0.0f},
144
          { 1.0f, -1.0f, -1.0f,  1.0f,  0.0f, -1.0f}
145
        };
146

    
147
  // AI Cube
148
  public static final float[][] POS_5 = new float[][]
149
        {
150
          {-1.5f,-1.5f, 1.5f, -0.5f,-1.5f, 1.5f, -1.5f,-0.5f, 1.5f, -0.5f,-0.5f, 1.5f,
151
           -1.5f,-1.5f, 0.5f, -0.5f,-1.5f, 0.5f, -1.5f,-0.5f, 0.5f, -0.5f,-0.5f, 0.5f, },
152
          { 1.5f, 1.5f, 1.5f,  0.5f, 1.5f, 1.5f,  1.5f, 0.5f, 1.5f,  0.5f, 0.5f, 1.5f,
153
            1.5f, 1.5f, 0.5f,  0.5f, 1.5f, 0.5f,  1.5f, 0.5f, 0.5f,  0.5f, 0.5f, 0.5f, },
154
          {-1.5f, 1.5f,-1.5f, -0.5f, 1.5f,-1.5f, -1.5f, 0.5f,-1.5f, -0.5f, 0.5f,-1.5f,
155
           -1.5f, 1.5f,-0.5f, -0.5f, 1.5f,-0.5f, -1.5f, 0.5f,-0.5f, -0.5f, 0.5f,-0.5f, },
156
          { 1.5f,-1.5f,-1.5f,  0.5f,-1.5f,-1.5f,  1.5f,-0.5f,-1.5f,  0.5f,-0.5f,-1.5f,
157
            1.5f,-1.5f,-0.5f,  0.5f,-1.5f,-0.5f,  1.5f,-0.5f,-0.5f,  0.5f,-0.5f,-0.5f, },
158

    
159
          {-1.5f, 1.5f, 1.5f },
160
          {-1.5f, 1.5f, 0.5f },
161
          {-1.5f, 0.5f, 1.5f },
162
          {-1.5f, 0.5f, 0.5f },
163
          {-0.5f, 1.5f, 1.5f },
164
          {-0.5f, 1.5f, 0.5f },
165
          {-0.5f, 0.5f, 1.5f },
166

    
167
          { 1.5f,-1.5f, 1.5f },
168
          { 1.5f,-1.5f, 0.5f },
169
          { 1.5f,-0.5f, 1.5f },
170
          { 1.5f,-0.5f, 0.5f },
171
          { 0.5f,-1.5f, 1.5f },
172
          { 0.5f,-1.5f, 0.5f },
173
          { 0.5f,-0.5f, 1.5f },
174

    
175
          { 1.5f, 1.5f,-1.5f },
176
          { 1.5f, 1.5f,-0.5f },
177
          { 1.5f, 0.5f,-1.5f },
178
          { 1.5f, 0.5f,-0.5f },
179
          { 0.5f, 1.5f,-1.5f },
180
          { 0.5f, 1.5f,-0.5f },
181
          { 0.5f, 0.5f,-1.5f },
182

    
183
          {-1.5f,-1.5f,-1.5f },
184
          {-1.5f,-1.5f,-0.5f },
185
          {-1.5f,-0.5f,-1.5f },
186
          {-1.5f,-0.5f,-0.5f },
187
          {-0.5f,-1.5f,-1.5f },
188
          {-0.5f,-1.5f,-0.5f },
189
          {-0.5f,-0.5f,-1.5f },
190
        };
191

    
192
  // Burr Cube
193
  public static final float[][] POS_6 = new float[][]
194
        {
195
          {-1.5f, 1.5f, 1.5f,-0.5f, 1.5f, 1.5f},
196
          { 1.5f, 1.5f, 1.5f, 0.5f, 1.5f, 1.5f},
197
          {-0.5f, 0.5f, 1.5f, 0.5f, 0.5f, 1.5f},
198
          {-1.5f,-0.5f, 1.5f,-0.5f,-0.5f, 1.5f},
199
          { 1.5f,-0.5f, 1.5f, 0.5f,-0.5f, 1.5f},
200
          {-0.5f,-1.5f, 1.5f, 0.5f,-1.5f, 1.5f},
201

    
202
          {-1.5f, 1.5f,-1.5f,-0.5f, 1.5f,-1.5f},
203
          { 1.5f, 1.5f,-1.5f, 0.5f, 1.5f,-1.5f},
204
          {-0.5f, 0.5f,-1.5f, 0.5f, 0.5f,-1.5f},
205
          {-1.5f,-0.5f,-1.5f,-0.5f,-0.5f,-1.5f},
206
          { 1.5f,-0.5f,-1.5f, 0.5f,-0.5f,-1.5f},
207
          {-0.5f,-1.5f,-1.5f, 0.5f,-1.5f,-1.5f},
208

    
209
          { 1.5f, 1.5f, 0.5f, 1.5f, 1.5f,-0.5f},
210
          { 1.5f, 0.5f, 1.5f, 1.5f, 0.5f, 0.5f},
211
          { 1.5f, 0.5f,-1.5f, 1.5f, 0.5f,-0.5f},
212
          { 1.5f,-0.5f, 0.5f, 1.5f,-0.5f,-0.5f},
213
          { 1.5f,-1.5f, 1.5f, 1.5f,-1.5f, 0.5f},
214
          { 1.5f,-1.5f,-1.5f, 1.5f,-1.5f,-0.5f},
215

    
216
          {-1.5f, 1.5f, 0.5f,-1.5f, 1.5f,-0.5f},
217
          {-1.5f, 0.5f, 1.5f,-1.5f, 0.5f, 0.5f},
218
          {-1.5f, 0.5f,-1.5f,-1.5f, 0.5f,-0.5f},
219
          {-1.5f,-0.5f, 0.5f,-1.5f,-0.5f,-0.5f},
220
          {-1.5f,-1.5f, 1.5f,-1.5f,-1.5f, 0.5f},
221
          {-1.5f,-1.5f,-1.5f,-1.5f,-1.5f,-0.5f},
222

    
223
          {-0.5f, 1.5f,-0.5f, 0.5f, 1.5f,-0.5f},
224
          {-0.5f, 1.5f, 0.5f, 0.5f, 1.5f, 0.5f},
225

    
226
          { 0.5f,-1.5f, 0.5f, 0.5f,-1.5f,-0.5f},
227
          {-0.5f,-1.5f, 0.5f,-0.5f,-1.5f,-0.5f},
228
        };
229

    
230
  private int[][] mEdges;
231
  private int[] mCubitVariantMap;
232
  private int[] mTypeVariantMap;
233
  private Static4D[] mInitQuats;
234

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

    
237
  public TwistyBandagedCuboid(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
238
    {
239
    super(meshState, iconMode, (data.getNumLayers()[0]+data.getNumLayers()[1]+data.getNumLayers()[2])/3.0f, quat, move, scale, data, asset);
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243
// Computing scramble states of many a bandaged cubes takes way too long time and too much space.
244
// Return null here and turn to construction of scramble tables just-in-time (scrambleType=2)
245
// Unless this is AI Cube :)
246

    
247
  public int[][] getScrambleEdges()
248
    {
249
    if( mPosition==null ) mPosition = getInitData().getPos();
250

    
251
    if( mPosition==POS_5 )
252
      {
253
      if( mEdges==null )
254
        {
255
        mEdges = new int[][]
256
          {
257
            { 36, 1,37, 2,38, 3,39, 4,40, 5,41, 6 },  // 0: beg
258
            {  6, 7, 7, 7, 8, 7, 9, 7,10, 7,11, 7 },  // 1: R before
259
            {  0, 8, 1, 8, 2, 8, 3, 8, 4, 8, 5, 8 },  // 2: L before
260
            { 12, 9,13, 9,14, 9,15, 9,16, 9,17, 9 },  // 3: D before
261
            { 18,10,19,10,20,10,21,10,22,10,23,10 },  // 4: U before
262
            { 24,11,25,11,26,11,27,11,28,11,29,11 },  // 5: B before
263
            { 30,12,31,12,32,12,33,12,34,12,35,12 },  // 6: F before
264
            { 42, 3,43, 4,44, 5,45, 6 }, // 7: R after
265
            { 46, 3,47, 4,48, 5,49, 6 }, // 8: L after
266
            { 50, 1,51, 2,52, 5,53, 6 }, // 9: D after
267
            { 54, 1,55, 2,56, 5,57, 6 }, //10: U after
268
            { 58, 1,59, 2,60, 3,61, 4 }, //11: B after
269
            { 62, 1,63, 2,64, 3,65, 4 }, //12: F after
270
          };
271
        }
272

    
273
      return mEdges;
274
      }
275

    
276
    return null;
277
    }
278

    
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280
// AI Cube is scrambled using algorithms
281

    
282
  @Override
283
  public int[][] getScrambleAlgorithms()
284
    {
285
    if( mPosition==null ) mPosition = getInitData().getPos();
286

    
287
    if( mPosition==POS_5 )
288
      {
289
      return new int[][]
290
          {
291
              { 0,1,-1 }, { 0,1, 1 }, { 0,1, 2 }, { 0,2,-1 }, { 0,2, 1 }, { 0,2, 2 },  //  0-5 : L
292
              { 0,4,-1 }, { 0,4, 1 }, { 0,4, 2 }, { 0,8,-1 }, { 0,8, 1 }, { 0,8, 2 },  //  6-11: R
293
              { 1,1,-1 }, { 1,1, 1 }, { 1,1, 2 }, { 1,2,-1 }, { 1,2, 1 }, { 1,2, 2 },  // 12-17: D
294
              { 1,4,-1 }, { 1,4, 1 }, { 1,4, 2 }, { 1,8,-1 }, { 1,8, 1 }, { 1,8, 2 },  // 18-23: U
295
              { 2,1,-1 }, { 2,1, 1 }, { 2,1, 2 }, { 2,2,-1 }, { 2,2, 1 }, { 2,2, 2 },  // 24-29: B
296
              { 2,4,-1 }, { 2,4, 1 }, { 2,4, 2 }, { 2,8,-1 }, { 2,8, 1 }, { 2,8, 2 },  // 30-35: F
297

    
298
              { 1,8,1, 2,1,2 },  // 36: BEG->R
299
              { 1,1,1, 2,1,2 },  // 37: BEG->L
300
              { 2,8,1, 0,8,2 },  // 38: BEG->D
301
              { 2,1,1, 0,8,2 },  // 39: BEG->U
302
              { 0,8,1, 1,8,2 },  // 40: BEG->B
303
              { 0,1,1, 1,8,2 },  // 41: BEG->F
304

    
305
              { 1,1,-1, 0,8,2, 2,1,-1 }, // 42: R->D
306
              { 1,8, 1, 0,8,2, 2,8, 1 }, // 43: R->U
307
              { 2,1, 1, 0,8,2, 1,1, 1 }, // 44: R->B
308
              { 2,8,-1, 0,8,2, 1,8,-1 }, // 45: R->F
309

    
310
              { 1,1,-1, 0,1,2, 2,8, 1 }, // 46: L->D
311
              { 1,8, 1, 0,1,2, 2,1,-1 }, // 47: L->U
312
              { 2,1, 1, 0,1,2, 1,8,-1 }, // 48: L->B
313
              { 2,8,-1, 0,1,2, 1,1, 1 }, // 49: L->F
314

    
315
              { 0,8,-1, 1,1,2, 2,1, 1 }, // 50: D->R
316
              { 0,1, 1, 1,1,2, 2,8,-1 }, // 51: D->L
317
              { 2,1,-1, 1,1,2, 0,8, 1 }, // 52: D->B
318
              { 2,8, 1, 1,1,2, 0,1,-1 }, // 53: D->F
319

    
320
              { 0,8,-1, 1,8,2, 2,8,-1 }, // 54: U->R
321
              { 0,1, 1, 1,8,2, 2,1, 1 }, // 55: U->L
322
              { 2,1,-1, 1,8,2, 0,1,-1 }, // 56: U->B
323
              { 2,8, 1, 1,8,2, 0,8, 1 }, // 57: U->F
324

    
325
              { 0,8, 1, 2,1,2, 1,1,-1 }, // 58: B->R
326
              { 0,1,-1, 2,1,2, 1,8, 1 }, // 59: B->L
327
              { 1,1, 1, 2,1,2, 0,8,-1 }, // 60: B->D
328
              { 1,8,-1, 2,1,2, 0,1, 1 }, // 61: B->U
329

    
330
              { 0,8, 1, 2,8,2, 1,8, 1 }, // 62: F->R
331
              { 0,1,-1, 2,8,2, 1,1,-1 }, // 63: F->L
332
              { 1,1, 1, 2,8,2, 0,1, 1 }, // 64: F->D
333
              { 1,8,-1, 2,8,2, 0,8,-1 }, // 65: F->U
334
          };
335
      }
336
    else
337
      {
338
      return super.getScrambleAlgorithms();
339
      }
340
    }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343
// AI Cube is scrambled using algorithms
344

    
345
  @Override
346
  public int getScrambleType()
347
    {
348
    if( mPosition==null ) mPosition = getInitData().getPos();
349

    
350
    return mPosition==POS_5 ? ObjectScrambler.SCRAMBLING_ALGORITHMS : ObjectScrambler.SCRAMBLING_BANDAGED;
351
    }
352

    
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354

    
355
  private int getType(float[] pos)
356
    {
357
    switch(pos.length)
358
      {
359
      case  3: return CUBIT_111;
360
      case  6: return CUBIT_211;
361
      case  9: boolean x1 = (pos[0]==pos[3] && pos[0]==pos[6]);
362
               boolean y1 = (pos[1]==pos[4] && pos[1]==pos[7]);
363
               boolean z1 = (pos[2]==pos[5] && pos[2]==pos[8]);
364
               return ( (x1&&y1) || (x1&&z1) || (y1&&z1) ) ? CUBIT_311 : CUBIT_OTH;
365
      case 12: float x = (pos[0]+pos[3]+pos[6]+pos[ 9])/4;
366
               float y = (pos[1]+pos[4]+pos[7]+pos[10])/4;
367
               float z = (pos[2]+pos[5]+pos[8]+pos[11])/4;
368
               float d1 = (pos[0]-x)*(pos[0]-x) + (pos[ 1]-y)*(pos[ 1]-y) + (pos[ 2]-z)*(pos[ 2]-z);
369
               float d2 = (pos[3]-x)*(pos[3]-x) + (pos[ 4]-y)*(pos[ 4]-y) + (pos[ 5]-z)*(pos[ 5]-z);
370
               float d3 = (pos[6]-x)*(pos[6]-x) + (pos[ 7]-y)*(pos[ 7]-y) + (pos[ 8]-z)*(pos[ 8]-z);
371
               float d4 = (pos[9]-x)*(pos[9]-x) + (pos[10]-y)*(pos[10]-y) + (pos[11]-z)*(pos[11]-z);
372
               return ( d1==0.5f && d2==0.5f && d3==0.5f && d4==0.5f ) ? CUBIT_221 : CUBIT_OTH;
373
      case 24: float x3 = pos[0];
374
               float y3 = pos[1];
375
               float z3 = pos[2];
376
               float x4=-10,y4=-10,z4=-10;
377
               int i;
378

    
379
               for(i=0; i<8; i++)
380
                 {
381
                 if( pos[3*i]!=x3 && pos[3*i+1]!=y3 && pos[3*i+2]!=z3 )
382
                   {
383
                   x4 = pos[3*i  ];
384
                   y4 = pos[3*i+1];
385
                   z4 = pos[3*i+2];
386
                   break;
387
                   }
388
                 }
389
               if( i==9 ) return CUBIT_OTH;
390

    
391
               float dX = x4-x3;
392
               float dY = y4-y3;
393
               float dZ = z4-z3;
394

    
395
               if( (dX==1.0f || dX==-1.0f) && (dY==1.0f || dY==-1.0f) && (dZ==1.0f || dZ==-1.0f) )
396
                 {
397
                 for(i=0; i<8; i++)
398
                   {
399
                   if( (pos[3*i  ]!=x3 && pos[3*i  ]!=x4) ||
400
                       (pos[3*i+1]!=y3 && pos[3*i+1]!=y4) ||
401
                       (pos[3*i+2]!=z3 && pos[3*i+2]!=z4)  ) return CUBIT_OTH;
402
                   }
403

    
404
                 return CUBIT_222;
405
                 }
406

    
407
      default: return CUBIT_OTH;
408
      }
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

    
413
  private int getQuatIndex(int cubit)
414
    {
415
    float[][] positions = getPositions();
416
    int len = positions.length;
417

    
418
    if( cubit>=0 && cubit<len )
419
      {
420
      float[] pos = positions[cubit];
421
      int type = getType(pos);
422

    
423
      switch(type)
424
        {
425
        case CUBIT_222:
426
        case CUBIT_111: return 0;
427
        case CUBIT_211:
428
        case CUBIT_311: return (pos[1]==pos[4]) ? (pos[0]==pos[3] ? 2 : 0) : 3;
429
        case CUBIT_221: if( pos[0]==pos[3] && pos[0]==pos[6] ) return 3;
430
                        if( pos[1]==pos[4] && pos[1]==pos[7] ) return 0;
431
                        if( pos[2]==pos[5] && pos[2]==pos[8] ) return 1;
432
        }
433
      }
434

    
435
    return 0;
436
    }
437

    
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439

    
440
  private int[] getDim(int variant)
441
    {
442
    int type,numTypes = mDims.length;
443
    for(type=0; type<numTypes; type++) if( mTypeVariantMap[type]==variant ) break;
444
    return type<numTypes ? mDims[type] : null;
445
    }
446

    
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448

    
449
  private void produceTmpShape(int variant)
450
    {
451
    float[][] positions = getPositions();
452
    int cubit,numCubits = positions.length;
453

    
454
    for(cubit=0; cubit<numCubits; cubit++)
455
      {
456
      if( mCubitVariantMap[cubit]==variant ) break;
457
      }
458

    
459
    if( cubit>=numCubits )
460
      {
461
      android.util.Log.e("D", "unknown variant: "+variant);
462
      }
463
    else
464
      {
465
      FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance();
466
      mTmpShapes[variant] = factory.createIrregularShape(variant,positions[cubit]);
467
      }
468
    }
469

    
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471
// PUBLIC API
472

    
473
  public int getTouchControlType()
474
    {
475
    return TC_CUBOID;
476
    }
477

    
478
///////////////////////////////////////////////////////////////////////////////////////////////////
479

    
480
  public ObjectShape getObjectShape(int variant)
481
    {
482
    if( getDim(variant)!=null )
483
      {
484
      int[][] indices =
485
        {
486
          {2,3,1,0},
487
          {7,6,4,5},
488
          {4,0,1,5},
489
          {7,3,2,6},
490
          {6,2,0,4},
491
          {3,7,5,1},
492
        };
493

    
494
      return new ObjectShape( getVertices(variant), indices);
495
      }
496

    
497
    if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
498
    if( mTmpShapes[variant]==null ) produceTmpShape(variant);
499
    return mTmpShapes[variant];
500
    }
501

    
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503

    
504
  public ObjectFaceShape getObjectFaceShape(int variant)
505
    {
506
    int[] numLayers = getNumLayers();
507
    int size = (numLayers[0]+numLayers[1]+numLayers[2])/3;
508
    int[] dim = getDim(variant);
509

    
510
    if( dim!=null )
511
      {
512
      int X = dim[0];
513
      int Y = dim[1];
514
      int Z = dim[2];
515

    
516
      float height     = isInIconMode() ? 0.001f : size<=5 ? 0.048f : 0.020f;
517
      int[] bandIndices= { 0,0,1,1,2,2 };
518

    
519
      int maxXY = Math.max(X,Y);
520
      int maxXZ = Math.max(X,Z);
521
      int maxYZ = Math.max(Y,Z);
522

    
523
      int angle = 45;
524
      float R = 0.25f;
525
      float S = 0.50f;
526
      float N = size<=4 ? 5 : size<=5 ? 4 : 3;
527

    
528
      float[][] bands =
529
        {
530
          {height/maxYZ,angle,R,S,N,0,0},
531
          {height/maxXZ,angle,R,S,N,0,0},
532
          {height/maxXY,angle,R,S,N,0,0}
533
        };
534

    
535
      return new ObjectFaceShape(bands,bandIndices,null);
536
      }
537

    
538
    FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance();
539
    return factory.createIrregularFaceShape(variant, isInIconMode() );
540
    }
541

    
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543

    
544
  public ObjectVertexEffects getVertexEffects(int variant)
545
    {
546
    int[] numLayers = getNumLayers();
547
    int size = (numLayers[0]+numLayers[1]+numLayers[2])/3;
548
    boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode());
549

    
550
    if( getDim(variant)!=null )
551
      {
552
      float[][] vertices = getVertices(variant);
553
      float strength = -STRENGTH;
554

    
555
      float[][] variables =
556
        {
557
          { 0, strength*vertices[0][0], strength*vertices[0][1], strength*vertices[0][2], 1  },
558
          { 0, strength*vertices[1][0], strength*vertices[1][1], strength*vertices[1][2], 1  },
559
          { 0, strength*vertices[2][0], strength*vertices[2][1], strength*vertices[2][2], 1  },
560
          { 0, strength*vertices[3][0], strength*vertices[3][1], strength*vertices[3][2], 1  },
561
          { 0, strength*vertices[4][0], strength*vertices[4][1], strength*vertices[4][2], 1  },
562
          { 0, strength*vertices[5][0], strength*vertices[5][1], strength*vertices[5][2], 1  },
563
          { 0, strength*vertices[6][0], strength*vertices[6][1], strength*vertices[6][2], 1  },
564
          { 0, strength*vertices[7][0], strength*vertices[7][1], strength*vertices[7][2], 1  },
565
        };
566

    
567
      String name = EffectName.DEFORM.name();
568
      float[] reg = {0,0,0,REGION_SIZE};
569

    
570
      String[] names = {name,name,name,name,name,name,name,name};
571
      float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg};
572
      boolean[] uses = {round,round,round,round,round,round,round,round};
573

    
574
      return new ObjectVertexEffects(names,variables,vertices,regions,uses);
575
      }
576

    
577
    FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance();
578
    return factory.createVertexEffects(variant,round);
579
    }
580

    
581
///////////////////////////////////////////////////////////////////////////////////////////////////
582

    
583
  public Static4D getCubitQuats(int cubit, int[] numLayers)
584
    {
585
    if( mInitQuats ==null )
586
      {
587
      mInitQuats = new Static4D[]
588
        {
589
        new Static4D(  0.0f,   0.0f,   0.0f,   1.0f),  // NULL
590
        new Static4D( SQ2/2,   0.0f,   0.0f, -SQ2/2),  // X
591
        new Static4D(  0.0f,  SQ2/2,   0.0f, -SQ2/2),  // Y
592
        new Static4D(  0.0f,   0.0f,  SQ2/2, -SQ2/2),  // Z
593
        new Static4D( -0.5f,  +0.5f,  -0.5f,  +0.5f),  // ZX
594
        new Static4D( +0.5f,  +0.5f,  +0.5f,  -0.5f),  // YX
595
        };
596
      }
597

    
598
    return mInitQuats[getQuatIndex(cubit)];
599
    }
600

    
601
///////////////////////////////////////////////////////////////////////////////////////////////////
602

    
603
  public int getNumCubitVariants(int[] numLayers)
604
    {
605
    if( mNumVariants==0 )
606
      {
607
      float[][] positions = getPositions();
608
      boolean C111=false;
609
      boolean C211=false;
610
      boolean C311=false;
611
      boolean C221=false;
612
      boolean C222=false;
613

    
614
      int numCubits = positions.length;
615
      mCubitVariantMap = new int[numCubits];
616

    
617
      int numTypes = mDims.length;
618
      mTypeVariantMap = new int[numTypes];
619
      for(int i=0; i<numTypes; i++) mTypeVariantMap[i] = -1;
620

    
621
      for (int cubit=0; cubit<numCubits; cubit++)
622
        {
623
        int type = getType(positions[cubit]);
624

    
625
        switch (type)
626
          {
627
          case CUBIT_111: if (!C111) { C111 = true; mTypeVariantMap[CUBIT_111]=mNumVariants++; }
628
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_111];
629
                          break;
630
          case CUBIT_211: if (!C211) { C211 = true; mTypeVariantMap[CUBIT_211]=mNumVariants++; }
631
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_211];
632
                          break;
633
          case CUBIT_311: if (!C311) { C311 = true; mTypeVariantMap[CUBIT_311]=mNumVariants++; }
634
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_311];
635
                          break;
636
          case CUBIT_221: if (!C221) { C221 = true; mTypeVariantMap[CUBIT_221]=mNumVariants++; }
637
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_221];
638
                          break;
639
          case CUBIT_222: if (!C222) { C222 = true; mTypeVariantMap[CUBIT_222]=mNumVariants++; }
640
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_222];
641
                          break;
642
          default       : mCubitVariantMap[cubit] = mNumVariants++;
643
          }
644
        }
645

    
646
      FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance();
647
      factory.prepare(mNumVariants,numLayers);
648
      }
649

    
650
    return mNumVariants;
651
    }
652

    
653
///////////////////////////////////////////////////////////////////////////////////////////////////
654

    
655
  public int getCubitVariant(int cubit, int[] numLayers)
656
    {
657
    return mCubitVariantMap[cubit];
658
    }
659

    
660
///////////////////////////////////////////////////////////////////////////////////////////////////
661

    
662
  private float[][] getVertices(int variant)
663
    {
664
    int[] dim = getDim(variant);
665

    
666
    if( dim!=null )
667
      {
668
      int X = dim[0];
669
      int Y = dim[1];
670
      int Z = dim[2];
671

    
672
      return new float[][]
673
        {
674
          { 0.5f*X, 0.5f*Y, 0.5f*Z},
675
          { 0.5f*X, 0.5f*Y,-0.5f*Z},
676
          { 0.5f*X,-0.5f*Y, 0.5f*Z},
677
          { 0.5f*X,-0.5f*Y,-0.5f*Z},
678
          {-0.5f*X, 0.5f*Y, 0.5f*Z},
679
          {-0.5f*X, 0.5f*Y,-0.5f*Z},
680
          {-0.5f*X,-0.5f*Y, 0.5f*Z},
681
          {-0.5f*X,-0.5f*Y,-0.5f*Z}
682
        };
683
      }
684

    
685
    if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
686
    if( mTmpShapes[variant]==null ) produceTmpShape(variant);
687
    return mTmpShapes[variant].getVertices();
688
    }
689

    
690
///////////////////////////////////////////////////////////////////////////////////////////////////
691
// PUBLIC API
692

    
693
  public float[] getDist3D(int[] numLayers)
694
    {
695
    float x = numLayers[0];
696
    float y = numLayers[1];
697
    float z = numLayers[2];
698
    float a = (x+y+z)/1.5f;
699

    
700
    return new float[] {x/a,x/a,y/a,y/a,z/a,z/a};
701
    }
702

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

    
705
  public float getStickerRadius()
706
    {
707
    return 0.10f;
708
    }
709

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

    
712
  public float getStickerStroke()
713
    {
714
    if( mPosition==null ) mPosition = getInitData().getPos();
715
    boolean icon = isInIconMode();
716

    
717
    if( mPosition==POS_5 ) return icon ? 0.30f : 0.11f;
718
    if( mPosition==POS_6 ) return icon ? 0.30f : 0.10f;
719

    
720
    return icon ? 0.16f : 0.08f;
721
    }
722

    
723
///////////////////////////////////////////////////////////////////////////////////////////////////
724

    
725
  public String getShortName()
726
    {
727
    if( mPosition==null ) mPosition = getInitData().getPos();
728

    
729
    if( mPosition==POS_1 ) return ObjectType.BAN1_3.name();
730
    if( mPosition==POS_2 ) return ObjectType.BAN2_3.name();
731
    if( mPosition==POS_3 ) return ObjectType.BAN3_3.name();
732
    if( mPosition==POS_4 ) return ObjectType.BAN4_3.name();
733
    if( mPosition==POS_5 ) return ObjectType.BAN5_4.name();
734
    if( mPosition==POS_6 ) return ObjectType.BAN6_4.name();
735

    
736
    if( mSignature==null ) mSignature = getSignature();
737
    int[] numLayers = getNumLayers();
738
    int number = 100*numLayers[0]+10*numLayers[1]+numLayers[2];
739

    
740
    return number+"_"+mSignature.getString();
741
    }
742

    
743
///////////////////////////////////////////////////////////////////////////////////////////////////
744

    
745
  public ObjectSignature getSignature()
746
    {
747
    if( mSignature==null )
748
      {
749
      int[] numLayers = getNumLayers();
750
      mSignature = new ObjectSignature(numLayers[0],numLayers[1],numLayers[2],mPosition);
751
      }
752
    return mSignature;
753
    }
754

    
755
///////////////////////////////////////////////////////////////////////////////////////////////////
756

    
757
  public String getObjectName()
758
    {
759
    if( mPosition==null ) mPosition = getInitData().getPos();
760

    
761
    if( mPosition==POS_1 ) return "Fused Cube";
762
    if( mPosition==POS_2 ) return "2Bar Cube";
763
    if( mPosition==POS_3 ) return "Bandaged Cube C";
764
    if( mPosition==POS_4 ) return "BiCube";
765
    if( mPosition==POS_5 ) return "AI Cube";
766
    if( mPosition==POS_6 ) return "Burr Cube";
767

    
768
    return OBJECT_NAME;
769
    }
770

    
771
///////////////////////////////////////////////////////////////////////////////////////////////////
772

    
773
  public String getInventor()
774
    {
775
    if( mPosition==null ) mPosition = getInitData().getPos();
776

    
777
    if( mPosition==POS_1 ) return "Ting Huang";
778
    if( mPosition==POS_2 ) return "Unknown";
779
    if( mPosition==POS_3 ) return "Andreas Nortmann";
780
    if( mPosition==POS_4 ) return "Uwe Meffert";
781
    if( mPosition==POS_5 ) return "David Adams";
782
    if( mPosition==POS_6 ) return "Unknown";
783

    
784
    return "??";
785
    }
786

    
787
///////////////////////////////////////////////////////////////////////////////////////////////////
788

    
789
  public int getYearOfInvention()
790
    {
791
    if( mPosition==null ) mPosition = getInitData().getPos();
792

    
793
    if( mPosition==POS_1 ) return 2011;
794
    if( mPosition==POS_2 ) return 0;
795
    if( mPosition==POS_3 ) return 2005;
796
    if( mPosition==POS_4 ) return 1999;
797
    if( mPosition==POS_5 ) return 2004;
798
    if( mPosition==POS_6 ) return 2002;
799

    
800
    return 0;
801
    }
802

    
803
///////////////////////////////////////////////////////////////////////////////////////////////////
804

    
805
  public int getComplexity()
806
    {
807
    if( mPosition==null ) mPosition = getInitData().getPos();
808

    
809
    if( mPosition==POS_1 ) return 1;
810
    if( mPosition==POS_2 ) return 2;
811
    if( mPosition==POS_3 ) return 2;
812
    if( mPosition==POS_4 ) return 3;
813
    if( mPosition==POS_5 ) return 4;
814
    if( mPosition==POS_6 ) return 3;
815

    
816
    return 4;
817
    }
818

    
819
///////////////////////////////////////////////////////////////////////////////////////////////////
820

    
821
  public String[][] getTutorials()
822
    {
823
    if( mPosition==null ) mPosition = getInitData().getPos();
824

    
825
    if( mPosition==POS_1 )
826
      {
827
      return new String[][]{
828
                            {"gb","F_iJk_IvpVo","Bandaged Cube","CanChrisSolve"},
829
                            {"es","_lTgw5aEFOg","Tutorial 3x3 Fuse Cube","QBAndo"},
830
                            {"ru","raYDwFEXIq4","Как собрать Fused Cube","Алексей Ярыгин"},
831
                            {"fr","9Cfi4rhKzIw","Tutoriel: résolution du Fused Cube","Skieur Cubb"},
832
                            {"pl","0PcUoGxQa6s","Bandaged 3x3 v.A cube","MrUK"},
833
                            {"kr","1RePOLrzJNE","밴디지 타입 A 해법","듀나메스 큐브 해법연구소"},
834
                            {"vn","vg4J0U0n1oA","Tutorial N.1 - Bandaged VA","Duy Thích Rubik"},
835
                           };
836
      }
837
    if( mPosition==POS_2 )
838
      {
839
      return new String[][]{
840
                            {"ru","lS_EK0PMWI8","Как собрать 2-bar Cube","Алексей Ярыгин"},
841
                            {"pl","tX8ubTLh6p8","Bandaged 3x3 (Two bar)","MrUK"},
842
                            {"kr","NE6XuC1r8xw","밴디지 큐브","Denzel Washington"},
843
                           };
844
      }
845
    if( mPosition==POS_3 )
846
      {
847
      return new String[][]{
848
                            {"gb","7UiCVGygUT4","Bandage Cube C Tutorial","PolyakB"},
849
                            {"ru","gXenRA92Wdc","Как собрать Bandaged 3x3 Type C","YG Cuber"},
850
                            {"pl","sKfdFLm79Zs","Bandaged 3x3 v.C cube","MrUK"},
851
                            {"kr","BcCFgeFy6Ec","밴디지 타입 C 해법","듀나메스 큐브 해법연구소"},
852
                            {"vn","9674LLkPSog","Tutorial N.2 - Bandaged VC","Duy Thích Rubik"},
853
                           };
854
      }
855
    if( mPosition==POS_4 )
856
      {
857
      return new String[][]{
858
                            {"gb","AnpdIKICBpM","Trying to Solve a Bandaged Cube","RedKB"},
859
                            {"es","cUyo5fycrvI","Tutorial Bandaged Cube en español","Rafa Garcia Benacazon"},
860
                            {"ru","-MTzeEJptsg","Как собрать bandaged Cube B","стратегия знаний"},
861
                            {"fr","3rsfIJ3roT0","Tutoriel: résolution du Bicube","Skieur Cubb"},
862
                            {"de","sqWVRwkXX9w","Bandaged Cube - Tutorial","GerCubing"},
863
                            {"pl","XcHzTvVR6Po","Bandaged 3x3 v.B cube","MrUK"},
864
                            {"kr","1gsoijF_5q0","BiCube Tutorial (해법)","듀나메스 큐브 해법연구소"},
865
                            {"vn","ZCJDaF4jEbc","Tutorial N.3 - BiCube","Duy Thích Rubik"},
866
                           };
867
      }
868
    if( mPosition==POS_5 )
869
      {
870
      return new String[][]{
871
                            {"gb","b62HPjlUmYQ","4x4x4 AI Bandaged Cube 1/2","Superantoniovivaldi"},
872
                            {"gb","DQeZ0iDqt4s","4x4x4 AI Bandaged Cube 2/2","Superantoniovivaldi"},
873
                            {"es","bZRV8aXyIY4","Tutorial AI Cube 4x4","QBAndo"},
874
                            {"ru","2NIEHu6jE9o","Как собрать AI Cube","Rodion Strizhakov"},
875
                            {"fr","iP9sSg1q0K0","Résolution de l'AI Cube","asthalis"},
876
                            {"pl","y6MNyoHgY8A","All Bandage 4x4 cube TUTORIAL","MrUK"},
877
                            {"br","yGnQ4ObiPRY","Como Resolver o 4x4 Bandaged 1/4","Rafael Cinoto"},
878
                            {"br","XJUtQrwrCmA","Como Resolver o 4x4 Bandaged 2/4","Rafael Cinoto"},
879
                            {"br","Wrdec2WNBSY","Como Resolver o 4x4 Bandaged 3/4","Rafael Cinoto"},
880
                            {"br","mWvYD53fqHI","Como Resolver o 4x4 Bandaged 4/4","Rafael Cinoto"},
881
                            {"kr","MvaFtrU4O_k","AI 밴디지 큐브 해법","듀나메스 큐브 해법연구소"},
882
                            {"vn","aAP1E567ADc","Tutorial N.78 - AI Cube","Duy Thích Rubik"},
883
                           };
884
      }
885
    if( mPosition==POS_6 )
886
      {
887
      return new String[][]{
888
                            {"gb","_FnNzFo0ITM","Burr Cube Tutorial 1/2","Superantoniovivaldi"},
889
                            {"gb","NOf-UcNh4sI","Burr Cube Tutorial 2/2","Superantoniovivaldi"},
890
                            {"es","xR2TLKQmym8","Cómo Resuelvo Wall Cube","Robert Cubes"},
891
                            {"vn","cbDUtkIJjfk","Tutorial N.96 - Burr Cube","Duy Thích Rubik"},
892
                           };
893
      }
894
    return null;
895
    }
896
}
(3-3/47)