Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyRex.java @ 8db55f55

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 getSolvedFunctionIndex()
202
    {
203
    return 0;
204
    }
205

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

    
208
  int getNumStickerTypes(int numLayers)
209
    {
210
    return NUM_STICKERS;
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
  float[][] getCuts(int numLayers)
216
    {
217
    float C = SQ3*0.15f; // bit less than 1/6 of the length of the main diagonal
218
    float[] cut = new float[] {-C,+C};
219
    return new float[][] { cut,cut,cut,cut };
220
    }
221

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

    
224
  int getNumCubitFaces()
225
    {
226
    return FACES_PER_CUBIT;
227
    }
228

    
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

    
231
  float[][] getCubitPositions(int numLayers)
232
    {
233
    final float DIST1= 0.50f;
234
    final float DIST2= (1+2*REX_D)/6;
235
    final float DIST3= 0.51f;
236

    
237
    final float[][] CENTERS = new float[24+6+12][];
238

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

    
264
    CENTERS[24] = new float[] { +DIST3, +0.00f, +0.00f};
265
    CENTERS[25] = new float[] { -DIST3, +0.00f, +0.00f};
266
    CENTERS[26] = new float[] { +0.00f, +DIST3, +0.00f};
267
    CENTERS[27] = new float[] { +0.00f, -DIST3, +0.00f};
268
    CENTERS[28] = new float[] { +0.00f, +0.00f, +DIST3};
269
    CENTERS[29] = new float[] { +0.00f, +0.00f, -DIST3};
270

    
271
    CENTERS[30] = new float[] { +0.00f, +DIST1, +DIST1};
272
    CENTERS[31] = new float[] { +DIST1, +0.00f, +DIST1};
273
    CENTERS[32] = new float[] { +0.00f, -DIST1, +DIST1};
274
    CENTERS[33] = new float[] { -DIST1, +0.00f, +DIST1};
275
    CENTERS[34] = new float[] { +DIST1, +DIST1, +0.00f};
276
    CENTERS[35] = new float[] { +DIST1, -DIST1, +0.00f};
277
    CENTERS[36] = new float[] { -DIST1, -DIST1, +0.00f};
278
    CENTERS[37] = new float[] { -DIST1, +DIST1, +0.00f};
279
    CENTERS[38] = new float[] { +0.00f, +DIST1, -DIST1};
280
    CENTERS[39] = new float[] { +DIST1, +0.00f, -DIST1};
281
    CENTERS[40] = new float[] { +0.00f, -DIST1, -DIST1};
282
    CENTERS[41] = new float[] { -DIST1, +0.00f, -DIST1};
283

    
284
    return CENTERS;
285
    }
286

    
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288

    
289
  ObjectShape getObjectShape(int cubit, int numLayers)
290
    {
291
    int variant = getCubitVariant(cubit,numLayers);
292

    
293
    if( variant==0 )
294
      {
295
      float G = (1-REX_D)*SQ2/2;
296

    
297
      double[][] vertices =
298
         {
299
             {  -0.033333f, 0.23333f, 0.0f },
300
             {  -0.233333f, 0.03333f, 0.0f },
301
             {  +0.216666f,-0.23666f, 0.0f },
302
             {  +0.236666f,-0.21666f, 0.0f }
303
         };
304

    
305
      int[][] vertIndexes = { {0,1,2,3},{3,2,1,0} };
306
      float[][] centers= new float[][] { {0.0f,0.0f,-G/3} };
307
      float[][] corners= new float[][] { {0.03f,0.10f} };
308
      int[] indices= {-1,-1,0,0};
309
      int[] bandIndices= new int[] { 0,1 };
310

    
311
      float[][] bands =
312
        {
313
            {+0.016f,10,G/3,0.5f,5,1,1},
314
            {+0.230f,45,G/3,0.0f,2,0,0}
315
        };
316
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
317
      }
318
    else if( variant==1 )
319
      {
320
      double[][] vertices =
321
        {
322
            { -REX_D,   0.0f, 0.0f },
323
            {   0.0f, -REX_D, 0.0f },
324
            { +REX_D,   0.0f, 0.0f },
325
            {   0.0f, +REX_D, 0.0f }
326
        };
327

    
328
      int[][] vertIndexes= { {0,1,2,3},{3,2,1,0} };
329
      int[] indices= {-1,-1,-1,-1};
330
      int[] bandIndices= new int[] { 0,1 };
331

    
332
      float[][] bands =
333
        {
334
            {0.025f,10,REX_D/2,0.5f,5,0,0},
335
            {0.000f,45,REX_D/2,0.0f,2,0,0}
336
        };
337

    
338
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,null,indices,null,indices,getNumCubitFaces(), null);
339
      }
340
    else
341
      {
342
      float E = 0.5f - REX_D;
343
      float F = 0.5f;
344
      float G = (float)Math.sqrt(E*E+F*F);
345

    
346
      double[][] vertices =
347
         {
348
             { -F, 0, 0 },
349
             {  0,-E, 0 },
350
             { +F, 0, 0 },
351
             {  0, 0,-E },
352
         };
353

    
354
      int[][] vertIndexes = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
355
      float[][] centers= new float[][] { {0.0f,-0.5f,-0.5f} };
356
      float[][] corners= new float[][] { {0.06f,0.10f} };
357
      int[] indices= {0,-1,0,-1};
358
      int[] bandIndices= new int[] { 0,0,1,1 };
359

    
360
      float[][] bands =
361
        {
362
           {0.03f,27,F/3,0.8f,5,2,3},
363
           {0.01f,45,G/3,0.2f,3,1,2}
364
        };
365

    
366
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
367
      }
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

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

    
401
      case 24: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
402
      case 25: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
403
      case 26: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
404
      case 27: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
405
      case 28: return QUATS[0];
406
      case 29: return QUATS[1];
407

    
408
      case 30: return QUATS[0];
409
      case 31: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
410
      case 32: return QUATS[3];
411
      case 33: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
412
      case 34: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
413
      case 35: return QUATS[7];
414
      case 36: return QUATS[9];
415
      case 37: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
416
      case 38: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
417
      case 39: return QUATS[8];
418
      case 40: return QUATS[1];
419
      case 41: return QUATS[6];
420
      }
421

    
422
    return QUATS[0];
423
    }
424

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

    
427
  int getNumCubitVariants(int numLayers)
428
    {
429
    return 3;
430
    }
431

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

    
434
  int getCubitVariant(int cubit, int numLayers)
435
    {
436
    return cubit<24 ? 0 : (cubit<30?1:2);
437
    }
438

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

    
441
  int getFaceColor(int cubit, int cubitface, int numLayers)
442
    {
443
    return mFaceMap[cubit][cubitface];
444
    }
445

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

    
448
  int getColor(int face)
449
    {
450
    return FACE_COLORS[face];
451
    }
452

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

    
455
  ObjectSticker retSticker(int face)
456
    {
457
    return mStickers[face/NUM_FACES];
458
    }
459

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

    
462
  float returnMultiplier()
463
    {
464
    return 2.0f;
465
    }
466

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468
// PUBLIC API
469

    
470
  public Static3D[] getRotationAxis()
471
    {
472
    return ROT_AXIS;
473
    }
474

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

    
477
  public int[] getBasicAngle()
478
    {
479
    return BASIC_ANGLE;
480
    }
481

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483

    
484
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
485
    {
486
    if( curr==0 )
487
      {
488
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
489
      }
490
    else
491
      {
492
      int newVector = rnd.nextInt(NUM_AXIS -1);
493
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
494
      }
495

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

    
498
    switch( rnd.nextInt(2) )
499
      {
500
      case 0: scramble[curr][2] = -1; break;
501
      case 1: scramble[curr][2] =  1; break;
502
      }
503
    }
504

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

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

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

    
514
  public int getInventor(int numLayers)
515
    {
516
    return R.string.rex3_inventor;
517
    }
518

    
519
///////////////////////////////////////////////////////////////////////////////////////////////////
520

    
521
  public int getComplexity(int numLayers)
522
    {
523
    return 3;
524
    }
525
}
(36-36/41)