Project

General

Profile

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

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

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