Project

General

Profile

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

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

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 TwistyObject
37
{
38
  // the four rotation axis of a Redi. Must be normalized.
39
  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
           COLOR_RED   , COLOR_ORANGE
52
         };
53

    
54
  private static final int FACES_PER_CUBIT =9;
55

    
56
  private ScrambleState[] mStates;
57
  private int[] mBasicAngle;
58
  private Static4D[] mQuats;
59
  private float[][] mCenters;
60
  private int[][] mFaceMap;
61
  private ObjectSticker[] mStickers;
62
  private Movement mMovement;
63

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

    
66
  TwistyRedi(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
67
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
68
    {
69
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REDI, res, scrWidth);
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  ScrambleState[] getScrambleStates()
75
    {
76
    if( mStates==null )
77
      {
78
      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
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  int[] getSolvedQuats(int cubit, int numLayers)
120
    {
121
    if( mQuats==null ) initializeQuats();
122
    int status = retCubitSolvedStatus(cubit,numLayers);
123
    return status<0 ? null : buildSolvedQuats(MovementCornerTwisting.FACE_AXIS[status],mQuats);
124
    }
125

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

    
128
  float getScreenRatio()
129
    {
130
    return 0.50f;
131
    }
132

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

    
135
  Static4D[] getQuats()
136
    {
137
    if( mQuats==null ) initializeQuats();
138
    return mQuats;
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
  int getNumFaceColors()
144
    {
145
    return FACE_COLORS.length;
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  int getSolvedFunctionIndex()
151
    {
152
    return 0;
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  boolean shouldResetTextureMaps()
158
    {
159
    return false;
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  int getNumStickerTypes(int numLayers)
165
    {
166
    return 2;
167
    }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

    
171
  float[][] getCuts(int size)
172
    {
173
    float C = +SQ3/3 +0.05f;
174
    float[] cut = new float[] {-C,+C};
175
    return new float[][] { cut,cut,cut,cut };
176
    }
177

    
178
///////////////////////////////////////////////////////////////////////////////////////////////////
179

    
180
  int getNumCubitFaces()
181
    {
182
    return FACES_PER_CUBIT;
183
    }
184

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

    
187
  float[][] getCubitPositions(int size)
188
    {
189
    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
    }
222

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

    
225
  ObjectShape getObjectShape(int cubit, int numLayers)
226
    {
227
    int variant = getCubitVariant(cubit,numLayers);
228

    
229
    if( variant==0 )
230
      {
231
      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
      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
      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
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
264
      }
265
    else
266
      {
267
      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
      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
      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
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
296
      }
297
    }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

    
301
  Static4D getQuat(int cubit, int numLayers)
302
    {
303
    if( mQuats==null ) initializeQuats();
304

    
305
    switch(cubit)
306
      {
307
      case  0: return mQuats[0];                         //  unit quat
308
      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
      case  3: return mQuats[1];                         // 180 along X
311
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
312
      case  5: return mQuats[2];                         // 180 along Y
313
      case  6: return mQuats[3];                         // 180 along Z
314
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
315

    
316
      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
      }
329

    
330
    return null;
331
    }
332

    
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334

    
335
  int getNumCubitVariants(int numLayers)
336
    {
337
    return 2;
338
    }
339

    
340
///////////////////////////////////////////////////////////////////////////////////////////////////
341

    
342
  int getCubitVariant(int cubit, int numLayers)
343
    {
344
    return cubit<8 ? 0:1;
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
  int getFaceColor(int cubit, int cubitface, int size)
350
    {
351
    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
    }
384

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386

    
387
  int getColor(int face)
388
    {
389
    return FACE_COLORS[face];
390
    }
391

    
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393

    
394
  ObjectSticker retSticker(int face)
395
    {
396
    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
    return mStickers[face/NUM_FACE_COLORS];
418
    }
419

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

    
422
  float returnMultiplier()
423
    {
424
    return 2.0f;
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428
// PUBLIC API
429

    
430
  public Static3D[] getRotationAxis()
431
    {
432
    return ROT_AXIS;
433
    }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

    
437
  public Movement getMovement()
438
    {
439
    if( mMovement==null ) mMovement = new MovementCornerTwisting();
440
    return mMovement;
441
    }
442

    
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444

    
445
  public int[] getBasicAngle()
446
    {
447
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
448
    return mBasicAngle;
449
    }
450

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
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
}
(38-38/44)