Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyRex.java @ 01b2ef5a

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.ScrambleStateGraph;
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
import java.util.Random;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
public class TwistyRex extends TwistyObject
39
{
40
  private static final int FACES_PER_CUBIT =6;
41

    
42
  public static final float REX_D = 0.2f;
43

    
44
  // the four rotation axis of a RubikRex. Must be normalized.
45
  static final Static3D[] ROT_AXIS = new Static3D[]
46
         {
47
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
48
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
49
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
50
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
51
         };
52

    
53
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
54

    
55
  private static final int[] FACE_COLORS = new int[]
56
         {
57
           COLOR_YELLOW, COLOR_WHITE,
58
           COLOR_BLUE  , COLOR_GREEN,
59
           COLOR_RED   , COLOR_ORANGE
60
         };
61

    
62
  // All legal rotation quats of a RubikRex
63
  private static final Static4D[] QUATS = new Static4D[]
64
         {
65
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
66
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
67
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
68
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
69

    
70
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
71
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
72
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
73
           new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
74
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
75
           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
76
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
77
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
78
         };
79

    
80
  private static final int[][] mFaceMap =
81
         {
82
           {  0, 18,18,18,18,18 },
83
           {  0, 18,18,18,18,18 },
84
           {  0, 18,18,18,18,18 },
85
           {  0, 18,18,18,18,18 },
86
           {  1, 18,18,18,18,18 },
87
           {  1, 18,18,18,18,18 },
88
           {  1, 18,18,18,18,18 },
89
           {  1, 18,18,18,18,18 },
90
           {  2, 18,18,18,18,18 },
91
           {  2, 18,18,18,18,18 },
92
           {  2, 18,18,18,18,18 },
93
           {  2, 18,18,18,18,18 },
94
           {  3, 18,18,18,18,18 },
95
           {  3, 18,18,18,18,18 },
96
           {  3, 18,18,18,18,18 },
97
           {  3, 18,18,18,18,18 },
98
           {  4, 18,18,18,18,18 },
99
           {  4, 18,18,18,18,18 },
100
           {  4, 18,18,18,18,18 },
101
           {  4, 18,18,18,18,18 },
102
           {  5, 18,18,18,18,18 },
103
           {  5, 18,18,18,18,18 },
104
           {  5, 18,18,18,18,18 },
105
           {  5, 18,18,18,18,18 },
106

    
107
           {  6, 18,18,18,18,18 },
108
           {  7, 18,18,18,18,18 },
109
           {  8, 18,18,18,18,18 },
110
           {  9, 18,18,18,18,18 },
111
           { 10, 18,18,18,18,18 },
112
           { 11, 18,18,18,18,18 },
113

    
114
           { 16,14, 18,18,18,18 },
115
           { 16,12, 18,18,18,18 },
116
           { 16,15, 18,18,18,18 },
117
           { 16,13, 18,18,18,18 },
118
           { 12,14, 18,18,18,18 },
119
           { 15,12, 18,18,18,18 },
120
           { 15,13, 18,18,18,18 },
121
           { 13,14, 18,18,18,18 },
122
           { 14,17, 18,18,18,18 },
123
           { 12,17, 18,18,18,18 },
124
           { 17,15, 18,18,18,18 },
125
           { 13,17, 18,18,18,18 },
126
         };
127

    
128
  private static final ObjectSticker[] mStickers;
129

    
130
  private static final float[][] STICKERS = new float[][]
131
          {
132
             { -0.5f, 0.1428f, -0.1428f, 0.5f, 0.35f, -0.35f },
133
             { -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
134
             { -0.525f, 0.105f, 0.525f, 0.105f, 0.000f, -0.210f  }
135
          };
136
  private static final int NUM_STICKERS = STICKERS.length;
137

    
138
  static
139
    {
140
    mStickers = new ObjectSticker[NUM_STICKERS];
141

    
142
    final float F = (float)(Math.PI/20);
143
    final float R1= 0.02f;
144
    final float R2= 0.09f;
145
    final float R3= 0.06f;
146
    final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } };
147
    final float[][] radii  = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} };
148
    final float[] strokes = { 0.06f, 0.07f, 0.05f };
149

    
150
    for(int s=0; s<NUM_STICKERS; s++)
151
      {
152
      mStickers[s] = new ObjectSticker(STICKERS[s],angles[s],radii[s],strokes[s]);
153
      }
154
    }
155

    
156
  private int mCurrState;
157
  private int mIndexExcluded;
158
  private final ScrambleStateGraph[] mStates;
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

    
162
  TwistyRex(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
163
            DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
164
    {
165
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REX, res, scrWidth);
166

    
167
    int[] tmp = {0,-1,0, 0,1,0, 2,-1,0, 2,1,0 };
168

    
169
    mStates = new ScrambleStateGraph[]
170
      {
171
      new ScrambleStateGraph( new int[][] {tmp,tmp,tmp,tmp} )
172
      };
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

    
177
  int[] getSolvedQuats(int cubit, int numLayers)
178
    {
179
    int status = retCubitSolvedStatus(cubit,numLayers);
180
    return status<0 ? null : buildSolvedQuats(MovementRex.FACE_AXIS[status],QUATS);
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  float getScreenRatio()
186
    {
187
    return 1.5f;
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  Static4D[] getQuats()
193
    {
194
    return QUATS;
195
    }
196

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

    
199
  int getNumFaces()
200
    {
201
    return FACE_COLORS.length;
202
    }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
  boolean shouldResetTextureMaps()
207
    {
208
    return false;
209
    }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

    
213
  int getSolvedFunctionIndex()
214
    {
215
    return 0;
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

    
220
  int getNumStickerTypes(int numLayers)
221
    {
222
    return NUM_STICKERS;
223
    }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
  float[][] getCuts(int numLayers)
228
    {
229
    float C = SQ3*0.15f; // bit less than 1/6 of the length of the main diagonal
230
    float[] cut = new float[] {-C,+C};
231
    return new float[][] { cut,cut,cut,cut };
232
    }
233

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

    
236
  int getNumCubitFaces()
237
    {
238
    return FACES_PER_CUBIT;
239
    }
240

    
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

    
243
  float[][] getCubitPositions(int numLayers)
244
    {
245
    final float DIST1= 0.50f;
246
    final float DIST2= (1+2*REX_D)/6;
247
    final float DIST3= 0.51f;
248

    
249
    final float[][] CENTERS = new float[24+6+12][];
250

    
251
    CENTERS[ 0] = new float[] { +DIST3, +DIST2, +DIST2};
252
    CENTERS[ 1] = new float[] { +DIST3, +DIST2, -DIST2};
253
    CENTERS[ 2] = new float[] { +DIST3, -DIST2, -DIST2};
254
    CENTERS[ 3] = new float[] { +DIST3, -DIST2, +DIST2};
255
    CENTERS[ 4] = new float[] { -DIST3, +DIST2, +DIST2};
256
    CENTERS[ 5] = new float[] { -DIST3, +DIST2, -DIST2};
257
    CENTERS[ 6] = new float[] { -DIST3, -DIST2, -DIST2};
258
    CENTERS[ 7] = new float[] { -DIST3, -DIST2, +DIST2};
259
    CENTERS[ 8] = new float[] { +DIST2, +DIST3, +DIST2};
260
    CENTERS[ 9] = new float[] { +DIST2, +DIST3, -DIST2};
261
    CENTERS[10] = new float[] { -DIST2, +DIST3, -DIST2};
262
    CENTERS[11] = new float[] { -DIST2, +DIST3, +DIST2};
263
    CENTERS[12] = new float[] { +DIST2, -DIST3, +DIST2};
264
    CENTERS[13] = new float[] { +DIST2, -DIST3, -DIST2};
265
    CENTERS[14] = new float[] { -DIST2, -DIST3, -DIST2};
266
    CENTERS[15] = new float[] { -DIST2, -DIST3, +DIST2};
267
    CENTERS[16] = new float[] { +DIST2, +DIST2, +DIST3};
268
    CENTERS[17] = new float[] { +DIST2, -DIST2, +DIST3};
269
    CENTERS[18] = new float[] { -DIST2, -DIST2, +DIST3};
270
    CENTERS[19] = new float[] { -DIST2, +DIST2, +DIST3};
271
    CENTERS[20] = new float[] { +DIST2, +DIST2, -DIST3};
272
    CENTERS[21] = new float[] { +DIST2, -DIST2, -DIST3};
273
    CENTERS[22] = new float[] { -DIST2, -DIST2, -DIST3};
274
    CENTERS[23] = new float[] { -DIST2, +DIST2, -DIST3};
275

    
276
    CENTERS[24] = new float[] { +DIST3, +0.00f, +0.00f};
277
    CENTERS[25] = new float[] { -DIST3, +0.00f, +0.00f};
278
    CENTERS[26] = new float[] { +0.00f, +DIST3, +0.00f};
279
    CENTERS[27] = new float[] { +0.00f, -DIST3, +0.00f};
280
    CENTERS[28] = new float[] { +0.00f, +0.00f, +DIST3};
281
    CENTERS[29] = new float[] { +0.00f, +0.00f, -DIST3};
282

    
283
    CENTERS[30] = new float[] { +0.00f, +DIST1, +DIST1};
284
    CENTERS[31] = new float[] { +DIST1, +0.00f, +DIST1};
285
    CENTERS[32] = new float[] { +0.00f, -DIST1, +DIST1};
286
    CENTERS[33] = new float[] { -DIST1, +0.00f, +DIST1};
287
    CENTERS[34] = new float[] { +DIST1, +DIST1, +0.00f};
288
    CENTERS[35] = new float[] { +DIST1, -DIST1, +0.00f};
289
    CENTERS[36] = new float[] { -DIST1, -DIST1, +0.00f};
290
    CENTERS[37] = new float[] { -DIST1, +DIST1, +0.00f};
291
    CENTERS[38] = new float[] { +0.00f, +DIST1, -DIST1};
292
    CENTERS[39] = new float[] { +DIST1, +0.00f, -DIST1};
293
    CENTERS[40] = new float[] { +0.00f, -DIST1, -DIST1};
294
    CENTERS[41] = new float[] { -DIST1, +0.00f, -DIST1};
295

    
296
    return CENTERS;
297
    }
298

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

    
301
  ObjectShape getObjectShape(int cubit, int numLayers)
302
    {
303
    int variant = getCubitVariant(cubit,numLayers);
304

    
305
    if( variant==0 )
306
      {
307
      float G = (1-REX_D)*SQ2/2;
308

    
309
      double[][] vertices =
310
         {
311
             {  -0.033333f, 0.23333f, 0.0f },
312
             {  -0.233333f, 0.03333f, 0.0f },
313
             {  +0.216666f,-0.23666f, 0.0f },
314
             {  +0.236666f,-0.21666f, 0.0f }
315
         };
316

    
317
      int[][] vertIndexes = { {0,1,2,3},{3,2,1,0} };
318
      float[][] centers= new float[][] { {0.0f,0.0f,-G/3} };
319
      float[][] corners= new float[][] { {0.03f,0.10f} };
320
      int[] indices= {-1,-1,0,0};
321
      int[] bandIndices= new int[] { 0,1 };
322

    
323
      float[][] bands =
324
        {
325
            {+0.016f,10,G/3,0.5f,5,1,1},
326
            {+0.230f,45,G/3,0.0f,2,0,0}
327
        };
328
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
329
      }
330
    else if( variant==1 )
331
      {
332
      double[][] vertices =
333
        {
334
            { -REX_D,   0.0f, 0.0f },
335
            {   0.0f, -REX_D, 0.0f },
336
            { +REX_D,   0.0f, 0.0f },
337
            {   0.0f, +REX_D, 0.0f }
338
        };
339

    
340
      int[][] vertIndexes= { {0,1,2,3},{3,2,1,0} };
341
      int[] indices= {-1,-1,-1,-1};
342
      int[] bandIndices= new int[] { 0,1 };
343

    
344
      float[][] bands =
345
        {
346
            {0.025f,10,REX_D/2,0.5f,5,0,0},
347
            {0.000f,45,REX_D/2,0.0f,2,0,0}
348
        };
349

    
350
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,null,indices,null,indices,getNumCubitFaces(), null);
351
      }
352
    else
353
      {
354
      float E = 0.5f - REX_D;
355
      float F = 0.5f;
356
      float G = (float)Math.sqrt(E*E+F*F);
357

    
358
      double[][] vertices =
359
         {
360
             { -F, 0, 0 },
361
             {  0,-E, 0 },
362
             { +F, 0, 0 },
363
             {  0, 0,-E },
364
         };
365

    
366
      int[][] vertIndexes = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
367
      float[][] centers= new float[][] { {0.0f,-0.5f,-0.5f} };
368
      float[][] corners= new float[][] { {0.06f,0.10f} };
369
      int[] indices= {0,-1,0,-1};
370
      int[] bandIndices= new int[] { 0,0,1,1 };
371

    
372
      float[][] bands =
373
        {
374
           {0.03f,27,F/3,0.8f,5,2,3},
375
           {0.01f,45,G/3,0.2f,3,1,2}
376
        };
377

    
378
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
379
      }
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

    
384
  Static4D getQuat(int cubit, int numLayers)
385
    {
386
    switch(cubit)
387
      {
388
      case  0: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
389
      case  1: return QUATS[5];
390
      case  2: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
391
      case  3: return QUATS[8];
392
      case  4: return QUATS[6];
393
      case  5: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
394
      case  6: return QUATS[11];
395
      case  7: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
396
      case  8: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
397
      case  9: return QUATS[10];
398
      case 10: return new Static4D(     0,+SQ2/2,+SQ2/2,     0);
399
      case 11: return QUATS[4];
400
      case 12: return QUATS[9];
401
      case 13: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
402
      case 14: return QUATS[7];
403
      case 15: return new Static4D(     0,-SQ2/2,+SQ2/2,     0);
404
      case 16: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
405
      case 17: return QUATS[0];
406
      case 18: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
407
      case 19: return QUATS[3];
408
      case 20: return QUATS[1];
409
      case 21: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
410
      case 22: return QUATS[2];
411
      case 23: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
412

    
413
      case 24: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
414
      case 25: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
415
      case 26: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
416
      case 27: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
417
      case 28: return QUATS[0];
418
      case 29: return QUATS[1];
419

    
420
      case 30: return QUATS[0];
421
      case 31: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
422
      case 32: return QUATS[3];
423
      case 33: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
424
      case 34: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
425
      case 35: return QUATS[7];
426
      case 36: return QUATS[9];
427
      case 37: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
428
      case 38: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
429
      case 39: return QUATS[8];
430
      case 40: return QUATS[1];
431
      case 41: return QUATS[6];
432
      }
433

    
434
    return QUATS[0];
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

    
439
  int getNumCubitVariants(int numLayers)
440
    {
441
    return 3;
442
    }
443

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445

    
446
  int getCubitVariant(int cubit, int numLayers)
447
    {
448
    return cubit<24 ? 0 : (cubit<30?1:2);
449
    }
450

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452

    
453
  int getFaceColor(int cubit, int cubitface, int numLayers)
454
    {
455
    return mFaceMap[cubit][cubitface];
456
    }
457

    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

    
460
  int getColor(int face)
461
    {
462
    return FACE_COLORS[face];
463
    }
464

    
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466

    
467
  ObjectSticker retSticker(int face)
468
    {
469
    return mStickers[face/NUM_FACES];
470
    }
471

    
472
///////////////////////////////////////////////////////////////////////////////////////////////////
473

    
474
  float returnMultiplier()
475
    {
476
    return 2.0f;
477
    }
478

    
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480
// PUBLIC API
481

    
482
  public Static3D[] getRotationAxis()
483
    {
484
    return ROT_AXIS;
485
    }
486

    
487
///////////////////////////////////////////////////////////////////////////////////////////////////
488

    
489
  public int[] getBasicAngle()
490
    {
491
    return BASIC_ANGLE;
492
    }
493

    
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495

    
496
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
497
    {
498
    if( curr==0 )
499
      {
500
      mCurrState     = 0;
501
      mIndexExcluded =-1;
502
      }
503

    
504
    int total = mStates[mCurrState].getTotal(mIndexExcluded);
505
    int random= rnd.nextInt(total);
506
    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
507

    
508
    scramble[curr][0] = info[0];
509
    scramble[curr][1] = info[1];
510
    scramble[curr][2] = info[2];
511

    
512
    mCurrState     = info[3];
513
    mIndexExcluded = info[0];
514
    }
515

    
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517

    
518
  public int getObjectName(int numLayers)
519
    {
520
    return R.string.rex3;
521
    }
522

    
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524

    
525
  public int getInventor(int numLayers)
526
    {
527
    return R.string.rex3_inventor;
528
    }
529

    
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531

    
532
  public int getComplexity(int numLayers)
533
    {
534
    return 3;
535
    }
536
}
(36-36/41)