Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyRex.java @ a480ee80

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.library.main.DistortedEffects;
27
import org.distorted.library.main.DistortedTexture;
28
import org.distorted.library.mesh.MeshSquare;
29
import org.distorted.library.type.Static3D;
30
import org.distorted.library.type.Static4D;
31
import org.distorted.main.R;
32

    
33
import java.util.Random;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

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

    
41
  public static final float REX_D = 0.2f;
42

    
43
  // the four rotation axis of a RubikRex. Must be normalized.
44
  static final Static3D[] ROT_AXIS = new Static3D[]
45
         {
46
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
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
         };
51

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

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

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

    
69
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
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
         };
78

    
79
  private static final int[][] mFaceMap =
80
         {
81
           {  0, 18,18,18,18,18 },
82
           {  0, 18,18,18,18,18 },
83
           {  0, 18,18,18,18,18 },
84
           {  0, 18,18,18,18,18 },
85
           {  1, 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
           {  2, 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
           {  3, 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
           {  4, 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
           {  5, 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

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

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

    
127
  private static final ObjectSticker[] mStickers;
128

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

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

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

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

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

    
157
  TwistyRex(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
158
            DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
159
    {
160
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REX, res, scrWidth);
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  int[] getSolvedQuats(int cubit, int numLayers)
166
    {
167
    int status = retCubitSolvedStatus(cubit,numLayers);
168
    return status<0 ? null : buildSolvedQuats(MovementRex.FACE_AXIS[status],QUATS);
169
    }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

    
173
  float getScreenRatio()
174
    {
175
    return 1.5f;
176
    }
177

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

    
180
  Static4D[] getQuats()
181
    {
182
    return QUATS;
183
    }
184

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

    
187
  int getNumFaces()
188
    {
189
    return FACE_COLORS.length;
190
    }
191

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

    
194
  boolean shouldResetTextureMaps()
195
    {
196
    return false;
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
  int getNumStickerTypes(int numLayers)
202
    {
203
    return NUM_STICKERS;
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  float[][] getCuts(int numLayers)
209
    {
210
    float C = SQ3*0.15f; // bit less than 1/6 of the length of the main diagonal
211
    float[] cut = new float[] {-C,+C};
212
    return new float[][] { cut,cut,cut,cut };
213
    }
214

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

    
217
  int getNumCubitFaces()
218
    {
219
    return FACES_PER_CUBIT;
220
    }
221

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

    
224
  float[][] getCubitPositions(int numLayers)
225
    {
226
    final float DIST1= 0.50f;
227
    final float DIST2= (1+2*REX_D)/6;
228
    final float DIST3= 0.51f;
229

    
230
    final float[][] CENTERS = new float[24+6+12][];
231

    
232
    CENTERS[ 0] = new float[] { +DIST3, +DIST2, +DIST2};
233
    CENTERS[ 1] = new float[] { +DIST3, +DIST2, -DIST2};
234
    CENTERS[ 2] = new float[] { +DIST3, -DIST2, -DIST2};
235
    CENTERS[ 3] = new float[] { +DIST3, -DIST2, +DIST2};
236
    CENTERS[ 4] = new float[] { -DIST3, +DIST2, +DIST2};
237
    CENTERS[ 5] = new float[] { -DIST3, +DIST2, -DIST2};
238
    CENTERS[ 6] = new float[] { -DIST3, -DIST2, -DIST2};
239
    CENTERS[ 7] = new float[] { -DIST3, -DIST2, +DIST2};
240
    CENTERS[ 8] = new float[] { +DIST2, +DIST3, +DIST2};
241
    CENTERS[ 9] = new float[] { +DIST2, +DIST3, -DIST2};
242
    CENTERS[10] = new float[] { -DIST2, +DIST3, -DIST2};
243
    CENTERS[11] = new float[] { -DIST2, +DIST3, +DIST2};
244
    CENTERS[12] = new float[] { +DIST2, -DIST3, +DIST2};
245
    CENTERS[13] = new float[] { +DIST2, -DIST3, -DIST2};
246
    CENTERS[14] = new float[] { -DIST2, -DIST3, -DIST2};
247
    CENTERS[15] = new float[] { -DIST2, -DIST3, +DIST2};
248
    CENTERS[16] = new float[] { +DIST2, +DIST2, +DIST3};
249
    CENTERS[17] = new float[] { +DIST2, -DIST2, +DIST3};
250
    CENTERS[18] = new float[] { -DIST2, -DIST2, +DIST3};
251
    CENTERS[19] = new float[] { -DIST2, +DIST2, +DIST3};
252
    CENTERS[20] = new float[] { +DIST2, +DIST2, -DIST3};
253
    CENTERS[21] = new float[] { +DIST2, -DIST2, -DIST3};
254
    CENTERS[22] = new float[] { -DIST2, -DIST2, -DIST3};
255
    CENTERS[23] = new float[] { -DIST2, +DIST2, -DIST3};
256

    
257
    CENTERS[24] = new float[] { +DIST3, +0.00f, +0.00f};
258
    CENTERS[25] = new float[] { -DIST3, +0.00f, +0.00f};
259
    CENTERS[26] = new float[] { +0.00f, +DIST3, +0.00f};
260
    CENTERS[27] = new float[] { +0.00f, -DIST3, +0.00f};
261
    CENTERS[28] = new float[] { +0.00f, +0.00f, +DIST3};
262
    CENTERS[29] = new float[] { +0.00f, +0.00f, -DIST3};
263

    
264
    CENTERS[30] = new float[] { +0.00f, +DIST1, +DIST1};
265
    CENTERS[31] = new float[] { +DIST1, +0.00f, +DIST1};
266
    CENTERS[32] = new float[] { +0.00f, -DIST1, +DIST1};
267
    CENTERS[33] = new float[] { -DIST1, +0.00f, +DIST1};
268
    CENTERS[34] = new float[] { +DIST1, +DIST1, +0.00f};
269
    CENTERS[35] = new float[] { +DIST1, -DIST1, +0.00f};
270
    CENTERS[36] = new float[] { -DIST1, -DIST1, +0.00f};
271
    CENTERS[37] = new float[] { -DIST1, +DIST1, +0.00f};
272
    CENTERS[38] = new float[] { +0.00f, +DIST1, -DIST1};
273
    CENTERS[39] = new float[] { +DIST1, +0.00f, -DIST1};
274
    CENTERS[40] = new float[] { +0.00f, -DIST1, -DIST1};
275
    CENTERS[41] = new float[] { -DIST1, +0.00f, -DIST1};
276

    
277
    return CENTERS;
278
    }
279

    
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

    
282
  ObjectShape getObjectShape(int cubit, int numLayers)
283
    {
284
    int variant = getCubitVariant(cubit,numLayers);
285

    
286
    if( variant==0 )
287
      {
288
      float G = (1-REX_D)*SQ2/2;
289

    
290
      double[][] vertices =
291
         {
292
             {  -0.033333f, 0.23333f, 0.0f },
293
             {  -0.233333f, 0.03333f, 0.0f },
294
             {  +0.216666f,-0.23666f, 0.0f },
295
             {  +0.236666f,-0.21666f, 0.0f }
296
         };
297

    
298
      int[][] vertIndexes = { {0,1,2,3},{3,2,1,0} };
299
      float[][] centers= new float[][] { {0.0f,0.0f,-G/3} };
300
      float[][] corners= new float[][] { {0.03f,0.10f} };
301
      int[] indices= {-1,-1,0,0};
302
      int[] bandIndices= new int[] { 0,1 };
303

    
304
      float[][] bands =
305
        {
306
            {+0.016f,10,G/3,0.5f,5,1,1},
307
            {+0.230f,45,G/3,0.0f,2,0,0}
308
        };
309
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
310
      }
311
    else if( variant==1 )
312
      {
313
      double[][] vertices =
314
        {
315
            { -REX_D,   0.0f, 0.0f },
316
            {   0.0f, -REX_D, 0.0f },
317
            { +REX_D,   0.0f, 0.0f },
318
            {   0.0f, +REX_D, 0.0f }
319
        };
320

    
321
      int[][] vertIndexes= { {0,1,2,3},{3,2,1,0} };
322
      int[] indices= {-1,-1,-1,-1};
323
      int[] bandIndices= new int[] { 0,1 };
324

    
325
      float[][] bands =
326
        {
327
            {0.025f,10,REX_D/2,0.5f,5,0,0},
328
            {0.000f,45,REX_D/2,0.0f,2,0,0}
329
        };
330

    
331
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,null,indices,null,indices,getNumCubitFaces(), null);
332
      }
333
    else
334
      {
335
      float E = 0.5f - REX_D;
336
      float F = 0.5f;
337
      float G = (float)Math.sqrt(E*E+F*F);
338

    
339
      double[][] vertices =
340
         {
341
             { -F, 0, 0 },
342
             {  0,-E, 0 },
343
             { +F, 0, 0 },
344
             {  0, 0,-E },
345
         };
346

    
347
      int[][] vertIndexes = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
348
      float[][] centers= new float[][] { {0.0f,-0.5f,-0.5f} };
349
      float[][] corners= new float[][] { {0.06f,0.10f} };
350
      int[] indices= {0,-1,0,-1};
351
      int[] bandIndices= new int[] { 0,0,1,1 };
352

    
353
      float[][] bands =
354
        {
355
           {0.03f,27,F/3,0.8f,5,2,3},
356
           {0.01f,45,G/3,0.2f,3,1,2}
357
        };
358

    
359
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
360
      }
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

    
365
  Static4D getQuat(int cubit, int numLayers)
366
    {
367
    switch(cubit)
368
      {
369
      case  0: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
370
      case  1: return QUATS[5];
371
      case  2: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
372
      case  3: return QUATS[8];
373
      case  4: return QUATS[6];
374
      case  5: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
375
      case  6: return QUATS[11];
376
      case  7: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
377
      case  8: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
378
      case  9: return QUATS[10];
379
      case 10: return new Static4D(     0,+SQ2/2,+SQ2/2,     0);
380
      case 11: return QUATS[4];
381
      case 12: return QUATS[9];
382
      case 13: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
383
      case 14: return QUATS[7];
384
      case 15: return new Static4D(     0,-SQ2/2,+SQ2/2,     0);
385
      case 16: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
386
      case 17: return QUATS[0];
387
      case 18: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
388
      case 19: return QUATS[3];
389
      case 20: return QUATS[1];
390
      case 21: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
391
      case 22: return QUATS[2];
392
      case 23: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
393

    
394
      case 24: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
395
      case 25: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
396
      case 26: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
397
      case 27: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
398
      case 28: return QUATS[0];
399
      case 29: return QUATS[1];
400

    
401
      case 30: return QUATS[0];
402
      case 31: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
403
      case 32: return QUATS[3];
404
      case 33: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
405
      case 34: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
406
      case 35: return QUATS[7];
407
      case 36: return QUATS[9];
408
      case 37: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
409
      case 38: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
410
      case 39: return QUATS[8];
411
      case 40: return QUATS[1];
412
      case 41: return QUATS[6];
413
      }
414

    
415
    return QUATS[0];
416
    }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419

    
420
  int getNumCubitVariants(int numLayers)
421
    {
422
    return 3;
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

    
427
  int getCubitVariant(int cubit, int numLayers)
428
    {
429
    return cubit<24 ? 0 : (cubit<30?1:2);
430
    }
431

    
432
///////////////////////////////////////////////////////////////////////////////////////////////////
433

    
434
  int getFaceColor(int cubit, int cubitface, int numLayers)
435
    {
436
    return mFaceMap[cubit][cubitface];
437
    }
438

    
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

    
441
  int getColor(int face)
442
    {
443
    return FACE_COLORS[face];
444
    }
445

    
446
///////////////////////////////////////////////////////////////////////////////////////////////////
447

    
448
  ObjectSticker retSticker(int face)
449
    {
450
    return mStickers[face/NUM_FACES];
451
    }
452

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

    
455
  float returnMultiplier()
456
    {
457
    return 2.0f;
458
    }
459

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461
// PUBLIC API
462

    
463
  public Static3D[] getRotationAxis()
464
    {
465
    return ROT_AXIS;
466
    }
467

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469

    
470
  public int[] getBasicAngle()
471
    {
472
    return BASIC_ANGLE;
473
    }
474

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

    
477
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
478
    {
479
    if( curr==0 )
480
      {
481
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
482
      }
483
    else
484
      {
485
      int newVector = rnd.nextInt(NUM_AXIS -1);
486
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
487
      }
488

    
489
    scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0 : 2;
490

    
491
    switch( rnd.nextInt(2) )
492
      {
493
      case 0: scramble[curr][2] = -1; break;
494
      case 1: scramble[curr][2] =  1; break;
495
      }
496
    }
497

    
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499

    
500
  public int getObjectName(int numLayers)
501
    {
502
    return R.string.rex3;
503
    }
504

    
505
///////////////////////////////////////////////////////////////////////////////////////////////////
506

    
507
  public int getInventor(int numLayers)
508
    {
509
    return R.string.rex3_inventor;
510
    }
511

    
512
///////////////////////////////////////////////////////////////////////////////////////////////////
513

    
514
  public int getComplexity(int numLayers)
515
    {
516
    return 3;
517
    }
518
}
(36-36/41)