Project

General

Profile

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

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

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
    return R.raw.redi;
98
    }
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 a57e6870 Leszek Koltunski
  protected 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
  protected Static4D[] getQuats()
134
    {
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 a57e6870 Leszek Koltunski
  protected int getNumStickerTypes(int[] numLayers)
149 29b82486 Leszek Koltunski
    {
150
    return 2;
151
    }
152
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154
155 a57e6870 Leszek Koltunski
  protected 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
  protected int getNumCubitFaces()
218
    {
219
    return 9;
220
    }
221
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
224 a57e6870 Leszek Koltunski
  protected 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 a57e6870 Leszek Koltunski
  protected ObjectShape getObjectShape(int cubit, int[] numLayers)
263 29b82486 Leszek Koltunski
    {
264
    int variant = getCubitVariant(cubit,numLayers);
265
266
    if( variant==0 )
267
      {
268
      double[][] vertices = new double[][]
269
          {
270
             { 0.0f, 0.0f, 0.0f },
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
             { 0.5f,-0.5f,-0.5f },
277
             {-0.5f, 0.5f,-0.5f },
278
          };
279
280
      int[][] vert_indices = new int[][]
281
          {
282
             { 2,4,3,1 },
283
             { 1,3,5,7 },
284
             { 4,6,5,3 },
285
286
             { 2,4,0 },
287
             { 5,7,0 },
288
             { 4,6,0 },
289
             { 7,1,0 },
290
             { 1,2,0 },
291
             { 6,5,0 }
292
          };
293
294
      float[][] bands     = new float[][] { {0.06f,35,0.5f,0.7f,5,2,2}, {0.01f,35,0.2f,0.4f,5,2,2} };
295
      int[] bandIndices   = new int[] { 0,0,0,1,1,1,1,1,1 };
296
      float[][] corners   = new float[][] { {0.06f,0.12f} };
297
      int[] cornerIndices = new int[]  { -1,0,-1,0,0,0,-1,-1 };
298
      float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
299
      int[] centerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
300
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
301
      }
302
    else
303
      {
304
      double[][] vertices = new double[][]
305
          {
306
             {-0.5f, 0.0f, 0.0f},
307
             { 0.5f, 0.0f, 0.0f},
308
             {-0.5f,-1.0f, 0.0f},
309
             { 0.5f,-1.0f, 0.0f},
310
             { 0.0f,-1.5f, 0.0f},
311
             {-0.5f, 0.0f,-1.0f},
312
             { 0.5f, 0.0f,-1.0f},
313
             { 0.0f, 0.0f,-1.5f},
314
          };
315
316
      int[][] vert_indices = new int[][]
317
          {
318
             { 0,2,4,3,1 },
319
             { 0,1,6,7,5 },
320
             { 1,3,6 },
321
             { 0,2,5 },
322
             { 4,7,6,3 },
323
             { 4,7,5,2 }
324
          };
325
326
      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} };
327
      int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
328
      float[][] corners   = new float[][] { {0.06f,0.20f} };
329
      int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
330
      float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
331
      int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
332
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
333
      }
334
    }
335
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337
338 a57e6870 Leszek Koltunski
  protected Static4D getQuat(int cubit, int[] numLayers)
339 29b82486 Leszek Koltunski
    {
340
    if( mQuats==null ) initializeQuats();
341
342
    switch(cubit)
343
      {
344
      case  0: return mQuats[0];                         //  unit quat
345
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
346
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
347
      case  3: return mQuats[1];                         // 180 along X
348
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
349
      case  5: return mQuats[2];                         // 180 along Y
350
      case  6: return mQuats[3];                         // 180 along Z
351
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
352
353
      case  8: return mQuats[0];
354
      case  9: return mQuats[5];
355
      case 10: return mQuats[3];
356
      case 11: return mQuats[11];
357
      case 12: return mQuats[4];
358
      case 13: return mQuats[7];
359
      case 14: return mQuats[9];
360
      case 15: return mQuats[10];
361
      case 16: return mQuats[2];
362
      case 17: return mQuats[8];
363
      case 18: return mQuats[1];
364
      case 19: return mQuats[6];
365
      }
366
367
    return null;
368
    }
369
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371
372 a57e6870 Leszek Koltunski
  protected int getNumCubitVariants(int[] numLayers)
373 29b82486 Leszek Koltunski
    {
374
    return 2;
375
    }
376
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378
379 a57e6870 Leszek Koltunski
  protected int getCubitVariant(int cubit, int[] numLayers)
380 29b82486 Leszek Koltunski
    {
381
    return cubit<8 ? 0:1;
382
    }
383
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385
386 a57e6870 Leszek Koltunski
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
387 29b82486 Leszek Koltunski
    {
388
    if( mFaceMap==null )
389
      {
390
      // Colors of the faces of cubits.
391
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4  ORANGE 5
392
      // YELLOW 6 WHITE 7 BLUE 8 GREEN 9 RED 10 ORANGE 11
393
      mFaceMap = new int[][]
394
         {
395
           {  4, 2, 0 },
396
           {  2, 5, 0 },
397
           {  3, 4, 0 },
398
           {  5, 3, 0 },
399
           {  1, 2, 4 },
400
           {  5, 2, 1 },
401
           {  4, 3, 1 },
402
           {  1, 3, 5 },
403
404
           { 10, 8,12 },
405
           {  6,10,12 },
406
           { 10, 9,12 },
407
           {  7,10,12 },
408
           {  8, 6,12 },
409
           {  9, 6,12 },
410
           {  9, 7,12 },
411
           {  8, 7,12 },
412
           { 11, 8,12 },
413
           {  6,11,12 },
414
           { 11, 9,12 },
415
           {  7,11,12 },
416
         };
417
      }
418
419
    return cubitface<3 ? mFaceMap[cubit][cubitface] : NUM_TEXTURES;
420
    }
421
422
///////////////////////////////////////////////////////////////////////////////////////////////////
423
424
  protected ObjectSticker retSticker(int face)
425
    {
426
    if( mStickers==null )
427
      {
428
      float[][] STICKERS = new float[][]
429
          {
430
             { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
431
             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
432
          };
433
434
      final float R0 = 0.09f;
435
      final float R1 = 0.06f;
436
      final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1} };
437 8592461c Leszek Koltunski
      float[] strokes = { 0.09f,0.06f };
438
439
      if( ObjectControl.isInIconMode() )
440
        {
441
        float mult = 2.2f;
442
        strokes[0]*=mult;
443
        strokes[1]*=mult;
444
        }
445 29b82486 Leszek Koltunski
446
      mStickers = new ObjectSticker[STICKERS.length];
447
448
      for(int s=0; s<STICKERS.length; s++)
449
        {
450
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
451
        }
452
      }
453
454
    return mStickers[face/NUM_FACE_COLORS];
455
    }
456
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458
// PUBLIC API
459
460
  public Static3D[] getRotationAxis()
461
    {
462
    return ROT_AXIS;
463
    }
464
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466
467
  public int[] getBasicAngle()
468
    {
469
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
470
    return mBasicAngle;
471
    }
472
473 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
474
475 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
476 61aa85e4 Leszek Koltunski
    {
477 8005e762 Leszek Koltunski
    return ObjectType.REDI_3;
478 61aa85e4 Leszek Koltunski
    }
479
480 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
481
482 a57e6870 Leszek Koltunski
  public int getObjectName(int[] numLayers)
483 29b82486 Leszek Koltunski
    {
484
    return R.string.redi2;
485
    }
486
487
///////////////////////////////////////////////////////////////////////////////////////////////////
488
489 a57e6870 Leszek Koltunski
  public int getInventor(int[] numLayers)
490 29b82486 Leszek Koltunski
    {
491
    return R.string.redi2_inventor;
492
    }
493
494 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
495
496
  public int getYearOfInvention(int[] numLayers)
497
    {
498
    return 2009;
499
    }
500
501 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
502
503 a57e6870 Leszek Koltunski
  public int getComplexity(int[] numLayers)
504 29b82486 Leszek Koltunski
    {
505
    return 4;
506
    }
507
}