Project

General

Profile

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

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

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.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.ObjectControl;
36
import org.distorted.objectlib.main.ObjectType;
37
import org.distorted.objectlib.helpers.ObjectShape;
38
import org.distorted.objectlib.helpers.ObjectSticker;
39
import org.distorted.objectlib.helpers.ScrambleState;
40
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 static final int[][][] ENABLED = new int[][][]
55
      {
56
          {{0,1},{3,1},{2,3},{0,2}},
57
          {{2,3},{3,1},{0,1},{0,2}},
58
          {{1,2},{0,1},{0,3},{2,3}},
59
          {{1,2},{2,3},{0,3},{0,1}},
60
          {{0,3},{0,2},{1,2},{1,3}},
61
          {{1,2},{0,2},{0,3},{1,3}},
62
      };
63

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

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  public TwistyRedi(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
77
                    MeshSquare mesh, DistortedEffects effects, Resources res, int scrWidth)
78
    {
79
    super(numL, numL[0], quat, move, texture, mesh, effects, res, scrWidth);
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

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

    
102
    return mStates;
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  protected int getResource(int[] numLayers)
108
    {
109
    return R.raw.redi;
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  private void initializeQuats()
115
    {
116
    mQuats = new Static4D[]
117
         {
118
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
119
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
120
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
121
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
122

    
123
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
124
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
125
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
126
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
127
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
128
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
129
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
130
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
131
         };
132
    }
133

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

    
136
  protected int[] getSolvedQuats(int cubit, int[] numLayers)
137
    {
138
    if( mQuats==null ) initializeQuats();
139
    int status = retCubitSolvedStatus(cubit,numLayers);
140
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status],mQuats);
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  protected Static4D[] getQuats()
146
    {
147
    if( mQuats==null ) initializeQuats();
148
    return mQuats;
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  protected int getSolvedFunctionIndex()
154
    {
155
    return 0;
156
    }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

    
160
  protected int getNumStickerTypes(int[] numLayers)
161
    {
162
    return 2;
163
    }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

    
167
  protected float[][] getCuts(int[] numLayers)
168
    {
169
    if( mCuts==null )
170
      {
171
      float C = +SQ3/3 +0.05f;
172
      float[] cut = new float[] {-C,+C};
173
      mCuts = new float[][] { cut,cut,cut,cut };
174
      }
175

    
176
    return mCuts;
177
    }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

    
181
  private void getLayerRotatable(int[] numLayers)
182
    {
183
    if( mLayerRotatable==null )
184
      {
185
      int numAxis = ROT_AXIS.length;
186
      boolean[] tmp = new boolean[] {true,false,true};
187
      mLayerRotatable = new boolean[numAxis][];
188
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
189
      }
190
    }
191

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

    
194
  protected int getNumCubitFaces()
195
    {
196
    return 9;
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
  protected float[][] getCubitPositions(int[] numLayers)
202
    {
203
    if( mCenters==null )
204
      {
205
      final float DIST_CORNER = 1.0f;
206
      final float DIST_EDGE   = 1.5f;
207

    
208
      mCenters = new float[][]
209
         {
210
             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
211
             { DIST_CORNER, DIST_CORNER,-DIST_CORNER },
212
             { DIST_CORNER,-DIST_CORNER, DIST_CORNER },
213
             { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
214
             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
215
             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
216
             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
217
             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
218

    
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
             { DIST_EDGE, DIST_EDGE,      0.0f },
224
             { DIST_EDGE,-DIST_EDGE,      0.0f },
225
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
226
             {-DIST_EDGE, DIST_EDGE,      0.0f },
227
             {      0.0f, DIST_EDGE,-DIST_EDGE },
228
             { DIST_EDGE,      0.0f,-DIST_EDGE },
229
             {      0.0f,-DIST_EDGE,-DIST_EDGE },
230
             {-DIST_EDGE,      0.0f,-DIST_EDGE }
231
         };
232
      }
233

    
234
    return mCenters;
235
    }
236

    
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

    
239
  protected ObjectShape getObjectShape(int cubit, int[] numLayers)
240
    {
241
    int variant = getCubitVariant(cubit,numLayers);
242

    
243
    if( variant==0 )
244
      {
245
      double[][] vertices = new double[][]
246
          {
247
             { 0.0f, 0.0f, 0.0f },
248
             {-0.5f, 0.5f, 0.5f },
249
             {-0.5f,-0.5f, 0.5f },
250
             { 0.5f, 0.5f, 0.5f },
251
             { 0.5f,-0.5f, 0.5f },
252
             { 0.5f, 0.5f,-0.5f },
253
             { 0.5f,-0.5f,-0.5f },
254
             {-0.5f, 0.5f,-0.5f },
255
          };
256

    
257
      int[][] vert_indices = new int[][]
258
          {
259
             { 2,4,3,1 },
260
             { 1,3,5,7 },
261
             { 4,6,5,3 },
262

    
263
             { 2,4,0 },
264
             { 5,7,0 },
265
             { 4,6,0 },
266
             { 7,1,0 },
267
             { 1,2,0 },
268
             { 6,5,0 }
269
          };
270

    
271
      float[][] bands     = new float[][] { {0.06f,35,0.5f,0.7f,5,2,2}, {0.01f,35,0.2f,0.4f,5,2,2} };
272
      int[] bandIndices   = new int[] { 0,0,0,1,1,1,1,1,1 };
273
      float[][] corners   = new float[][] { {0.06f,0.12f} };
274
      int[] cornerIndices = new int[]  { -1,0,-1,0,0,0,-1,-1 };
275
      float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
276
      int[] centerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
277
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
278
      }
279
    else
280
      {
281
      double[][] vertices = new double[][]
282
          {
283
             {-0.5f, 0.0f, 0.0f},
284
             { 0.5f, 0.0f, 0.0f},
285
             {-0.5f,-1.0f, 0.0f},
286
             { 0.5f,-1.0f, 0.0f},
287
             { 0.0f,-1.5f, 0.0f},
288
             {-0.5f, 0.0f,-1.0f},
289
             { 0.5f, 0.0f,-1.0f},
290
             { 0.0f, 0.0f,-1.5f},
291
          };
292

    
293
      int[][] vert_indices = new int[][]
294
          {
295
             { 0,2,4,3,1 },
296
             { 0,1,6,7,5 },
297
             { 1,3,6 },
298
             { 0,2,5 },
299
             { 4,7,6,3 },
300
             { 4,7,5,2 }
301
          };
302

    
303
      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} };
304
      int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
305
      float[][] corners   = new float[][] { {0.06f,0.20f} };
306
      int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
307
      float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
308
      int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
309
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
310
      }
311
    }
312

    
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314

    
315
  protected Static4D getQuat(int cubit, int[] numLayers)
316
    {
317
    if( mQuats==null ) initializeQuats();
318

    
319
    switch(cubit)
320
      {
321
      case  0: return mQuats[0];                         //  unit quat
322
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
323
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
324
      case  3: return mQuats[1];                         // 180 along X
325
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
326
      case  5: return mQuats[2];                         // 180 along Y
327
      case  6: return mQuats[3];                         // 180 along Z
328
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
329

    
330
      case  8: return mQuats[0];
331
      case  9: return mQuats[5];
332
      case 10: return mQuats[3];
333
      case 11: return mQuats[11];
334
      case 12: return mQuats[4];
335
      case 13: return mQuats[7];
336
      case 14: return mQuats[9];
337
      case 15: return mQuats[10];
338
      case 16: return mQuats[2];
339
      case 17: return mQuats[8];
340
      case 18: return mQuats[1];
341
      case 19: return mQuats[6];
342
      }
343

    
344
    return null;
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
  protected int getNumCubitVariants(int[] numLayers)
350
    {
351
    return 2;
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

    
356
  protected int getCubitVariant(int cubit, int[] numLayers)
357
    {
358
    return cubit<8 ? 0:1;
359
    }
360

    
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362

    
363
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
364
    {
365
    if( mFaceMap==null )
366
      {
367
      // Colors of the faces of cubits.
368
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4  ORANGE 5
369
      // YELLOW 6 WHITE 7 BLUE 8 GREEN 9 RED 10 ORANGE 11
370
      mFaceMap = new int[][]
371
         {
372
           {  4, 2, 0 },
373
           {  2, 5, 0 },
374
           {  3, 4, 0 },
375
           {  5, 3, 0 },
376
           {  1, 2, 4 },
377
           {  5, 2, 1 },
378
           {  4, 3, 1 },
379
           {  1, 3, 5 },
380

    
381
           { 10, 8,12 },
382
           {  6,10,12 },
383
           { 10, 9,12 },
384
           {  7,10,12 },
385
           {  8, 6,12 },
386
           {  9, 6,12 },
387
           {  9, 7,12 },
388
           {  8, 7,12 },
389
           { 11, 8,12 },
390
           {  6,11,12 },
391
           { 11, 9,12 },
392
           {  7,11,12 },
393
         };
394
      }
395

    
396
    return cubitface<3 ? mFaceMap[cubit][cubitface] : NUM_TEXTURES;
397
    }
398

    
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400

    
401
  protected ObjectSticker retSticker(int face)
402
    {
403
    if( mStickers==null )
404
      {
405
      float[][] STICKERS = new float[][]
406
          {
407
             { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
408
             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
409
          };
410

    
411
      final float R0 = 0.09f;
412
      final float R1 = 0.06f;
413
      final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1} };
414
      float[] strokes = { 0.09f,0.06f };
415

    
416
      if( ObjectControl.isInIconMode() )
417
        {
418
        float mult = 2.2f;
419
        strokes[0]*=mult;
420
        strokes[1]*=mult;
421
        }
422

    
423
      mStickers = new ObjectSticker[STICKERS.length];
424

    
425
      for(int s=0; s<STICKERS.length; s++)
426
        {
427
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
428
        }
429
      }
430

    
431
    return mStickers[face/NUM_FACE_COLORS];
432
    }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435
// PUBLIC API
436

    
437
  public Static3D[] getRotationAxis()
438
    {
439
    return ROT_AXIS;
440
    }
441

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

    
444
  public Movement getMovement()
445
    {
446
    if( mMovement==null )
447
      {
448
      int[] numLayers = getNumLayers();
449
      if( mCuts==null ) getCuts(numLayers);
450
      getLayerRotatable(numLayers);
451
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers[0],TYPE_SPLIT_CORNER,ENABLED);
452
      }
453
    return mMovement;
454
    }
455

    
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457

    
458
  public int[] getBasicAngle()
459
    {
460
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
461
    return mBasicAngle;
462
    }
463

    
464
///////////////////////////////////////////////////////////////////////////////////////////////////
465

    
466
  public ObjectType intGetObjectType(int[] numLayers)
467
    {
468
    return ObjectType.REDI_3;
469
    }
470

    
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472

    
473
  public int getObjectName(int[] numLayers)
474
    {
475
    return R.string.redi2;
476
    }
477

    
478
///////////////////////////////////////////////////////////////////////////////////////////////////
479

    
480
  public int getInventor(int[] numLayers)
481
    {
482
    return R.string.redi2_inventor;
483
    }
484

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486

    
487
  public int getComplexity(int[] numLayers)
488
    {
489
    return 4;
490
    }
491
}
(19-19/25)