Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyRedi.java @ 053ffa02

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.touchcontrol.TouchControl.TC_HEXAHEDRON;
23
import static org.distorted.objectlib.touchcontrol.TouchControl.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.touchcontrol.TouchControlHexahedron;
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 TwistyRedi 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
  private ScrambleState[] mStates;
51
  private int[] mBasicAngle;
52
  private Static4D[] mQuats;
53
  private float[][] mCuts;
54
  private float[][] mCenters;
55
  private int[][] mFaceMap;
56
  private ObjectSticker[] mStickers;
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

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

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  public ScrambleState[] getScrambleStates()
68
    {
69
    if( mStates==null )
70
      {
71
      mStates = new ScrambleState[]
72
        {
73
        new ScrambleState( new int[][] { {0,1,1,0,-1,1, 2,1,2,2,-1,2},{0,1,3,0,-1,3, 2,1,4,2,-1,4},{0,1,5,0,-1,5, 2,1,6,2,-1,6},{0,1,7,0,-1,7, 2,1,8,2,-1,8} } ),
74
        new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
75
        new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
76
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
77
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
78
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
79
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
80
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
81
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
82
        };
83
      }
84

    
85
    return mStates;
86
    }
87

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

    
90
  private void initializeQuats()
91
    {
92
    mQuats = new Static4D[]
93
         {
94
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
95
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
96
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
97
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
98

    
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
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
103
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
104
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
105
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
106
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
107
         };
108
    }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

    
112
  public int[] getSolvedQuats(int cubit, int[] numLayers)
113
    {
114
    if( mQuats==null ) initializeQuats();
115
    int status = retCubitSolvedStatus(cubit,numLayers);
116
    return status<0 ? null : buildSolvedQuats(TouchControlHexahedron.FACE_AXIS[status],mQuats);
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
  public Static4D[] getQuats()
122
    {
123
    if( mQuats==null ) initializeQuats();
124
    return mQuats;
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
  public int getSolvedFunctionIndex()
130
    {
131
    return 0;
132
    }
133

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

    
136
  public float[][] getCuts(int[] numLayers)
137
    {
138
    if( mCuts==null )
139
      {
140
      float C = +SQ3/3 +0.05f;
141
      float[] cut = new float[] {-C,+C};
142
      mCuts = new float[][] { cut,cut,cut,cut };
143
      }
144

    
145
    return mCuts;
146
    }
147

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

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

    
157
    return layerRotatable;
158
    }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

    
162
  public int getTouchControlType()
163
    {
164
    return TC_HEXAHEDRON;
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  public int getTouchControlSplit()
170
    {
171
    return TYPE_SPLIT_CORNER;
172
    }
173

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

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

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

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

    
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197

    
198
  public int getNumCubitFaces()
199
    {
200
    return 9;
201
    }
202

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

    
205
  public float[][] getCubitPositions(int[] numLayers)
206
    {
207
    if( mCenters==null )
208
      {
209
      final float DIST_CORNER = 1.0f;
210
      final float DIST_EDGE   = 1.5f;
211

    
212
      mCenters = new float[][]
213
         {
214
             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
215
             { DIST_CORNER, DIST_CORNER,-DIST_CORNER },
216
             { DIST_CORNER,-DIST_CORNER, DIST_CORNER },
217
             { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
218
             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
219
             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
220
             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
221
             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
222

    
223
             {      0.0f, DIST_EDGE, DIST_EDGE },
224
             { DIST_EDGE,      0.0f, DIST_EDGE },
225
             {      0.0f,-DIST_EDGE, DIST_EDGE },
226
             {-DIST_EDGE,      0.0f, DIST_EDGE },
227
             { DIST_EDGE, DIST_EDGE,      0.0f },
228
             { DIST_EDGE,-DIST_EDGE,      0.0f },
229
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
230
             {-DIST_EDGE, DIST_EDGE,      0.0f },
231
             {      0.0f, DIST_EDGE,-DIST_EDGE },
232
             { DIST_EDGE,      0.0f,-DIST_EDGE },
233
             {      0.0f,-DIST_EDGE,-DIST_EDGE },
234
             {-DIST_EDGE,      0.0f,-DIST_EDGE }
235
         };
236
      }
237

    
238
    return mCenters;
239
    }
240

    
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

    
243
  public ObjectShape getObjectShape(int variant)
244
    {
245
    if( variant==0 )
246
      {
247
      float[][] vertices = new float[][]
248
          {
249
             { 0.0f, 0.0f, 0.0f },
250
             {-0.5f, 0.5f, 0.5f },
251
             {-0.5f,-0.5f, 0.5f },
252
             { 0.5f, 0.5f, 0.5f },
253
             { 0.5f,-0.5f, 0.5f },
254
             { 0.5f, 0.5f,-0.5f },
255
             { 0.5f,-0.5f,-0.5f },
256
             {-0.5f, 0.5f,-0.5f },
257
          };
258

    
259
      int[][] vert_indices = new int[][]
260
          {
261
             { 2,4,3,1 },
262
             { 1,3,5,7 },
263
             { 4,6,5,3 },
264

    
265
             { 2,4,0 },
266
             { 5,7,0 },
267
             { 4,6,0 },
268
             { 7,1,0 },
269
             { 1,2,0 },
270
             { 6,5,0 }
271
          };
272

    
273
      float[][] bands     = new float[][] { {0.06f,35,0.5f,0.7f,5,2,2}, {0.01f,35,0.2f,0.4f,5,2,2} };
274
      int[] bandIndices   = new int[] { 0,0,0,1,1,1,1,1,1 };
275
      float[][] corners   = new float[][] { {0.06f,0.12f} };
276
      int[] cornerIndices = new int[]  { -1,0,-1,0,0,0,-1,-1 };
277
      float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
278
      int[] centerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
279
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null, 3);
280
      }
281
    else
282
      {
283
      float[][] vertices = new float[][]
284
          {
285
             {-0.5f, 0.0f, 0.0f},
286
             { 0.5f, 0.0f, 0.0f},
287
             {-0.5f,-1.0f, 0.0f},
288
             { 0.5f,-1.0f, 0.0f},
289
             { 0.0f,-1.5f, 0.0f},
290
             {-0.5f, 0.0f,-1.0f},
291
             { 0.5f, 0.0f,-1.0f},
292
             { 0.0f, 0.0f,-1.5f},
293
          };
294

    
295
      int[][] vert_indices = new int[][]
296
          {
297
             { 0,2,4,3,1 },
298
             { 0,1,6,7,5 },
299
             { 1,3,6 },
300
             { 0,2,5 },
301
             { 4,7,6,3 },
302
             { 4,7,5,2 }
303
          };
304

    
305
      float[][] bands     = new float[][] { {0.038f,35,0.250f,0.7f,7,2,2}, {0.020f,35,0.125f,0.2f,3,1,2}, {0.020f,35,0.125f,0.2f,3,1,1} };
306
      int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
307
      float[][] corners   = new float[][] { {0.06f,0.20f} };
308
      int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
309
      float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
310
      int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
311
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null, 2);
312
      }
313
    }
314

    
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

    
317
  public Static4D getQuat(int cubit, int[] numLayers)
318
    {
319
    if( mQuats==null ) initializeQuats();
320

    
321
    switch(cubit)
322
      {
323
      case  0: return mQuats[0];                         //  unit quat
324
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
325
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
326
      case  3: return mQuats[1];                         // 180 along X
327
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
328
      case  5: return mQuats[2];                         // 180 along Y
329
      case  6: return mQuats[3];                         // 180 along Z
330
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
331

    
332
      case  8: return mQuats[0];
333
      case  9: return mQuats[5];
334
      case 10: return mQuats[3];
335
      case 11: return mQuats[11];
336
      case 12: return mQuats[4];
337
      case 13: return mQuats[7];
338
      case 14: return mQuats[9];
339
      case 15: return mQuats[10];
340
      case 16: return mQuats[2];
341
      case 17: return mQuats[8];
342
      case 18: return mQuats[1];
343
      case 19: return mQuats[6];
344
      }
345

    
346
    return null;
347
    }
348

    
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350

    
351
  public int getNumCubitVariants(int[] numLayers)
352
    {
353
    return 2;
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

    
358
  public int getCubitVariant(int cubit, int[] numLayers)
359
    {
360
    return cubit<8 ? 0:1;
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

    
365
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
366
    {
367
    if( mFaceMap==null )
368
      {
369
      mFaceMap = new int[][]
370
         {
371
           { 4, 2, 0 },
372
           { 2, 5, 0 },
373
           { 3, 4, 0 },
374
           { 5, 3, 0 },
375
           { 1, 2, 4 },
376
           { 5, 2, 1 },
377
           { 4, 3, 1 },
378
           { 1, 3, 5 },
379

    
380
           { 4, 2,-1 },
381
           { 0, 4,-1 },
382
           { 4, 3,-1 },
383
           { 1, 4,-1 },
384
           { 2, 0,-1 },
385
           { 3, 0,-1 },
386
           { 3, 1,-1 },
387
           { 2, 1,-1 },
388
           { 5, 2,-1 },
389
           { 0, 5,-1 },
390
           { 5, 3,-1 },
391
           { 1, 5,-1 },
392
         };
393
      }
394

    
395
    return face<3 ? mFaceMap[cubit][face] : -1;
396
    }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

    
400
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
401
    {
402
    return face>=mStickerVariants[variant].length ? -1 : mStickerVariants[variant][face];
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

    
407
  private float getRadius()
408
    {
409
    return 0.09f;
410
    }
411

    
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413

    
414
  private float getStroke()
415
    {
416
    return ObjectControl.isInIconMode() ? 0.20f : 0.09f;
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

    
421
  public ObjectSticker retSticker(int sticker)
422
    {
423
    if( mStickers==null )
424
      {
425
      float rad = getRadius();
426
      float str = getStroke();
427
      int numStickers = mStickerCoords.length;
428
      mStickers = new ObjectSticker[numStickers];
429

    
430
      for(int s=0; s<numStickers; s++)
431
        {
432
        float scale = mStickerScales[s];
433
        float radius = rad / scale;
434
        float stroke = str / scale;
435
        int len = mStickerCoords[s].length;
436
        float[] radii = new float[len];
437
        for(int r=0; r<len; r++) radii[r] = radius;
438
        mStickers[s] = new ObjectSticker(mStickerCoords[s],null,radii,stroke);
439
        }
440
      }
441

    
442
    return mStickers[sticker];
443
    }
444

    
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446
// PUBLIC API
447

    
448
  public Static3D[] getRotationAxis()
449
    {
450
    return ROT_AXIS;
451
    }
452

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

    
455
  public int[] getBasicAngle()
456
    {
457
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
458
    return mBasicAngle;
459
    }
460

    
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462

    
463
  public ObjectType intGetObjectType(int[] numLayers)
464
    {
465
    return ObjectType.REDI_3;
466
    }
467

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469

    
470
  public String getObjectName()
471
    {
472
    return "Redi Cube";
473
    }
474

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

    
477
  public String getInventor()
478
    {
479
    return "Oskar van Deventer";
480
    }
481

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483

    
484
  public int getYearOfInvention()
485
    {
486
    return 2009;
487
    }
488

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

    
491
  public int getComplexity()
492
    {
493
    return 1;
494
    }
495
}
(19-19/26)