Project

General

Profile

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

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

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