Project

General

Profile

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

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

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 59c20632 Leszek Koltunski
import static org.distorted.objectlib.main.Movement.MOVEMENT_HEXAHEDRON;
23 29b82486 Leszek Koltunski
import static org.distorted.objectlib.main.Movement.TYPE_SPLIT_CORNER;
24
25
import android.content.res.Resources;
26
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29
30
import org.distorted.objectlib.R;
31
import org.distorted.objectlib.main.Movement6;
32 8592461c Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
33 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
34 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ObjectSticker;
36
import org.distorted.objectlib.helpers.ScrambleState;
37 29b82486 Leszek Koltunski
import org.distorted.objectlib.main.Twisty6;
38
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41
public class TwistyRedi extends Twisty6
42
{
43
  static final Static3D[] ROT_AXIS = new Static3D[]
44
         {
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
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
49
         };
50
51
  private ScrambleState[] mStates;
52
  private int[] mBasicAngle;
53
  private Static4D[] mQuats;
54
  private float[][] mCuts;
55
  private float[][] mCenters;
56
  private int[][] mFaceMap;
57
  private ObjectSticker[] mStickers;
58
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61 7ba38dd4 Leszek Koltunski
  public TwistyRedi(int[] numL, Static4D quat, Static3D move, Resources res)
62 29b82486 Leszek Koltunski
    {
63 7ba38dd4 Leszek Koltunski
    super(numL, numL[0], quat, move, res);
64 29b82486 Leszek Koltunski
    }
65
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
68 f9a81f52 Leszek Koltunski
  public ScrambleState[] getScrambleStates()
69 29b82486 Leszek Koltunski
    {
70
    if( mStates==null )
71
      {
72
      mStates = new ScrambleState[]
73
        {
74
        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} } ),
75
        new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
76
        new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
77
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
78
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
79
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
80
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
81
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
82
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
83
        };
84
      }
85
86
    return mStates;
87
    }
88
89 4e1dc313 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
90
91 a57e6870 Leszek Koltunski
  protected int getResource(int[] numLayers)
92 4e1dc313 Leszek Koltunski
    {
93 55fa6993 Leszek Koltunski
    return R.raw.redi_3;
94 4e1dc313 Leszek Koltunski
    }
95
96 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
97
98
  private void initializeQuats()
99
    {
100
    mQuats = new Static4D[]
101
         {
102
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
103
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
104
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
105
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
106
107
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
108
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
109
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
110
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
111
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
112
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
113
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
114
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
115
         };
116
    }
117
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119
120 7b832206 Leszek Koltunski
  public int[] getSolvedQuats(int cubit, int[] numLayers)
121 29b82486 Leszek Koltunski
    {
122
    if( mQuats==null ) initializeQuats();
123
    int status = retCubitSolvedStatus(cubit,numLayers);
124
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status],mQuats);
125
    }
126
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
129 1bb09f88 Leszek Koltunski
  public Static4D[] getQuats()
130 29b82486 Leszek Koltunski
    {
131
    if( mQuats==null ) initializeQuats();
132
    return mQuats;
133
    }
134
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
137 59c20632 Leszek Koltunski
  public int getSolvedFunctionIndex()
138 29b82486 Leszek Koltunski
    {
139
    return 0;
140
    }
141
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
144 1bb09f88 Leszek Koltunski
  public int getNumStickerTypes(int[] numLayers)
145 29b82486 Leszek Koltunski
    {
146
    return 2;
147
    }
148
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150
151 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
152 29b82486 Leszek Koltunski
    {
153
    if( mCuts==null )
154
      {
155
      float C = +SQ3/3 +0.05f;
156
      float[] cut = new float[] {-C,+C};
157
      mCuts = new float[][] { cut,cut,cut,cut };
158
      }
159
160
    return mCuts;
161
    }
162
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164
165 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
166
    {
167
    int numAxis = ROT_AXIS.length;
168
    boolean[] tmp = new boolean[] {true,false,true};
169
    boolean[][] layerRotatable = new boolean[numAxis][];
170
    for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
171
172
    return layerRotatable;
173
    }
174
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176
177
  public int getMovementType()
178
    {
179
    return MOVEMENT_HEXAHEDRON;
180
    }
181
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183
184
  public int getMovementSplit()
185 29b82486 Leszek Koltunski
    {
186 59c20632 Leszek Koltunski
    return TYPE_SPLIT_CORNER;
187
    }
188
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190
191
  public int[][][] getEnabled()
192
    {
193
    return new int[][][]
194 29b82486 Leszek Koltunski
      {
195 59c20632 Leszek Koltunski
          {{0,1},{3,1},{2,3},{0,2}},
196
          {{2,3},{3,1},{0,1},{0,2}},
197
          {{1,2},{0,1},{0,3},{2,3}},
198
          {{1,2},{2,3},{0,3},{0,1}},
199
          {{0,3},{0,2},{1,2},{1,3}},
200
          {{1,2},{0,2},{0,3},{1,3}},
201
      };
202
    }
203
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205
206
  public float[] getDist3D(int[] numLayers)
207
    {
208
    return null;
209 29b82486 Leszek Koltunski
    }
210
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212
213 a75ae1ee Leszek Koltunski
  public int getNumCubitFaces()
214 29b82486 Leszek Koltunski
    {
215
    return 9;
216
    }
217
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
220 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
221 29b82486 Leszek Koltunski
    {
222
    if( mCenters==null )
223
      {
224
      final float DIST_CORNER = 1.0f;
225
      final float DIST_EDGE   = 1.5f;
226
227
      mCenters = new float[][]
228
         {
229
             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
230
             { DIST_CORNER, DIST_CORNER,-DIST_CORNER },
231
             { DIST_CORNER,-DIST_CORNER, DIST_CORNER },
232
             { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
233
             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
234
             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
235
             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
236
             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
237
238
             {      0.0f, DIST_EDGE, DIST_EDGE },
239
             { DIST_EDGE,      0.0f, DIST_EDGE },
240
             {      0.0f,-DIST_EDGE, DIST_EDGE },
241
             {-DIST_EDGE,      0.0f, DIST_EDGE },
242
             { DIST_EDGE, DIST_EDGE,      0.0f },
243
             { DIST_EDGE,-DIST_EDGE,      0.0f },
244
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
245
             {-DIST_EDGE, DIST_EDGE,      0.0f },
246
             {      0.0f, DIST_EDGE,-DIST_EDGE },
247
             { DIST_EDGE,      0.0f,-DIST_EDGE },
248
             {      0.0f,-DIST_EDGE,-DIST_EDGE },
249
             {-DIST_EDGE,      0.0f,-DIST_EDGE }
250
         };
251
      }
252
253
    return mCenters;
254
    }
255
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257
258 e30c522a Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
259 29b82486 Leszek Koltunski
    {
260
    if( variant==0 )
261
      {
262
      double[][] vertices = new double[][]
263
          {
264
             { 0.0f, 0.0f, 0.0f },
265
             {-0.5f, 0.5f, 0.5f },
266
             {-0.5f,-0.5f, 0.5f },
267
             { 0.5f, 0.5f, 0.5f },
268
             { 0.5f,-0.5f, 0.5f },
269
             { 0.5f, 0.5f,-0.5f },
270
             { 0.5f,-0.5f,-0.5f },
271
             {-0.5f, 0.5f,-0.5f },
272
          };
273
274
      int[][] vert_indices = new int[][]
275
          {
276
             { 2,4,3,1 },
277
             { 1,3,5,7 },
278
             { 4,6,5,3 },
279
280
             { 2,4,0 },
281
             { 5,7,0 },
282
             { 4,6,0 },
283
             { 7,1,0 },
284
             { 1,2,0 },
285
             { 6,5,0 }
286
          };
287
288
      float[][] bands     = new float[][] { {0.06f,35,0.5f,0.7f,5,2,2}, {0.01f,35,0.2f,0.4f,5,2,2} };
289
      int[] bandIndices   = new int[] { 0,0,0,1,1,1,1,1,1 };
290
      float[][] corners   = new float[][] { {0.06f,0.12f} };
291
      int[] cornerIndices = new int[]  { -1,0,-1,0,0,0,-1,-1 };
292
      float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
293
      int[] centerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
294
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
295
      }
296
    else
297
      {
298
      double[][] vertices = new double[][]
299
          {
300
             {-0.5f, 0.0f, 0.0f},
301
             { 0.5f, 0.0f, 0.0f},
302
             {-0.5f,-1.0f, 0.0f},
303
             { 0.5f,-1.0f, 0.0f},
304
             { 0.0f,-1.5f, 0.0f},
305
             {-0.5f, 0.0f,-1.0f},
306
             { 0.5f, 0.0f,-1.0f},
307
             { 0.0f, 0.0f,-1.5f},
308
          };
309
310
      int[][] vert_indices = new int[][]
311
          {
312
             { 0,2,4,3,1 },
313
             { 0,1,6,7,5 },
314
             { 1,3,6 },
315
             { 0,2,5 },
316
             { 4,7,6,3 },
317
             { 4,7,5,2 }
318
          };
319
320
      float[][] bands     = new float[][] { {0.038f,35,0.250f,0.7f,7,2,2}, {0.020f,35,0.125f,0.2f,3,1,2}, {0.020f,35,0.125f,0.2f,3,1,1} };
321
      int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
322
      float[][] corners   = new float[][] { {0.06f,0.20f} };
323
      int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
324
      float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
325
      int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
326
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
327
      }
328
    }
329
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331
332 7b832206 Leszek Koltunski
  public Static4D getQuat(int cubit, int[] numLayers)
333 29b82486 Leszek Koltunski
    {
334
    if( mQuats==null ) initializeQuats();
335
336
    switch(cubit)
337
      {
338
      case  0: return mQuats[0];                         //  unit quat
339
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
340
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
341
      case  3: return mQuats[1];                         // 180 along X
342
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
343
      case  5: return mQuats[2];                         // 180 along Y
344
      case  6: return mQuats[3];                         // 180 along Z
345
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
346
347
      case  8: return mQuats[0];
348
      case  9: return mQuats[5];
349
      case 10: return mQuats[3];
350
      case 11: return mQuats[11];
351
      case 12: return mQuats[4];
352
      case 13: return mQuats[7];
353
      case 14: return mQuats[9];
354
      case 15: return mQuats[10];
355
      case 16: return mQuats[2];
356
      case 17: return mQuats[8];
357
      case 18: return mQuats[1];
358
      case 19: return mQuats[6];
359
      }
360
361
    return null;
362
    }
363
364
///////////////////////////////////////////////////////////////////////////////////////////////////
365
366 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
367 29b82486 Leszek Koltunski
    {
368
    return 2;
369
    }
370
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372
373 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
374 29b82486 Leszek Koltunski
    {
375
    return cubit<8 ? 0:1;
376
    }
377
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379
380 a75ae1ee Leszek Koltunski
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
381
    {
382
    return variant;
383
    }
384
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386
387
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
388 29b82486 Leszek Koltunski
    {
389
    if( mFaceMap==null )
390
      {
391
      mFaceMap = new int[][]
392
         {
393 a75ae1ee Leszek Koltunski
           { 4, 2, 0 },
394
           { 2, 5, 0 },
395
           { 3, 4, 0 },
396
           { 5, 3, 0 },
397
           { 1, 2, 4 },
398
           { 5, 2, 1 },
399
           { 4, 3, 1 },
400
           { 1, 3, 5 },
401
402
           { 4, 2,-1 },
403
           { 0, 4,-1 },
404
           { 4, 3,-1 },
405
           { 1, 4,-1 },
406
           { 2, 0,-1 },
407
           { 3, 0,-1 },
408
           { 3, 1,-1 },
409
           { 2, 1,-1 },
410
           { 5, 2,-1 },
411
           { 0, 5,-1 },
412
           { 5, 3,-1 },
413
           { 1, 5,-1 },
414 29b82486 Leszek Koltunski
         };
415
      }
416
417 a75ae1ee Leszek Koltunski
    return face<3 ? mFaceMap[cubit][face] : -1;
418 29b82486 Leszek Koltunski
    }
419
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421
422 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
423 29b82486 Leszek Koltunski
    {
424
    if( mStickers==null )
425
      {
426
      float[][] STICKERS = new float[][]
427
          {
428
             { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
429
             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
430
          };
431
432
      final float R0 = 0.09f;
433
      final float R1 = 0.06f;
434
      final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1} };
435 8592461c Leszek Koltunski
      float[] strokes = { 0.09f,0.06f };
436
437
      if( ObjectControl.isInIconMode() )
438
        {
439
        float mult = 2.2f;
440
        strokes[0]*=mult;
441
        strokes[1]*=mult;
442
        }
443 29b82486 Leszek Koltunski
444
      mStickers = new ObjectSticker[STICKERS.length];
445
446
      for(int s=0; s<STICKERS.length; s++)
447
        {
448
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
449
        }
450
      }
451
452 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
453
    }
454
455 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
456
// PUBLIC API
457
458
  public Static3D[] getRotationAxis()
459
    {
460
    return ROT_AXIS;
461
    }
462
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464
465
  public int[] getBasicAngle()
466
    {
467
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
468
    return mBasicAngle;
469
    }
470
471 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
472
473 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
474 61aa85e4 Leszek Koltunski
    {
475 8005e762 Leszek Koltunski
    return ObjectType.REDI_3;
476 61aa85e4 Leszek Koltunski
    }
477
478 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
479
480 a57e6870 Leszek Koltunski
  public int getObjectName(int[] numLayers)
481 29b82486 Leszek Koltunski
    {
482
    return R.string.redi2;
483
    }
484
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486
487 a57e6870 Leszek Koltunski
  public int getInventor(int[] numLayers)
488 29b82486 Leszek Koltunski
    {
489
    return R.string.redi2_inventor;
490
    }
491
492 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
493
494
  public int getYearOfInvention(int[] numLayers)
495
    {
496
    return 2009;
497
    }
498
499 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
500
501 a57e6870 Leszek Koltunski
  public int getComplexity(int[] numLayers)
502 29b82486 Leszek Koltunski
    {
503
    return 4;
504
    }
505
}