Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyRedi.java @ cf93ea4e

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 6133be67 Leszek Koltunski
// 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 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.objectlib.objects;
11
12 c9c71c3f Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
14 29b82486 Leszek Koltunski
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17
18 84a17011 Leszek Koltunski
import org.distorted.objectlib.helpers.FactoryCubit;
19 3ee1d662 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectFaceShape;
20 1d581993 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectSignature;
21 84a17011 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22 cf93ea4e Leszek Koltunski
import org.distorted.objectlib.main.InitAssets;
23 a8295031 Leszek Koltunski
import org.distorted.objectlib.main.InitData;
24 2dffaf22 Leszek Koltunski
import org.distorted.objectlib.main.ObjectSignatures;
25 c9c71c3f Leszek Koltunski
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
26 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
27 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
28 b31249d6 Leszek Koltunski
import org.distorted.objectlib.shape.ShapeHexahedron;
29 29b82486 Leszek Koltunski
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31
32 386af988 Leszek Koltunski
public class TwistyRedi extends ShapeHexahedron
33 29b82486 Leszek Koltunski
{
34
  static final Static3D[] ROT_AXIS = new Static3D[]
35
         {
36 84a17011 Leszek Koltunski
           new Static3D( SQ3/3, SQ3/3, SQ3/3),
37
           new Static3D( SQ3/3, SQ3/3,-SQ3/3),
38
           new Static3D( SQ3/3,-SQ3/3, SQ3/3),
39
           new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
40 29b82486 Leszek Koltunski
         };
41
42 9ba7f3f6 Leszek Koltunski
  private int[][] mEdges;
43 beee90ab Leszek Koltunski
  private int[][] mBasicAngle;
44 29b82486 Leszek Koltunski
  private float[][] mCuts;
45 52f4db8a Leszek Koltunski
  private float[][] mPosition;
46 29b82486 Leszek Koltunski
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
49 cf93ea4e Leszek Koltunski
  public TwistyRedi(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
50 29b82486 Leszek Koltunski
    {
51 cf93ea4e Leszek Koltunski
    super(meshState, iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
52 29b82486 Leszek Koltunski
    }
53
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
56 9ba7f3f6 Leszek Koltunski
  public int[][] getScrambleEdges()
57 29b82486 Leszek Koltunski
    {
58 9ba7f3f6 Leszek Koltunski
    if( mEdges==null )
59 29b82486 Leszek Koltunski
      {
60 9ba7f3f6 Leszek Koltunski
      mEdges = new int[][]
61 29b82486 Leszek Koltunski
        {
62 e8bf9b51 Leszek Koltunski
          { 0,8,1,8, 4,1,5,1, 6,7,7,7, 10,2,11,2, 12,6,13,6, 16,3,17,3, 18,5,19,5, 22,4,23,4 },  // 0
63
          {                            10,2,11,2,            16,3,17,3, 18,5,19,5            },  // 1
64
          {          4,1,5,1,                     12,6,13,6,                       22,4,23,4 },  // 2
65
          {          4,1,5,1, 6,7,7,7,                                             22,4,23,4 },  // 3
66
          { 0,8,1,8,                   10,2,11,2,            16,3,17,3                       },  // 4
67
          {          4,1,5,1, 6,7,7,7,            12,6,13,6                                  },  // 5
68
          { 0,8,1,8,                   10,2,11,2,                       18,5,19,5            },  // 6
69
          { 0,8,1,8,                                         16,3,17,3, 18,5,19,5            },  // 7
70
          {                   6,7,7,7,            12,6,13,6,                       22,4,23,4 },  // 8
71 29b82486 Leszek Koltunski
        };
72
      }
73
74 9ba7f3f6 Leszek Koltunski
    return mEdges;
75 29b82486 Leszek Koltunski
    }
76
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
79 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
80 29b82486 Leszek Koltunski
    {
81
    if( mCuts==null )
82
      {
83 84a17011 Leszek Koltunski
      float C = SQ3/3 +0.05f;
84
      float[] cut = new float[] {-C,C};
85 29b82486 Leszek Koltunski
      mCuts = new float[][] { cut,cut,cut,cut };
86
      }
87
88
    return mCuts;
89
    }
90
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
93 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
94
    {
95
    boolean[] tmp = new boolean[] {true,false,true};
96 802fe251 Leszek Koltunski
    return new boolean[][] { tmp,tmp,tmp,tmp };
97 59c20632 Leszek Koltunski
    }
98
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
101 11fa413d Leszek Koltunski
  public int getTouchControlType()
102 59c20632 Leszek Koltunski
    {
103 c9c71c3f Leszek Koltunski
    return TC_HEXAHEDRON;
104 59c20632 Leszek Koltunski
    }
105
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
108 11fa413d Leszek Koltunski
  public int getTouchControlSplit()
109 29b82486 Leszek Koltunski
    {
110 59c20632 Leszek Koltunski
    return TYPE_SPLIT_CORNER;
111
    }
112
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114
115
  public int[][][] getEnabled()
116
    {
117
    return new int[][][]
118 29b82486 Leszek Koltunski
      {
119 59c20632 Leszek Koltunski
          {{0,1},{3,1},{2,3},{0,2}},
120
          {{2,3},{3,1},{0,1},{0,2}},
121
          {{1,2},{0,1},{0,3},{2,3}},
122
          {{1,2},{2,3},{0,3},{0,1}},
123
          {{0,3},{0,2},{1,2},{1,3}},
124
          {{1,2},{0,2},{0,3},{1,3}},
125
      };
126
    }
127
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
130
  public float[] getDist3D(int[] numLayers)
131
    {
132 4c9ca251 Leszek Koltunski
    return TouchControlHexahedron.D3D;
133
    }
134
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
137
  public Static3D[] getFaceAxis()
138
    {
139
    return TouchControlHexahedron.FACE_AXIS;
140 29b82486 Leszek Koltunski
    }
141
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
144 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
145 29b82486 Leszek Koltunski
    {
146 52f4db8a Leszek Koltunski
    if( mPosition==null )
147 29b82486 Leszek Koltunski
      {
148
      final float DIST_CORNER = 1.0f;
149
      final float DIST_EDGE   = 1.5f;
150
151 52f4db8a Leszek Koltunski
      mPosition = new float[][]
152 29b82486 Leszek Koltunski
         {
153
             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
154
             { DIST_CORNER, DIST_CORNER,-DIST_CORNER },
155
             { DIST_CORNER,-DIST_CORNER, DIST_CORNER },
156
             { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
157
             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
158
             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
159
             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
160
             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
161
162
             {      0.0f, DIST_EDGE, DIST_EDGE },
163
             { DIST_EDGE,      0.0f, DIST_EDGE },
164
             {      0.0f,-DIST_EDGE, DIST_EDGE },
165
             {-DIST_EDGE,      0.0f, DIST_EDGE },
166
             { DIST_EDGE, DIST_EDGE,      0.0f },
167
             { DIST_EDGE,-DIST_EDGE,      0.0f },
168
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
169
             {-DIST_EDGE, DIST_EDGE,      0.0f },
170
             {      0.0f, DIST_EDGE,-DIST_EDGE },
171
             { DIST_EDGE,      0.0f,-DIST_EDGE },
172
             {      0.0f,-DIST_EDGE,-DIST_EDGE },
173
             {-DIST_EDGE,      0.0f,-DIST_EDGE }
174
         };
175
      }
176
177 52f4db8a Leszek Koltunski
    return mPosition;
178 29b82486 Leszek Koltunski
    }
179
180 d0e6cf7f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
181
182
  public Static4D getCubitQuats(int cubit, int[] numLayers)
183
    {
184
    switch(cubit)
185
      {
186 802fe251 Leszek Koltunski
      case  0: return mObjectQuats[0];                   //  unit quat
187 d0e6cf7f Leszek Koltunski
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
188
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
189 802fe251 Leszek Koltunski
      case  3: return mObjectQuats[9];                   // 180 along X
190 d0e6cf7f Leszek Koltunski
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
191 802fe251 Leszek Koltunski
      case  5: return mObjectQuats[11];                  // 180 along Y
192
      case  6: return mObjectQuats[10];                  // 180 along Z
193 d0e6cf7f Leszek Koltunski
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
194
195 802fe251 Leszek Koltunski
      case  8: return mObjectQuats[0];
196
      case  9: return mObjectQuats[2];
197
      case 10: return mObjectQuats[10];
198
      case 11: return mObjectQuats[8];
199
      case 12: return mObjectQuats[1];
200
      case 13: return mObjectQuats[4];
201
      case 14: return mObjectQuats[6];
202
      case 15: return mObjectQuats[7];
203
      case 16: return mObjectQuats[11];
204
      case 17: return mObjectQuats[5];
205
      case 18: return mObjectQuats[9];
206
      case 19: return mObjectQuats[3];
207 d0e6cf7f Leszek Koltunski
      }
208
209
    return null;
210
    }
211
212 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
213
214 84a17011 Leszek Koltunski
  private float[][] getVertices(int variant)
215 29b82486 Leszek Koltunski
    {
216
    if( variant==0 )
217
      {
218 84a17011 Leszek Koltunski
      return new float[][]
219 29b82486 Leszek Koltunski
          {
220
             { 0.0f, 0.0f, 0.0f },
221
             {-0.5f, 0.5f, 0.5f },
222
             {-0.5f,-0.5f, 0.5f },
223
             { 0.5f, 0.5f, 0.5f },
224
             { 0.5f,-0.5f, 0.5f },
225
             { 0.5f, 0.5f,-0.5f },
226
             { 0.5f,-0.5f,-0.5f },
227
             {-0.5f, 0.5f,-0.5f },
228
          };
229 84a17011 Leszek Koltunski
      }
230
    else
231
      {
232
      return new float[][]
233
          {
234
             {-0.5f, 0.0f, 0.0f},
235
             { 0.5f, 0.0f, 0.0f},
236
             {-0.5f,-1.0f, 0.0f},
237
             { 0.5f,-1.0f, 0.0f},
238
             { 0.0f,-1.5f, 0.0f},
239
             {-0.5f, 0.0f,-1.0f},
240
             { 0.5f, 0.0f,-1.0f},
241
             { 0.0f, 0.0f,-1.5f},
242
          };
243
      }
244
    }
245 29b82486 Leszek Koltunski
246 84a17011 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
247
248
  public ObjectShape getObjectShape(int variant)
249
    {
250
    if( variant==0 )
251
      {
252 4e9f2df5 Leszek Koltunski
      int[][] indices =
253 29b82486 Leszek Koltunski
          {
254
             { 2,4,3,1 },
255
             { 1,3,5,7 },
256
             { 4,6,5,3 },
257
258 846b69f3 Leszek Koltunski
             { 0,4,2 },
259
             { 0,7,5 },
260
             { 0,6,4 },
261
             { 0,1,7 },
262
             { 0,2,1 },
263
             { 0,5,6 }
264 29b82486 Leszek Koltunski
          };
265
266 84a17011 Leszek Koltunski
      return new ObjectShape(getVertices(variant), indices);
267 29b82486 Leszek Koltunski
      }
268
    else
269
      {
270 4e9f2df5 Leszek Koltunski
      int[][] indices =
271 29b82486 Leszek Koltunski
          {
272
             { 0,2,4,3,1 },
273
             { 0,1,6,7,5 },
274
             { 1,3,6 },
275 846b69f3 Leszek Koltunski
             { 5,2,0 },
276 29b82486 Leszek Koltunski
             { 4,7,6,3 },
277 846b69f3 Leszek Koltunski
             { 2,5,7,4 }
278 29b82486 Leszek Koltunski
          };
279
280 84a17011 Leszek Koltunski
      return new ObjectShape(getVertices(variant), indices);
281 3ee1d662 Leszek Koltunski
      }
282
    }
283
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285
286
  public ObjectFaceShape getObjectFaceShape(int variant)
287
    {
288
    if( variant==0 )
289
      {
290 3bf19410 Leszek Koltunski
      float h1 = isInIconMode() ? 0.001f : 0.06f;
291
      float h2 = isInIconMode() ? 0.001f : 0.01f;
292 84a17011 Leszek Koltunski
      float[][] bands = { {h1,35,0.5f,0.7f,5,2,2}, {h2,35,0.2f,0.4f,5,2,2} };
293
      int[] indices   = { 0,0,0,1,1,1,1,1,1 };
294
      return new ObjectFaceShape(bands,indices,null);
295 3ee1d662 Leszek Koltunski
      }
296
    else
297
      {
298 3bf19410 Leszek Koltunski
      float h1 = isInIconMode() ? 0.001f : 0.038f;
299
      float h2 = isInIconMode() ? 0.001f : 0.020f;
300 84a17011 Leszek Koltunski
      float[][] bands = { {h1,35,0.250f,0.7f,7,2,2}, {h2,35,0.125f,0.2f,3,1,2}, {h2,35,0.125f,0.2f,3,1,1} };
301
      int[] indices   = { 0,0,1,1,2,2 };
302
      return new ObjectFaceShape(bands,indices,null);
303
      }
304
    }
305 3bf19410 Leszek Koltunski
306 84a17011 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
307
308
  public ObjectVertexEffects getVertexEffects(int variant)
309
    {
310
    if( variant==0 )
311
      {
312
      float[][] corners = { {0.06f,0.12f} };
313
      int[] indices     = { -1,0,-1,0,0,0,-1,-1 };
314
      float[][] centers = { { 0.0f, 0.0f, 0.0f} };
315
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
316
      }
317
    else
318
      {
319
      float[][] corners = { {0.06f,0.20f} };
320
      int[] indices     = { 0,0,-1,-1,-1,-1,-1,-1 };
321
      float[][] centers = { { 0.0f,-0.75f,-0.75f} };
322
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
323 29b82486 Leszek Koltunski
      }
324
    }
325
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327
328 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
329 29b82486 Leszek Koltunski
    {
330
    return 2;
331
    }
332
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334
335 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
336 29b82486 Leszek Koltunski
    {
337
    return cubit<8 ? 0:1;
338
    }
339
340 053ffa02 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
341 8592461c Leszek Koltunski
342 d53fb890 Leszek Koltunski
  public float getStickerRadius()
343 053ffa02 Leszek Koltunski
    {
344
    return 0.09f;
345
    }
346
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348
349 d53fb890 Leszek Koltunski
  public float getStickerStroke()
350 053ffa02 Leszek Koltunski
    {
351 3bf19410 Leszek Koltunski
    return isInIconMode() ? 0.20f : 0.09f;
352 053ffa02 Leszek Koltunski
    }
353
354 00f4980d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
355
356 d53fb890 Leszek Koltunski
  public float[][] getStickerAngles()
357 00f4980d Leszek Koltunski
    {
358
    return null;
359
    }
360
361 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
362
// PUBLIC API
363
364
  public Static3D[] getRotationAxis()
365
    {
366
    return ROT_AXIS;
367
    }
368
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370
371 beee90ab Leszek Koltunski
  public int[][] getBasicAngles()
372 29b82486 Leszek Koltunski
    {
373 beee90ab Leszek Koltunski
    if( mBasicAngle ==null )
374
      {
375
      int num = getNumLayers()[0];
376
      int[] tmp = new int[num];
377
      for(int i=0; i<num; i++) tmp[i] = 3;
378
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
379
      }
380
381 29b82486 Leszek Koltunski
    return mBasicAngle;
382
    }
383
384 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
385
386 5f54927b Leszek Koltunski
  public String getShortName()
387 61aa85e4 Leszek Koltunski
    {
388 5f54927b Leszek Koltunski
    return ObjectType.REDI_3.name();
389
    }
390
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392
393 1d581993 Leszek Koltunski
  public ObjectSignature getSignature()
394 5f54927b Leszek Koltunski
    {
395 2dffaf22 Leszek Koltunski
    return new ObjectSignature(ObjectSignatures.REDI_3);
396 61aa85e4 Leszek Koltunski
    }
397
398 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
399
400 e26eb4e7 Leszek Koltunski
  public String getObjectName()
401 29b82486 Leszek Koltunski
    {
402 e26eb4e7 Leszek Koltunski
    return "Redi Cube";
403 29b82486 Leszek Koltunski
    }
404
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406
407 e26eb4e7 Leszek Koltunski
  public String getInventor()
408 29b82486 Leszek Koltunski
    {
409 e26eb4e7 Leszek Koltunski
    return "Oskar van Deventer";
410 29b82486 Leszek Koltunski
    }
411
412 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
413
414 e26eb4e7 Leszek Koltunski
  public int getYearOfInvention()
415 59c20632 Leszek Koltunski
    {
416
    return 2009;
417
    }
418
419 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
420
421 e26eb4e7 Leszek Koltunski
  public int getComplexity()
422 29b82486 Leszek Koltunski
    {
423 b4223a92 Leszek Koltunski
    return 1;
424 29b82486 Leszek Koltunski
    }
425 052e0362 Leszek Koltunski
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427
428
  public String[][] getTutorials()
429
    {
430
    return new String[][] {
431
                          {"gb","Qn7TJED6O-4","How to Solve the MoYu Redi Cube","Z3"},
432
                          {"es","g0M38Aotgac","Resolver Redi Cube","Cuby"},
433
                          {"ru","dlNRbE-hyzU","Как собрать Реди Куб","Алексей Ярыгин"},
434
                          {"fr","zw7UZcqqsgA","Comment résoudre le Redi Cube","ValentinoCube"},
435
                          {"de","YU8riouyC2w","Redi Cube Solve","CubaroCubing"},
436
                          {"pl","vxo3lXMsWQI","Jak ułożyć Redi Cube?","DJ rubiks"},
437
                          {"br","muQ8U_G4LmM","Como resolver o Redi Cube","Rafael Cinoto"},
438
                          {"kr","a5CzDMbRzbY","레디큐브를 배우기","vincentcube"},
439 a399e91b Leszek Koltunski
                          {"vn","2JZxtmrKUn4","Tutorial N.6 - Redi","Duy Thích Rubik"},
440 052e0362 Leszek Koltunski
                         };
441
    }
442 29b82486 Leszek Koltunski
}