Project

General

Profile

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

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

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_HEXAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
14

    
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17

    
18
import org.distorted.objectlib.helpers.FactoryCubit;
19
import org.distorted.objectlib.helpers.ObjectFaceShape;
20
import org.distorted.objectlib.helpers.ObjectSignature;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitAssets;
23
import org.distorted.objectlib.main.InitData;
24
import org.distorted.objectlib.main.ObjectSignatures;
25
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
26
import org.distorted.objectlib.main.ObjectType;
27
import org.distorted.objectlib.helpers.ObjectShape;
28
import org.distorted.objectlib.shape.ShapeHexahedron;
29

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

    
32
public class TwistyRedi extends ShapeHexahedron
33
{
34
  static final Static3D[] ROT_AXIS = new Static3D[]
35
         {
36
           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
         };
41

    
42
  private int[][] mEdges;
43
  private int[][] mBasicAngle;
44
  private float[][] mCuts;
45
  private float[][] mPosition;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  public TwistyRedi(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
50
    {
51
    super(meshState, iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
52
    }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  @Override
57
  public float[][] returnRotationFactor()
58
    {
59
    float C = 1.5f;
60
    float[] f = new float[] { C,C,C };
61
    return new float[][] { f,f,f,f };
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  public int[][] getScrambleEdges()
67
    {
68
    if( mEdges==null )
69
      {
70
      mEdges = new int[][]
71
        {
72
          { 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
73
          {                            10,2,11,2,            16,3,17,3, 18,5,19,5            },  // 1
74
          {          4,1,5,1,                     12,6,13,6,                       22,4,23,4 },  // 2
75
          {          4,1,5,1, 6,7,7,7,                                             22,4,23,4 },  // 3
76
          { 0,8,1,8,                   10,2,11,2,            16,3,17,3                       },  // 4
77
          {          4,1,5,1, 6,7,7,7,            12,6,13,6                                  },  // 5
78
          { 0,8,1,8,                   10,2,11,2,                       18,5,19,5            },  // 6
79
          { 0,8,1,8,                                         16,3,17,3, 18,5,19,5            },  // 7
80
          {                   6,7,7,7,            12,6,13,6,                       22,4,23,4 },  // 8
81
        };
82
      }
83

    
84
    return mEdges;
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  public float[][] getCuts(int[] numLayers)
90
    {
91
    if( mCuts==null )
92
      {
93
      float C = SQ3/3 +0.05f;
94
      float[] cut = new float[] {-C,C};
95
      mCuts = new float[][] { cut,cut,cut,cut };
96
      }
97

    
98
    return mCuts;
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  public boolean[][] getLayerRotatable(int[] numLayers)
104
    {
105
    boolean[] tmp = new boolean[] {true,false,true};
106
    return new boolean[][] { tmp,tmp,tmp,tmp };
107
    }
108

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

    
111
  public int getTouchControlType()
112
    {
113
    return TC_HEXAHEDRON;
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  public int getTouchControlSplit()
119
    {
120
    return TYPE_SPLIT_CORNER;
121
    }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
  public int[][][] getEnabled()
126
    {
127
    return new int[][][]
128
      {
129
          {{0,1},{3,1},{2,3},{0,2}},
130
          {{2,3},{3,1},{0,1},{0,2}},
131
          {{1,2},{0,1},{0,3},{2,3}},
132
          {{1,2},{2,3},{0,3},{0,1}},
133
          {{0,3},{0,2},{1,2},{1,3}},
134
          {{1,2},{0,2},{0,3},{1,3}},
135
      };
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  public float[] getDist3D(int[] numLayers)
141
    {
142
    return TouchControlHexahedron.D3D;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  public Static3D[] getFaceAxis()
148
    {
149
    return TouchControlHexahedron.FACE_AXIS;
150
    }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
  public float[][] getCubitPositions(int[] numLayers)
155
    {
156
    if( mPosition==null )
157
      {
158
      final float DIST_CORNER = 1.0f;
159
      final float DIST_EDGE   = 1.5f;
160

    
161
      mPosition = new float[][]
162
         {
163
             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
164
             { DIST_CORNER, DIST_CORNER,-DIST_CORNER },
165
             { DIST_CORNER,-DIST_CORNER, DIST_CORNER },
166
             { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
167
             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
168
             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
169
             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
170
             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
171

    
172
             {      0.0f, DIST_EDGE, DIST_EDGE },
173
             { DIST_EDGE,      0.0f, DIST_EDGE },
174
             {      0.0f,-DIST_EDGE, DIST_EDGE },
175
             {-DIST_EDGE,      0.0f, DIST_EDGE },
176
             { DIST_EDGE, DIST_EDGE,      0.0f },
177
             { DIST_EDGE,-DIST_EDGE,      0.0f },
178
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
179
             {-DIST_EDGE, DIST_EDGE,      0.0f },
180
             {      0.0f, DIST_EDGE,-DIST_EDGE },
181
             { DIST_EDGE,      0.0f,-DIST_EDGE },
182
             {      0.0f,-DIST_EDGE,-DIST_EDGE },
183
             {-DIST_EDGE,      0.0f,-DIST_EDGE }
184
         };
185
      }
186

    
187
    return mPosition;
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  public Static4D getCubitQuats(int cubit, int[] numLayers)
193
    {
194
    switch(cubit)
195
      {
196
      case  0: return mObjectQuats[0];                   //  unit quat
197
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
198
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
199
      case  3: return mObjectQuats[9];                   // 180 along X
200
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
201
      case  5: return mObjectQuats[11];                  // 180 along Y
202
      case  6: return mObjectQuats[10];                  // 180 along Z
203
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
204

    
205
      case  8: return mObjectQuats[0];
206
      case  9: return mObjectQuats[2];
207
      case 10: return mObjectQuats[10];
208
      case 11: return mObjectQuats[8];
209
      case 12: return mObjectQuats[1];
210
      case 13: return mObjectQuats[4];
211
      case 14: return mObjectQuats[6];
212
      case 15: return mObjectQuats[7];
213
      case 16: return mObjectQuats[11];
214
      case 17: return mObjectQuats[5];
215
      case 18: return mObjectQuats[9];
216
      case 19: return mObjectQuats[3];
217
      }
218

    
219
    return null;
220
    }
221

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

    
224
  private float[][] getVertices(int variant)
225
    {
226
    if( variant==0 )
227
      {
228
      return new float[][]
229
          {
230
             { 0.0f, 0.0f, 0.0f },
231
             {-0.5f, 0.5f, 0.5f },
232
             {-0.5f,-0.5f, 0.5f },
233
             { 0.5f, 0.5f, 0.5f },
234
             { 0.5f,-0.5f, 0.5f },
235
             { 0.5f, 0.5f,-0.5f },
236
             { 0.5f,-0.5f,-0.5f },
237
             {-0.5f, 0.5f,-0.5f },
238
          };
239
      }
240
    else
241
      {
242
      return new float[][]
243
          {
244
             {-0.5f, 0.0f, 0.0f},
245
             { 0.5f, 0.0f, 0.0f},
246
             {-0.5f,-1.0f, 0.0f},
247
             { 0.5f,-1.0f, 0.0f},
248
             { 0.0f,-1.5f, 0.0f},
249
             {-0.5f, 0.0f,-1.0f},
250
             { 0.5f, 0.0f,-1.0f},
251
             { 0.0f, 0.0f,-1.5f},
252
          };
253
      }
254
    }
255

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

    
258
  public ObjectShape getObjectShape(int variant)
259
    {
260
    if( variant==0 )
261
      {
262
      int[][] indices =
263
          {
264
             { 2,4,3,1 },
265
             { 1,3,5,7 },
266
             { 4,6,5,3 },
267

    
268
             { 0,4,2 },
269
             { 0,7,5 },
270
             { 0,6,4 },
271
             { 0,1,7 },
272
             { 0,2,1 },
273
             { 0,5,6 }
274
          };
275

    
276
      return new ObjectShape(getVertices(variant), indices);
277
      }
278
    else
279
      {
280
      int[][] indices =
281
          {
282
             { 0,2,4,3,1 },
283
             { 0,1,6,7,5 },
284
             { 1,3,6 },
285
             { 5,2,0 },
286
             { 4,7,6,3 },
287
             { 2,5,7,4 }
288
          };
289

    
290
      return new ObjectShape(getVertices(variant), indices);
291
      }
292
    }
293

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

    
296
  public ObjectFaceShape getObjectFaceShape(int variant)
297
    {
298
    if( variant==0 )
299
      {
300
      float h1 = isInIconMode() ? 0.001f : 0.06f;
301
      float h2 = isInIconMode() ? 0.001f : 0.01f;
302
      float[][] bands = { {h1,35,0.5f,0.7f,5,2,2}, {h2,35,0.2f,0.4f,5,2,2} };
303
      int[] indices   = { 0,0,0,1,1,1,1,1,1 };
304
      return new ObjectFaceShape(bands,indices,null);
305
      }
306
    else
307
      {
308
      float h1 = isInIconMode() ? 0.001f : 0.038f;
309
      float h2 = isInIconMode() ? 0.001f : 0.020f;
310
      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} };
311
      int[] indices   = { 0,0,1,1,2,2 };
312
      return new ObjectFaceShape(bands,indices,null);
313
      }
314
    }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

    
318
  public ObjectVertexEffects getVertexEffects(int variant)
319
    {
320
    if( variant==0 )
321
      {
322
      float[][] corners = { {0.06f,0.12f} };
323
      int[] indices     = { -1,0,-1,0,0,0,-1,-1 };
324
      float[][] centers = { { 0.0f, 0.0f, 0.0f} };
325
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
326
      }
327
    else
328
      {
329
      float[][] corners = { {0.06f,0.20f} };
330
      int[] indices     = { 0,0,-1,-1,-1,-1,-1,-1 };
331
      float[][] centers = { { 0.0f,-0.75f,-0.75f} };
332
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
333
      }
334
    }
335

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

    
338
  public int getNumCubitVariants(int[] numLayers)
339
    {
340
    return 2;
341
    }
342

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

    
345
  public int getCubitVariant(int cubit, int[] numLayers)
346
    {
347
    return cubit<8 ? 0:1;
348
    }
349

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

    
352
  public float getStickerRadius()
353
    {
354
    return 0.09f;
355
    }
356

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

    
359
  public float getStickerStroke()
360
    {
361
    return isInIconMode() ? 0.20f : 0.09f;
362
    }
363

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

    
366
  public float[][] getStickerAngles()
367
    {
368
    return null;
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372
// PUBLIC API
373

    
374
  public Static3D[] getRotationAxis()
375
    {
376
    return ROT_AXIS;
377
    }
378

    
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

    
381
  public int[][] getBasicAngles()
382
    {
383
    if( mBasicAngle ==null )
384
      {
385
      int num = getNumLayers()[0];
386
      int[] tmp = new int[num];
387
      for(int i=0; i<num; i++) tmp[i] = 3;
388
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
389
      }
390

    
391
    return mBasicAngle;
392
    }
393

    
394
///////////////////////////////////////////////////////////////////////////////////////////////////
395

    
396
  public String getShortName()
397
    {
398
    return ObjectType.REDI_3.name();
399
    }
400

    
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402

    
403
  public ObjectSignature getSignature()
404
    {
405
    return new ObjectSignature(ObjectSignatures.REDI_3);
406
    }
407

    
408
///////////////////////////////////////////////////////////////////////////////////////////////////
409

    
410
  public String getObjectName()
411
    {
412
    return "Redi Cube";
413
    }
414

    
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416

    
417
  public String getInventor()
418
    {
419
    return "Oskar van Deventer";
420
    }
421

    
422
///////////////////////////////////////////////////////////////////////////////////////////////////
423

    
424
  public int getYearOfInvention()
425
    {
426
    return 2009;
427
    }
428

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

    
431
  public int getComplexity()
432
    {
433
    return 1;
434
    }
435

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

    
438
  public String[][] getTutorials()
439
    {
440
    return new String[][] {
441
                          {"gb","Qn7TJED6O-4","How to Solve the MoYu Redi Cube","Z3"},
442
                          {"es","g0M38Aotgac","Resolver Redi Cube","Cuby"},
443
                          {"ru","dlNRbE-hyzU","Как собрать Реди Куб","Алексей Ярыгин"},
444
                          {"fr","zw7UZcqqsgA","Comment résoudre le Redi Cube","ValentinoCube"},
445
                          {"de","YU8riouyC2w","Redi Cube Solve","CubaroCubing"},
446
                          {"pl","vxo3lXMsWQI","Jak ułożyć Redi Cube?","DJ rubiks"},
447
                          {"br","muQ8U_G4LmM","Como resolver o Redi Cube","Rafael Cinoto"},
448
                          {"kr","a5CzDMbRzbY","레디큐브를 배우기","vincentcube"},
449
                          {"vn","2JZxtmrKUn4","Tutorial N.6 - Redi","Duy Thích Rubik"},
450
                         };
451
    }
452
}
(35-35/47)