Project

General

Profile

Download (16.5 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyRedi.java @ 7ee89540

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