Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyRex.java @ 23afe4c4

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

    
25
import java.io.InputStream;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.movement.MovementHexahedron;
31
import org.distorted.objectlib.main.ObjectControl;
32
import org.distorted.objectlib.main.ObjectType;
33
import org.distorted.objectlib.helpers.ObjectShape;
34
import org.distorted.objectlib.helpers.ObjectSticker;
35
import org.distorted.objectlib.helpers.ScrambleState;
36
import org.distorted.objectlib.main.ShapeHexahedron;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class TwistyRex extends ShapeHexahedron
41
{
42
  static final Static3D[] ROT_AXIS = new Static3D[]
43
         {
44
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
45
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
46
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
47
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
48
         };
49

    
50
  public static final float REX_D = 0.2f;
51

    
52
  private ScrambleState[] mStates;
53
  private int[] mBasicAngle;
54
  private Static4D[] mQuats;
55
  private float[][] mCuts;
56
  private int[][] mFaceMap;
57
  private ObjectSticker[] mStickers;
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
  public TwistyRex(int[] numL, Static4D quat, Static3D move, float scale, InputStream stream)
62
    {
63
    super(numL, numL[0], quat, move, scale, stream);
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  public ScrambleState[] getScrambleStates()
69
    {
70
    if( mStates==null )
71
      {
72
      int[] tmp = {0,-1,0, 0,1,0, 2,-1,0, 2,1,0 };
73

    
74
      mStates = new ScrambleState[]
75
        {
76
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
77
        };
78
      }
79

    
80
    return mStates;
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  private void initializeQuats()
86
    {
87
    mQuats = new Static4D[]
88
         {
89
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
90
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
91
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
92
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
93

    
94
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
95
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
96
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
97
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
98
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
99
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
100
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
101
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
102
         };
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  public int[] getSolvedQuats(int cubit, int[] numLayers)
108
    {
109
    if( mQuats==null ) initializeQuats();
110
    int status = retCubitSolvedStatus(cubit,numLayers);
111
    return status<0 ? null : buildSolvedQuats(MovementHexahedron.FACE_AXIS[status],mQuats);
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  public Static4D[] getQuats()
117
    {
118
    if( mQuats==null ) initializeQuats();
119
    return mQuats;
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
  public int getSolvedFunctionIndex()
125
    {
126
    return 0;
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public int getNumStickerTypes(int[] numLayers)
132
    {
133
    return 3;
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  public float[][] getCuts(int[] numLayers)
139
    {
140
    if( mCuts==null )
141
      {
142
      float C = SQ3*0.45f; // bit less than 1/2 of the length of the main diagonal
143
      float[] cut = new float[] {-C,+C};
144
      mCuts = new float[][] { cut,cut,cut,cut };
145
      }
146

    
147
    return mCuts;
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  public boolean[][] getLayerRotatable(int[] numLayers)
153
    {
154
    int numAxis = ROT_AXIS.length;
155
    boolean[] tmp = new boolean[] {true,false,true};
156
    boolean[][] layerRotatable = new boolean[numAxis][];
157
    for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
158

    
159
    return layerRotatable;
160
    }
161

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

    
164
  public int getMovementType()
165
    {
166
    return MOVEMENT_HEXAHEDRON;
167
    }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

    
171
  public int getMovementSplit()
172
    {
173
    return TYPE_SPLIT_CORNER;
174
    }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

    
178
  public int[][][] getEnabled()
179
    {
180
    return new int[][][]
181
      {
182
          {{0,1},{3,1},{2,3},{0,2}},
183
          {{2,3},{3,1},{0,1},{0,2}},
184
          {{1,2},{0,1},{0,3},{2,3}},
185
          {{1,2},{2,3},{0,3},{0,1}},
186
          {{0,3},{0,2},{1,2},{1,3}},
187
          {{1,2},{0,2},{0,3},{1,3}},
188
      };
189
    }
190

    
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

    
193
  public float[] getDist3D(int[] numLayers)
194
    {
195
    return null;
196
    }
197

    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

    
200
  public int getNumCubitFaces()
201
    {
202
    return 6;
203
    }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

    
207
  public float[][] getCubitPositions(int[] numLayers)
208
    {
209
    final float DIST1= 1.50f;
210
    final float DIST2= (1+2*REX_D)/2;
211
    final float DIST3= 1.53f;
212

    
213
    final float[][] CENTERS = new float[24+6+12][];
214

    
215
    CENTERS[ 0] = new float[] { +DIST3, +DIST2, +DIST2};
216
    CENTERS[ 1] = new float[] { +DIST3, +DIST2, -DIST2};
217
    CENTERS[ 2] = new float[] { +DIST3, -DIST2, -DIST2};
218
    CENTERS[ 3] = new float[] { +DIST3, -DIST2, +DIST2};
219
    CENTERS[ 4] = new float[] { -DIST3, +DIST2, +DIST2};
220
    CENTERS[ 5] = new float[] { -DIST3, +DIST2, -DIST2};
221
    CENTERS[ 6] = new float[] { -DIST3, -DIST2, -DIST2};
222
    CENTERS[ 7] = new float[] { -DIST3, -DIST2, +DIST2};
223
    CENTERS[ 8] = new float[] { +DIST2, +DIST3, +DIST2};
224
    CENTERS[ 9] = new float[] { +DIST2, +DIST3, -DIST2};
225
    CENTERS[10] = new float[] { -DIST2, +DIST3, -DIST2};
226
    CENTERS[11] = new float[] { -DIST2, +DIST3, +DIST2};
227
    CENTERS[12] = new float[] { +DIST2, -DIST3, +DIST2};
228
    CENTERS[13] = new float[] { +DIST2, -DIST3, -DIST2};
229
    CENTERS[14] = new float[] { -DIST2, -DIST3, -DIST2};
230
    CENTERS[15] = new float[] { -DIST2, -DIST3, +DIST2};
231
    CENTERS[16] = new float[] { +DIST2, +DIST2, +DIST3};
232
    CENTERS[17] = new float[] { +DIST2, -DIST2, +DIST3};
233
    CENTERS[18] = new float[] { -DIST2, -DIST2, +DIST3};
234
    CENTERS[19] = new float[] { -DIST2, +DIST2, +DIST3};
235
    CENTERS[20] = new float[] { +DIST2, +DIST2, -DIST3};
236
    CENTERS[21] = new float[] { +DIST2, -DIST2, -DIST3};
237
    CENTERS[22] = new float[] { -DIST2, -DIST2, -DIST3};
238
    CENTERS[23] = new float[] { -DIST2, +DIST2, -DIST3};
239

    
240
    CENTERS[24] = new float[] { +DIST3, +0.00f, +0.00f};
241
    CENTERS[25] = new float[] { -DIST3, +0.00f, +0.00f};
242
    CENTERS[26] = new float[] { +0.00f, +DIST3, +0.00f};
243
    CENTERS[27] = new float[] { +0.00f, -DIST3, +0.00f};
244
    CENTERS[28] = new float[] { +0.00f, +0.00f, +DIST3};
245
    CENTERS[29] = new float[] { +0.00f, +0.00f, -DIST3};
246

    
247
    CENTERS[30] = new float[] { +0.00f, +DIST1, +DIST1};
248
    CENTERS[31] = new float[] { +DIST1, +0.00f, +DIST1};
249
    CENTERS[32] = new float[] { +0.00f, -DIST1, +DIST1};
250
    CENTERS[33] = new float[] { -DIST1, +0.00f, +DIST1};
251
    CENTERS[34] = new float[] { +DIST1, +DIST1, +0.00f};
252
    CENTERS[35] = new float[] { +DIST1, -DIST1, +0.00f};
253
    CENTERS[36] = new float[] { -DIST1, -DIST1, +0.00f};
254
    CENTERS[37] = new float[] { -DIST1, +DIST1, +0.00f};
255
    CENTERS[38] = new float[] { +0.00f, +DIST1, -DIST1};
256
    CENTERS[39] = new float[] { +DIST1, +0.00f, -DIST1};
257
    CENTERS[40] = new float[] { +0.00f, -DIST1, -DIST1};
258
    CENTERS[41] = new float[] { -DIST1, +0.00f, -DIST1};
259

    
260
    return CENTERS;
261
    }
262

    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

    
265
  public ObjectShape getObjectShape(int variant)
266
    {
267
    if( variant==0 )
268
      {
269
      float G = (1-REX_D)*SQ2/2;
270
      double[][] vertices ={{-0.10f,0.70f,0},{-0.70f,0.10f,0},{+0.65f,-0.71f,0},{+0.71f,-0.65f,0}};
271
      int[][] vertIndexes = { {0,1,2,3},{3,2,1,0} };
272
      float[][] centers= new float[][] { {0.0f,0.0f,-G} };
273
      float[][] corners= new float[][] { {0.03f,0.30f} };
274
      int[] indices= {-1,-1,0,0};
275
      int[] bandIndices= new int[] { 0,1 };
276
      float[][] bands = { {+0.016f,10,G/3,0.5f,5,1,1},{+0.230f,45,G/3,0.0f,2,0,0} };
277

    
278
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
279
      }
280
    else if( variant==1 )
281
      {
282
      float G = 3*REX_D;
283
      double[][] vertices= { { -G, 0, 0 },{ 0, -G, 0 },{ +G, 0, 0 },{ 0,+G,0 } };
284
      int[][] vertIndexes= { {0,1,2,3},{3,2,1,0} };
285
      int[] indices= {-1,-1,-1,-1};
286
      int[] bandIndices= new int[] { 0,1 };
287
      float[][] bands = { {0.025f,10,G/2,0.5f,5,0,0},{0.000f,45,G/2,0.0f,2,0,0} };
288

    
289
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,null,indices,null,indices,getNumCubitFaces(), null);
290
      }
291
    else
292
      {
293
      float E = 1.5f - 3*REX_D;
294
      float F = 1.5f;
295
      float G = (float)Math.sqrt(E*E+F*F);
296
      double[][] vertices = { { -F, 0, 0 },{  0,-E, 0 },{ +F, 0, 0 },{  0, 0,-E } };
297
      int[][] vertIndexes = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
298
      float[][] centers= new float[][] { {0.0f,-1.5f,-1.5f} };
299
      float[][] corners= new float[][] { {0.06f,0.20f} };
300
      int[] indices= {0,-1,0,-1};
301
      int[] bandIndices= new int[] { 0,0,1,1 };
302
      float[][] bands = { {0.03f,27,F/3,0.8f,5,2,3},{0.01f,45,G/3,0.2f,3,1,2} };
303

    
304
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
305
      }
306
    }
307

    
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309

    
310
  public Static4D getQuat(int cubit, int[] numLayers)
311
    {
312
    if( mQuats==null ) initializeQuats();
313

    
314
    switch(cubit)
315
      {
316
      case  0: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
317
      case  1: return mQuats[5];
318
      case  2: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
319
      case  3: return mQuats[8];
320
      case  4: return mQuats[6];
321
      case  5: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
322
      case  6: return mQuats[11];
323
      case  7: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
324
      case  8: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
325
      case  9: return mQuats[10];
326
      case 10: return new Static4D(     0,+SQ2/2,+SQ2/2,     0);
327
      case 11: return mQuats[4];
328
      case 12: return mQuats[9];
329
      case 13: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
330
      case 14: return mQuats[7];
331
      case 15: return new Static4D(     0,-SQ2/2,+SQ2/2,     0);
332
      case 16: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
333
      case 17: return mQuats[0];
334
      case 18: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
335
      case 19: return mQuats[3];
336
      case 20: return mQuats[1];
337
      case 21: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
338
      case 22: return mQuats[2];
339
      case 23: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
340

    
341
      case 24: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
342
      case 25: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
343
      case 26: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
344
      case 27: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
345
      case 28: return mQuats[0];
346
      case 29: return mQuats[1];
347

    
348
      case 30: return mQuats[0];
349
      case 31: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
350
      case 32: return mQuats[3];
351
      case 33: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
352
      case 34: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
353
      case 35: return mQuats[7];
354
      case 36: return mQuats[9];
355
      case 37: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
356
      case 38: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
357
      case 39: return mQuats[8];
358
      case 40: return mQuats[1];
359
      case 41: return mQuats[6];
360
      }
361

    
362
    return mQuats[0];
363
    }
364

    
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366

    
367
  public int getNumCubitVariants(int[] numLayers)
368
    {
369
    return 3;
370
    }
371

    
372
///////////////////////////////////////////////////////////////////////////////////////////////////
373

    
374
  public int getCubitVariant(int cubit, int[] numLayers)
375
    {
376
    return cubit<24 ? 0 : (cubit<30?1:2);
377
    }
378

    
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

    
381
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
382
    {
383
    return variant;
384
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

    
388
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
389
    {
390
    if( mFaceMap==null )
391
      {
392
      mFaceMap = new int[][]
393
         {
394
           { 0, -1,-1,-1,-1,-1 },
395
           { 0, -1,-1,-1,-1,-1 },
396
           { 0, -1,-1,-1,-1,-1 },
397
           { 0, -1,-1,-1,-1,-1 },
398
           { 1, -1,-1,-1,-1,-1 },
399
           { 1, -1,-1,-1,-1,-1 },
400
           { 1, -1,-1,-1,-1,-1 },
401
           { 1, -1,-1,-1,-1,-1 },
402
           { 2, -1,-1,-1,-1,-1 },
403
           { 2, -1,-1,-1,-1,-1 },
404
           { 2, -1,-1,-1,-1,-1 },
405
           { 2, -1,-1,-1,-1,-1 },
406
           { 3, -1,-1,-1,-1,-1 },
407
           { 3, -1,-1,-1,-1,-1 },
408
           { 3, -1,-1,-1,-1,-1 },
409
           { 3, -1,-1,-1,-1,-1 },
410
           { 4, -1,-1,-1,-1,-1 },
411
           { 4, -1,-1,-1,-1,-1 },
412
           { 4, -1,-1,-1,-1,-1 },
413
           { 4, -1,-1,-1,-1,-1 },
414
           { 5, -1,-1,-1,-1,-1 },
415
           { 5, -1,-1,-1,-1,-1 },
416
           { 5, -1,-1,-1,-1,-1 },
417
           { 5, -1,-1,-1,-1,-1 },
418

    
419
           { 0, -1,-1,-1,-1,-1 },
420
           { 1, -1,-1,-1,-1,-1 },
421
           { 2, -1,-1,-1,-1,-1 },
422
           { 3, -1,-1,-1,-1,-1 },
423
           { 4, -1,-1,-1,-1,-1 },
424
           { 5, -1,-1,-1,-1,-1 },
425

    
426
           { 4, 2, -1,-1,-1,-1 },
427
           { 4, 0, -1,-1,-1,-1 },
428
           { 4, 3, -1,-1,-1,-1 },
429
           { 4, 1, -1,-1,-1,-1 },
430
           { 0, 2, -1,-1,-1,-1 },
431
           { 3, 0, -1,-1,-1,-1 },
432
           { 3, 1, -1,-1,-1,-1 },
433
           { 1, 2, -1,-1,-1,-1 },
434
           { 2, 5, -1,-1,-1,-1 },
435
           { 0, 5, -1,-1,-1,-1 },
436
           { 5, 3, -1,-1,-1,-1 },
437
           { 1, 5, -1,-1,-1,-1 },
438
         };
439
      }
440

    
441
    return mFaceMap[cubit][face];
442
    }
443

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445

    
446
  public ObjectSticker retSticker(int sticker)
447
    {
448
    if( mStickers==null )
449
      {
450
      float[][] STICKERS = new float[][]
451
          {
452
             { -0.5f, 0.1428f, -0.1428f, 0.5f, 0.35f, -0.35f },
453
             { -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
454
             { -0.525f, 0.105f, 0.525f, 0.105f, 0.000f, -0.210f  }
455
          };
456

    
457
      final float F = (float)(Math.PI/20);
458
      final float R1= 0.02f;
459
      final float R2= 0.09f;
460
      final float R3= 0.06f;
461
      final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } };
462
      final float[][] radii  = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} };
463
      final float[] strokes = { 0.06f, 0.07f, 0.05f };
464

    
465
      if( ObjectControl.isInIconMode() )
466
        {
467
        float mult = 1.5f;
468
        strokes[0]*=mult;
469
        strokes[1]*=mult;
470
        strokes[2]*=mult;
471
        }
472

    
473
      mStickers = new ObjectSticker[STICKERS.length];
474

    
475
      for(int s=0; s<STICKERS.length; s++)
476
        {
477
        mStickers[s] = new ObjectSticker(STICKERS[s],angles[s],radii[s],strokes[s]);
478
        }
479
      }
480

    
481
    return mStickers[sticker];
482
    }
483

    
484
///////////////////////////////////////////////////////////////////////////////////////////////////
485
// PUBLIC API
486

    
487
  public Static3D[] getRotationAxis()
488
    {
489
    return ROT_AXIS;
490
    }
491

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493

    
494
  public int[] getBasicAngle()
495
    {
496
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
497
    return mBasicAngle;
498
    }
499

    
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501

    
502
  public ObjectType intGetObjectType(int[] numLayers)
503
    {
504
    return ObjectType.REX_3;
505
    }
506

    
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508

    
509
  public String getObjectName()
510
    {
511
    return "Rex Cube";
512
    }
513

    
514
///////////////////////////////////////////////////////////////////////////////////////////////////
515

    
516
  public String getInventor()
517
    {
518
    return "Andrew Cormier";
519
    }
520

    
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522

    
523
  public int getYearOfInvention()
524
    {
525
    return 2009;
526
    }
527

    
528
///////////////////////////////////////////////////////////////////////////////////////////////////
529

    
530
  public int getComplexity()
531
    {
532
    return 3;
533
    }
534
}
(20-20/25)