Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import static org.distorted.objectlib.main.Movement.MOVEMENT_HEXAHEDRON;
23
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
import org.distorted.objectlib.main.ObjectControl;
33
import org.distorted.objectlib.main.ObjectType;
34
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ObjectSticker;
36
import org.distorted.objectlib.helpers.ScrambleState;
37
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
  public TwistyRedi(int[] numL, Static4D quat, Static3D move, Resources res)
62
    {
63
    super(numL, numL[0], quat, move, res);
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  public ScrambleState[] getScrambleStates()
69
    {
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
///////////////////////////////////////////////////////////////////////////////////////////////////
90

    
91
  protected int getResource(int[] numLayers)
92
    {
93
    return R.raw.redi_3;
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
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
  public int[] getSolvedQuats(int cubit, int[] numLayers)
121
    {
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
  public Static4D[] getQuats()
130
    {
131
    if( mQuats==null ) initializeQuats();
132
    return mQuats;
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  public int getSolvedFunctionIndex()
138
    {
139
    return 0;
140
    }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
  public int getNumStickerTypes(int[] numLayers)
145
    {
146
    return 2;
147
    }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

    
151
  public float[][] getCuts(int[] numLayers)
152
    {
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
  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
    {
186
    return TYPE_SPLIT_CORNER;
187
    }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

    
191
  public int[][][] getEnabled()
192
    {
193
    return new int[][][]
194
      {
195
          {{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
    }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

    
213
  public int getNumCubitFaces()
214
    {
215
    return 9;
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

    
220
  public float[][] getCubitPositions(int[] numLayers)
221
    {
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
  public ObjectShape getObjectShape(int variant)
259
    {
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
  public Static4D getQuat(int cubit, int[] numLayers)
333
    {
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
  public int getNumCubitVariants(int[] numLayers)
367
    {
368
    return 2;
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

    
373
  public int getCubitVariant(int cubit, int[] numLayers)
374
    {
375
    return cubit<8 ? 0:1;
376
    }
377

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

    
380
  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
    {
389
    if( mFaceMap==null )
390
      {
391
      mFaceMap = new int[][]
392
         {
393
           { 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
         };
415
      }
416

    
417
    return face<3 ? mFaceMap[cubit][face] : -1;
418
    }
419

    
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421

    
422
  public ObjectSticker retSticker(int sticker)
423
    {
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
      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

    
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
    return mStickers[sticker];
453
    }
454

    
455
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
472

    
473
  public ObjectType intGetObjectType(int[] numLayers)
474
    {
475
    return ObjectType.REDI_3;
476
    }
477

    
478
///////////////////////////////////////////////////////////////////////////////////////////////////
479

    
480
  public int getObjectName(int[] numLayers)
481
    {
482
    return R.string.redi2;
483
    }
484

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486

    
487
  public int getInventor(int[] numLayers)
488
    {
489
    return R.string.redi2_inventor;
490
    }
491

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493

    
494
  public int getYearOfInvention(int[] numLayers)
495
    {
496
    return 2009;
497
    }
498

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

    
501
  public int getComplexity(int[] numLayers)
502
    {
503
    return 4;
504
    }
505
}
(19-19/25)