Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyRedi.java @ 967c1d17

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.objects.Movement.TYPE_SPLIT_CORNER;
23

    
24
import android.content.res.Resources;
25

    
26
import org.distorted.helpers.ObjectShape;
27
import org.distorted.helpers.ObjectSticker;
28
import org.distorted.helpers.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

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
public class TwistyRedi extends Twisty6
39
{
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
  private static final int[] NUM_ENABLED = {2,2,2,2,2,2};
49

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

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

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

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

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

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

    
98
    return mStates;
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

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

    
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
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
119
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
120
         };
121
    }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

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

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  Static4D[] getQuats()
135
    {
136
    if( mQuats==null ) initializeQuats();
137
    return mQuats;
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
  int getSolvedFunctionIndex()
143
    {
144
    return 0;
145
    }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

    
149
  int getNumStickerTypes(int numLayers)
150
    {
151
    return 2;
152
    }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

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

    
165
    return mCuts;
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

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

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  int getNumCubitFaces()
184
    {
185
    return 9;
186
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

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

    
197
      mCenters = new float[][]
198
         {
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
             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
206
             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
207

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

    
223
    return mCenters;
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
  ObjectShape getObjectShape(int cubit, int numLayers)
229
    {
230
    int variant = getCubitVariant(cubit,numLayers);
231

    
232
    if( variant==0 )
233
      {
234
      double[][] vertices = new double[][]
235
          {
236
             { 0.0f, 0.0f, 0.0f },
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
             { 0.5f,-0.5f,-0.5f },
243
             {-0.5f, 0.5f,-0.5f },
244
          };
245

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

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

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

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

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

    
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303

    
304
  Static4D getQuat(int cubit, int numLayers)
305
    {
306
    if( mQuats==null ) initializeQuats();
307

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

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

    
333
    return null;
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  int getNumCubitVariants(int numLayers)
339
    {
340
    return 2;
341
    }
342

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344

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

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351

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

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

    
385
    return cubitface<3 ? mFaceMap[cubit][cubitface] : NUM_TEXTURES;
386
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

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

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

    
405
      mStickers = new ObjectSticker[STICKERS.length];
406

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

    
413
    return mStickers[face/NUM_FACE_COLORS];
414
    }
415

    
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417
// PUBLIC API
418

    
419
  public Static3D[] getRotationAxis()
420
    {
421
    return ROT_AXIS;
422
    }
423

    
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425

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

    
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439

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

    
446
///////////////////////////////////////////////////////////////////////////////////////////////////
447

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

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

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

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

    
462
  public int getComplexity(int numLayers)
463
    {
464
    return 4;
465
    }
466
}
(32-32/38)