Project

General

Profile

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

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

1 59b87d56 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 749ef882 Leszek Koltunski
import org.distorted.helpers.FactoryCubit;
25 a38fe4b2 Leszek Koltunski
import org.distorted.helpers.ObjectShape;
26 9c06394a Leszek Koltunski
import org.distorted.helpers.ObjectSticker;
27 59b87d56 Leszek Koltunski
import org.distorted.library.effect.MatrixEffectQuaternion;
28
import org.distorted.library.main.DistortedEffects;
29
import org.distorted.library.main.DistortedTexture;
30
import org.distorted.library.mesh.MeshBase;
31
import org.distorted.library.mesh.MeshSquare;
32
import org.distorted.library.type.Static3D;
33
import org.distorted.library.type.Static4D;
34
import org.distorted.main.R;
35
36
import java.util.Random;
37
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39
40
public class TwistyRex extends TwistyObject
41
{
42 da36b97e Leszek Koltunski
  private static final int FACES_PER_CUBIT =6;
43 59b87d56 Leszek Koltunski
44 be56193c Leszek Koltunski
  public static final float REX_D = 0.2f;
45
46 59b87d56 Leszek Koltunski
  // the four rotation axis of a RubikRex. Must be normalized.
47
  static final Static3D[] ROT_AXIS = new Static3D[]
48
         {
49
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
50
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
51
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
52
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
53
         };
54
55 925ed78f Leszek Koltunski
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
56
57 59b87d56 Leszek Koltunski
  private static final int[] FACE_COLORS = new int[]
58
         {
59
           COLOR_YELLOW, COLOR_WHITE,
60
           COLOR_BLUE  , COLOR_GREEN,
61 323b217c Leszek Koltunski
           COLOR_RED   , COLOR_ORANGE
62 59b87d56 Leszek Koltunski
         };
63
64
  // All legal rotation quats of a RubikRex
65
  private static final Static4D[] QUATS = new Static4D[]
66
         {
67
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
68
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
69
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
70
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
71
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
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
79
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
80
         };
81
82
  private static final int[][] mFaceMap =
83
         {
84 da36b97e Leszek Koltunski
           {  0, 18,18,18,18,18 },
85
           {  0, 18,18,18,18,18 },
86
           {  0, 18,18,18,18,18 },
87
           {  0, 18,18,18,18,18 },
88
           {  1, 18,18,18,18,18 },
89
           {  1, 18,18,18,18,18 },
90
           {  1, 18,18,18,18,18 },
91
           {  1, 18,18,18,18,18 },
92
           {  2, 18,18,18,18,18 },
93
           {  2, 18,18,18,18,18 },
94
           {  2, 18,18,18,18,18 },
95
           {  2, 18,18,18,18,18 },
96
           {  3, 18,18,18,18,18 },
97
           {  3, 18,18,18,18,18 },
98
           {  3, 18,18,18,18,18 },
99
           {  3, 18,18,18,18,18 },
100
           {  4, 18,18,18,18,18 },
101
           {  4, 18,18,18,18,18 },
102
           {  4, 18,18,18,18,18 },
103
           {  4, 18,18,18,18,18 },
104
           {  5, 18,18,18,18,18 },
105
           {  5, 18,18,18,18,18 },
106
           {  5, 18,18,18,18,18 },
107
           {  5, 18,18,18,18,18 },
108
109
           {  6, 18,18,18,18,18 },
110
           {  7, 18,18,18,18,18 },
111
           {  8, 18,18,18,18,18 },
112
           {  9, 18,18,18,18,18 },
113
           { 10, 18,18,18,18,18 },
114
           { 11, 18,18,18,18,18 },
115
116
           { 16,14, 18,18,18,18 },
117
           { 16,12, 18,18,18,18 },
118
           { 16,15, 18,18,18,18 },
119
           { 16,13, 18,18,18,18 },
120
           { 12,14, 18,18,18,18 },
121
           { 15,12, 18,18,18,18 },
122
           { 15,13, 18,18,18,18 },
123
           { 13,14, 18,18,18,18 },
124
           { 14,17, 18,18,18,18 },
125
           { 12,17, 18,18,18,18 },
126
           { 17,15, 18,18,18,18 },
127
           { 13,17, 18,18,18,18 },
128 59b87d56 Leszek Koltunski
         };
129
130 9c06394a Leszek Koltunski
  private static final ObjectSticker[] mStickers;
131
132 c75ab933 Leszek Koltunski
  private static final float[][] STICKERS = new float[][]
133
          {
134 a38fe4b2 Leszek Koltunski
             { -0.5f, 0.1428f, -0.1428f, 0.5f, 0.35f, -0.35f },
135 c75ab933 Leszek Koltunski
             { -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
136 a38fe4b2 Leszek Koltunski
             { -0.525f, 0.105f, 0.525f, 0.105f, 0.000f, -0.210f  }
137 c75ab933 Leszek Koltunski
          };
138
  private static final int NUM_STICKERS = STICKERS.length;
139
140 9c06394a Leszek Koltunski
  static
141
    {
142
    mStickers = new ObjectSticker[NUM_STICKERS];
143
144
    final float F = (float)(Math.PI/20);
145
    final float R1= 0.02f;
146 c75ab933 Leszek Koltunski
    final float R2= 0.09f;
147 9c06394a Leszek Koltunski
    final float R3= 0.06f;
148 c75ab933 Leszek Koltunski
    final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } };
149 9c06394a Leszek Koltunski
    final float[][] radii  = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} };
150 a38fe4b2 Leszek Koltunski
    final float[] strokes = { 0.06f, 0.07f, 0.05f };
151 9c06394a Leszek Koltunski
152
    for(int s=0; s<NUM_STICKERS; s++)
153
      {
154 c75ab933 Leszek Koltunski
      mStickers[s] = new ObjectSticker(STICKERS[s],angles[s],radii[s],strokes[s]);
155 9c06394a Leszek Koltunski
      }
156
    }
157
158 59b87d56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
159
160
  TwistyRex(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
161
            DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
162
    {
163 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REX, res, scrWidth);
164 59b87d56 Leszek Koltunski
    }
165
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167
168
  float getScreenRatio()
169
    {
170 80ec6abf Leszek Koltunski
    return 1.5f;
171 59b87d56 Leszek Koltunski
    }
172
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174
175
  Static4D[] getQuats()
176
    {
177
    return QUATS;
178
    }
179
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181
182
  int getNumFaces()
183
    {
184
    return FACE_COLORS.length;
185
    }
186
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188
189
  boolean shouldResetTextureMaps()
190
    {
191
    return false;
192
    }
193
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195
196 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
197 59b87d56 Leszek Koltunski
    {
198 9c06394a Leszek Koltunski
    return NUM_STICKERS;
199 59b87d56 Leszek Koltunski
    }
200
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202
203 e6734aa9 Leszek Koltunski
  float[][] getCuts(int numLayers)
204 59b87d56 Leszek Koltunski
    {
205 c75ab933 Leszek Koltunski
    float C = SQ3*0.15f; // bit less than 1/6 of the length of the main diagonal
206
    float[] cut = new float[] {-C,+C};
207 e6734aa9 Leszek Koltunski
    return new float[][] { cut,cut,cut,cut };
208 59b87d56 Leszek Koltunski
    }
209
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211
212
  int getNumCubitFaces()
213
    {
214
    return FACES_PER_CUBIT;
215
    }
216
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218
219 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int numLayers)
220 59b87d56 Leszek Koltunski
    {
221 c75ab933 Leszek Koltunski
    final float DIST1= 0.50f;
222 da36b97e Leszek Koltunski
    final float DIST2= (1+2*REX_D)/6;
223 c75ab933 Leszek Koltunski
    final float DIST3= 0.51f;
224
225
    final float[][] CENTERS = new float[24+6+12][];
226
227
    CENTERS[ 0] = new float[] { +DIST3, +DIST2, +DIST2};
228
    CENTERS[ 1] = new float[] { +DIST3, +DIST2, -DIST2};
229
    CENTERS[ 2] = new float[] { +DIST3, -DIST2, -DIST2};
230
    CENTERS[ 3] = new float[] { +DIST3, -DIST2, +DIST2};
231
    CENTERS[ 4] = new float[] { -DIST3, +DIST2, +DIST2};
232
    CENTERS[ 5] = new float[] { -DIST3, +DIST2, -DIST2};
233
    CENTERS[ 6] = new float[] { -DIST3, -DIST2, -DIST2};
234
    CENTERS[ 7] = new float[] { -DIST3, -DIST2, +DIST2};
235
    CENTERS[ 8] = new float[] { +DIST2, +DIST3, +DIST2};
236
    CENTERS[ 9] = new float[] { +DIST2, +DIST3, -DIST2};
237
    CENTERS[10] = new float[] { -DIST2, +DIST3, -DIST2};
238
    CENTERS[11] = new float[] { -DIST2, +DIST3, +DIST2};
239
    CENTERS[12] = new float[] { +DIST2, -DIST3, +DIST2};
240
    CENTERS[13] = new float[] { +DIST2, -DIST3, -DIST2};
241
    CENTERS[14] = new float[] { -DIST2, -DIST3, -DIST2};
242
    CENTERS[15] = new float[] { -DIST2, -DIST3, +DIST2};
243
    CENTERS[16] = new float[] { +DIST2, +DIST2, +DIST3};
244
    CENTERS[17] = new float[] { +DIST2, -DIST2, +DIST3};
245
    CENTERS[18] = new float[] { -DIST2, -DIST2, +DIST3};
246
    CENTERS[19] = new float[] { -DIST2, +DIST2, +DIST3};
247
    CENTERS[20] = new float[] { +DIST2, +DIST2, -DIST3};
248
    CENTERS[21] = new float[] { +DIST2, -DIST2, -DIST3};
249
    CENTERS[22] = new float[] { -DIST2, -DIST2, -DIST3};
250
    CENTERS[23] = new float[] { -DIST2, +DIST2, -DIST3};
251
252
    CENTERS[24] = new float[] { +DIST3, +0.00f, +0.00f};
253
    CENTERS[25] = new float[] { -DIST3, +0.00f, +0.00f};
254
    CENTERS[26] = new float[] { +0.00f, +DIST3, +0.00f};
255
    CENTERS[27] = new float[] { +0.00f, -DIST3, +0.00f};
256
    CENTERS[28] = new float[] { +0.00f, +0.00f, +DIST3};
257
    CENTERS[29] = new float[] { +0.00f, +0.00f, -DIST3};
258
259
    CENTERS[30] = new float[] { +0.00f, +DIST1, +DIST1};
260
    CENTERS[31] = new float[] { +DIST1, +0.00f, +DIST1};
261
    CENTERS[32] = new float[] { +0.00f, -DIST1, +DIST1};
262
    CENTERS[33] = new float[] { -DIST1, +0.00f, +DIST1};
263
    CENTERS[34] = new float[] { +DIST1, +DIST1, +0.00f};
264
    CENTERS[35] = new float[] { +DIST1, -DIST1, +0.00f};
265
    CENTERS[36] = new float[] { -DIST1, -DIST1, +0.00f};
266
    CENTERS[37] = new float[] { -DIST1, +DIST1, +0.00f};
267
    CENTERS[38] = new float[] { +0.00f, +DIST1, -DIST1};
268
    CENTERS[39] = new float[] { +DIST1, +0.00f, -DIST1};
269
    CENTERS[40] = new float[] { +0.00f, -DIST1, -DIST1};
270
    CENTERS[41] = new float[] { -DIST1, +0.00f, -DIST1};
271 59b87d56 Leszek Koltunski
272
    return CENTERS;
273
    }
274
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276
277 a38fe4b2 Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
278
    {
279
    int variant = getCubitVariant(cubit,numLayers);
280
281
    if( variant==0 )
282
      {
283
      float G = (1-REX_D)*SQ2/2;
284
285
      double[][] vertices =
286
         {
287
             {  -0.033333f, 0.23333f, 0.0f },
288
             {  -0.233333f, 0.03333f, 0.0f },
289
             {  +0.216666f,-0.23666f, 0.0f },
290
             {  +0.236666f,-0.21666f, 0.0f }
291
         };
292
293
      int[][] vertIndexes = { {0,1,2,3},{3,2,1,0} };
294
      float[][] centers= new float[][] { {0.0f,0.0f,-G/3} };
295
      float[][] corners= new float[][] { {0.03f,0.10f} };
296
      int[] indices= {-1,-1,0,0};
297
      int[] bandIndices= new int[] { 0,1 };
298
299
      float[][] bands =
300
        {
301
            {+0.016f,10,G/3,0.5f,5,1,1},
302
            {+0.230f,45,G/3,0.0f,2,0,0}
303
        };
304
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
305
      }
306
    else if( variant==1 )
307
      {
308
      double[][] vertices =
309
        {
310
            { -REX_D,   0.0f, 0.0f },
311
            {   0.0f, -REX_D, 0.0f },
312
            { +REX_D,   0.0f, 0.0f },
313
            {   0.0f, +REX_D, 0.0f }
314
        };
315
316
      int[][] vertIndexes= { {0,1,2,3},{3,2,1,0} };
317
      int[] indices= {-1,-1,-1,-1};
318
      int[] bandIndices= new int[] { 0,1 };
319
320
      float[][] bands =
321
        {
322
            {0.025f,10,REX_D/2,0.5f,5,0,0},
323
            {0.000f,45,REX_D/2,0.0f,2,0,0}
324
        };
325
326
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,null,indices,null,indices,getNumCubitFaces(), null);
327
      }
328
    else
329
      {
330
      float E = 0.5f - REX_D;
331
      float F = 0.5f;
332
      float G = (float)Math.sqrt(E*E+F*F);
333
334
      double[][] vertices =
335
         {
336
             { -F, 0, 0 },
337
             {  0,-E, 0 },
338
             { +F, 0, 0 },
339
             {  0, 0,-E },
340
         };
341
342
      int[][] vertIndexes = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
343
      float[][] centers= new float[][] { {0.0f,-0.5f,-0.5f} };
344
      float[][] corners= new float[][] { {0.06f,0.10f} };
345
      int[] indices= {0,-1,0,-1};
346
      int[] bandIndices= new int[] { 0,0,1,1 };
347
348
      float[][] bands =
349
        {
350
           {0.03f,27,F/3,0.8f,5,2,3},
351
           {0.01f,45,G/3,0.2f,3,1,2}
352
        };
353
354
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
355
      }
356
    }
357
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359
360
  private Static4D getQuat(int cubit, int numLayers)
361 59b87d56 Leszek Koltunski
    {
362
    switch(cubit)
363
      {
364 80ec6abf Leszek Koltunski
      case  0: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
365
      case  1: return QUATS[5];
366
      case  2: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
367
      case  3: return QUATS[8];
368 59b87d56 Leszek Koltunski
      case  4: return QUATS[6];
369 80ec6abf Leszek Koltunski
      case  5: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
370 59b87d56 Leszek Koltunski
      case  6: return QUATS[11];
371 80ec6abf Leszek Koltunski
      case  7: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
372
      case  8: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
373
      case  9: return QUATS[10];
374 59b87d56 Leszek Koltunski
      case 10: return new Static4D(     0,+SQ2/2,+SQ2/2,     0);
375
      case 11: return QUATS[4];
376
      case 12: return QUATS[9];
377
      case 13: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
378
      case 14: return QUATS[7];
379
      case 15: return new Static4D(     0,-SQ2/2,+SQ2/2,     0);
380
      case 16: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
381
      case 17: return QUATS[0];
382
      case 18: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
383
      case 19: return QUATS[3];
384 80ec6abf Leszek Koltunski
      case 20: return QUATS[1];
385
      case 21: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
386
      case 22: return QUATS[2];
387
      case 23: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
388 59b87d56 Leszek Koltunski
389 80ec6abf Leszek Koltunski
      case 24: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
390
      case 25: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
391 59b87d56 Leszek Koltunski
      case 26: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
392
      case 27: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
393
      case 28: return QUATS[0];
394
      case 29: return QUATS[1];
395
396
      case 30: return QUATS[0];
397
      case 31: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
398
      case 32: return QUATS[3];
399
      case 33: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
400 80ec6abf Leszek Koltunski
      case 34: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
401 59b87d56 Leszek Koltunski
      case 35: return QUATS[7];
402
      case 36: return QUATS[9];
403 80ec6abf Leszek Koltunski
      case 37: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
404 59b87d56 Leszek Koltunski
      case 38: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
405
      case 39: return QUATS[8];
406
      case 40: return QUATS[1];
407
      case 41: return QUATS[6];
408
      }
409
410
    return QUATS[0];
411
    }
412
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414
415 a38fe4b2 Leszek Koltunski
  private int getNumCubitVariants(int numLayers)
416 59b87d56 Leszek Koltunski
    {
417 a38fe4b2 Leszek Koltunski
    return 3;
418
    }
419 c75ab933 Leszek Koltunski
420 a38fe4b2 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
421 c75ab933 Leszek Koltunski
422 a38fe4b2 Leszek Koltunski
  int getCubitVariant(int cubit, int numLayers)
423
    {
424
    return cubit<24 ? 0 : (cubit<30?1:2);
425
    }
426 c75ab933 Leszek Koltunski
427 a38fe4b2 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
428 c75ab933 Leszek Koltunski
429 a38fe4b2 Leszek Koltunski
  MeshBase createCubitMesh(int cubit, int numLayers)
430
    {
431
    int variant = getCubitVariant(cubit,numLayers);
432 c75ab933 Leszek Koltunski
433 a38fe4b2 Leszek Koltunski
    if( mMeshes==null )
434 59b87d56 Leszek Koltunski
      {
435 a38fe4b2 Leszek Koltunski
      FactoryCubit factory = FactoryCubit.getInstance();
436
      factory.clear();
437
      mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
438 59b87d56 Leszek Koltunski
      }
439 c75ab933 Leszek Koltunski
440 a38fe4b2 Leszek Koltunski
    if( mMeshes[variant]==null )
441
      {
442
      ObjectShape shape = getObjectShape(cubit,numLayers);
443
      FactoryCubit factory = FactoryCubit.getInstance();
444
      factory.createNewFaceTransform(shape);
445
      mMeshes[variant] = factory.createRoundedSolid(shape);
446 59b87d56 Leszek Koltunski
      }
447
448 a38fe4b2 Leszek Koltunski
    MeshBase mesh = mMeshes[variant].copy(true);
449
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
450 59b87d56 Leszek Koltunski
    mesh.apply(quat,0xffffffff,0);
451
452
    return mesh;
453
    }
454
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456
457
  int getFaceColor(int cubit, int cubitface, int numLayers)
458
    {
459
    return mFaceMap[cubit][cubitface];
460
    }
461
462
///////////////////////////////////////////////////////////////////////////////////////////////////
463
464 9c06394a Leszek Koltunski
  int getColor(int face)
465 59b87d56 Leszek Koltunski
    {
466 9c06394a Leszek Koltunski
    return FACE_COLORS[face];
467
    }
468 29bc084f Leszek Koltunski
469 9c06394a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
470 29bc084f Leszek Koltunski
471 9c06394a Leszek Koltunski
  ObjectSticker retSticker(int face)
472
    {
473
    return mStickers[face/NUM_FACES];
474 59b87d56 Leszek Koltunski
    }
475
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477
478
  float returnMultiplier()
479
    {
480
    return 2.0f;
481
    }
482
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484
// PUBLIC API
485
486
  public Static3D[] getRotationAxis()
487
    {
488
    return ROT_AXIS;
489
    }
490
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492
493 925ed78f Leszek Koltunski
  public int[] getBasicAngle()
494 59b87d56 Leszek Koltunski
    {
495 925ed78f Leszek Koltunski
    return BASIC_ANGLE;
496 59b87d56 Leszek Koltunski
    }
497
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499
500 9f171eba Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
501 59b87d56 Leszek Koltunski
    {
502 9f171eba Leszek Koltunski
    if( curr==0 )
503 59b87d56 Leszek Koltunski
      {
504 9f171eba Leszek Koltunski
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
505 59b87d56 Leszek Koltunski
      }
506
    else
507
      {
508 582617c1 Leszek Koltunski
      int newVector = rnd.nextInt(NUM_AXIS -1);
509 9f171eba Leszek Koltunski
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
510 59b87d56 Leszek Koltunski
      }
511
512 9f171eba Leszek Koltunski
    scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0 : 2;
513 59b87d56 Leszek Koltunski
514 5043d5d0 Leszek Koltunski
    switch( rnd.nextInt(2) )
515
      {
516 9f171eba Leszek Koltunski
      case 0: scramble[curr][2] = -1; break;
517
      case 1: scramble[curr][2] =  1; break;
518 5043d5d0 Leszek Koltunski
      }
519 59b87d56 Leszek Koltunski
    }
520
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522
// The Rex is solved if and only if:
523
//
524 5eedd516 Leszek Koltunski
// 1) all 12 of its edge cubits are rotated with the same quat
525
// 2) all its face & corner cubits are rotated with the same quat like the edge ones,
526
//    and optionally they also might be upside down.
527
//
528
// i.e.
529
// corners ( 0, 1, 2, 3, 4, 5, 6, 7) and faces (24,25) - might be extra QUAT[1]
530
// corners ( 8, 9,10,11,12,13,14,15) and faces (26,27) - might be extra QUAT[2]
531
// corners (16,17,18,19,20,21,22,23) and faces (28,29) - might be extra QUAT[3]
532 59b87d56 Leszek Koltunski
533
  public boolean isSolved()
534
    {
535 cce59cd4 Leszek Koltunski
    int q1,q = CUBITS[30].mQuatIndex;
536 59b87d56 Leszek Koltunski
537 cce59cd4 Leszek Koltunski
    for(int i=31; i<42; i++)
538 59b87d56 Leszek Koltunski
      {
539
      if( CUBITS[i].mQuatIndex != q) return false;
540
      }
541
542 5eedd516 Leszek Koltunski
    q1 = mulQuat(q,1);
543
544
    for(int i=0; i<8; i++)
545
      {
546
      if( CUBITS[i].mQuatIndex != q && CUBITS[i].mQuatIndex != q1 ) return false;
547
      }
548
549
    if( CUBITS[24].mQuatIndex != q && CUBITS[24].mQuatIndex != q1 ) return false;
550
    if( CUBITS[25].mQuatIndex != q && CUBITS[25].mQuatIndex != q1 ) return false;
551
552
    q1 = mulQuat(q,2);
553
554
    for(int i=8; i<16; i++)
555
      {
556
      if( CUBITS[i].mQuatIndex != q && CUBITS[i].mQuatIndex != q1 ) return false;
557
      }
558
559
    if( CUBITS[26].mQuatIndex != q && CUBITS[26].mQuatIndex != q1 ) return false;
560
    if( CUBITS[27].mQuatIndex != q && CUBITS[27].mQuatIndex != q1 ) return false;
561
562
    q1 = mulQuat(q,3);
563
564
    for(int i=16; i<24; i++)
565
      {
566
      if( CUBITS[i].mQuatIndex != q && CUBITS[i].mQuatIndex != q1 ) return false;
567
      }
568
569
    if( CUBITS[28].mQuatIndex != q && CUBITS[28].mQuatIndex != q1 ) return false;
570
    if( CUBITS[29].mQuatIndex != q && CUBITS[29].mQuatIndex != q1 ) return false;
571
572 59b87d56 Leszek Koltunski
    return true;
573
    }
574
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576
577
  public int getObjectName(int numLayers)
578
    {
579
    return R.string.rex3;
580
    }
581
582
///////////////////////////////////////////////////////////////////////////////////////////////////
583
584
  public int getInventor(int numLayers)
585
    {
586
    return R.string.rex3_inventor;
587
    }
588
589
///////////////////////////////////////////////////////////////////////////////////////////////////
590
591
  public int getComplexity(int numLayers)
592
    {
593
    return 3;
594
    }
595
}