Project

General

Profile

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

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

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
import android.graphics.Canvas;
24
import android.graphics.Paint;
25
26 749ef882 Leszek Koltunski
import org.distorted.helpers.FactoryCubit;
27
import org.distorted.helpers.FactorySticker;
28 59b87d56 Leszek Koltunski
import org.distorted.library.effect.MatrixEffectQuaternion;
29 be56193c Leszek Koltunski
import org.distorted.library.effect.VertexEffect;
30
import org.distorted.library.effect.VertexEffectMove;
31
import org.distorted.library.effect.VertexEffectRotate;
32
import org.distorted.library.effect.VertexEffectScale;
33 59b87d56 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
34
import org.distorted.library.main.DistortedTexture;
35
import org.distorted.library.mesh.MeshBase;
36 be56193c Leszek Koltunski
import org.distorted.library.mesh.MeshJoined;
37
import org.distorted.library.mesh.MeshPolygon;
38 59b87d56 Leszek Koltunski
import org.distorted.library.mesh.MeshSquare;
39 be56193c Leszek Koltunski
import org.distorted.library.type.Static1D;
40 59b87d56 Leszek Koltunski
import org.distorted.library.type.Static3D;
41
import org.distorted.library.type.Static4D;
42
import org.distorted.main.R;
43
44
import java.util.Random;
45
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
48
public class TwistyRex extends TwistyObject
49
{
50 da36b97e Leszek Koltunski
  private static final int FACES_PER_CUBIT =6;
51 59b87d56 Leszek Koltunski
52 be56193c Leszek Koltunski
  public static final float REX_D = 0.2f;
53
54 59b87d56 Leszek Koltunski
  // the four rotation axis of a RubikRex. Must be normalized.
55
  static final Static3D[] ROT_AXIS = new Static3D[]
56
         {
57
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
58
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
59
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
60
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
61
         };
62
63
  private static final int[] FACE_COLORS = new int[]
64
         {
65
           COLOR_YELLOW, COLOR_WHITE,
66
           COLOR_BLUE  , COLOR_GREEN,
67 323b217c Leszek Koltunski
           COLOR_RED   , COLOR_ORANGE
68 59b87d56 Leszek Koltunski
         };
69
70
  // All legal rotation quats of a RubikRex
71
  private static final Static4D[] QUATS = new Static4D[]
72
         {
73
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
74
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
75
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
76
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
77
78
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
79
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
80
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
81
           new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
82
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
83
           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
84
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
85
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
86
         };
87
88
  private static final int[][] mFaceMap =
89
         {
90 da36b97e Leszek Koltunski
           {  0, 18,18,18,18,18 },
91
           {  0, 18,18,18,18,18 },
92
           {  0, 18,18,18,18,18 },
93
           {  0, 18,18,18,18,18 },
94
           {  1, 18,18,18,18,18 },
95
           {  1, 18,18,18,18,18 },
96
           {  1, 18,18,18,18,18 },
97
           {  1, 18,18,18,18,18 },
98
           {  2, 18,18,18,18,18 },
99
           {  2, 18,18,18,18,18 },
100
           {  2, 18,18,18,18,18 },
101
           {  2, 18,18,18,18,18 },
102
           {  3, 18,18,18,18,18 },
103
           {  3, 18,18,18,18,18 },
104
           {  3, 18,18,18,18,18 },
105
           {  3, 18,18,18,18,18 },
106
           {  4, 18,18,18,18,18 },
107
           {  4, 18,18,18,18,18 },
108
           {  4, 18,18,18,18,18 },
109
           {  4, 18,18,18,18,18 },
110
           {  5, 18,18,18,18,18 },
111
           {  5, 18,18,18,18,18 },
112
           {  5, 18,18,18,18,18 },
113
           {  5, 18,18,18,18,18 },
114
115
           {  6, 18,18,18,18,18 },
116
           {  7, 18,18,18,18,18 },
117
           {  8, 18,18,18,18,18 },
118
           {  9, 18,18,18,18,18 },
119
           { 10, 18,18,18,18,18 },
120
           { 11, 18,18,18,18,18 },
121
122
           { 16,14, 18,18,18,18 },
123
           { 16,12, 18,18,18,18 },
124
           { 16,15, 18,18,18,18 },
125
           { 16,13, 18,18,18,18 },
126
           { 12,14, 18,18,18,18 },
127
           { 15,12, 18,18,18,18 },
128
           { 15,13, 18,18,18,18 },
129
           { 13,14, 18,18,18,18 },
130
           { 14,17, 18,18,18,18 },
131
           { 12,17, 18,18,18,18 },
132
           { 17,15, 18,18,18,18 },
133
           { 13,17, 18,18,18,18 },
134 59b87d56 Leszek Koltunski
         };
135
136
  private static MeshBase mCornerMesh, mFaceMesh, mEdgeMesh;
137
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
140
  TwistyRex(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
141
            DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
142
    {
143 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REX, res, scrWidth);
144 59b87d56 Leszek Koltunski
    }
145
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147
148
  float getScreenRatio()
149
    {
150 80ec6abf Leszek Koltunski
    return 1.5f;
151 59b87d56 Leszek Koltunski
    }
152
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154
155
  Static4D[] getQuats()
156
    {
157
    return QUATS;
158
    }
159
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161
162
  int getNumFaces()
163
    {
164
    return FACE_COLORS.length;
165
    }
166
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168
169
  boolean shouldResetTextureMaps()
170
    {
171
    return false;
172
    }
173
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175
176 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
177 59b87d56 Leszek Koltunski
    {
178
    return 3;
179
    }
180
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
183
  float[] getCuts(int numLayers)
184
    {
185
    float C = SQ3*0.15f;   // bit less than 1/6 of the length of the main diagonal
186
187
    return new float[] {-C,+C};
188
    }
189
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
192
  int getNumCubitFaces()
193
    {
194
    return FACES_PER_CUBIT;
195
    }
196
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198
199 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int numLayers)
200 59b87d56 Leszek Koltunski
    {
201
    final float DIST = 0.50f;
202 da36b97e Leszek Koltunski
    final float DIST2= (1+2*REX_D)/6;
203 59b87d56 Leszek Koltunski
204 e6cf7283 Leszek Koltunski
    final float[][] CENTERS = new float[42][];
205
206
    CENTERS[ 0] = new float[] { +DIST , +DIST2, +DIST2};
207
    CENTERS[ 1] = new float[] { +DIST , +DIST2, -DIST2};
208
    CENTERS[ 2] = new float[] { +DIST , -DIST2, -DIST2};
209
    CENTERS[ 3] = new float[] { +DIST , -DIST2, +DIST2};
210
    CENTERS[ 4] = new float[] { -DIST , +DIST2, +DIST2};
211
    CENTERS[ 5] = new float[] { -DIST , +DIST2, -DIST2};
212
    CENTERS[ 6] = new float[] { -DIST , -DIST2, -DIST2};
213
    CENTERS[ 7] = new float[] { -DIST , -DIST2, +DIST2};
214
    CENTERS[ 8] = new float[] { +DIST2, +DIST , +DIST2};
215
    CENTERS[ 9] = new float[] { +DIST2, +DIST , -DIST2};
216
    CENTERS[10] = new float[] { -DIST2, +DIST , -DIST2};
217
    CENTERS[11] = new float[] { -DIST2, +DIST , +DIST2};
218
    CENTERS[12] = new float[] { +DIST2, -DIST , +DIST2};
219
    CENTERS[13] = new float[] { +DIST2, -DIST , -DIST2};
220
    CENTERS[14] = new float[] { -DIST2, -DIST , -DIST2};
221
    CENTERS[15] = new float[] { -DIST2, -DIST , +DIST2};
222
    CENTERS[16] = new float[] { +DIST2, +DIST2, +DIST };
223
    CENTERS[17] = new float[] { +DIST2, -DIST2, +DIST };
224
    CENTERS[18] = new float[] { -DIST2, -DIST2, +DIST };
225
    CENTERS[19] = new float[] { -DIST2, +DIST2, +DIST };
226
    CENTERS[20] = new float[] { +DIST2, +DIST2, -DIST };
227
    CENTERS[21] = new float[] { +DIST2, -DIST2, -DIST };
228
    CENTERS[22] = new float[] { -DIST2, -DIST2, -DIST };
229
    CENTERS[23] = new float[] { -DIST2, +DIST2, -DIST };
230
231
    CENTERS[24] = new float[] { +DIST , +0.00f, +0.00f};
232
    CENTERS[25] = new float[] { -DIST , +0.00f, +0.00f};
233
    CENTERS[26] = new float[] { +0.00f, +DIST , +0.00f};
234
    CENTERS[27] = new float[] { +0.00f, -DIST , +0.00f};
235
    CENTERS[28] = new float[] { +0.00f, +0.00f, +DIST };
236
    CENTERS[29] = new float[] { +0.00f, +0.00f, -DIST };
237
238
    CENTERS[30] = new float[] { +0.00f, +DIST , +DIST };
239
    CENTERS[31] = new float[] { +DIST , +0.00f, +DIST };
240
    CENTERS[32] = new float[] { +0.00f, -DIST , +DIST };
241
    CENTERS[33] = new float[] { -DIST , +0.00f, +DIST };
242
    CENTERS[34] = new float[] { +DIST , +DIST , +0.00f};
243
    CENTERS[35] = new float[] { +DIST , -DIST , +0.00f};
244
    CENTERS[36] = new float[] { -DIST , -DIST , +0.00f};
245
    CENTERS[37] = new float[] { -DIST , +DIST , +0.00f};
246
    CENTERS[38] = new float[] { +0.00f, +DIST , -DIST };
247
    CENTERS[39] = new float[] { +DIST , +0.00f, -DIST };
248
    CENTERS[40] = new float[] { +0.00f, -DIST , -DIST };
249
    CENTERS[41] = new float[] { -DIST , +0.00f, -DIST };
250 59b87d56 Leszek Koltunski
251
    return CENTERS;
252
    }
253
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255
256
  private Static4D getQuat(int cubit)
257
    {
258
    switch(cubit)
259
      {
260 80ec6abf Leszek Koltunski
      case  0: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
261
      case  1: return QUATS[5];
262
      case  2: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
263
      case  3: return QUATS[8];
264 59b87d56 Leszek Koltunski
      case  4: return QUATS[6];
265 80ec6abf Leszek Koltunski
      case  5: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
266 59b87d56 Leszek Koltunski
      case  6: return QUATS[11];
267 80ec6abf Leszek Koltunski
      case  7: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
268
      case  8: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
269
      case  9: return QUATS[10];
270 59b87d56 Leszek Koltunski
      case 10: return new Static4D(     0,+SQ2/2,+SQ2/2,     0);
271
      case 11: return QUATS[4];
272
      case 12: return QUATS[9];
273
      case 13: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
274
      case 14: return QUATS[7];
275
      case 15: return new Static4D(     0,-SQ2/2,+SQ2/2,     0);
276
      case 16: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
277
      case 17: return QUATS[0];
278
      case 18: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
279
      case 19: return QUATS[3];
280 80ec6abf Leszek Koltunski
      case 20: return QUATS[1];
281
      case 21: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
282
      case 22: return QUATS[2];
283
      case 23: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
284 59b87d56 Leszek Koltunski
285 80ec6abf Leszek Koltunski
      case 24: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
286
      case 25: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
287 59b87d56 Leszek Koltunski
      case 26: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
288
      case 27: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
289
      case 28: return QUATS[0];
290
      case 29: return QUATS[1];
291
292
      case 30: return QUATS[0];
293
      case 31: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
294
      case 32: return QUATS[3];
295
      case 33: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
296 80ec6abf Leszek Koltunski
      case 34: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
297 59b87d56 Leszek Koltunski
      case 35: return QUATS[7];
298
      case 36: return QUATS[9];
299 80ec6abf Leszek Koltunski
      case 37: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
300 59b87d56 Leszek Koltunski
      case 38: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
301
      case 39: return QUATS[8];
302
      case 40: return QUATS[1];
303
      case 41: return QUATS[6];
304
      }
305
306
    return QUATS[0];
307
    }
308
309 be56193c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
310
311
  MeshBase createFacesRexCorner()
312
    {
313
    MeshBase[] meshes = new MeshBase[2];
314
315
    float F = REX_D*SQ2;
316
    float G = (1-REX_D)*SQ2/2;
317
    float H = 0.1f;
318
    float J = +2*G/3 - H*G;
319
320
    float[] vertices = { -F/2, -G/3, +F/2, -G/3, H*F/2, J, -H*F/2, J};
321
322
    FactoryCubit factory = FactoryCubit.getInstance();
323
    float[] bands0 = factory.computeBands(+0.016f,10,G/3,0.5f,5);
324
    float[] bands1 = factory.computeBands(-0.230f,45,G/3,0.0f,2);
325
326
    meshes[0] = new MeshPolygon(vertices,bands0,1,1);
327
    meshes[0].setEffectAssociation(0,1,0);
328
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
329
    meshes[1].setEffectAssociation(0,2,0);
330
331
    return new MeshJoined(meshes);
332
    }
333
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335
336
  MeshBase createFacesRexFace()
337
    {
338
    MeshBase[] meshes = new MeshBase[2];
339
340
    float[] vertices = { -REX_D,0.0f, 0.0f, -REX_D, +REX_D, 0.0f, 0.0f, +REX_D};
341
342
    FactoryCubit factory = FactoryCubit.getInstance();
343
    float[] bands0 = factory.computeBands(0.016f,10,REX_D/2,0.5f,5);
344
    float[] bands1 = factory.computeBands(0.000f,45,REX_D/2,0.0f,2);
345
346
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
347
    meshes[0].setEffectAssociation(0,1,0);
348
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
349
    meshes[1].setEffectAssociation(0,2,0);
350
351
    return new MeshJoined(meshes);
352
    }
353
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355
356
  MeshBase createFacesRexEdge()
357
    {
358
    MeshBase[] meshes = new MeshPolygon[6];
359
    FactoryCubit factory = FactoryCubit.getInstance();
360
361
    float E = 0.5f - REX_D;
362
    float F = 0.5f;
363
    float[] vertices0 = { -F,E/3, 0,-2*E/3, +F,E/3 };
364
    float[] bands0 = factory.computeBands(0.03f,27,F/3,0.8f,5);
365
366
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 3);
367
    meshes[0].setEffectAssociation(0,1,0);
368
    meshes[1] = meshes[0].copy(true);
369
    meshes[1].setEffectAssociation(0,2,0);
370
371
    float G = (float)Math.sqrt(E*E+F*F);
372
    float[] vertices1 = { -2*G/3, -E/3, G/3, -E/3, G/3, 2*E/3 };
373
    float[] bands1 = factory.computeBands(0.00f,45,G/3,0.2f,3);
374
375
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
376
    meshes[2].setEffectAssociation(0,4,0);
377
    meshes[3] = meshes[2].copy(true);
378
    meshes[3].setEffectAssociation(0,8,0);
379
    meshes[4] = meshes[2].copy(true);
380
    meshes[4].setEffectAssociation(0,16,0);
381
    meshes[5] = meshes[2].copy(true);
382
    meshes[5].setEffectAssociation(0,32,0);
383
384
    return new MeshJoined(meshes);
385
    }
386
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388
389
  private VertexEffect[] createVertexEffectsRexEdge()
390
    {
391
    float E = 0.5f - REX_D;
392
    float F = 0.5f;
393
    float G = (float)Math.sqrt(E*E+F*F);
394
    float A = (float)((180/Math.PI)*Math.asin(E/G));
395
396
    Static3D move1 = new Static3D(    0.0f, -E/3, 0.0f);
397
    Static3D move2 = new Static3D(2*G/3 -F, +E/3, 0.0f);
398
399
    Static3D center0= new Static3D(0.0f, 0.0f, 0.0f);
400
    Static3D center1= new Static3D(  -F, 0.0f, 0.0f);
401
    Static3D center2= new Static3D(  +F, 0.0f, 0.0f);
402
    Static3D axisX  = new Static3D(1.0f, 0.0f, 0.0f);
403
    Static3D axisY  = new Static3D(0.0f, 1.0f, 0.0f);
404
    Static3D axisZ  = new Static3D(0.0f, 0.0f, 1.0f);
405
406
    Static1D angle180 = new Static1D(180);
407
    Static1D angle90  = new Static1D( 90);
408
    Static1D angle270 = new Static1D(270);
409
    Static1D angle1   = new Static1D(+A);
410
    Static1D angle2   = new Static1D(-A);
411
412
    VertexEffect[] effect = new VertexEffect[12];
413
414
    effect[0] = new VertexEffectMove(move1);
415
    effect[1] = new VertexEffectMove(move2);
416
    effect[2] = new VertexEffectRotate(  angle90, axisX, center0 );
417
    effect[3] = new VertexEffectRotate( angle270, axisX, center0 );
418
    effect[4] = new VertexEffectRotate( angle180, axisX, center0 );
419
    effect[5] = new VertexEffectRotate( angle180, axisY, center0 );
420
    effect[6] = new VertexEffectScale( new Static3D(-1, 1, 1) );
421
    effect[7] = new VertexEffectScale ( new Static3D( 1,-1, 1) );
422
    effect[8] = new VertexEffectRotate(   angle1, axisY, center1);
423
    effect[9] = new VertexEffectRotate(   angle2, axisY, center2);
424
    effect[10]= new VertexEffectRotate(   angle2, axisZ, center1);
425
    effect[11]= new VertexEffectRotate(   angle1, axisZ, center2);
426
427
    effect[0].setMeshAssociation( 3,-1);  // meshes 0 & 1
428
    effect[1].setMeshAssociation(60,-1);  // meshes 2,3,4,5
429
    effect[2].setMeshAssociation( 2,-1);  // meshes 1
430
    effect[3].setMeshAssociation(12,-1);  // meshes 2,3
431
    effect[4].setMeshAssociation(48,-1);  // meshes 4,5
432
    effect[5].setMeshAssociation(32,-1);  // mesh 5
433
    effect[6].setMeshAssociation( 8,-1);  // apply to mesh 3
434
    effect[7].setMeshAssociation( 2,-1);  // apply to mesh 1
435
    effect[8].setMeshAssociation(16,-1);  // apply to mesh 4
436
    effect[9].setMeshAssociation(32,-1);  // apply to mesh 5
437
    effect[10].setMeshAssociation(4,-1);  // apply to mesh 2
438
    effect[11].setMeshAssociation(8,-1);  // apply to mesh 3
439
440
    return effect;
441
    }
442
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444
445
  private VertexEffect[] createVertexEffectsRexCorner()
446
    {
447
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
448
    Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
449
    Static1D angle = new Static1D(225);
450
451
    VertexEffect[] effect = new VertexEffect[1];
452
    effect[0] = new VertexEffectRotate(angle, axisZ, center);
453
454
    return effect;
455
    }
456
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458
459
  private MeshBase createRexCornerMesh()
460
    {
461
    MeshBase mesh = createFacesRexCorner();
462
    VertexEffect[] effects = createVertexEffectsRexCorner();
463
    for( VertexEffect effect : effects ) mesh.apply(effect);
464
465
    final float G = (1-REX_D)/3;
466
    Static3D center = new Static3D(0.0f,0.0f,-G*SQ2/2);
467
    Static3D[] vertices = new Static3D[1];
468
    vertices[0] = new Static3D(+G,-G,+0.0f);
469
    FactoryCubit.getInstance().roundCorners(mesh,center,vertices,0.10f,0.10f);
470
471
    mesh.mergeEffComponents();
472
    mesh.addEmptyTexComponent();
473
    mesh.addEmptyTexComponent();
474
    mesh.addEmptyTexComponent();
475
    mesh.addEmptyTexComponent();
476
477
    return mesh;
478
    }
479
480
///////////////////////////////////////////////////////////////////////////////////////////////////
481
482
  private MeshBase createRexFaceMesh()
483
    {
484
    MeshBase mesh = createFacesRexFace();
485
486
    mesh.mergeEffComponents();
487
    mesh.addEmptyTexComponent();
488
    mesh.addEmptyTexComponent();
489
    mesh.addEmptyTexComponent();
490
    mesh.addEmptyTexComponent();
491
492
    return mesh;
493
    }
494
495
///////////////////////////////////////////////////////////////////////////////////////////////////
496
497
  private MeshBase createRexEdgeMesh()
498
    {
499
    MeshBase mesh = createFacesRexEdge();
500
    VertexEffect[] effects = createVertexEffectsRexEdge();
501
    for( VertexEffect effect : effects ) mesh.apply(effect);
502
503
    Static3D center = new Static3D(0.0f,-0.5f,-0.5f);
504
    Static3D[] vertices = new Static3D[2];
505
    vertices[0] = new Static3D(+0.5f,+0.0f,+0.0f);
506
    vertices[1] = new Static3D(-0.5f,+0.0f,+0.0f);
507
    FactoryCubit.getInstance().roundCorners(mesh,center,vertices,0.06f,0.10f);
508
509
    mesh.mergeEffComponents();
510
511
    return mesh;
512
    }
513
514 59b87d56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
515
516 a64e07d0 Leszek Koltunski
  MeshBase createCubitMesh(int cubit, int numLayers)
517 59b87d56 Leszek Koltunski
    {
518
    MeshBase mesh;
519
520 f5c134c3 Leszek Koltunski
    if( cubit<24 )
521 59b87d56 Leszek Koltunski
      {
522 be56193c Leszek Koltunski
      if( mCornerMesh==null ) mCornerMesh = createRexCornerMesh();
523 59b87d56 Leszek Koltunski
      mesh = mCornerMesh.copy(true);
524
      }
525 f5c134c3 Leszek Koltunski
    else if( cubit<30 )
526 59b87d56 Leszek Koltunski
      {
527 be56193c Leszek Koltunski
      if( mFaceMesh==null ) mFaceMesh = createRexFaceMesh();
528 59b87d56 Leszek Koltunski
      mesh = mFaceMesh.copy(true);
529
      }
530
    else
531
      {
532 be56193c Leszek Koltunski
      if( mEdgeMesh==null ) mEdgeMesh = createRexEdgeMesh();
533 59b87d56 Leszek Koltunski
      mesh = mEdgeMesh.copy(true);
534
      }
535
536
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
537
    mesh.apply(quat,0xffffffff,0);
538
539
    return mesh;
540
    }
541
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543
544
  int getFaceColor(int cubit, int cubitface, int numLayers)
545
    {
546
    return mFaceMap[cubit][cubitface];
547
    }
548
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550
551
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
552
    {
553
    int COLORS = FACE_COLORS.length;
554
    FactorySticker factory = FactorySticker.getInstance();
555 da36b97e Leszek Koltunski
    float S1 = 0.050f;
556
    float S2 = 0.051f;
557
    float R1 = 0.07f;
558
    float R2 = 0.02f;
559
    float R3 = 0.06f;
560
    float R4 = 0.04f;
561 59b87d56 Leszek Koltunski
562
    if( face<COLORS )
563
      {
564 da36b97e Leszek Koltunski
      factory.drawRexCornerSticker(canvas, paint, left, top, FACE_COLORS[face%COLORS], S1, R2, R3);
565 59b87d56 Leszek Koltunski
      }
566
    else if( face<2*COLORS )
567
      {
568 da36b97e Leszek Koltunski
      float[] vertices = { -REX_D,0.0f, 0.0f, -REX_D, +REX_D, 0.0f, 0.0f, +REX_D};
569
      factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S1, FACE_COLORS[face%COLORS], R4);
570 59b87d56 Leszek Koltunski
      }
571
    else
572
      {
573 5eedd516 Leszek Koltunski
      factory.drawRexEdgeSticker(canvas, paint, left, top, FACE_COLORS[face%COLORS], S2, R1);
574 59b87d56 Leszek Koltunski
      }
575
    }
576
577
///////////////////////////////////////////////////////////////////////////////////////////////////
578
579
  float returnMultiplier()
580
    {
581
    return 2.0f;
582
    }
583
584
///////////////////////////////////////////////////////////////////////////////////////////////////
585
586 a64e07d0 Leszek Koltunski
  float[] getRowChances(int numLayers)
587 59b87d56 Leszek Koltunski
    {
588
    return new float[] { 0.5f, 0.5f, 1.0f };
589
    }
590
591
///////////////////////////////////////////////////////////////////////////////////////////////////
592
// PUBLIC API
593
594
  public Static3D[] getRotationAxis()
595
    {
596
    return ROT_AXIS;
597
    }
598
599
///////////////////////////////////////////////////////////////////////////////////////////////////
600
601
  public int getBasicAngle()
602
    {
603
    return 3;
604
    }
605
606
///////////////////////////////////////////////////////////////////////////////////////////////////
607
608 5043d5d0 Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
609 59b87d56 Leszek Koltunski
    {
610 5043d5d0 Leszek Koltunski
    if( num==0 )
611 59b87d56 Leszek Koltunski
      {
612 5043d5d0 Leszek Koltunski
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
613 59b87d56 Leszek Koltunski
      }
614
    else
615
      {
616 bbc6471c Leszek Koltunski
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
617 5043d5d0 Leszek Koltunski
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
618 59b87d56 Leszek Koltunski
      }
619
620
    float rowFloat = rnd.nextFloat();
621
622
    for(int row=0; row<mRowChances.length; row++)
623
      {
624 bbc6471c Leszek Koltunski
      if( rowFloat<=mRowChances[row] )
625
        {
626 5043d5d0 Leszek Koltunski
        scramble[num][1] = row;
627 bbc6471c Leszek Koltunski
        break;
628
        }
629 59b87d56 Leszek Koltunski
      }
630
631 5043d5d0 Leszek Koltunski
    switch( rnd.nextInt(2) )
632
      {
633
      case 0: scramble[num][2] = -1; break;
634
      case 1: scramble[num][2] =  1; break;
635
      }
636 59b87d56 Leszek Koltunski
    }
637
638
///////////////////////////////////////////////////////////////////////////////////////////////////
639
// The Rex is solved if and only if:
640
//
641 5eedd516 Leszek Koltunski
// 1) all 12 of its edge cubits are rotated with the same quat
642
// 2) all its face & corner cubits are rotated with the same quat like the edge ones,
643
//    and optionally they also might be upside down.
644
//
645
// i.e.
646
// corners ( 0, 1, 2, 3, 4, 5, 6, 7) and faces (24,25) - might be extra QUAT[1]
647
// corners ( 8, 9,10,11,12,13,14,15) and faces (26,27) - might be extra QUAT[2]
648
// corners (16,17,18,19,20,21,22,23) and faces (28,29) - might be extra QUAT[3]
649 59b87d56 Leszek Koltunski
650
  public boolean isSolved()
651
    {
652 cce59cd4 Leszek Koltunski
    int q1,q = CUBITS[30].mQuatIndex;
653 59b87d56 Leszek Koltunski
654 cce59cd4 Leszek Koltunski
    for(int i=31; i<42; i++)
655 59b87d56 Leszek Koltunski
      {
656
      if( CUBITS[i].mQuatIndex != q) return false;
657
      }
658
659 5eedd516 Leszek Koltunski
    q1 = mulQuat(q,1);
660
661
    for(int i=0; i<8; i++)
662
      {
663
      if( CUBITS[i].mQuatIndex != q && CUBITS[i].mQuatIndex != q1 ) return false;
664
      }
665
666
    if( CUBITS[24].mQuatIndex != q && CUBITS[24].mQuatIndex != q1 ) return false;
667
    if( CUBITS[25].mQuatIndex != q && CUBITS[25].mQuatIndex != q1 ) return false;
668
669
    q1 = mulQuat(q,2);
670
671
    for(int i=8; i<16; i++)
672
      {
673
      if( CUBITS[i].mQuatIndex != q && CUBITS[i].mQuatIndex != q1 ) return false;
674
      }
675
676
    if( CUBITS[26].mQuatIndex != q && CUBITS[26].mQuatIndex != q1 ) return false;
677
    if( CUBITS[27].mQuatIndex != q && CUBITS[27].mQuatIndex != q1 ) return false;
678
679
    q1 = mulQuat(q,3);
680
681
    for(int i=16; i<24; i++)
682
      {
683
      if( CUBITS[i].mQuatIndex != q && CUBITS[i].mQuatIndex != q1 ) return false;
684
      }
685
686
    if( CUBITS[28].mQuatIndex != q && CUBITS[28].mQuatIndex != q1 ) return false;
687
    if( CUBITS[29].mQuatIndex != q && CUBITS[29].mQuatIndex != q1 ) return false;
688
689 59b87d56 Leszek Koltunski
    return true;
690
    }
691
692
///////////////////////////////////////////////////////////////////////////////////////////////////
693 688f7712 Leszek Koltunski
// only needed for solvers - there are no Rex solvers ATM
694 59b87d56 Leszek Koltunski
695
  public String retObjectString()
696
    {
697
    return "";
698
    }
699
700
///////////////////////////////////////////////////////////////////////////////////////////////////
701
702
  public int getObjectName(int numLayers)
703
    {
704
    return R.string.rex3;
705
    }
706
707
///////////////////////////////////////////////////////////////////////////////////////////////////
708
709
  public int getInventor(int numLayers)
710
    {
711
    return R.string.rex3_inventor;
712
    }
713
714
///////////////////////////////////////////////////////////////////////////////////////////////////
715
716
  public int getComplexity(int numLayers)
717
    {
718
    return 3;
719
    }
720
}