Project

General

Profile

Download (18.7 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyRex.java @ 8005e762

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.objectlib.objects;
21

    
22
import static org.distorted.objectlib.main.Movement.TYPE_SPLIT_CORNER;
23

    
24
import android.content.res.Resources;
25

    
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

    
32
import org.distorted.objectlib.R;
33
import org.distorted.objectlib.main.Movement;
34
import org.distorted.objectlib.main.Movement6;
35
import org.distorted.objectlib.main.ObjectType;
36
import org.distorted.objectlib.main.ObjectShape;
37
import org.distorted.objectlib.main.ObjectSticker;
38
import org.distorted.objectlib.main.ScrambleState;
39
import org.distorted.objectlib.main.Twisty6;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
public class TwistyRex extends Twisty6
44
{
45
  static final Static3D[] ROT_AXIS = new Static3D[]
46
         {
47
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
48
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
49
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
50
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
51
         };
52

    
53
  private static final int[][][] ENABLED = new int[][][]
54
      {
55
          {{0,1},{3,1},{2,3},{0,2}},
56
          {{2,3},{3,1},{0,1},{0,2}},
57
          {{1,2},{0,1},{0,3},{2,3}},
58
          {{1,2},{2,3},{0,3},{0,1}},
59
          {{0,3},{0,2},{1,2},{1,3}},
60
          {{1,2},{0,2},{0,3},{1,3}},
61
      };
62

    
63
  public static final float REX_D = 0.2f;
64

    
65
  private ScrambleState[] mStates;
66
  private int[] mBasicAngle;
67
  private Static4D[] mQuats;
68
  private float[][] mCuts;
69
  private boolean[][] mLayerRotatable;
70
  private int[][] mFaceMap;
71
  private ObjectSticker[] mStickers;
72
  private Movement mMovement;
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  public TwistyRex(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
77
                   DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
78
    {
79
    super(size, size, quat, texture, mesh, effects, moves, res, scrWidth);
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  protected ScrambleState[] getScrambleStates()
85
    {
86
    if( mStates==null )
87
      {
88
      int[] tmp = {0,-1,0, 0,1,0, 2,-1,0, 2,1,0 };
89

    
90
      mStates = new ScrambleState[]
91
        {
92
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
93
        };
94
      }
95

    
96
    return mStates;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  protected int getResource(int numLayers)
102
    {
103
    return R.raw.rex;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  private void initializeQuats()
109
    {
110
    mQuats = new Static4D[]
111
         {
112
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
113
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
114
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
115
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
116

    
117
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
118
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
119
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
120
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
121
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
122
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
123
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
124
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
125
         };
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  protected int[] getSolvedQuats(int cubit, int numLayers)
131
    {
132
    if( mQuats==null ) initializeQuats();
133
    int status = retCubitSolvedStatus(cubit,numLayers);
134
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status],mQuats);
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  protected Static4D[] getQuats()
140
    {
141
    if( mQuats==null ) initializeQuats();
142
    return mQuats;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  protected int getSolvedFunctionIndex()
148
    {
149
    return 0;
150
    }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
  protected int getNumStickerTypes(int numLayers)
155
    {
156
    return 3;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  protected float[][] getCuts(int numLayers)
162
    {
163
    if( mCuts==null )
164
      {
165
      float C = SQ3*0.45f; // bit less than 1/2 of the length of the main diagonal
166
      float[] cut = new float[] {-C,+C};
167
      mCuts = new float[][] { cut,cut,cut,cut };
168
      }
169

    
170
    return mCuts;
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  private void getLayerRotatable(int numLayers)
176
    {
177
    if( mLayerRotatable==null )
178
      {
179
      int numAxis = ROT_AXIS.length;
180
      boolean[] tmp = new boolean[] {true,false,true};
181
      mLayerRotatable = new boolean[numAxis][];
182
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
183
      }
184
    }
185

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

    
188
  protected int getNumCubitFaces()
189
    {
190
    return 6;
191
    }
192

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

    
195
  protected float[][] getCubitPositions(int numLayers)
196
    {
197
    final float DIST1= 1.50f;
198
    final float DIST2= (1+2*REX_D)/2;
199
    final float DIST3= 1.53f;
200

    
201
    final float[][] CENTERS = new float[24+6+12][];
202

    
203
    CENTERS[ 0] = new float[] { +DIST3, +DIST2, +DIST2};
204
    CENTERS[ 1] = new float[] { +DIST3, +DIST2, -DIST2};
205
    CENTERS[ 2] = new float[] { +DIST3, -DIST2, -DIST2};
206
    CENTERS[ 3] = new float[] { +DIST3, -DIST2, +DIST2};
207
    CENTERS[ 4] = new float[] { -DIST3, +DIST2, +DIST2};
208
    CENTERS[ 5] = new float[] { -DIST3, +DIST2, -DIST2};
209
    CENTERS[ 6] = new float[] { -DIST3, -DIST2, -DIST2};
210
    CENTERS[ 7] = new float[] { -DIST3, -DIST2, +DIST2};
211
    CENTERS[ 8] = new float[] { +DIST2, +DIST3, +DIST2};
212
    CENTERS[ 9] = new float[] { +DIST2, +DIST3, -DIST2};
213
    CENTERS[10] = new float[] { -DIST2, +DIST3, -DIST2};
214
    CENTERS[11] = new float[] { -DIST2, +DIST3, +DIST2};
215
    CENTERS[12] = new float[] { +DIST2, -DIST3, +DIST2};
216
    CENTERS[13] = new float[] { +DIST2, -DIST3, -DIST2};
217
    CENTERS[14] = new float[] { -DIST2, -DIST3, -DIST2};
218
    CENTERS[15] = new float[] { -DIST2, -DIST3, +DIST2};
219
    CENTERS[16] = new float[] { +DIST2, +DIST2, +DIST3};
220
    CENTERS[17] = new float[] { +DIST2, -DIST2, +DIST3};
221
    CENTERS[18] = new float[] { -DIST2, -DIST2, +DIST3};
222
    CENTERS[19] = new float[] { -DIST2, +DIST2, +DIST3};
223
    CENTERS[20] = new float[] { +DIST2, +DIST2, -DIST3};
224
    CENTERS[21] = new float[] { +DIST2, -DIST2, -DIST3};
225
    CENTERS[22] = new float[] { -DIST2, -DIST2, -DIST3};
226
    CENTERS[23] = new float[] { -DIST2, +DIST2, -DIST3};
227

    
228
    CENTERS[24] = new float[] { +DIST3, +0.00f, +0.00f};
229
    CENTERS[25] = new float[] { -DIST3, +0.00f, +0.00f};
230
    CENTERS[26] = new float[] { +0.00f, +DIST3, +0.00f};
231
    CENTERS[27] = new float[] { +0.00f, -DIST3, +0.00f};
232
    CENTERS[28] = new float[] { +0.00f, +0.00f, +DIST3};
233
    CENTERS[29] = new float[] { +0.00f, +0.00f, -DIST3};
234

    
235
    CENTERS[30] = new float[] { +0.00f, +DIST1, +DIST1};
236
    CENTERS[31] = new float[] { +DIST1, +0.00f, +DIST1};
237
    CENTERS[32] = new float[] { +0.00f, -DIST1, +DIST1};
238
    CENTERS[33] = new float[] { -DIST1, +0.00f, +DIST1};
239
    CENTERS[34] = new float[] { +DIST1, +DIST1, +0.00f};
240
    CENTERS[35] = new float[] { +DIST1, -DIST1, +0.00f};
241
    CENTERS[36] = new float[] { -DIST1, -DIST1, +0.00f};
242
    CENTERS[37] = new float[] { -DIST1, +DIST1, +0.00f};
243
    CENTERS[38] = new float[] { +0.00f, +DIST1, -DIST1};
244
    CENTERS[39] = new float[] { +DIST1, +0.00f, -DIST1};
245
    CENTERS[40] = new float[] { +0.00f, -DIST1, -DIST1};
246
    CENTERS[41] = new float[] { -DIST1, +0.00f, -DIST1};
247

    
248
    return CENTERS;
249
    }
250

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

    
253
  protected ObjectShape getObjectShape(int cubit, int numLayers)
254
    {
255
    int variant = getCubitVariant(cubit,numLayers);
256

    
257
    if( variant==0 )
258
      {
259
      float G = (1-REX_D)*SQ2/2;
260
      double[][] vertices ={{-0.10f,0.70f,0},{-0.70f,0.10f,0},{+0.65f,-0.71f,0},{+0.71f,-0.65f,0}};
261
      int[][] vertIndexes = { {0,1,2,3},{3,2,1,0} };
262
      float[][] centers= new float[][] { {0.0f,0.0f,-G} };
263
      float[][] corners= new float[][] { {0.03f,0.30f} };
264
      int[] indices= {-1,-1,0,0};
265
      int[] bandIndices= new int[] { 0,1 };
266
      float[][] bands = { {+0.016f,10,G/3,0.5f,5,1,1},{+0.230f,45,G/3,0.0f,2,0,0} };
267

    
268
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
269
      }
270
    else if( variant==1 )
271
      {
272
      float G = 3*REX_D;
273
      double[][] vertices= { { -G, 0, 0 },{ 0, -G, 0 },{ +G, 0, 0 },{ 0,+G,0 } };
274
      int[][] vertIndexes= { {0,1,2,3},{3,2,1,0} };
275
      int[] indices= {-1,-1,-1,-1};
276
      int[] bandIndices= new int[] { 0,1 };
277
      float[][] bands = { {0.025f,10,G/2,0.5f,5,0,0},{0.000f,45,G/2,0.0f,2,0,0} };
278

    
279
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,null,indices,null,indices,getNumCubitFaces(), null);
280
      }
281
    else
282
      {
283
      float E = 1.5f - 3*REX_D;
284
      float F = 1.5f;
285
      float G = (float)Math.sqrt(E*E+F*F);
286
      double[][] vertices = { { -F, 0, 0 },{  0,-E, 0 },{ +F, 0, 0 },{  0, 0,-E } };
287
      int[][] vertIndexes = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
288
      float[][] centers= new float[][] { {0.0f,-1.5f,-1.5f} };
289
      float[][] corners= new float[][] { {0.06f,0.20f} };
290
      int[] indices= {0,-1,0,-1};
291
      int[] bandIndices= new int[] { 0,0,1,1 };
292
      float[][] bands = { {0.03f,27,F/3,0.8f,5,2,3},{0.01f,45,G/3,0.2f,3,1,2} };
293

    
294
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
295
      }
296
    }
297

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

    
300
  protected Static4D getQuat(int cubit, int numLayers)
301
    {
302
    if( mQuats==null ) initializeQuats();
303

    
304
    switch(cubit)
305
      {
306
      case  0: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
307
      case  1: return mQuats[5];
308
      case  2: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
309
      case  3: return mQuats[8];
310
      case  4: return mQuats[6];
311
      case  5: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
312
      case  6: return mQuats[11];
313
      case  7: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
314
      case  8: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
315
      case  9: return mQuats[10];
316
      case 10: return new Static4D(     0,+SQ2/2,+SQ2/2,     0);
317
      case 11: return mQuats[4];
318
      case 12: return mQuats[9];
319
      case 13: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
320
      case 14: return mQuats[7];
321
      case 15: return new Static4D(     0,-SQ2/2,+SQ2/2,     0);
322
      case 16: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
323
      case 17: return mQuats[0];
324
      case 18: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
325
      case 19: return mQuats[3];
326
      case 20: return mQuats[1];
327
      case 21: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
328
      case 22: return mQuats[2];
329
      case 23: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
330

    
331
      case 24: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
332
      case 25: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
333
      case 26: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
334
      case 27: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
335
      case 28: return mQuats[0];
336
      case 29: return mQuats[1];
337

    
338
      case 30: return mQuats[0];
339
      case 31: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
340
      case 32: return mQuats[3];
341
      case 33: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
342
      case 34: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
343
      case 35: return mQuats[7];
344
      case 36: return mQuats[9];
345
      case 37: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
346
      case 38: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
347
      case 39: return mQuats[8];
348
      case 40: return mQuats[1];
349
      case 41: return mQuats[6];
350
      }
351

    
352
    return mQuats[0];
353
    }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

    
357
  protected int getNumCubitVariants(int numLayers)
358
    {
359
    return 3;
360
    }
361

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

    
364
  protected int getCubitVariant(int cubit, int numLayers)
365
    {
366
    return cubit<24 ? 0 : (cubit<30?1:2);
367
    }
368

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

    
371
  protected int getFaceColor(int cubit, int cubitface, int numLayers)
372
    {
373
    if( mFaceMap==null )
374
      {
375
      mFaceMap = new int[][]
376
         {
377
           {  0, 18,18,18,18,18 },
378
           {  0, 18,18,18,18,18 },
379
           {  0, 18,18,18,18,18 },
380
           {  0, 18,18,18,18,18 },
381
           {  1, 18,18,18,18,18 },
382
           {  1, 18,18,18,18,18 },
383
           {  1, 18,18,18,18,18 },
384
           {  1, 18,18,18,18,18 },
385
           {  2, 18,18,18,18,18 },
386
           {  2, 18,18,18,18,18 },
387
           {  2, 18,18,18,18,18 },
388
           {  2, 18,18,18,18,18 },
389
           {  3, 18,18,18,18,18 },
390
           {  3, 18,18,18,18,18 },
391
           {  3, 18,18,18,18,18 },
392
           {  3, 18,18,18,18,18 },
393
           {  4, 18,18,18,18,18 },
394
           {  4, 18,18,18,18,18 },
395
           {  4, 18,18,18,18,18 },
396
           {  4, 18,18,18,18,18 },
397
           {  5, 18,18,18,18,18 },
398
           {  5, 18,18,18,18,18 },
399
           {  5, 18,18,18,18,18 },
400
           {  5, 18,18,18,18,18 },
401

    
402
           {  6, 18,18,18,18,18 },
403
           {  7, 18,18,18,18,18 },
404
           {  8, 18,18,18,18,18 },
405
           {  9, 18,18,18,18,18 },
406
           { 10, 18,18,18,18,18 },
407
           { 11, 18,18,18,18,18 },
408

    
409
           { 16,14, 18,18,18,18 },
410
           { 16,12, 18,18,18,18 },
411
           { 16,15, 18,18,18,18 },
412
           { 16,13, 18,18,18,18 },
413
           { 12,14, 18,18,18,18 },
414
           { 15,12, 18,18,18,18 },
415
           { 15,13, 18,18,18,18 },
416
           { 13,14, 18,18,18,18 },
417
           { 14,17, 18,18,18,18 },
418
           { 12,17, 18,18,18,18 },
419
           { 17,15, 18,18,18,18 },
420
           { 13,17, 18,18,18,18 },
421
         };
422
      }
423

    
424
    return mFaceMap[cubit][cubitface];
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  protected ObjectSticker retSticker(int face)
430
    {
431
    if( mStickers==null )
432
      {
433
      float[][] STICKERS = new float[][]
434
          {
435
             { -0.5f, 0.1428f, -0.1428f, 0.5f, 0.35f, -0.35f },
436
             { -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
437
             { -0.525f, 0.105f, 0.525f, 0.105f, 0.000f, -0.210f  }
438
          };
439

    
440
      final float F = (float)(Math.PI/20);
441
      final float R1= 0.02f;
442
      final float R2= 0.09f;
443
      final float R3= 0.06f;
444
      final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } };
445
      final float[][] radii  = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} };
446
      final float[] strokes = { 0.06f, 0.07f, 0.05f };
447

    
448
      mStickers = new ObjectSticker[STICKERS.length];
449

    
450
      for(int s=0; s<STICKERS.length; s++)
451
        {
452
        mStickers[s] = new ObjectSticker(STICKERS[s],angles[s],radii[s],strokes[s]);
453
        }
454
      }
455

    
456
    return mStickers[face/NUM_FACE_COLORS];
457
    }
458

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460
// PUBLIC API
461

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

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

    
469
  public Movement getMovement()
470
    {
471
    if( mMovement==null )
472
      {
473
      int numLayers = getNumLayers();
474
      if( mCuts==null ) getCuts(numLayers);
475
      getLayerRotatable(numLayers);
476
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_SPLIT_CORNER,ENABLED);
477
      }
478
    return mMovement;
479
    }
480

    
481
///////////////////////////////////////////////////////////////////////////////////////////////////
482

    
483
  public int[] getBasicAngle()
484
    {
485
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
486
    return mBasicAngle;
487
    }
488

    
489
///////////////////////////////////////////////////////////////////////////////////////////////////
490

    
491
  public ObjectType intGetObjectList(int numLayers)
492
    {
493
    return ObjectType.REX_3;
494
    }
495

    
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497

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

    
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

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

    
510
///////////////////////////////////////////////////////////////////////////////////////////////////
511

    
512
  public int getComplexity(int numLayers)
513
    {
514
    return 3;
515
    }
516
}
(20-20/25)