Project

General

Profile

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

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

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[][][] 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
  private ScrambleState[] mStates;
59
  private int[] mBasicAngle;
60
  private Static4D[] mQuats;
61
  private float[][] mCuts;
62
  private boolean[][] mLayerRotatable;
63
  private float[][] mCenters;
64
  private int[][] mFaceMap;
65
  private ObjectSticker[] mStickers;
66
  private Movement mMovement;
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

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

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
  ScrambleState[] getScrambleStates()
79
    {
80
    if( mStates==null )
81
      {
82
      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
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
122

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

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

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

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  int getSolvedFunctionIndex()
141
    {
142
    return 0;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  int getNumStickerTypes(int numLayers)
148
    {
149
    return 2;
150
    }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
  float[][] getCuts(int size)
155
    {
156
    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
    }
178

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

    
181
  int getNumCubitFaces()
182
    {
183
    return 9;
184
    }
185

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

    
188
  float[][] getCubitPositions(int size)
189
    {
190
    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
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  ObjectShape getObjectShape(int cubit, int numLayers)
227
    {
228
    int variant = getCubitVariant(cubit,numLayers);
229

    
230
    if( variant==0 )
231
      {
232
      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
      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
      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
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
265
      }
266
    else
267
      {
268
      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
      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
      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
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
297
      }
298
    }
299

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

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

    
306
    switch(cubit)
307
      {
308
      case  0: return mQuats[0];                         //  unit quat
309
      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
      case  3: return mQuats[1];                         // 180 along X
312
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
313
      case  5: return mQuats[2];                         // 180 along Y
314
      case  6: return mQuats[3];                         // 180 along Z
315
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
316

    
317
      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
      }
330

    
331
    return null;
332
    }
333

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

    
336
  int getNumCubitVariants(int numLayers)
337
    {
338
    return 2;
339
    }
340

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

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

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349

    
350
  int getFaceColor(int cubit, int cubitface, int size)
351
    {
352
    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
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

    
388
  ObjectSticker retSticker(int face)
389
    {
390
    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
    return mStickers[face/NUM_FACE_COLORS];
412
    }
413

    
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415
// PUBLIC API
416

    
417
  public Static3D[] getRotationAxis()
418
    {
419
    return ROT_AXIS;
420
    }
421

    
422
///////////////////////////////////////////////////////////////////////////////////////////////////
423

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

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

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

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
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
}
(32-32/38)