Project

General

Profile

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

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

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