Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyRedi.java @ ef018c1b

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
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class TwistyRedi extends Twisty6
37
{
38
  static final Static3D[] ROT_AXIS = new Static3D[]
39
         {
40
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
41
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
42
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
43
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
44
         };
45

    
46
  private ScrambleState[] mStates;
47
  private int[] mBasicAngle;
48
  private Static4D[] mQuats;
49
  private float[][] mCuts;
50
  private boolean[][] mLayerRotatable;
51
  private float[][] mCenters;
52
  private int[][] mFaceMap;
53
  private ObjectSticker[] mStickers;
54
  private Movement mMovement;
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  TwistyRedi(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
59
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
60
    {
61
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REDI, res, scrWidth);
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  ScrambleState[] getScrambleStates()
67
    {
68
    if( mStates==null )
69
      {
70
      mStates = new ScrambleState[]
71
        {
72
        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} } ),
73
        new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
74
        new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
75
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
76
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
77
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
78
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
79
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
80
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
81
        };
82
      }
83

    
84
    return mStates;
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  private void initializeQuats()
90
    {
91
    mQuats = new Static4D[]
92
         {
93
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
94
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
95
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
96
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
97

    
98
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
99
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
100
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
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
         };
107
    }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
  int[] getSolvedQuats(int cubit, int numLayers)
112
    {
113
    if( mQuats==null ) initializeQuats();
114
    int status = retCubitSolvedStatus(cubit,numLayers);
115
    return status<0 ? null : buildSolvedQuats(MovementCornerTwisting.FACE_AXIS[status],mQuats);
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  Static4D[] getQuats()
121
    {
122
    if( mQuats==null ) initializeQuats();
123
    return mQuats;
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
  int getSolvedFunctionIndex()
129
    {
130
    return 0;
131
    }
132

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

    
135
  int getNumStickerTypes(int numLayers)
136
    {
137
    return 2;
138
    }
139

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

    
142
  float[][] getCuts(int size)
143
    {
144
    if( mCuts==null )
145
      {
146
      float C = +SQ3/3 +0.05f;
147
      float[] cut = new float[] {-C,+C};
148
      mCuts = new float[][] { cut,cut,cut,cut };
149
      }
150

    
151
    return mCuts;
152
    }
153

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

    
156
  private void getLayerRotatable(int numLayers)
157
    {
158
    if( mLayerRotatable==null )
159
      {
160
      int numAxis = ROT_AXIS.length;
161
      boolean[] tmp = new boolean[] {true,false,true};
162
      mLayerRotatable = new boolean[numAxis][];
163
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
164
      }
165
    }
166

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

    
169
  int getNumCubitFaces()
170
    {
171
    return 9;
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  float[][] getCubitPositions(int size)
177
    {
178
    if( mCenters==null )
179
      {
180
      final float DIST_CORNER = 1.0f;
181
      final float DIST_EDGE   = 1.5f;
182

    
183
      mCenters = new float[][]
184
         {
185
             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
186
             { DIST_CORNER, DIST_CORNER,-DIST_CORNER },
187
             { DIST_CORNER,-DIST_CORNER, DIST_CORNER },
188
             { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
189
             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
190
             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
191
             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
192
             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
193

    
194
             {      0.0f, DIST_EDGE, DIST_EDGE },
195
             { DIST_EDGE,      0.0f, DIST_EDGE },
196
             {      0.0f,-DIST_EDGE, DIST_EDGE },
197
             {-DIST_EDGE,      0.0f, DIST_EDGE },
198
             { DIST_EDGE, DIST_EDGE,      0.0f },
199
             { DIST_EDGE,-DIST_EDGE,      0.0f },
200
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
201
             {-DIST_EDGE, DIST_EDGE,      0.0f },
202
             {      0.0f, DIST_EDGE,-DIST_EDGE },
203
             { DIST_EDGE,      0.0f,-DIST_EDGE },
204
             {      0.0f,-DIST_EDGE,-DIST_EDGE },
205
             {-DIST_EDGE,      0.0f,-DIST_EDGE }
206
         };
207
      }
208

    
209
    return mCenters;
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  ObjectShape getObjectShape(int cubit, int numLayers)
215
    {
216
    int variant = getCubitVariant(cubit,numLayers);
217

    
218
    if( variant==0 )
219
      {
220
      double[][] vertices = new double[][]
221
          {
222
             { 0.0f, 0.0f, 0.0f },
223
             {-0.5f, 0.5f, 0.5f },
224
             {-0.5f,-0.5f, 0.5f },
225
             { 0.5f, 0.5f, 0.5f },
226
             { 0.5f,-0.5f, 0.5f },
227
             { 0.5f, 0.5f,-0.5f },
228
             { 0.5f,-0.5f,-0.5f },
229
             {-0.5f, 0.5f,-0.5f },
230
          };
231

    
232
      int[][] vert_indices = new int[][]
233
          {
234
             { 2,4,3,1 },
235
             { 1,3,5,7 },
236
             { 4,6,5,3 },
237

    
238
             { 2,4,0 },
239
             { 5,7,0 },
240
             { 4,6,0 },
241
             { 7,1,0 },
242
             { 1,2,0 },
243
             { 6,5,0 }
244
          };
245

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

    
268
      int[][] vert_indices = new int[][]
269
          {
270
             { 0,2,4,3,1 },
271
             { 0,1,6,7,5 },
272
             { 1,3,6 },
273
             { 0,2,5 },
274
             { 4,7,6,3 },
275
             { 4,7,5,2 }
276
          };
277

    
278
      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} };
279
      int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
280
      float[][] corners   = new float[][] { {0.06f,0.20f} };
281
      int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
282
      float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
283
      int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
284
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
285
      }
286
    }
287

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

    
290
  Static4D getQuat(int cubit, int numLayers)
291
    {
292
    if( mQuats==null ) initializeQuats();
293

    
294
    switch(cubit)
295
      {
296
      case  0: return mQuats[0];                         //  unit quat
297
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
298
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
299
      case  3: return mQuats[1];                         // 180 along X
300
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
301
      case  5: return mQuats[2];                         // 180 along Y
302
      case  6: return mQuats[3];                         // 180 along Z
303
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
304

    
305
      case  8: return mQuats[0];
306
      case  9: return mQuats[5];
307
      case 10: return mQuats[3];
308
      case 11: return mQuats[11];
309
      case 12: return mQuats[4];
310
      case 13: return mQuats[7];
311
      case 14: return mQuats[9];
312
      case 15: return mQuats[10];
313
      case 16: return mQuats[2];
314
      case 17: return mQuats[8];
315
      case 18: return mQuats[1];
316
      case 19: return mQuats[6];
317
      }
318

    
319
    return null;
320
    }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
  int getNumCubitVariants(int numLayers)
325
    {
326
    return 2;
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

    
331
  int getCubitVariant(int cubit, int numLayers)
332
    {
333
    return cubit<8 ? 0:1;
334
    }
335

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

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

    
356
           { 10, 8,12 },
357
           {  6,10,12 },
358
           { 10, 9,12 },
359
           {  7,10,12 },
360
           {  8, 6,12 },
361
           {  9, 6,12 },
362
           {  9, 7,12 },
363
           {  8, 7,12 },
364
           { 11, 8,12 },
365
           {  6,11,12 },
366
           { 11, 9,12 },
367
           {  7,11,12 },
368
         };
369
      }
370

    
371
    return cubitface<3 ? mFaceMap[cubit][cubitface] : NUM_TEXTURES;
372
    }
373

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

    
376
  ObjectSticker retSticker(int face)
377
    {
378
    if( mStickers==null )
379
      {
380
      float[][] STICKERS = new float[][]
381
          {
382
             { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
383
             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
384
          };
385

    
386
      final float R0 = 0.09f;
387
      final float R1 = 0.06f;
388
      final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1} };
389
      final float[] strokes = { 0.09f,0.06f };
390

    
391
      mStickers = new ObjectSticker[STICKERS.length];
392

    
393
      for(int s=0; s<STICKERS.length; s++)
394
        {
395
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
396
        }
397
      }
398

    
399
    return mStickers[face/NUM_FACE_COLORS];
400
    }
401

    
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403
// PUBLIC API
404

    
405
  public Static3D[] getRotationAxis()
406
    {
407
    return ROT_AXIS;
408
    }
409

    
410
///////////////////////////////////////////////////////////////////////////////////////////////////
411

    
412
  public Movement getMovement()
413
    {
414
    if( mMovement==null )
415
      {
416
      int numLayers = getNumLayers();
417
      if( mCuts==null ) getCuts(numLayers);
418
      getLayerRotatable(numLayers);
419

    
420
      mMovement = new MovementCornerTwisting(mCuts,mLayerRotatable,numLayers);
421
      }
422
    return mMovement;
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

    
427
  public int[] getBasicAngle()
428
    {
429
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
430
    return mBasicAngle;
431
    }
432

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

    
435
  public int getObjectName(int numLayers)
436
    {
437
    return R.string.redi2;
438
    }
439

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

    
442
  public int getInventor(int numLayers)
443
    {
444
    return R.string.redi2_inventor;
445
    }
446

    
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448

    
449
  public int getComplexity(int numLayers)
450
    {
451
    return 4;
452
    }
453
}
(42-42/48)