Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyRedi.java @ 1dd8d3af

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 android.content.res.Resources;
23

    
24
import org.distorted.helpers.ObjectShape;
25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.ScrambleState;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32
import org.distorted.main.R;
33

    
34
import java.util.Random;
35

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

    
38
public class TwistyRedi extends TwistyObject
39
{
40
  // the four rotation axis of a Redi. Must be normalized.
41
  static final Static3D[] ROT_AXIS = new Static3D[]
42
         {
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
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
47
         };
48

    
49
  private static final int[] FACE_COLORS = new int[]
50
         {
51
           COLOR_YELLOW, COLOR_WHITE,
52
           COLOR_BLUE  , COLOR_GREEN,
53
           COLOR_RED   , COLOR_ORANGE
54
         };
55

    
56
  private static final int FACES_PER_CUBIT =9;
57

    
58
  private int mCurrState;
59
  private int mIndexExcluded;
60
  private final ScrambleState[] mStates;
61
  private int[][] mScrambleTable;
62
  private int[] mNumOccurences;
63
  private int[] mBasicAngle;
64
  private Static4D[] mQuats;
65
  private float[][] mCenters;
66
  private int[][] mFaceMap;
67
  private ObjectSticker[] mStickers;
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

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

    
76
    mStates = new ScrambleState[]
77
      {
78
      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} } ),
79
      new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
80
      new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
81
      new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
82
      new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
83
      new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
84
      new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
85
      new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
86
      new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
87
      };
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  private void initializeQuats()
93
    {
94
    mQuats = new Static4D[]
95
         {
96
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
97
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
98
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
99
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
100

    
101
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
102
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
103
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
104
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
105
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
106
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
107
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
108
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
109
         };
110
    }
111

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

    
114
  int[] getSolvedQuats(int cubit, int numLayers)
115
    {
116
    if( mQuats==null ) initializeQuats();
117
    int status = retCubitSolvedStatus(cubit,numLayers);
118
    return status<0 ? null : buildSolvedQuats(MovementRedi.FACE_AXIS[status],mQuats);
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  float getScreenRatio()
124
    {
125
    return 0.50f;
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

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

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  int getNumFaces()
139
    {
140
    return FACE_COLORS.length;
141
    }
142

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

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

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

    
152
  boolean shouldResetTextureMaps()
153
    {
154
    return false;
155
    }
156

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

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

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

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

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  int getNumCubitFaces()
176
    {
177
    return FACES_PER_CUBIT;
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

    
182
  float[][] getCubitPositions(int size)
183
    {
184
    if( mCenters==null )
185
      {
186
      final float DIST_CORNER = 1.0f;
187
      final float DIST_EDGE   = 1.5f;
188

    
189
      mCenters = new float[][]
190
         {
191
             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
192
             { DIST_CORNER, DIST_CORNER,-DIST_CORNER },
193
             { DIST_CORNER,-DIST_CORNER, DIST_CORNER },
194
             { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
195
             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
196
             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
197
             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
198
             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
199

    
200
             {      0.0f, DIST_EDGE, DIST_EDGE },
201
             { DIST_EDGE,      0.0f, DIST_EDGE },
202
             {      0.0f,-DIST_EDGE, DIST_EDGE },
203
             {-DIST_EDGE,      0.0f, DIST_EDGE },
204
             { DIST_EDGE, DIST_EDGE,      0.0f },
205
             { DIST_EDGE,-DIST_EDGE,      0.0f },
206
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
207
             {-DIST_EDGE, DIST_EDGE,      0.0f },
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
         };
213
      }
214

    
215
    return mCenters;
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

    
220
  ObjectShape getObjectShape(int cubit, int numLayers)
221
    {
222
    int variant = getCubitVariant(cubit,numLayers);
223

    
224
    if( variant==0 )
225
      {
226
      double[][] vertices = new double[][]
227
          {
228
             { 0.0f, 0.0f, 0.0f },
229
             {-0.5f, 0.5f, 0.5f },
230
             {-0.5f,-0.5f, 0.5f },
231
             { 0.5f, 0.5f, 0.5f },
232
             { 0.5f,-0.5f, 0.5f },
233
             { 0.5f, 0.5f,-0.5f },
234
             { 0.5f,-0.5f,-0.5f },
235
             {-0.5f, 0.5f,-0.5f },
236
          };
237

    
238
      int[][] vert_indices = new int[][]
239
          {
240
             { 2,4,3,1 },
241
             { 1,3,5,7 },
242
             { 4,6,5,3 },
243

    
244
             { 2,4,0 },
245
             { 5,7,0 },
246
             { 4,6,0 },
247
             { 7,1,0 },
248
             { 1,2,0 },
249
             { 6,5,0 }
250
          };
251

    
252
      float[][] bands     = new float[][] { {0.06f,35,0.5f,0.7f,5,2,2}, {0.01f,35,0.2f,0.4f,5,2,2} };
253
      int[] bandIndices   = new int[] { 0,0,0,1,1,1,1,1,1 };
254
      float[][] corners   = new float[][] { {0.06f,0.12f} };
255
      int[] cornerIndices = new int[]  { -1,0,-1,0,0,0,-1,-1 };
256
      float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
257
      int[] centerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
258
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
259
      }
260
    else
261
      {
262
      double[][] vertices = new double[][]
263
          {
264
             {-0.5f, 0.0f, 0.0f},
265
             { 0.5f, 0.0f, 0.0f},
266
             {-0.5f,-1.0f, 0.0f},
267
             { 0.5f,-1.0f, 0.0f},
268
             { 0.0f,-1.5f, 0.0f},
269
             {-0.5f, 0.0f,-1.0f},
270
             { 0.5f, 0.0f,-1.0f},
271
             { 0.0f, 0.0f,-1.5f},
272
          };
273

    
274
      int[][] vert_indices = new int[][]
275
          {
276
             { 0,2,4,3,1 },
277
             { 0,1,6,7,5 },
278
             { 1,3,6 },
279
             { 0,2,5 },
280
             { 4,7,6,3 },
281
             { 4,7,5,2 }
282
          };
283

    
284
      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} };
285
      int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
286
      float[][] corners   = new float[][] { {0.06f,0.20f} };
287
      int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
288
      float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
289
      int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
290
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
291
      }
292
    }
293

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

    
296
  Static4D getQuat(int cubit, int numLayers)
297
    {
298
    if( mQuats==null ) initializeQuats();
299

    
300
    switch(cubit)
301
      {
302
      case  0: return mQuats[0];                         //  unit quat
303
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
304
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
305
      case  3: return mQuats[1];                         // 180 along X
306
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
307
      case  5: return mQuats[2];                         // 180 along Y
308
      case  6: return mQuats[3];                         // 180 along Z
309
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
310

    
311
      case  8: return mQuats[0];
312
      case  9: return mQuats[5];
313
      case 10: return mQuats[3];
314
      case 11: return mQuats[11];
315
      case 12: return mQuats[4];
316
      case 13: return mQuats[7];
317
      case 14: return mQuats[9];
318
      case 15: return mQuats[10];
319
      case 16: return mQuats[2];
320
      case 17: return mQuats[8];
321
      case 18: return mQuats[1];
322
      case 19: return mQuats[6];
323
      }
324

    
325
    return null;
326
    }
327

    
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329

    
330
  int getNumCubitVariants(int numLayers)
331
    {
332
    return 2;
333
    }
334

    
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336

    
337
  int getCubitVariant(int cubit, int numLayers)
338
    {
339
    return cubit<8 ? 0:1;
340
    }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343

    
344
  int getFaceColor(int cubit, int cubitface, int size)
345
    {
346
    if( mFaceMap==null )
347
      {
348
      // Colors of the faces of cubits.
349
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4  ORANGE 5
350
      // YELLOW 6 WHITE 7 BLUE 8 GREEN 9 RED 10 ORANGE 11
351
      mFaceMap = new int[][]
352
         {
353
           {  4, 2, 0 },
354
           {  2, 5, 0 },
355
           {  3, 4, 0 },
356
           {  5, 3, 0 },
357
           {  1, 2, 4 },
358
           {  5, 2, 1 },
359
           {  4, 3, 1 },
360
           {  1, 3, 5 },
361

    
362
           { 10, 8,12 },
363
           {  6,10,12 },
364
           { 10, 9,12 },
365
           {  7,10,12 },
366
           {  8, 6,12 },
367
           {  9, 6,12 },
368
           {  9, 7,12 },
369
           {  8, 7,12 },
370
           { 11, 8,12 },
371
           {  6,11,12 },
372
           { 11, 9,12 },
373
           {  7,11,12 },
374
         };
375
      }
376

    
377
    return cubitface<3 ? mFaceMap[cubit][cubitface] : NUM_TEXTURES;
378
    }
379

    
380
///////////////////////////////////////////////////////////////////////////////////////////////////
381

    
382
  int getColor(int face)
383
    {
384
    return FACE_COLORS[face];
385
    }
386

    
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388

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

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

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

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

    
412
    return mStickers[face/NUM_FACES];
413
    }
414

    
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416

    
417
  float returnMultiplier()
418
    {
419
    return 2.0f;
420
    }
421

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

    
424
  private void initializeScrambling()
425
    {
426
    int numLayers = getNumLayers();
427

    
428
    if( mScrambleTable ==null )
429
      {
430
      mScrambleTable = new int[NUM_AXIS][numLayers];
431
      }
432
    if( mNumOccurences ==null )
433
      {
434
      int max=0;
435

    
436
      for (ScrambleState mState : mStates)
437
        {
438
        int tmp = mState.getTotal(-1);
439
        if (max < tmp) max = tmp;
440
        }
441

    
442
      mNumOccurences = new int[max];
443
      }
444

    
445
    for(int i=0; i<NUM_AXIS; i++)
446
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450
// PUBLIC API
451

    
452
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
453
    {
454
    if( curr==0 )
455
      {
456
      mCurrState     = 0;
457
      mIndexExcluded =-1;
458
      initializeScrambling();
459
      }
460

    
461
    int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
462

    
463
    scramble[curr][0] = info[0];
464
    scramble[curr][1] = info[1];
465
    scramble[curr][2] = info[2];
466

    
467
    mCurrState     = info[3];
468
    mIndexExcluded = info[0];
469
    }
470

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

    
473
  public Static3D[] getRotationAxis()
474
    {
475
    return ROT_AXIS;
476
    }
477

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

    
480
  public int[] getBasicAngle()
481
    {
482
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
483
    return mBasicAngle;
484
    }
485

    
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487

    
488
  public int getObjectName(int numLayers)
489
    {
490
    return R.string.redi2;
491
    }
492

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494

    
495
  public int getInventor(int numLayers)
496
    {
497
    return R.string.redi2_inventor;
498
    }
499

    
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501

    
502
  public int getComplexity(int numLayers)
503
    {
504
    return 4;
505
    }
506
}
(35-35/41)