Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyJing.java @ f86b282a

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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_TETRAHEDRON;
23
import static org.distorted.objectlib.main.Movement.TYPE_NOT_SPLIT;
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.main.MovementTetrahedron;
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.TwistyTetrahedron;
37

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

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

    
50
  static final float F = 0.48f;  // length of the edge of the corner cubit. Keep<0.5
51
                                 // Assuming the length of the edge of the whole
52
                                 // tetrahedron is 2.0 (ie standard, equal to numLayers
53

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

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

    
65
  public TwistyJing(int[] numL, Static4D quat, Static3D move, float scale, InputStream stream)
66
    {
67
    super(numL, numL[0], quat, move, scale, stream);
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

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

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

    
84
    return mStates;
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  private void initializeQuats()
90
    {
91
    mQuats = new Static4D[]
92
         {
93
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
94
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
95
         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
96
         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
97
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
98
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
99
         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
100
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
101
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
102
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
103
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
104
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
105
         };
106
    }
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

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

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

    
119
  public float[][] getCubitPositions(int[] numLayers)
120
    {
121
    if( mCenters==null )
122
      {
123
      mCenters = new float[][]
124
         {
125
           { 0.000f, -SQ2/2, 1.000f },
126
           { 0.000f, -SQ2/2,-1.000f },
127
           {-1.000f,  SQ2/2, 0.000f },
128
           { 1.000f,  SQ2/2, 0.000f },
129

    
130
           { 0.000f, -SQ2/2, 0.000f },
131
           {-0.500f, 0.000f, 0.500f },
132
           { 0.500f, 0.000f, 0.500f },
133
           {-0.500f, 0.000f,-0.500f },
134
           { 0.500f, 0.000f,-0.500f },
135
           { 0.000f,  SQ2/2, 0.000f },
136

    
137
           { 0.000f,  SQ2/6, 1.0f/3 },
138
           { 0.000f,  SQ2/6,-1.0f/3 },
139
           {-1.0f/3, -SQ2/6, 0.000f },
140
           { 1.0f/3, -SQ2/6, 0.000f },
141
         };
142
      }
143

    
144
    return mCenters;
145
    }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

    
149
  public Static4D[] getQuats()
150
    {
151
    if( mQuats==null ) initializeQuats();
152
    return mQuats;
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  public int getSolvedFunctionIndex()
158
    {
159
    return 0;
160
    }
161

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

    
164
  public int getNumStickerTypes(int[] numLayers)
165
    {
166
    return 3;
167
    }
168

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

    
171
  public float[][] getCuts(int[] numLayers)
172
    {
173
    if( mCuts==null )
174
      {
175
      float[] cut = { (F-0.5f)*(SQ6/3) };
176
      mCuts = new float[][] { cut,cut,cut,cut };
177
      }
178

    
179
    return mCuts;
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
  public boolean[][] getLayerRotatable(int[] numLayers)
185
    {
186
    int numAxis = ROT_AXIS.length;
187
    boolean[][] layerRotatable = new boolean[numAxis][];
188

    
189
    for(int i=0; i<numAxis; i++)
190
      {
191
      layerRotatable[i] = new boolean[numLayers[i]];
192
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
193
      }
194

    
195
    return layerRotatable;
196
    }
197

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

    
200
  public int getMovementType()
201
    {
202
    return MOVEMENT_TETRAHEDRON;
203
    }
204

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

    
207
  public int getMovementSplit()
208
    {
209
    return TYPE_NOT_SPLIT;
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  public int[][][] getEnabled()
215
    {
216
    return new int[][][]
217
      {
218
          {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}}
219
      };
220
    }
221

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

    
224
  public float[] getDist3D(int[] numLayers)
225
    {
226
    return null;
227
    }
228

    
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

    
231
  public int getNumCubitFaces()
232
    {
233
    return 6;
234
    }
235

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

    
238
  public ObjectShape getObjectShape(int variant)
239
    {
240
    final float X = F/2;
241
    final float Y = F*SQ2/2;
242
    final float Z =-F/2;
243
    final float L = (2.0f-3*F);
244
    final float X2= L/2;
245
    final float Y2= L*SQ2/2;
246
    final float Z2=-L/2;
247
    final float D = F/L;
248
    final float G = 1.0f-F;
249

    
250
    if( variant==0 )
251
      {
252
      double[][] vertices = new double[][]
253
          {
254
             { 0.0, 0.0, 0.0 },
255
             {   X,   Y,   Z },
256
             { 0.0, 2*Y, 2*Z },
257
             {  -X,   Y,   Z },
258
             { 0.0, 0.0,    -F },
259
             {   X,   Y,   Z-F },
260
             { 0.0, 2*Y, 2*Z-F },
261
             {  -X,   Y,   Z-F },
262
          };
263
      int[][] vert_indices = new int[][]
264
          {
265
             {0,1,2,3},
266
             {1,0,4,5},
267
             {7,4,0,3},
268
             {1,5,6,2},
269
             {7,3,2,6},
270
             {4,7,6,5}
271
          };
272

    
273
      float[][] bands     = new float[][] { {0.015f,35,0.25f*F,0.5f*F,5,1,1},{0.001f,35,0.25f*F,0.5f*F,5,1,1} };
274
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
275
      float[][] corners   = new float[][] { {0.08f,0.20f*F},{0.07f,0.20f*F} };
276
      int[] cornerIndices = new int[] { 0,1,1,-1,1,-1,-1,-1 };
277
      float[][] centers   = new float[][] { { 0.0f, Y, Z-F/2} };
278
      int[] centerIndices = new int[] { 0,0,0,-1,0,-1,-1,-1 };
279
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
280
      }
281
    else if( variant==1 )
282
      {
283
      double[][] vertices = new double[][]
284
          {
285
             { 0.0, 0.0,     G },
286
             {   X,   Y,   Z+G },
287
             { 0.0, 2*Y, 2*Z+G },
288
             {  -X,   Y,   Z+G },
289
             { 0.0, 0.0,    -G },
290
             {   X,   Y,  -Z-G },
291
             { 0.0, 2*Y,-2*Z-G },
292
             {  -X,   Y,  -Z-G },
293
          };
294
      int[][] vert_indices = new int[][]
295
          {
296
             {0,4,5,1},
297
             {3,7,4,0},
298
             {0,1,2,3},
299
             {4,7,6,5},
300
             {1,5,6,2},
301
             {2,6,7,3}
302
          };
303

    
304
      float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
305
      int[] bandIndices   = new int[] { 0,0,1,1,1,1 };
306
      float[][] corners   = new float[][] { {0.07f,0.20f*F} };
307
      int[] cornerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
308
      float[][] centers   = new float[][] { { 0, F*SQ2/2, 0 } };
309
      int[] centerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
310
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
311
      }
312
    else
313
      {
314
      double[][] vertices = new double[][]
315
          {
316
             {    0.0,     -2*Y2/3,   -2*Z2/3 },
317
             {      X2,       Y2/3,      Z2/3 },
318
             {     -X2,       Y2/3,      Z2/3 },
319
             {    0.0,     -2*Y2/3,-2*Z2/3+2*D*Z2 },
320
             {  X2-D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
321
             { -X2+D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
322
          };
323
      int[][] vert_indices = new int[][]
324
          {
325
             {0,1,2},
326
             {3,5,4},
327
             {0,3,4,1},
328
             {5,3,0,2},
329
             {4,5,2,1}
330
          };
331

    
332
      float[][] bands     = new float[][] { {0.020f,35,0.20f*L,0.6f*L,5,1,1}, {0.001f,35,0.05f*L,0.1f*L,5,1,1} };
333
      int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
334
      float[][] corners   = new float[][] { {0.04f,0.6f*F} };
335
      int[] cornerIndices = new int[] { 0,0,0,-1,-1,-1 };
336
      float[][] centers   = new float[][] { { 0, -2*Y/3, 4*Z/3 } };
337
      int[] centerIndices = new int[] { 0,0,0,-1,-1,-1 };
338
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
339
      }
340
    }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343

    
344
  public Static4D getQuat(int cubit, int[] numLayers)
345
    {
346
    if( mQuats==null ) initializeQuats();
347
    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
348
    return mQuats[mRotQuat[cubit]];
349
    }
350

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

    
353
  public int getNumCubitVariants(int[] numLayers)
354
    {
355
    return 3;
356
    }
357

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

    
360
  public int getCubitVariant(int cubit, int[] numLayers)
361
    {
362
    return cubit<4 ? 0 : (cubit<10?1:2);
363
    }
364

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

    
367
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
368
    {
369
    return face+variant<3 ? variant : -1;
370
    }
371

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

    
374
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
375
    {
376
    if( mFaceMap==null )
377
      {
378
      mFaceMap = new int[][]
379
         {
380
           { 0,  3,  2, -1, -1, -1 },
381
           { 1,  2,  3, -1, -1, -1 },
382
           { 1,  0,  2, -1, -1, -1 },
383
           { 1,  3,  0, -1, -1, -1 },
384

    
385
           { 3,  2, -1, -1, -1, -1 },
386
           { 0,  2, -1, -1, -1, -1 },
387
           { 3,  0, -1, -1, -1, -1 },
388
           { 1,  2, -1, -1, -1, -1 },
389
           { 3,  1, -1, -1, -1, -1 },
390
           { 0,  1, -1, -1, -1, -1 },
391

    
392
           { 0, -1, -1, -1, -1, -1 },
393
           { 1, -1, -1, -1, -1, -1 },
394
           { 2, -1, -1, -1, -1, -1 },
395
           { 3, -1, -1, -1, -1, -1 },
396
         };
397
      }
398

    
399
    return mFaceMap[cubit][face];
400
    }
401

    
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403

    
404
  public ObjectSticker retSticker(int sticker)
405
    {
406
    if( mStickers==null )
407
      {
408
      float[][] STICKERS = new float[][]
409
          {
410
             { 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
411
             { -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
412
             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
413
          };
414

    
415
      mStickers = new ObjectSticker[STICKERS.length];
416
      final float R1 = 0.05f;
417
      final float R2 = 0.10f;
418
      final float R3 = 0.03f;
419
      final float[][] radii  = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
420
      float[] strokes = { 0.06f, 0.03f, 0.05f };
421

    
422
      if( ObjectControl.isInIconMode() )
423
        {
424
        strokes[0]*=2.0f;
425
        strokes[1]*=2.0f;
426
        strokes[2]*=2.0f;
427
        }
428

    
429
      for(int s=0; s<STICKERS.length; s++)
430
        {
431
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
432
        }
433
      }
434

    
435
    return mStickers[sticker];
436
    }
437

    
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439
// PUBLIC API
440

    
441
  public Static3D[] getRotationAxis()
442
    {
443
    return ROT_AXIS;
444
    }
445

    
446
///////////////////////////////////////////////////////////////////////////////////////////////////
447

    
448
  public int[] getBasicAngle()
449
    {
450
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
451
    return mBasicAngle;
452
    }
453

    
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455

    
456
  public ObjectType intGetObjectType(int[] numLayers)
457
    {
458
    return ObjectType.JING_2;
459
    }
460

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

    
463
  public String getObjectName()
464
    {
465
    return "Jing Pyraminx";
466
    }
467

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

    
470
  public String getInventor()
471
    {
472
    return "Tony Fisher";
473
    }
474

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

    
477
  public int getYearOfInvention()
478
    {
479
    return 1991;
480
    }
481

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

    
484
  public int getComplexity()
485
    {
486
    return 4;
487
    }
488
}
(13-13/25)