Project

General

Profile

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

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

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.MOVEMENT_HEXAHEDRON;
23
import static org.distorted.objectlib.main.Movement.TYPE_SPLIT_CORNER;
24

    
25
import android.content.res.Resources;
26

    
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

    
33
import org.distorted.objectlib.R;
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 ScrambleState[] mStates;
55
  private int[] mBasicAngle;
56
  private Static4D[] mQuats;
57
  private float[][] mCuts;
58
  private float[][] mCenters;
59
  private int[][] mFaceMap;
60
  private ObjectSticker[] mStickers;
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  public TwistyRedi(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
65
                    MeshSquare mesh, DistortedEffects effects, Resources res, int surfaceW, int surfaceH)
66
    {
67
    super(numL, numL[0], quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
68
    }
69

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

    
72
  public ScrambleState[] getScrambleStates()
73
    {
74
    if( mStates==null )
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
    return mStates;
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
  protected int getResource(int[] numLayers)
96
    {
97
    return R.raw.redi;
98
    }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

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

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

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

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

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

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

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

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

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  public int getNumStickerTypes(int[] numLayers)
149
    {
150
    return 2;
151
    }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

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

    
164
    return mCuts;
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  public boolean[][] getLayerRotatable(int[] numLayers)
170
    {
171
    int numAxis = ROT_AXIS.length;
172
    boolean[] tmp = new boolean[] {true,false,true};
173
    boolean[][] layerRotatable = new boolean[numAxis][];
174
    for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
175

    
176
    return layerRotatable;
177
    }
178

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

    
181
  public int getMovementType()
182
    {
183
    return MOVEMENT_HEXAHEDRON;
184
    }
185

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

    
188
  public int getMovementSplit()
189
    {
190
    return TYPE_SPLIT_CORNER;
191
    }
192

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

    
195
  public int[][][] getEnabled()
196
    {
197
    return new int[][][]
198
      {
199
          {{0,1},{3,1},{2,3},{0,2}},
200
          {{2,3},{3,1},{0,1},{0,2}},
201
          {{1,2},{0,1},{0,3},{2,3}},
202
          {{1,2},{2,3},{0,3},{0,1}},
203
          {{0,3},{0,2},{1,2},{1,3}},
204
          {{1,2},{0,2},{0,3},{1,3}},
205
      };
206
    }
207

    
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209

    
210
  public float[] getDist3D(int[] numLayers)
211
    {
212
    return null;
213
    }
214

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

    
217
  protected int getNumCubitFaces()
218
    {
219
    return 9;
220
    }
221

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

    
224
  public float[][] getCubitPositions(int[] numLayers)
225
    {
226
    if( mCenters==null )
227
      {
228
      final float DIST_CORNER = 1.0f;
229
      final float DIST_EDGE   = 1.5f;
230

    
231
      mCenters = new float[][]
232
         {
233
             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
234
             { DIST_CORNER, DIST_CORNER,-DIST_CORNER },
235
             { DIST_CORNER,-DIST_CORNER, DIST_CORNER },
236
             { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
237
             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
238
             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
239
             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
240
             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
241

    
242
             {      0.0f, DIST_EDGE, DIST_EDGE },
243
             { DIST_EDGE,      0.0f, DIST_EDGE },
244
             {      0.0f,-DIST_EDGE, DIST_EDGE },
245
             {-DIST_EDGE,      0.0f, DIST_EDGE },
246
             { DIST_EDGE, DIST_EDGE,      0.0f },
247
             { DIST_EDGE,-DIST_EDGE,      0.0f },
248
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
249
             {-DIST_EDGE, DIST_EDGE,      0.0f },
250
             {      0.0f, DIST_EDGE,-DIST_EDGE },
251
             { DIST_EDGE,      0.0f,-DIST_EDGE },
252
             {      0.0f,-DIST_EDGE,-DIST_EDGE },
253
             {-DIST_EDGE,      0.0f,-DIST_EDGE }
254
         };
255
      }
256

    
257
    return mCenters;
258
    }
259

    
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

    
262
  public ObjectShape getObjectShape(int variant)
263
    {
264
    if( variant==0 )
265
      {
266
      double[][] vertices = new double[][]
267
          {
268
             { 0.0f, 0.0f, 0.0f },
269
             {-0.5f, 0.5f, 0.5f },
270
             {-0.5f,-0.5f, 0.5f },
271
             { 0.5f, 0.5f, 0.5f },
272
             { 0.5f,-0.5f, 0.5f },
273
             { 0.5f, 0.5f,-0.5f },
274
             { 0.5f,-0.5f,-0.5f },
275
             {-0.5f, 0.5f,-0.5f },
276
          };
277

    
278
      int[][] vert_indices = new int[][]
279
          {
280
             { 2,4,3,1 },
281
             { 1,3,5,7 },
282
             { 4,6,5,3 },
283

    
284
             { 2,4,0 },
285
             { 5,7,0 },
286
             { 4,6,0 },
287
             { 7,1,0 },
288
             { 1,2,0 },
289
             { 6,5,0 }
290
          };
291

    
292
      float[][] bands     = new float[][] { {0.06f,35,0.5f,0.7f,5,2,2}, {0.01f,35,0.2f,0.4f,5,2,2} };
293
      int[] bandIndices   = new int[] { 0,0,0,1,1,1,1,1,1 };
294
      float[][] corners   = new float[][] { {0.06f,0.12f} };
295
      int[] cornerIndices = new int[]  { -1,0,-1,0,0,0,-1,-1 };
296
      float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
297
      int[] centerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
298
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
299
      }
300
    else
301
      {
302
      double[][] vertices = new double[][]
303
          {
304
             {-0.5f, 0.0f, 0.0f},
305
             { 0.5f, 0.0f, 0.0f},
306
             {-0.5f,-1.0f, 0.0f},
307
             { 0.5f,-1.0f, 0.0f},
308
             { 0.0f,-1.5f, 0.0f},
309
             {-0.5f, 0.0f,-1.0f},
310
             { 0.5f, 0.0f,-1.0f},
311
             { 0.0f, 0.0f,-1.5f},
312
          };
313

    
314
      int[][] vert_indices = new int[][]
315
          {
316
             { 0,2,4,3,1 },
317
             { 0,1,6,7,5 },
318
             { 1,3,6 },
319
             { 0,2,5 },
320
             { 4,7,6,3 },
321
             { 4,7,5,2 }
322
          };
323

    
324
      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} };
325
      int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
326
      float[][] corners   = new float[][] { {0.06f,0.20f} };
327
      int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
328
      float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
329
      int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
330
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
331
      }
332
    }
333

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

    
336
  public Static4D getQuat(int cubit, int[] numLayers)
337
    {
338
    if( mQuats==null ) initializeQuats();
339

    
340
    switch(cubit)
341
      {
342
      case  0: return mQuats[0];                         //  unit quat
343
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
344
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
345
      case  3: return mQuats[1];                         // 180 along X
346
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
347
      case  5: return mQuats[2];                         // 180 along Y
348
      case  6: return mQuats[3];                         // 180 along Z
349
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
350

    
351
      case  8: return mQuats[0];
352
      case  9: return mQuats[5];
353
      case 10: return mQuats[3];
354
      case 11: return mQuats[11];
355
      case 12: return mQuats[4];
356
      case 13: return mQuats[7];
357
      case 14: return mQuats[9];
358
      case 15: return mQuats[10];
359
      case 16: return mQuats[2];
360
      case 17: return mQuats[8];
361
      case 18: return mQuats[1];
362
      case 19: return mQuats[6];
363
      }
364

    
365
    return null;
366
    }
367

    
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369

    
370
  public int getNumCubitVariants(int[] numLayers)
371
    {
372
    return 2;
373
    }
374

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376

    
377
  public int getCubitVariant(int cubit, int[] numLayers)
378
    {
379
    return cubit<8 ? 0:1;
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

    
384
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
385
    {
386
    if( mFaceMap==null )
387
      {
388
      // Colors of the faces of cubits.
389
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4  ORANGE 5
390
      // YELLOW 6 WHITE 7 BLUE 8 GREEN 9 RED 10 ORANGE 11
391
      mFaceMap = new int[][]
392
         {
393
           {  4, 2, 0 },
394
           {  2, 5, 0 },
395
           {  3, 4, 0 },
396
           {  5, 3, 0 },
397
           {  1, 2, 4 },
398
           {  5, 2, 1 },
399
           {  4, 3, 1 },
400
           {  1, 3, 5 },
401

    
402
           { 10, 8,12 },
403
           {  6,10,12 },
404
           { 10, 9,12 },
405
           {  7,10,12 },
406
           {  8, 6,12 },
407
           {  9, 6,12 },
408
           {  9, 7,12 },
409
           {  8, 7,12 },
410
           { 11, 8,12 },
411
           {  6,11,12 },
412
           { 11, 9,12 },
413
           {  7,11,12 },
414
         };
415
      }
416

    
417
    return cubitface<3 ? mFaceMap[cubit][cubitface] : NUM_TEXTURES;
418
    }
419

    
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421

    
422
  public ObjectSticker retSticker(int sticker)
423
    {
424
    if( mStickers==null )
425
      {
426
      float[][] STICKERS = new float[][]
427
          {
428
             { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
429
             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
430
          };
431

    
432
      final float R0 = 0.09f;
433
      final float R1 = 0.06f;
434
      final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1} };
435
      float[] strokes = { 0.09f,0.06f };
436

    
437
      if( ObjectControl.isInIconMode() )
438
        {
439
        float mult = 2.2f;
440
        strokes[0]*=mult;
441
        strokes[1]*=mult;
442
        }
443

    
444
      mStickers = new ObjectSticker[STICKERS.length];
445

    
446
      for(int s=0; s<STICKERS.length; s++)
447
        {
448
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
449
        }
450
      }
451

    
452
    return mStickers[sticker];
453
    }
454

    
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456
// PUBLIC API
457

    
458
  public Static3D[] getRotationAxis()
459
    {
460
    return ROT_AXIS;
461
    }
462

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

    
465
  public int[] getBasicAngle()
466
    {
467
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
468
    return mBasicAngle;
469
    }
470

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

    
473
  public ObjectType intGetObjectType(int[] numLayers)
474
    {
475
    return ObjectType.REDI_3;
476
    }
477

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

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

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

    
487
  public int getInventor(int[] numLayers)
488
    {
489
    return R.string.redi2_inventor;
490
    }
491

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493

    
494
  public int getYearOfInvention(int[] numLayers)
495
    {
496
    return 2009;
497
    }
498

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

    
501
  public int getComplexity(int[] numLayers)
502
    {
503
    return 4;
504
    }
505
}
(19-19/25)