Project

General

Profile

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

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

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