Project

General

Profile

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

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

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 59c20632 Leszek Koltunski
import static org.distorted.objectlib.main.Movement.MOVEMENT_TETRAHEDRON;
23 29b82486 Leszek Koltunski
import static org.distorted.objectlib.main.Movement.TYPE_NOT_SPLIT;
24
25
import android.content.res.Resources;
26
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29
30
import org.distorted.objectlib.R;
31
import org.distorted.objectlib.main.Movement4;
32 8592461c Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
33 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
34 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ObjectSticker;
36
import org.distorted.objectlib.helpers.ScrambleState;
37 29b82486 Leszek Koltunski
import org.distorted.objectlib.main.Twisty4;
38
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41
public class TwistyJing extends Twisty4
42
{
43
  static final Static3D[] ROT_AXIS = new Static3D[]
44
         {
45
           new Static3D(     0,-SQ3/3,-SQ6/3),
46
           new Static3D(     0,-SQ3/3,+SQ6/3),
47
           new Static3D(+SQ6/3,+SQ3/3,     0),
48
           new Static3D(-SQ6/3,+SQ3/3,     0),
49
         };
50
51
  static final float F = 0.48f;  // length of the edge of the corner cubit. Keep<0.5
52
                                 // Assuming the length of the edge of the whole
53
                                 // tetrahedron is 2.0 (ie standard, equal to numLayers
54
55
  private ScrambleState[] mStates;
56
  private int[] mBasicAngle;
57
  private int[] mRotQuat;
58
  private Static4D[] mQuats;
59
  private float[][] mCuts;
60
  private float[][] mCenters;
61
  private int[][] mFaceMap;
62
  private ObjectSticker[] mStickers;
63
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
66 7ba38dd4 Leszek Koltunski
  public TwistyJing(int[] numL, Static4D quat, Static3D move, Resources res)
67 29b82486 Leszek Koltunski
    {
68 7ba38dd4 Leszek Koltunski
    super(numL, numL[0], quat, move, res);
69 29b82486 Leszek Koltunski
    }
70
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73 f9a81f52 Leszek Koltunski
  public ScrambleState[] getScrambleStates()
74 29b82486 Leszek Koltunski
    {
75
    if( mStates==null )
76
      {
77
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,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 4e1dc313 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
89
90 a57e6870 Leszek Koltunski
  protected int getResource(int[] numLayers)
91 4e1dc313 Leszek Koltunski
    {
92 55fa6993 Leszek Koltunski
    return R.raw.jing_2;
93 4e1dc313 Leszek Koltunski
    }
94
95 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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(  0.0f,   1.0f,   0.0f,  0.0f),
103
         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
104
         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
105
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
106
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
107
         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
108
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
109
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
110
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
111
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
112
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
113
         };
114
    }
115
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117
118 7b832206 Leszek Koltunski
  public int[] getSolvedQuats(int cubit, int[] numLayers)
119 29b82486 Leszek Koltunski
    {
120
    if( mQuats==null ) initializeQuats();
121
    int status = retCubitSolvedStatus(cubit,numLayers);
122
    return status<0 ? null : buildSolvedQuats(Movement4.FACE_AXIS[status],mQuats);
123
    }
124
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126
127 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
128 29b82486 Leszek Koltunski
    {
129
    if( mCenters==null )
130
      {
131
      mCenters = new float[][]
132
         {
133
           { 0.000f, -SQ2/2, 1.000f },
134
           { 0.000f, -SQ2/2,-1.000f },
135
           {-1.000f,  SQ2/2, 0.000f },
136
           { 1.000f,  SQ2/2, 0.000f },
137
138
           { 0.000f, -SQ2/2, 0.000f },
139
           {-0.500f, 0.000f, 0.500f },
140
           { 0.500f, 0.000f, 0.500f },
141
           {-0.500f, 0.000f,-0.500f },
142
           { 0.500f, 0.000f,-0.500f },
143
           { 0.000f,  SQ2/2, 0.000f },
144
145
           { 0.000f,  SQ2/6, 1.0f/3 },
146
           { 0.000f,  SQ2/6,-1.0f/3 },
147
           {-1.0f/3, -SQ2/6, 0.000f },
148
           { 1.0f/3, -SQ2/6, 0.000f },
149
         };
150
      }
151
152
    return mCenters;
153
    }
154
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156
157 1bb09f88 Leszek Koltunski
  public Static4D[] getQuats()
158 29b82486 Leszek Koltunski
    {
159
    if( mQuats==null ) initializeQuats();
160
    return mQuats;
161
    }
162
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164
165 59c20632 Leszek Koltunski
  public int getSolvedFunctionIndex()
166 29b82486 Leszek Koltunski
    {
167
    return 0;
168
    }
169
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
172 1bb09f88 Leszek Koltunski
  public int getNumStickerTypes(int[] numLayers)
173 29b82486 Leszek Koltunski
    {
174
    return 3;
175
    }
176
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178
179 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
180 29b82486 Leszek Koltunski
    {
181
    if( mCuts==null )
182
      {
183
      float[] cut = { (F-0.5f)*(SQ6/3) };
184
      mCuts = new float[][] { cut,cut,cut,cut };
185
      }
186
187
    return mCuts;
188
    }
189
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
192 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
193 29b82486 Leszek Koltunski
    {
194 59c20632 Leszek Koltunski
    int numAxis = ROT_AXIS.length;
195
    boolean[][] layerRotatable = new boolean[numAxis][];
196 a57e6870 Leszek Koltunski
197 59c20632 Leszek Koltunski
    for(int i=0; i<numAxis; i++)
198
      {
199
      layerRotatable[i] = new boolean[numLayers[i]];
200
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
201 29b82486 Leszek Koltunski
      }
202 59c20632 Leszek Koltunski
203
    return layerRotatable;
204
    }
205
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207
208
  public int getMovementType()
209
    {
210
    return MOVEMENT_TETRAHEDRON;
211
    }
212
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
215
  public int getMovementSplit()
216
    {
217
    return TYPE_NOT_SPLIT;
218
    }
219
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221
222
  public int[][][] getEnabled()
223
    {
224
    return new int[][][]
225
      {
226
          {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}}
227
      };
228
    }
229
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231
232
  public float[] getDist3D(int[] numLayers)
233
    {
234
    return null;
235 29b82486 Leszek Koltunski
    }
236
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238
239 a75ae1ee Leszek Koltunski
  public int getNumCubitFaces()
240 29b82486 Leszek Koltunski
    {
241
    return 6;
242
    }
243
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245
246 e30c522a Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
247 29b82486 Leszek Koltunski
    {
248
    final float X = F/2;
249
    final float Y = F*SQ2/2;
250
    final float Z =-F/2;
251
    final float L = (2.0f-3*F);
252
    final float X2= L/2;
253
    final float Y2= L*SQ2/2;
254
    final float Z2=-L/2;
255
    final float D = F/L;
256
    final float G = 1.0f-F;
257
258
    if( variant==0 )
259
      {
260
      double[][] vertices = new double[][]
261
          {
262
             { 0.0, 0.0, 0.0 },
263
             {   X,   Y,   Z },
264
             { 0.0, 2*Y, 2*Z },
265
             {  -X,   Y,   Z },
266
             { 0.0, 0.0,    -F },
267
             {   X,   Y,   Z-F },
268
             { 0.0, 2*Y, 2*Z-F },
269
             {  -X,   Y,   Z-F },
270
          };
271
      int[][] vert_indices = new int[][]
272
          {
273
             {0,1,2,3},
274
             {1,0,4,5},
275
             {7,4,0,3},
276
             {1,5,6,2},
277
             {7,3,2,6},
278
             {4,7,6,5}
279
          };
280
281 2289cab1 Leszek Koltunski
      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} };
282 29b82486 Leszek Koltunski
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
283
      float[][] corners   = new float[][] { {0.08f,0.20f*F},{0.07f,0.20f*F} };
284
      int[] cornerIndices = new int[] { 0,1,1,-1,1,-1,-1,-1 };
285 854b09be Leszek Koltunski
      float[][] centers   = new float[][] { { 0.0f, Y, Z-F/2} };
286 29b82486 Leszek Koltunski
      int[] centerIndices = new int[] { 0,0,0,-1,0,-1,-1,-1 };
287
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
288
      }
289
    else if( variant==1 )
290
      {
291
      double[][] vertices = new double[][]
292
          {
293
             { 0.0, 0.0,     G },
294
             {   X,   Y,   Z+G },
295
             { 0.0, 2*Y, 2*Z+G },
296
             {  -X,   Y,   Z+G },
297
             { 0.0, 0.0,    -G },
298
             {   X,   Y,  -Z-G },
299
             { 0.0, 2*Y,-2*Z-G },
300
             {  -X,   Y,  -Z-G },
301
          };
302
      int[][] vert_indices = new int[][]
303
          {
304
             {0,4,5,1},
305
             {3,7,4,0},
306
             {0,1,2,3},
307
             {4,7,6,5},
308
             {1,5,6,2},
309
             {2,6,7,3}
310
          };
311
312
      float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
313
      int[] bandIndices   = new int[] { 0,0,1,1,1,1 };
314
      float[][] corners   = new float[][] { {0.07f,0.20f*F} };
315
      int[] cornerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
316
      float[][] centers   = new float[][] { { 0, F*SQ2/2, 0 } };
317
      int[] centerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
318
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
319
      }
320
    else
321
      {
322
      double[][] vertices = new double[][]
323
          {
324
             {    0.0,     -2*Y2/3,   -2*Z2/3 },
325
             {      X2,       Y2/3,      Z2/3 },
326
             {     -X2,       Y2/3,      Z2/3 },
327
             {    0.0,     -2*Y2/3,-2*Z2/3+2*D*Z2 },
328
             {  X2-D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
329
             { -X2+D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
330
          };
331
      int[][] vert_indices = new int[][]
332
          {
333
             {0,1,2},
334
             {3,5,4},
335
             {0,3,4,1},
336
             {5,3,0,2},
337
             {4,5,2,1}
338
          };
339
340
      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} };
341
      int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
342
      float[][] corners   = new float[][] { {0.04f,0.6f*F} };
343
      int[] cornerIndices = new int[] { 0,0,0,-1,-1,-1 };
344
      float[][] centers   = new float[][] { { 0, -2*Y/3, 4*Z/3 } };
345
      int[] centerIndices = new int[] { 0,0,0,-1,-1,-1 };
346
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
347
      }
348
    }
349
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351
352 7b832206 Leszek Koltunski
  public Static4D getQuat(int cubit, int[] numLayers)
353 29b82486 Leszek Koltunski
    {
354
    if( mQuats==null ) initializeQuats();
355
    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
356
    return mQuats[mRotQuat[cubit]];
357
    }
358
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360
361 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
362 29b82486 Leszek Koltunski
    {
363
    return 3;
364
    }
365
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367
368 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
369 29b82486 Leszek Koltunski
    {
370
    return cubit<4 ? 0 : (cubit<10?1:2);
371
    }
372
373 a75ae1ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
374
375
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
376
    {
377
    return face+variant<3 ? variant : -1;
378
    }
379
380
///////////////////////////////////////////////////////////////////////////////////////////////////
381
382
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
383
    {
384
    if( mFaceMap==null )
385
      {
386
      mFaceMap = new int[][]
387
         {
388
           { 0,  3,  2, -1, -1, -1 },
389
           { 1,  2,  3, -1, -1, -1 },
390
           { 1,  0,  2, -1, -1, -1 },
391
           { 1,  3,  0, -1, -1, -1 },
392
393
           { 3,  2, -1, -1, -1, -1 },
394
           { 0,  2, -1, -1, -1, -1 },
395
           { 3,  0, -1, -1, -1, -1 },
396
           { 1,  2, -1, -1, -1, -1 },
397
           { 3,  1, -1, -1, -1, -1 },
398
           { 0,  1, -1, -1, -1, -1 },
399
400
           { 0, -1, -1, -1, -1, -1 },
401
           { 1, -1, -1, -1, -1, -1 },
402
           { 2, -1, -1, -1, -1, -1 },
403
           { 3, -1, -1, -1, -1, -1 },
404
         };
405
      }
406
407
    return mFaceMap[cubit][face];
408
    }
409
410 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
411
412 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
413 29b82486 Leszek Koltunski
    {
414
    if( mStickers==null )
415
      {
416
      float[][] STICKERS = new float[][]
417
          {
418
             { 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
419
             { -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
420
             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
421
          };
422
423
      mStickers = new ObjectSticker[STICKERS.length];
424
      final float R1 = 0.05f;
425
      final float R2 = 0.10f;
426
      final float R3 = 0.03f;
427
      final float[][] radii  = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
428 8592461c Leszek Koltunski
      float[] strokes = { 0.06f, 0.03f, 0.05f };
429
430
      if( ObjectControl.isInIconMode() )
431
        {
432
        strokes[0]*=2.0f;
433
        strokes[1]*=2.0f;
434
        strokes[2]*=2.0f;
435
        }
436 29b82486 Leszek Koltunski
437
      for(int s=0; s<STICKERS.length; s++)
438
        {
439
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
440
        }
441
      }
442
443 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
444
    }
445
446 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
447
// PUBLIC API
448
449
  public Static3D[] getRotationAxis()
450
    {
451
    return ROT_AXIS;
452
    }
453
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455
456
  public int[] getBasicAngle()
457
    {
458
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
459
    return mBasicAngle;
460
    }
461
462 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
463
464 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
465 61aa85e4 Leszek Koltunski
    {
466 8005e762 Leszek Koltunski
    return ObjectType.JING_2;
467 61aa85e4 Leszek Koltunski
    }
468
469 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
470
471 e26eb4e7 Leszek Koltunski
  public String getObjectName()
472 29b82486 Leszek Koltunski
    {
473 e26eb4e7 Leszek Koltunski
    return "Jing Pyraminx";
474 29b82486 Leszek Koltunski
    }
475
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477
478 e26eb4e7 Leszek Koltunski
  public String getInventor()
479 29b82486 Leszek Koltunski
    {
480 e26eb4e7 Leszek Koltunski
    return "Tony Fisher";
481 29b82486 Leszek Koltunski
    }
482
483 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
484
485 e26eb4e7 Leszek Koltunski
  public int getYearOfInvention()
486 59c20632 Leszek Koltunski
    {
487
    return 1991;
488
    }
489
490 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
491
492 e26eb4e7 Leszek Koltunski
  public int getComplexity()
493 29b82486 Leszek Koltunski
    {
494
    return 4;
495
    }
496
}