Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyRedi.java @ 588ace55

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.objects;
21

    
22
import static org.distorted.objectlib.Movement.TYPE_SPLIT_CORNER;
23

    
24
import android.content.res.Resources;
25

    
26
import org.distorted.objectlib.ObjectShape;
27
import org.distorted.objectlib.ObjectSticker;
28
import org.distorted.objectlib.ScrambleState;
29
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
import org.distorted.main.R;
35
import org.distorted.objectlib.Movement;
36
import org.distorted.objectlib.Movement6;
37
import org.distorted.objectlib.ObjectList;
38
import org.distorted.objectlib.Twisty6;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
public class TwistyRedi extends Twisty6
43
{
44
  static final Static3D[] ROT_AXIS = new Static3D[]
45
         {
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
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
50
         };
51

    
52
  private static final int[][][] ENABLED = new int[][][]
53
      {
54
          {{0,1},{3,1},{2,3},{0,2}},
55
          {{2,3},{3,1},{0,1},{0,2}},
56
          {{1,2},{0,1},{0,3},{2,3}},
57
          {{1,2},{2,3},{0,3},{0,1}},
58
          {{0,3},{0,2},{1,2},{1,3}},
59
          {{1,2},{0,2},{0,3},{1,3}},
60
      };
61

    
62
  private ScrambleState[] mStates;
63
  private int[] mBasicAngle;
64
  private Static4D[] mQuats;
65
  private float[][] mCuts;
66
  private boolean[][] mLayerRotatable;
67
  private float[][] mCenters;
68
  private int[][] mFaceMap;
69
  private ObjectSticker[] mStickers;
70
  private Movement mMovement;
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  public TwistyRedi(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
75
                    DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
76
    {
77
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REDI, res, scrWidth);
78
    }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
  protected ScrambleState[] getScrambleStates()
83
    {
84
    if( mStates==null )
85
      {
86
      mStates = new ScrambleState[]
87
        {
88
        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} } ),
89
        new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
90
        new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
91
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
92
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
93
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
94
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
95
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
96
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
97
        };
98
      }
99

    
100
    return mStates;
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  private void initializeQuats()
106
    {
107
    mQuats = new Static4D[]
108
         {
109
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
110
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
111
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
112
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
113

    
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
         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
         };
123
    }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
  protected int[] getSolvedQuats(int cubit, int numLayers)
128
    {
129
    if( mQuats==null ) initializeQuats();
130
    int status = retCubitSolvedStatus(cubit,numLayers);
131
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status],mQuats);
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
  protected Static4D[] getQuats()
137
    {
138
    if( mQuats==null ) initializeQuats();
139
    return mQuats;
140
    }
141

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

    
144
  protected int getSolvedFunctionIndex()
145
    {
146
    return 0;
147
    }
148

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

    
151
  protected int getNumStickerTypes(int numLayers)
152
    {
153
    return 2;
154
    }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

    
158
  protected float[][] getCuts(int size)
159
    {
160
    if( mCuts==null )
161
      {
162
      float C = +SQ3/3 +0.05f;
163
      float[] cut = new float[] {-C,+C};
164
      mCuts = new float[][] { cut,cut,cut,cut };
165
      }
166

    
167
    return mCuts;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  private void getLayerRotatable(int numLayers)
173
    {
174
    if( mLayerRotatable==null )
175
      {
176
      int numAxis = ROT_AXIS.length;
177
      boolean[] tmp = new boolean[] {true,false,true};
178
      mLayerRotatable = new boolean[numAxis][];
179
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
180
      }
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  protected int getNumCubitFaces()
186
    {
187
    return 9;
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  protected float[][] getCubitPositions(int size)
193
    {
194
    if( mCenters==null )
195
      {
196
      final float DIST_CORNER = 1.0f;
197
      final float DIST_EDGE   = 1.5f;
198

    
199
      mCenters = new float[][]
200
         {
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
             {-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

    
210
             {      0.0f, DIST_EDGE, DIST_EDGE },
211
             { DIST_EDGE,      0.0f, DIST_EDGE },
212
             {      0.0f,-DIST_EDGE, DIST_EDGE },
213
             {-DIST_EDGE,      0.0f, DIST_EDGE },
214
             { DIST_EDGE, DIST_EDGE,      0.0f },
215
             { DIST_EDGE,-DIST_EDGE,      0.0f },
216
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
217
             {-DIST_EDGE, DIST_EDGE,      0.0f },
218
             {      0.0f, DIST_EDGE,-DIST_EDGE },
219
             { DIST_EDGE,      0.0f,-DIST_EDGE },
220
             {      0.0f,-DIST_EDGE,-DIST_EDGE },
221
             {-DIST_EDGE,      0.0f,-DIST_EDGE }
222
         };
223
      }
224

    
225
    return mCenters;
226
    }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

    
230
  protected ObjectShape getObjectShape(int cubit, int numLayers)
231
    {
232
    int variant = getCubitVariant(cubit,numLayers);
233

    
234
    if( variant==0 )
235
      {
236
      double[][] vertices = new double[][]
237
          {
238
             { 0.0f, 0.0f, 0.0f },
239
             {-0.5f, 0.5f, 0.5f },
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
          };
247

    
248
      int[][] vert_indices = new int[][]
249
          {
250
             { 2,4,3,1 },
251
             { 1,3,5,7 },
252
             { 4,6,5,3 },
253

    
254
             { 2,4,0 },
255
             { 5,7,0 },
256
             { 4,6,0 },
257
             { 7,1,0 },
258
             { 1,2,0 },
259
             { 6,5,0 }
260
          };
261

    
262
      float[][] bands     = new float[][] { {0.06f,35,0.5f,0.7f,5,2,2}, {0.01f,35,0.2f,0.4f,5,2,2} };
263
      int[] bandIndices   = new int[] { 0,0,0,1,1,1,1,1,1 };
264
      float[][] corners   = new float[][] { {0.06f,0.12f} };
265
      int[] cornerIndices = new int[]  { -1,0,-1,0,0,0,-1,-1 };
266
      float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
267
      int[] centerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
268
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
269
      }
270
    else
271
      {
272
      double[][] vertices = new double[][]
273
          {
274
             {-0.5f, 0.0f, 0.0f},
275
             { 0.5f, 0.0f, 0.0f},
276
             {-0.5f,-1.0f, 0.0f},
277
             { 0.5f,-1.0f, 0.0f},
278
             { 0.0f,-1.5f, 0.0f},
279
             {-0.5f, 0.0f,-1.0f},
280
             { 0.5f, 0.0f,-1.0f},
281
             { 0.0f, 0.0f,-1.5f},
282
          };
283

    
284
      int[][] vert_indices = new int[][]
285
          {
286
             { 0,2,4,3,1 },
287
             { 0,1,6,7,5 },
288
             { 1,3,6 },
289
             { 0,2,5 },
290
             { 4,7,6,3 },
291
             { 4,7,5,2 }
292
          };
293

    
294
      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} };
295
      int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
296
      float[][] corners   = new float[][] { {0.06f,0.20f} };
297
      int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
298
      float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
299
      int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
300
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
301
      }
302
    }
303

    
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305

    
306
  protected Static4D getQuat(int cubit, int numLayers)
307
    {
308
    if( mQuats==null ) initializeQuats();
309

    
310
    switch(cubit)
311
      {
312
      case  0: return mQuats[0];                         //  unit quat
313
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
314
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
315
      case  3: return mQuats[1];                         // 180 along X
316
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
317
      case  5: return mQuats[2];                         // 180 along Y
318
      case  6: return mQuats[3];                         // 180 along Z
319
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
320

    
321
      case  8: return mQuats[0];
322
      case  9: return mQuats[5];
323
      case 10: return mQuats[3];
324
      case 11: return mQuats[11];
325
      case 12: return mQuats[4];
326
      case 13: return mQuats[7];
327
      case 14: return mQuats[9];
328
      case 15: return mQuats[10];
329
      case 16: return mQuats[2];
330
      case 17: return mQuats[8];
331
      case 18: return mQuats[1];
332
      case 19: return mQuats[6];
333
      }
334

    
335
    return null;
336
    }
337

    
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

    
340
  protected int getNumCubitVariants(int numLayers)
341
    {
342
    return 2;
343
    }
344

    
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346

    
347
  protected int getCubitVariant(int cubit, int numLayers)
348
    {
349
    return cubit<8 ? 0:1;
350
    }
351

    
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

    
354
  protected int getFaceColor(int cubit, int cubitface, int size)
355
    {
356
    if( mFaceMap==null )
357
      {
358
      // Colors of the faces of cubits.
359
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4  ORANGE 5
360
      // YELLOW 6 WHITE 7 BLUE 8 GREEN 9 RED 10 ORANGE 11
361
      mFaceMap = new int[][]
362
         {
363
           {  4, 2, 0 },
364
           {  2, 5, 0 },
365
           {  3, 4, 0 },
366
           {  5, 3, 0 },
367
           {  1, 2, 4 },
368
           {  5, 2, 1 },
369
           {  4, 3, 1 },
370
           {  1, 3, 5 },
371

    
372
           { 10, 8,12 },
373
           {  6,10,12 },
374
           { 10, 9,12 },
375
           {  7,10,12 },
376
           {  8, 6,12 },
377
           {  9, 6,12 },
378
           {  9, 7,12 },
379
           {  8, 7,12 },
380
           { 11, 8,12 },
381
           {  6,11,12 },
382
           { 11, 9,12 },
383
           {  7,11,12 },
384
         };
385
      }
386

    
387
    return cubitface<3 ? mFaceMap[cubit][cubitface] : NUM_TEXTURES;
388
    }
389

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

    
392
  protected ObjectSticker retSticker(int face)
393
    {
394
    if( mStickers==null )
395
      {
396
      float[][] STICKERS = new float[][]
397
          {
398
             { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
399
             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
400
          };
401

    
402
      final float R0 = 0.09f;
403
      final float R1 = 0.06f;
404
      final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1} };
405
      final float[] strokes = { 0.09f,0.06f };
406

    
407
      mStickers = new ObjectSticker[STICKERS.length];
408

    
409
      for(int s=0; s<STICKERS.length; s++)
410
        {
411
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
412
        }
413
      }
414

    
415
    return mStickers[face/NUM_FACE_COLORS];
416
    }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419
// PUBLIC API
420

    
421
  public Static3D[] getRotationAxis()
422
    {
423
    return ROT_AXIS;
424
    }
425

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

    
428
  public Movement getMovement()
429
    {
430
    if( mMovement==null )
431
      {
432
      int numLayers = getNumLayers();
433
      if( mCuts==null ) getCuts(numLayers);
434
      getLayerRotatable(numLayers);
435
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_SPLIT_CORNER,ENABLED);
436
      }
437
    return mMovement;
438
    }
439

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

    
442
  public int[] getBasicAngle()
443
    {
444
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
445
    return mBasicAngle;
446
    }
447

    
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449

    
450
  public int getObjectName(int numLayers)
451
    {
452
    return R.string.redi2;
453
    }
454

    
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456

    
457
  public int getInventor(int numLayers)
458
    {
459
    return R.string.redi2_inventor;
460
    }
461

    
462
///////////////////////////////////////////////////////////////////////////////////////////////////
463

    
464
  public int getComplexity(int numLayers)
465
    {
466
    return 4;
467
    }
468
}
(19-19/25)