Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyRex.java @ 43a4ccff

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.MOVEMENT_HEXAHEDRON;
23
import static org.distorted.objectlib.main.Movement.TYPE_SPLIT_CORNER;
24

    
25
import android.content.res.Resources;
26

    
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32

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

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
public class TwistyRex extends Twisty6
45
{
46
  static final Static3D[] ROT_AXIS = new Static3D[]
47
         {
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
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
52
         };
53

    
54
  public static final float REX_D = 0.2f;
55

    
56
  private ScrambleState[] mStates;
57
  private int[] mBasicAngle;
58
  private Static4D[] mQuats;
59
  private float[][] mCuts;
60
  private int[][] mFaceMap;
61
  private ObjectSticker[] mStickers;
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  public TwistyRex(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
66
                   MeshSquare mesh, DistortedEffects effects, Resources res, int surfaceW, int surfaceH)
67
    {
68
    super(numL, numL[0], quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
69
    }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

    
73
  public ScrambleState[] getScrambleStates()
74
    {
75
    if( mStates==null )
76
      {
77
      int[] tmp = {0,-1,0, 0,1,0, 2,-1,0, 2,1,0 };
78

    
79
      mStates = new ScrambleState[]
80
        {
81
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
82
        };
83
      }
84

    
85
    return mStates;
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  protected int getResource(int[] numLayers)
91
    {
92
    return R.raw.rex;
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  private void initializeQuats()
98
    {
99
    mQuats = new Static4D[]
100
         {
101
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
102
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
103
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
104
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
105

    
106
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
107
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
108
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
109
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
110
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
111
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
112
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
113
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
114
         };
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  public int[] getSolvedQuats(int cubit, int[] numLayers)
120
    {
121
    if( mQuats==null ) initializeQuats();
122
    int status = retCubitSolvedStatus(cubit,numLayers);
123
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status],mQuats);
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
  public Static4D[] getQuats()
129
    {
130
    if( mQuats==null ) initializeQuats();
131
    return mQuats;
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
  public int getSolvedFunctionIndex()
137
    {
138
    return 0;
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
  public int getNumStickerTypes(int[] numLayers)
144
    {
145
    return 3;
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  public float[][] getCuts(int[] numLayers)
151
    {
152
    if( mCuts==null )
153
      {
154
      float C = SQ3*0.45f; // bit less than 1/2 of the length of the main diagonal
155
      float[] cut = new float[] {-C,+C};
156
      mCuts = new float[][] { cut,cut,cut,cut };
157
      }
158

    
159
    return mCuts;
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  public boolean[][] getLayerRotatable(int[] numLayers)
165
    {
166
    int numAxis = ROT_AXIS.length;
167
    boolean[] tmp = new boolean[] {true,false,true};
168
    boolean[][] layerRotatable = new boolean[numAxis][];
169
    for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
170

    
171
    return layerRotatable;
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  public int getMovementType()
177
    {
178
    return MOVEMENT_HEXAHEDRON;
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  public int getMovementSplit()
184
    {
185
    return TYPE_SPLIT_CORNER;
186
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

    
190
  public int[][][] getEnabled()
191
    {
192
    return new int[][][]
193
      {
194
          {{0,1},{3,1},{2,3},{0,2}},
195
          {{2,3},{3,1},{0,1},{0,2}},
196
          {{1,2},{0,1},{0,3},{2,3}},
197
          {{1,2},{2,3},{0,3},{0,1}},
198
          {{0,3},{0,2},{1,2},{1,3}},
199
          {{1,2},{0,2},{0,3},{1,3}},
200
      };
201
    }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

    
205
  public float[] getDist3D(int[] numLayers)
206
    {
207
    return null;
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

    
212
  protected int getNumCubitFaces()
213
    {
214
    return 6;
215
    }
216

    
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

    
219
  public float[][] getCubitPositions(int[] numLayers)
220
    {
221
    final float DIST1= 1.50f;
222
    final float DIST2= (1+2*REX_D)/2;
223
    final float DIST3= 1.53f;
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

    
272
    return CENTERS;
273
    }
274

    
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

    
277
  public ObjectShape getObjectShape(int variant)
278
    {
279
    if( variant==0 )
280
      {
281
      float G = (1-REX_D)*SQ2/2;
282
      double[][] vertices ={{-0.10f,0.70f,0},{-0.70f,0.10f,0},{+0.65f,-0.71f,0},{+0.71f,-0.65f,0}};
283
      int[][] vertIndexes = { {0,1,2,3},{3,2,1,0} };
284
      float[][] centers= new float[][] { {0.0f,0.0f,-G} };
285
      float[][] corners= new float[][] { {0.03f,0.30f} };
286
      int[] indices= {-1,-1,0,0};
287
      int[] bandIndices= new int[] { 0,1 };
288
      float[][] bands = { {+0.016f,10,G/3,0.5f,5,1,1},{+0.230f,45,G/3,0.0f,2,0,0} };
289

    
290
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
291
      }
292
    else if( variant==1 )
293
      {
294
      float G = 3*REX_D;
295
      double[][] vertices= { { -G, 0, 0 },{ 0, -G, 0 },{ +G, 0, 0 },{ 0,+G,0 } };
296
      int[][] vertIndexes= { {0,1,2,3},{3,2,1,0} };
297
      int[] indices= {-1,-1,-1,-1};
298
      int[] bandIndices= new int[] { 0,1 };
299
      float[][] bands = { {0.025f,10,G/2,0.5f,5,0,0},{0.000f,45,G/2,0.0f,2,0,0} };
300

    
301
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,null,indices,null,indices,getNumCubitFaces(), null);
302
      }
303
    else
304
      {
305
      float E = 1.5f - 3*REX_D;
306
      float F = 1.5f;
307
      float G = (float)Math.sqrt(E*E+F*F);
308
      double[][] vertices = { { -F, 0, 0 },{  0,-E, 0 },{ +F, 0, 0 },{  0, 0,-E } };
309
      int[][] vertIndexes = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
310
      float[][] centers= new float[][] { {0.0f,-1.5f,-1.5f} };
311
      float[][] corners= new float[][] { {0.06f,0.20f} };
312
      int[] indices= {0,-1,0,-1};
313
      int[] bandIndices= new int[] { 0,0,1,1 };
314
      float[][] bands = { {0.03f,27,F/3,0.8f,5,2,3},{0.01f,45,G/3,0.2f,3,1,2} };
315

    
316
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
317
      }
318
    }
319

    
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321

    
322
  public Static4D getQuat(int cubit, int[] numLayers)
323
    {
324
    if( mQuats==null ) initializeQuats();
325

    
326
    switch(cubit)
327
      {
328
      case  0: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
329
      case  1: return mQuats[5];
330
      case  2: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
331
      case  3: return mQuats[8];
332
      case  4: return mQuats[6];
333
      case  5: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
334
      case  6: return mQuats[11];
335
      case  7: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
336
      case  8: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
337
      case  9: return mQuats[10];
338
      case 10: return new Static4D(     0,+SQ2/2,+SQ2/2,     0);
339
      case 11: return mQuats[4];
340
      case 12: return mQuats[9];
341
      case 13: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
342
      case 14: return mQuats[7];
343
      case 15: return new Static4D(     0,-SQ2/2,+SQ2/2,     0);
344
      case 16: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
345
      case 17: return mQuats[0];
346
      case 18: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
347
      case 19: return mQuats[3];
348
      case 20: return mQuats[1];
349
      case 21: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
350
      case 22: return mQuats[2];
351
      case 23: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
352

    
353
      case 24: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
354
      case 25: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
355
      case 26: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
356
      case 27: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
357
      case 28: return mQuats[0];
358
      case 29: return mQuats[1];
359

    
360
      case 30: return mQuats[0];
361
      case 31: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
362
      case 32: return mQuats[3];
363
      case 33: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
364
      case 34: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
365
      case 35: return mQuats[7];
366
      case 36: return mQuats[9];
367
      case 37: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
368
      case 38: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
369
      case 39: return mQuats[8];
370
      case 40: return mQuats[1];
371
      case 41: return mQuats[6];
372
      }
373

    
374
    return mQuats[0];
375
    }
376

    
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

    
379
  public int getNumCubitVariants(int[] numLayers)
380
    {
381
    return 3;
382
    }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

    
386
  public int getCubitVariant(int cubit, int[] numLayers)
387
    {
388
    return cubit<24 ? 0 : (cubit<30?1:2);
389
    }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

    
393
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
394
    {
395
    if( mFaceMap==null )
396
      {
397
      mFaceMap = new int[][]
398
         {
399
           {  0, 18,18,18,18,18 },
400
           {  0, 18,18,18,18,18 },
401
           {  0, 18,18,18,18,18 },
402
           {  0, 18,18,18,18,18 },
403
           {  1, 18,18,18,18,18 },
404
           {  1, 18,18,18,18,18 },
405
           {  1, 18,18,18,18,18 },
406
           {  1, 18,18,18,18,18 },
407
           {  2, 18,18,18,18,18 },
408
           {  2, 18,18,18,18,18 },
409
           {  2, 18,18,18,18,18 },
410
           {  2, 18,18,18,18,18 },
411
           {  3, 18,18,18,18,18 },
412
           {  3, 18,18,18,18,18 },
413
           {  3, 18,18,18,18,18 },
414
           {  3, 18,18,18,18,18 },
415
           {  4, 18,18,18,18,18 },
416
           {  4, 18,18,18,18,18 },
417
           {  4, 18,18,18,18,18 },
418
           {  4, 18,18,18,18,18 },
419
           {  5, 18,18,18,18,18 },
420
           {  5, 18,18,18,18,18 },
421
           {  5, 18,18,18,18,18 },
422
           {  5, 18,18,18,18,18 },
423

    
424
           {  6, 18,18,18,18,18 },
425
           {  7, 18,18,18,18,18 },
426
           {  8, 18,18,18,18,18 },
427
           {  9, 18,18,18,18,18 },
428
           { 10, 18,18,18,18,18 },
429
           { 11, 18,18,18,18,18 },
430

    
431
           { 16,14, 18,18,18,18 },
432
           { 16,12, 18,18,18,18 },
433
           { 16,15, 18,18,18,18 },
434
           { 16,13, 18,18,18,18 },
435
           { 12,14, 18,18,18,18 },
436
           { 15,12, 18,18,18,18 },
437
           { 15,13, 18,18,18,18 },
438
           { 13,14, 18,18,18,18 },
439
           { 14,17, 18,18,18,18 },
440
           { 12,17, 18,18,18,18 },
441
           { 17,15, 18,18,18,18 },
442
           { 13,17, 18,18,18,18 },
443
         };
444
      }
445

    
446
    return mFaceMap[cubit][cubitface];
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450

    
451
  public ObjectSticker retSticker(int sticker)
452
    {
453
    if( mStickers==null )
454
      {
455
      float[][] STICKERS = new float[][]
456
          {
457
             { -0.5f, 0.1428f, -0.1428f, 0.5f, 0.35f, -0.35f },
458
             { -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
459
             { -0.525f, 0.105f, 0.525f, 0.105f, 0.000f, -0.210f  }
460
          };
461

    
462
      final float F = (float)(Math.PI/20);
463
      final float R1= 0.02f;
464
      final float R2= 0.09f;
465
      final float R3= 0.06f;
466
      final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } };
467
      final float[][] radii  = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} };
468
      final float[] strokes = { 0.06f, 0.07f, 0.05f };
469

    
470
      if( ObjectControl.isInIconMode() )
471
        {
472
        float mult = 1.5f;
473
        strokes[0]*=mult;
474
        strokes[1]*=mult;
475
        strokes[2]*=mult;
476
        }
477

    
478
      mStickers = new ObjectSticker[STICKERS.length];
479

    
480
      for(int s=0; s<STICKERS.length; s++)
481
        {
482
        mStickers[s] = new ObjectSticker(STICKERS[s],angles[s],radii[s],strokes[s]);
483
        }
484
      }
485

    
486
    return mStickers[sticker];
487
    }
488

    
489
///////////////////////////////////////////////////////////////////////////////////////////////////
490
// PUBLIC API
491

    
492
  public Static3D[] getRotationAxis()
493
    {
494
    return ROT_AXIS;
495
    }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498

    
499
  public int[] getBasicAngle()
500
    {
501
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
502
    return mBasicAngle;
503
    }
504

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

    
507
  public ObjectType intGetObjectType(int[] numLayers)
508
    {
509
    return ObjectType.REX_3;
510
    }
511

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

    
514
  public int getObjectName(int[] numLayers)
515
    {
516
    return R.string.rex3;
517
    }
518

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

    
521
  public int getInventor(int[] numLayers)
522
    {
523
    return R.string.rex3_inventor;
524
    }
525

    
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527

    
528
  public int getYearOfInvention(int[] numLayers)
529
    {
530
    return 2009;
531
    }
532

    
533
///////////////////////////////////////////////////////////////////////////////////////////////////
534

    
535
  public int getComplexity(int[] numLayers)
536
    {
537
    return 3;
538
    }
539
}
(20-20/25)