Project

General

Profile

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

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

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