Project

General

Profile

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

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

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.touchcontrol.TouchControl.TC_TETRAHEDRON;
23
import static org.distorted.objectlib.touchcontrol.TouchControl.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.helpers.ObjectFaceShape;
31
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
32
import org.distorted.objectlib.main.ObjectControl;
33
import org.distorted.objectlib.main.ObjectType;
34
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ScrambleState;
36
import org.distorted.objectlib.main.ShapeTetrahedron;
37

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

    
40
public class TwistyJing extends ShapeTetrahedron
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

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

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

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

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

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

    
83
    return mStates;
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

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

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

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

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

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

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

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

    
143
    return mCenters;
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

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

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

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

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
  public float[][] getCuts(int[] numLayers)
164
    {
165
    if( mCuts==null )
166
      {
167
      float[] cut = { (F-0.5f)*(SQ6/3) };
168
      mCuts = new float[][] { cut,cut,cut,cut };
169
      }
170

    
171
    return mCuts;
172
    }
173

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

    
176
  public boolean[][] getLayerRotatable(int[] numLayers)
177
    {
178
    int numAxis = ROT_AXIS.length;
179
    boolean[][] layerRotatable = new boolean[numAxis][];
180

    
181
    for(int i=0; i<numAxis; i++)
182
      {
183
      layerRotatable[i] = new boolean[numLayers[i]];
184
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
185
      }
186

    
187
    return layerRotatable;
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  public int getTouchControlType()
193
    {
194
    return TC_TETRAHEDRON;
195
    }
196

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

    
199
  public int getTouchControlSplit()
200
    {
201
    return TYPE_NOT_SPLIT;
202
    }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
  public int[][][] getEnabled()
207
    {
208
    return new int[][][]
209
      {
210
          {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}}
211
      };
212
    }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

    
216
  public float[] getDist3D(int[] numLayers)
217
    {
218
    return null;
219
    }
220

    
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

    
223
  public int getNumCubitFaces()
224
    {
225
    return 6;
226
    }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

    
230
  public ObjectShape getObjectShape(int variant)
231
    {
232
    final float X = F/2;
233
    final float Y = F*SQ2/2;
234
    final float Z =-F/2;
235
    final float L = (2.0f-3*F);
236
    final float X2= L/2;
237
    final float Y2= L*SQ2/2;
238
    final float Z2=-L/2;
239
    final float D = F/L;
240
    final float G = 1.0f-F;
241

    
242
    if( variant==0 )
243
      {
244
      float[][] vertices =
245
          {
246
             {   0,   0,   0 },
247
             {   X,   Y,   Z },
248
             {   0, 2*Y, 2*Z },
249
             {  -X,   Y,   Z },
250
             {   0,   0,    -F },
251
             {   X,   Y,   Z-F },
252
             {   0, 2*Y, 2*Z-F },
253
             {  -X,   Y,   Z-F },
254
          };
255
      int[][] indices =
256
          {
257
             {0,1,2,3},
258
             {1,0,4,5},
259
             {7,4,0,3},
260
             {1,5,6,2},
261
             {7,3,2,6},
262
             {4,7,6,5}
263
          };
264

    
265
      return new ObjectShape(vertices, indices, getNumCubitFaces(), 3);
266
      }
267
    else if( variant==1 )
268
      {
269
      float[][] vertices =
270
          {
271
             {   0,   0,     G },
272
             {   X,   Y,   Z+G },
273
             {   0, 2*Y, 2*Z+G },
274
             {  -X,   Y,   Z+G },
275
             {   0,   0,    -G },
276
             {   X,   Y,  -Z-G },
277
             {   0, 2*Y,-2*Z-G },
278
             {  -X,   Y,  -Z-G },
279
          };
280
      int[][] indices =
281
          {
282
             {0,4,5,1},
283
             {3,7,4,0},
284
             {0,1,2,3},
285
             {4,7,6,5},
286
             {1,5,6,2},
287
             {2,6,7,3}
288
          };
289

    
290
      return new ObjectShape(vertices, indices, getNumCubitFaces(), 2);
291
      }
292
    else
293
      {
294
      float[][] vertices =
295
          {
296
             {        0,   -2*Y2/3,       -2*Z2/3 },
297
             {       X2,      Y2/3,          Z2/3 },
298
             {      -X2,      Y2/3,          Z2/3 },
299
             {        0,   -2*Y2/3,-2*Z2/3+2*D*Z2 },
300
             {  X2-D*X2, Y2/3-D*Y2,     Z2/3+D*Z2 },
301
             { -X2+D*X2, Y2/3-D*Y2,     Z2/3+D*Z2 },
302
          };
303
      int[][] indices =
304
          {
305
             {0,1,2},
306
             {3,5,4},
307
             {0,3,4,1},
308
             {5,3,0,2},
309
             {4,5,2,1}
310
          };
311

    
312
      return new ObjectShape(vertices, indices, getNumCubitFaces(), 1);
313
      }
314
    }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

    
318
  public ObjectFaceShape getObjectFaceShape(int variant)
319
    {
320
    final float Y = F*SQ2/2;
321
    final float Z =-F/2;
322
    final float L = (2.0f-3*F);
323

    
324
    if( variant==0 )
325
      {
326
      float[][] bands     = { {0.015f,35,0.25f*F,0.5f*F,5,1,1},{0.001f,35,0.25f*F,0.5f*F,5,1,1} };
327
      int[] bandIndices   = { 0,0,0,1,1,1 };
328
      float[][] corners   = { {0.08f,0.20f*F},{0.07f,0.20f*F} };
329
      int[] cornerIndices = { 0,1,1,-1,1,-1,-1,-1 };
330
      float[][] centers   = { { 0.0f, Y, Z-F/2} };
331
      int[] centerIndices = { 0,0,0,-1,0,-1,-1,-1 };
332
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
333
      }
334
    else if( variant==1 )
335
      {
336
      float[][] bands     = { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
337
      int[] bandIndices   = { 0,0,1,1,1,1 };
338
      float[][] corners   = { {0.07f,0.20f*F} };
339
      int[] cornerIndices = { 0,0,-1,0,0,0,-1,0 };
340
      float[][] centers   = { { 0, F*SQ2/2, 0 } };
341
      int[] centerIndices = { 0,0,-1,0,0,0,-1,0 };
342
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
343
      }
344
    else
345
      {
346
      float[][] bands     = { {0.020f,35,0.20f*L,0.6f*L,5,1,1}, {0.001f,35,0.05f*L,0.1f*L,5,1,1} };
347
      int[] bandIndices   = { 0,1,1,1,1,1 };
348
      float[][] corners   = { {0.04f,0.6f*F} };
349
      int[] cornerIndices = { 0,0,0,-1,-1,-1 };
350
      float[][] centers   = { { 0, -2*Y/3, 4*Z/3 } };
351
      int[] centerIndices = { 0,0,0,-1,-1,-1 };
352
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
353
      }
354
    }
355

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

    
358
  public Static4D getQuat(int cubit, int[] numLayers)
359
    {
360
    if( mQuats==null ) initializeQuats();
361
    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
362
    return mQuats[mRotQuat[cubit]];
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<4 ? 0 : (cubit<10?1:2);
377
    }
378

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

    
381
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
382
    {
383
    if( mFaceMap==null )
384
      {
385
      mFaceMap = new int[][]
386
         {
387
           { 0,  3,  2, -1, -1, -1 },
388
           { 1,  2,  3, -1, -1, -1 },
389
           { 1,  0,  2, -1, -1, -1 },
390
           { 1,  3,  0, -1, -1, -1 },
391

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

    
399
           { 0, -1, -1, -1, -1, -1 },
400
           { 1, -1, -1, -1, -1, -1 },
401
           { 2, -1, -1, -1, -1, -1 },
402
           { 3, -1, -1, -1, -1, -1 },
403
         };
404
      }
405

    
406
    return mFaceMap[cubit][face];
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410

    
411
  public float getStickerRadius()
412
    {
413
    return 0.04f;
414
    }
415

    
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417

    
418
  public float getStickerStroke()
419
    {
420
    return ObjectControl.isInIconMode() ? 0.08f : 0.04f;
421
    }
422

    
423
///////////////////////////////////////////////////////////////////////////////////////////////////
424

    
425
  public float[][] getStickerAngles()
426
    {
427
    return null;
428
    }
429

    
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431
// PUBLIC API
432

    
433
  public Static3D[] getRotationAxis()
434
    {
435
    return ROT_AXIS;
436
    }
437

    
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439

    
440
  public int[] getBasicAngle()
441
    {
442
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
443
    return mBasicAngle;
444
    }
445

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

    
448
  public ObjectType intGetObjectType(int[] numLayers)
449
    {
450
    return ObjectType.JING_2;
451
    }
452

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

    
455
  public String getObjectName()
456
    {
457
    return "Jing Pyraminx";
458
    }
459

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

    
462
  public String getInventor()
463
    {
464
    return "Tony Fisher";
465
    }
466

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

    
469
  public int getYearOfInvention()
470
    {
471
    return 1991;
472
    }
473

    
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475

    
476
  public int getComplexity()
477
    {
478
    return 1;
479
    }
480
}
(13-13/26)