Project

General

Profile

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

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

1 68f6046c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 2077dd18 Leszek Koltunski
import org.distorted.helpers.ObjectShape;
25 9c06394a Leszek Koltunski
import org.distorted.helpers.ObjectSticker;
26 cda32fc1 Leszek Koltunski
import org.distorted.helpers.ScrambleState;
27 68f6046c Leszek Koltunski
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 6fd4a72c Leszek Koltunski
import org.distorted.main.R;
33 68f6046c Leszek Koltunski
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36 efa81f0c Leszek Koltunski
public class TwistyRedi extends Twisty6
37 68f6046c Leszek Koltunski
{
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 91792184 Leszek Koltunski
  private ScrambleState[] mStates;
47 1dd8d3af Leszek Koltunski
  private int[] mBasicAngle;
48
  private Static4D[] mQuats;
49 ef018c1b Leszek Koltunski
  private float[][] mCuts;
50
  private boolean[][] mLayerRotatable;
51 1dd8d3af Leszek Koltunski
  private float[][] mCenters;
52
  private int[][] mFaceMap;
53
  private ObjectSticker[] mStickers;
54 e9a87113 Leszek Koltunski
  private Movement mMovement;
55 cda32fc1 Leszek Koltunski
56 68f6046c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58
  TwistyRedi(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
59
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
60
    {
61 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REDI, res, scrWidth);
62 91792184 Leszek Koltunski
    }
63 cda32fc1 Leszek Koltunski
64 91792184 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
65
66
  ScrambleState[] getScrambleStates()
67
    {
68
    if( mStates==null )
69 cda32fc1 Leszek Koltunski
      {
70 91792184 Leszek Koltunski
      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 68f6046c Leszek Koltunski
    }
86
87 1dd8d3af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 a480ee80 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
110
111
  int[] getSolvedQuats(int cubit, int numLayers)
112
    {
113 1dd8d3af Leszek Koltunski
    if( mQuats==null ) initializeQuats();
114 a480ee80 Leszek Koltunski
    int status = retCubitSolvedStatus(cubit,numLayers);
115 e782e026 Leszek Koltunski
    return status<0 ? null : buildSolvedQuats(MovementCornerTwisting.FACE_AXIS[status],mQuats);
116 a480ee80 Leszek Koltunski
    }
117
118 68f6046c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
119
120
  Static4D[] getQuats()
121
    {
122 1dd8d3af Leszek Koltunski
    if( mQuats==null ) initializeQuats();
123
    return mQuats;
124 68f6046c Leszek Koltunski
    }
125
126 169219a7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
127
128
  int getSolvedFunctionIndex()
129
    {
130
    return 0;
131
    }
132
133 68f6046c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
134
135 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
136 68f6046c Leszek Koltunski
    {
137 1dd8d3af Leszek Koltunski
    return 2;
138 68f6046c Leszek Koltunski
    }
139
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141
142 e6734aa9 Leszek Koltunski
  float[][] getCuts(int size)
143 68f6046c Leszek Koltunski
    {
144 ef018c1b Leszek Koltunski
    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 68f6046c Leszek Koltunski
    }
166
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168
169
  int getNumCubitFaces()
170
    {
171 efa81f0c Leszek Koltunski
    return 9;
172 68f6046c Leszek Koltunski
    }
173
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175
176 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int size)
177 68f6046c Leszek Koltunski
    {
178 1dd8d3af Leszek Koltunski
    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 68f6046c Leszek Koltunski
    }
211
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213
214 2077dd18 Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
215
    {
216
    int variant = getCubitVariant(cubit,numLayers);
217
218
    if( variant==0 )
219
      {
220 1dd8d3af Leszek Koltunski
      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 668423be Leszek Koltunski
      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 2077dd18 Leszek Koltunski
      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 1dd8d3af Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
253 2077dd18 Leszek Koltunski
      }
254
    else
255
      {
256 1dd8d3af Leszek Koltunski
      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 668423be Leszek Koltunski
      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 2077dd18 Leszek Koltunski
      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 1dd8d3af Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
285 2077dd18 Leszek Koltunski
      }
286
    }
287
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289
290 3e605536 Leszek Koltunski
  Static4D getQuat(int cubit, int numLayers)
291 68f6046c Leszek Koltunski
    {
292 1dd8d3af Leszek Koltunski
    if( mQuats==null ) initializeQuats();
293
294 68f6046c Leszek Koltunski
    switch(cubit)
295
      {
296 1dd8d3af Leszek Koltunski
      case  0: return mQuats[0];                         //  unit quat
297 68f6046c Leszek Koltunski
      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 1dd8d3af Leszek Koltunski
      case  3: return mQuats[1];                         // 180 along X
300 68f6046c Leszek Koltunski
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
301 1dd8d3af Leszek Koltunski
      case  5: return mQuats[2];                         // 180 along Y
302
      case  6: return mQuats[3];                         // 180 along Z
303 68f6046c Leszek Koltunski
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
304
305 1dd8d3af Leszek Koltunski
      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 68f6046c Leszek Koltunski
      }
318
319
    return null;
320
    }
321
322 2077dd18 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
323
324 3e605536 Leszek Koltunski
  int getNumCubitVariants(int numLayers)
325 2077dd18 Leszek Koltunski
    {
326
    return 2;
327
    }
328
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330
331
  int getCubitVariant(int cubit, int numLayers)
332
    {
333
    return cubit<8 ? 0:1;
334
    }
335
336 68f6046c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
337
338
  int getFaceColor(int cubit, int cubitface, int size)
339
    {
340 1dd8d3af Leszek Koltunski
    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 68f6046c Leszek Koltunski
    }
373
374 9c06394a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
375
376
  ObjectSticker retSticker(int face)
377
    {
378 1dd8d3af Leszek Koltunski
    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 abf36986 Leszek Koltunski
    return mStickers[face/NUM_FACE_COLORS];
400 68f6046c Leszek Koltunski
    }
401
402 4c737817 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
403 cda32fc1 Leszek Koltunski
// PUBLIC API
404 4c737817 Leszek Koltunski
405 cda32fc1 Leszek Koltunski
  public Static3D[] getRotationAxis()
406
    {
407
    return ROT_AXIS;
408 0812242b Leszek Koltunski
    }
409
410 e9a87113 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
411
412
  public Movement getMovement()
413
    {
414 ef018c1b Leszek Koltunski
    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 e9a87113 Leszek Koltunski
    return mMovement;
423
    }
424
425 68f6046c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
426
427 cda32fc1 Leszek Koltunski
  public int[] getBasicAngle()
428 68f6046c Leszek Koltunski
    {
429 1dd8d3af Leszek Koltunski
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
430
    return mBasicAngle;
431 68f6046c Leszek Koltunski
    }
432
433 6fd4a72c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 68f6046c Leszek Koltunski
}