Project

General

Profile

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

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

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
public class TwistyRedi extends TwistyObject
37
{
38 1dd8d3af Leszek Koltunski
  // the four rotation axis of a Redi. Must be normalized.
39 68f6046c Leszek Koltunski
  static final Static3D[] ROT_AXIS = new Static3D[]
40
         {
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
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
45
         };
46
47
  private static final int[] FACE_COLORS = new int[]
48
         {
49
           COLOR_YELLOW, COLOR_WHITE,
50
           COLOR_BLUE  , COLOR_GREEN,
51 323b217c Leszek Koltunski
           COLOR_RED   , COLOR_ORANGE
52 68f6046c Leszek Koltunski
         };
53
54 1dd8d3af Leszek Koltunski
  private static final int FACES_PER_CUBIT =9;
55 9c06394a Leszek Koltunski
56 91792184 Leszek Koltunski
  private ScrambleState[] mStates;
57 1dd8d3af Leszek Koltunski
  private int[] mBasicAngle;
58
  private Static4D[] mQuats;
59
  private float[][] mCenters;
60
  private int[][] mFaceMap;
61
  private ObjectSticker[] mStickers;
62 cda32fc1 Leszek Koltunski
63 68f6046c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
64
65
  TwistyRedi(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
66
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
67
    {
68 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REDI, res, scrWidth);
69 91792184 Leszek Koltunski
    }
70 cda32fc1 Leszek Koltunski
71 91792184 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73
  ScrambleState[] getScrambleStates()
74
    {
75
    if( mStates==null )
76 cda32fc1 Leszek Koltunski
      {
77 91792184 Leszek Koltunski
      mStates = new ScrambleState[]
78
        {
79
        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} } ),
80
        new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
81
        new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
82
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
83
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
84
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
85
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
86
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
87
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
88
        };
89
      }
90
91
    return mStates;
92 68f6046c Leszek Koltunski
    }
93
94 1dd8d3af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
95
96
  private void initializeQuats()
97
    {
98
    mQuats = new Static4D[]
99
         {
100
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
101
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
102
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
103
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
104
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
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
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
         };
114
    }
115
116 a480ee80 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
117
118
  int[] getSolvedQuats(int cubit, int numLayers)
119
    {
120 1dd8d3af Leszek Koltunski
    if( mQuats==null ) initializeQuats();
121 a480ee80 Leszek Koltunski
    int status = retCubitSolvedStatus(cubit,numLayers);
122 1dd8d3af Leszek Koltunski
    return status<0 ? null : buildSolvedQuats(MovementRedi.FACE_AXIS[status],mQuats);
123 a480ee80 Leszek Koltunski
    }
124
125 68f6046c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
126
127
  float getScreenRatio()
128
    {
129
    return 0.50f;
130
    }
131
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133
134
  Static4D[] getQuats()
135
    {
136 1dd8d3af Leszek Koltunski
    if( mQuats==null ) initializeQuats();
137
    return mQuats;
138 68f6046c Leszek Koltunski
    }
139
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141
142 abf36986 Leszek Koltunski
  int getNumFaceColors()
143 68f6046c Leszek Koltunski
    {
144
    return FACE_COLORS.length;
145
    }
146
147 169219a7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
148
149
  int getSolvedFunctionIndex()
150
    {
151
    return 0;
152
    }
153
154 68f6046c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
155
156
  boolean shouldResetTextureMaps()
157
    {
158
    return false;
159
    }
160
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162
163 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
164 68f6046c Leszek Koltunski
    {
165 1dd8d3af Leszek Koltunski
    return 2;
166 68f6046c Leszek Koltunski
    }
167
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169
170 e6734aa9 Leszek Koltunski
  float[][] getCuts(int size)
171 68f6046c Leszek Koltunski
    {
172 668423be Leszek Koltunski
    float C = +SQ3/3 +0.05f;
173
    float[] cut = new float[] {-C,+C};
174 e6734aa9 Leszek Koltunski
    return new float[][] { cut,cut,cut,cut };
175 68f6046c Leszek Koltunski
    }
176
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178
179
  int getNumCubitFaces()
180
    {
181
    return FACES_PER_CUBIT;
182
    }
183
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185
186 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int size)
187 68f6046c Leszek Koltunski
    {
188 1dd8d3af Leszek Koltunski
    if( mCenters==null )
189
      {
190
      final float DIST_CORNER = 1.0f;
191
      final float DIST_EDGE   = 1.5f;
192
193
      mCenters = new float[][]
194
         {
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
             {-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
204
             {      0.0f, DIST_EDGE, DIST_EDGE },
205
             { DIST_EDGE,      0.0f, DIST_EDGE },
206
             {      0.0f,-DIST_EDGE, DIST_EDGE },
207
             {-DIST_EDGE,      0.0f, DIST_EDGE },
208
             { DIST_EDGE, DIST_EDGE,      0.0f },
209
             { DIST_EDGE,-DIST_EDGE,      0.0f },
210
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
211
             {-DIST_EDGE, DIST_EDGE,      0.0f },
212
             {      0.0f, DIST_EDGE,-DIST_EDGE },
213
             { DIST_EDGE,      0.0f,-DIST_EDGE },
214
             {      0.0f,-DIST_EDGE,-DIST_EDGE },
215
             {-DIST_EDGE,      0.0f,-DIST_EDGE }
216
         };
217
      }
218
219
    return mCenters;
220 68f6046c Leszek Koltunski
    }
221
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
224 2077dd18 Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
225
    {
226
    int variant = getCubitVariant(cubit,numLayers);
227
228
    if( variant==0 )
229
      {
230 1dd8d3af Leszek Koltunski
      double[][] vertices = new double[][]
231
          {
232
             { 0.0f, 0.0f, 0.0f },
233
             {-0.5f, 0.5f, 0.5f },
234
             {-0.5f,-0.5f, 0.5f },
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
          };
241
242
      int[][] vert_indices = new int[][]
243
          {
244
             { 2,4,3,1 },
245
             { 1,3,5,7 },
246
             { 4,6,5,3 },
247
248
             { 2,4,0 },
249
             { 5,7,0 },
250
             { 4,6,0 },
251
             { 7,1,0 },
252
             { 1,2,0 },
253
             { 6,5,0 }
254
          };
255
256 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} };
257 2077dd18 Leszek Koltunski
      int[] bandIndices   = new int[] { 0,0,0,1,1,1,1,1,1 };
258
      float[][] corners   = new float[][] { {0.06f,0.12f} };
259
      int[] cornerIndices = new int[]  { -1,0,-1,0,0,0,-1,-1 };
260
      float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
261
      int[] centerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
262 1dd8d3af Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
263 2077dd18 Leszek Koltunski
      }
264
    else
265
      {
266 1dd8d3af Leszek Koltunski
      double[][] vertices = new double[][]
267
          {
268
             {-0.5f, 0.0f, 0.0f},
269
             { 0.5f, 0.0f, 0.0f},
270
             {-0.5f,-1.0f, 0.0f},
271
             { 0.5f,-1.0f, 0.0f},
272
             { 0.0f,-1.5f, 0.0f},
273
             {-0.5f, 0.0f,-1.0f},
274
             { 0.5f, 0.0f,-1.0f},
275
             { 0.0f, 0.0f,-1.5f},
276
          };
277
278
      int[][] vert_indices = new int[][]
279
          {
280
             { 0,2,4,3,1 },
281
             { 0,1,6,7,5 },
282
             { 1,3,6 },
283
             { 0,2,5 },
284
             { 4,7,6,3 },
285
             { 4,7,5,2 }
286
          };
287
288 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} };
289 2077dd18 Leszek Koltunski
      int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
290
      float[][] corners   = new float[][] { {0.06f,0.20f} };
291
      int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
292
      float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
293
      int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
294 1dd8d3af Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
295 2077dd18 Leszek Koltunski
      }
296
    }
297
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299
300 3e605536 Leszek Koltunski
  Static4D getQuat(int cubit, int numLayers)
301 68f6046c Leszek Koltunski
    {
302 1dd8d3af Leszek Koltunski
    if( mQuats==null ) initializeQuats();
303
304 68f6046c Leszek Koltunski
    switch(cubit)
305
      {
306 1dd8d3af Leszek Koltunski
      case  0: return mQuats[0];                         //  unit quat
307 68f6046c Leszek Koltunski
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
308
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
309 1dd8d3af Leszek Koltunski
      case  3: return mQuats[1];                         // 180 along X
310 68f6046c Leszek Koltunski
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
311 1dd8d3af Leszek Koltunski
      case  5: return mQuats[2];                         // 180 along Y
312
      case  6: return mQuats[3];                         // 180 along Z
313 68f6046c Leszek Koltunski
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
314
315 1dd8d3af Leszek Koltunski
      case  8: return mQuats[0];
316
      case  9: return mQuats[5];
317
      case 10: return mQuats[3];
318
      case 11: return mQuats[11];
319
      case 12: return mQuats[4];
320
      case 13: return mQuats[7];
321
      case 14: return mQuats[9];
322
      case 15: return mQuats[10];
323
      case 16: return mQuats[2];
324
      case 17: return mQuats[8];
325
      case 18: return mQuats[1];
326
      case 19: return mQuats[6];
327 68f6046c Leszek Koltunski
      }
328
329
    return null;
330
    }
331
332 2077dd18 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
333
334 3e605536 Leszek Koltunski
  int getNumCubitVariants(int numLayers)
335 2077dd18 Leszek Koltunski
    {
336
    return 2;
337
    }
338
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340
341
  int getCubitVariant(int cubit, int numLayers)
342
    {
343
    return cubit<8 ? 0:1;
344
    }
345
346 68f6046c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
347
348
  int getFaceColor(int cubit, int cubitface, int size)
349
    {
350 1dd8d3af Leszek Koltunski
    if( mFaceMap==null )
351
      {
352
      // Colors of the faces of cubits.
353
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4  ORANGE 5
354
      // YELLOW 6 WHITE 7 BLUE 8 GREEN 9 RED 10 ORANGE 11
355
      mFaceMap = new int[][]
356
         {
357
           {  4, 2, 0 },
358
           {  2, 5, 0 },
359
           {  3, 4, 0 },
360
           {  5, 3, 0 },
361
           {  1, 2, 4 },
362
           {  5, 2, 1 },
363
           {  4, 3, 1 },
364
           {  1, 3, 5 },
365
366
           { 10, 8,12 },
367
           {  6,10,12 },
368
           { 10, 9,12 },
369
           {  7,10,12 },
370
           {  8, 6,12 },
371
           {  9, 6,12 },
372
           {  9, 7,12 },
373
           {  8, 7,12 },
374
           { 11, 8,12 },
375
           {  6,11,12 },
376
           { 11, 9,12 },
377
           {  7,11,12 },
378
         };
379
      }
380
381
    return cubitface<3 ? mFaceMap[cubit][cubitface] : NUM_TEXTURES;
382 68f6046c Leszek Koltunski
    }
383
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385
386 9c06394a Leszek Koltunski
  int getColor(int face)
387 68f6046c Leszek Koltunski
    {
388 9c06394a Leszek Koltunski
    return FACE_COLORS[face];
389
    }
390 68f6046c Leszek Koltunski
391 9c06394a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
392
393
  ObjectSticker retSticker(int face)
394
    {
395 1dd8d3af Leszek Koltunski
    if( mStickers==null )
396
      {
397
      float[][] STICKERS = new float[][]
398
          {
399
             { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
400
             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
401
          };
402
403
      final float R0 = 0.09f;
404
      final float R1 = 0.06f;
405
      final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1} };
406
      final float[] strokes = { 0.09f,0.06f };
407
408
      mStickers = new ObjectSticker[STICKERS.length];
409
410
      for(int s=0; s<STICKERS.length; s++)
411
        {
412
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
413
        }
414
      }
415
416 abf36986 Leszek Koltunski
    return mStickers[face/NUM_FACE_COLORS];
417 68f6046c Leszek Koltunski
    }
418
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420
421
  float returnMultiplier()
422
    {
423
    return 2.0f;
424
    }
425
426 4c737817 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
427 cda32fc1 Leszek Koltunski
// PUBLIC API
428 4c737817 Leszek Koltunski
429 cda32fc1 Leszek Koltunski
  public Static3D[] getRotationAxis()
430
    {
431
    return ROT_AXIS;
432 0812242b Leszek Koltunski
    }
433
434 68f6046c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
435
436 cda32fc1 Leszek Koltunski
  public int[] getBasicAngle()
437 68f6046c Leszek Koltunski
    {
438 1dd8d3af Leszek Koltunski
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
439
    return mBasicAngle;
440 68f6046c Leszek Koltunski
    }
441
442 6fd4a72c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
443
444
  public int getObjectName(int numLayers)
445
    {
446
    return R.string.redi2;
447
    }
448
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450
451
  public int getInventor(int numLayers)
452
    {
453
    return R.string.redi2_inventor;
454
    }
455
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457
458
  public int getComplexity(int numLayers)
459
    {
460
    return 4;
461
    }
462 68f6046c Leszek Koltunski
}