Project

General

Profile

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

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

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.ObjectType;
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, 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
  protected int getResource(int numLayers)
107
    {
108
    return R.raw.redi;
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

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

    
122
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
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
         };
131
    }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

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

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

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

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

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

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  protected int getNumStickerTypes(int numLayers)
160
    {
161
    return 2;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

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

    
175
    return mCuts;
176
    }
177

    
178
///////////////////////////////////////////////////////////////////////////////////////////////////
179

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

    
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

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

    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

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

    
207
      mCenters = new float[][]
208
         {
209
             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
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

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

    
233
    return mCenters;
234
    }
235

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

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

    
242
    if( variant==0 )
243
      {
244
      double[][] vertices = new double[][]
245
          {
246
             { 0.0f, 0.0f, 0.0f },
247
             {-0.5f, 0.5f, 0.5f },
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
          };
255

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

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

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

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

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

    
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

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

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

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

    
343
    return null;
344
    }
345

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

    
348
  protected int getNumCubitVariants(int numLayers)
349
    {
350
    return 2;
351
    }
352

    
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354

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

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

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

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

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

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

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

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

    
415
      mStickers = new ObjectSticker[STICKERS.length];
416

    
417
      for(int s=0; s<STICKERS.length; s++)
418
        {
419
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
420
        }
421
      }
422

    
423
    return mStickers[face/NUM_FACE_COLORS];
424
    }
425

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427
// PUBLIC API
428

    
429
  public Static3D[] getRotationAxis()
430
    {
431
    return ROT_AXIS;
432
    }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
  public Movement getMovement()
437
    {
438
    if( mMovement==null )
439
      {
440
      int numLayers = getNumLayers();
441
      if( mCuts==null ) getCuts(numLayers);
442
      getLayerRotatable(numLayers);
443
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_SPLIT_CORNER,ENABLED);
444
      }
445
    return mMovement;
446
    }
447

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

    
450
  public int[] getBasicAngle()
451
    {
452
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
453
    return mBasicAngle;
454
    }
455

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

    
458
  public ObjectType intGetObjectList(int numLayers)
459
    {
460
    return ObjectType.REDI_3;
461
    }
462

    
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464

    
465
  public int getObjectName(int numLayers)
466
    {
467
    return R.string.redi2;
468
    }
469

    
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471

    
472
  public int getInventor(int numLayers)
473
    {
474
    return R.string.redi2_inventor;
475
    }
476

    
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478

    
479
  public int getComplexity(int numLayers)
480
    {
481
    return 4;
482
    }
483
}
(19-19/25)