Project

General

Profile

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

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

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.touchcontrol.TouchControlTetrahedron;
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.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
  private ObjectSticker[] mStickers;
62

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

    
65
  public TwistyJing(int[] numL, int meshState, Static4D quat, Static3D move, float scale, InputStream stream)
66
    {
67
    super(numL, meshState, 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(TouchControlTetrahedron.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 float[][] getCuts(int[] numLayers)
165
    {
166
    if( mCuts==null )
167
      {
168
      float[] cut = { (F-0.5f)*(SQ6/3) };
169
      mCuts = new float[][] { cut,cut,cut,cut };
170
      }
171

    
172
    return mCuts;
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

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

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

    
188
    return layerRotatable;
189
    }
190

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

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

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

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

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

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

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

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

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

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

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

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

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

    
266
      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} };
267
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
268
      float[][] corners   = new float[][] { {0.08f,0.20f*F},{0.07f,0.20f*F} };
269
      int[] cornerIndices = new int[] { 0,1,1,-1,1,-1,-1,-1 };
270
      float[][] centers   = new float[][] { { 0.0f, Y, Z-F/2} };
271
      int[] centerIndices = new int[] { 0,0,0,-1,0,-1,-1,-1 };
272
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null, 3);
273
      }
274
    else if( variant==1 )
275
      {
276
      float[][] vertices = new float[][]
277
          {
278
             {   0,   0,     G },
279
             {   X,   Y,   Z+G },
280
             {   0, 2*Y, 2*Z+G },
281
             {  -X,   Y,   Z+G },
282
             {   0,   0,    -G },
283
             {   X,   Y,  -Z-G },
284
             {   0, 2*Y,-2*Z-G },
285
             {  -X,   Y,  -Z-G },
286
          };
287
      int[][] vert_indices = new int[][]
288
          {
289
             {0,4,5,1},
290
             {3,7,4,0},
291
             {0,1,2,3},
292
             {4,7,6,5},
293
             {1,5,6,2},
294
             {2,6,7,3}
295
          };
296

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

    
325
      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} };
326
      int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
327
      float[][] corners   = new float[][] { {0.04f,0.6f*F} };
328
      int[] cornerIndices = new int[] { 0,0,0,-1,-1,-1 };
329
      float[][] centers   = new float[][] { { 0, -2*Y/3, 4*Z/3 } };
330
      int[] centerIndices = new int[] { 0,0,0,-1,-1,-1 };
331
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null, 1);
332
      }
333
    }
334

    
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336

    
337
  public Static4D getQuat(int cubit, int[] numLayers)
338
    {
339
    if( mQuats==null ) initializeQuats();
340
    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
341
    return mQuats[mRotQuat[cubit]];
342
    }
343

    
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345

    
346
  public int getNumCubitVariants(int[] numLayers)
347
    {
348
    return 3;
349
    }
350

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

    
353
  public int getCubitVariant(int cubit, int[] numLayers)
354
    {
355
    return cubit<4 ? 0 : (cubit<10?1:2);
356
    }
357

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

    
360
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
361
    {
362
    if( mFaceMap==null )
363
      {
364
      mFaceMap = new int[][]
365
         {
366
           { 0,  3,  2, -1, -1, -1 },
367
           { 1,  2,  3, -1, -1, -1 },
368
           { 1,  0,  2, -1, -1, -1 },
369
           { 1,  3,  0, -1, -1, -1 },
370

    
371
           { 3,  2, -1, -1, -1, -1 },
372
           { 0,  2, -1, -1, -1, -1 },
373
           { 3,  0, -1, -1, -1, -1 },
374
           { 1,  2, -1, -1, -1, -1 },
375
           { 3,  1, -1, -1, -1, -1 },
376
           { 0,  1, -1, -1, -1, -1 },
377

    
378
           { 0, -1, -1, -1, -1, -1 },
379
           { 1, -1, -1, -1, -1, -1 },
380
           { 2, -1, -1, -1, -1, -1 },
381
           { 3, -1, -1, -1, -1, -1 },
382
         };
383
      }
384

    
385
    return mFaceMap[cubit][face];
386
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

    
390
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
391
    {
392
    return face>=mStickerVariants[variant].length ? -1 : mStickerVariants[variant][face];
393
    }
394

    
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396

    
397
  private float getRadius()
398
    {
399
    return 0.04f;
400
    }
401

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

    
404
  private float getStroke()
405
    {
406
    return ObjectControl.isInIconMode() ? 0.08f : 0.04f;
407
    }
408

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

    
411
  private float[][] getAngles()
412
    {
413
    return null;
414
    }
415

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

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

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

    
440
    return mStickers[sticker];
441
    }
442

    
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444
// PUBLIC API
445

    
446
  public Static3D[] getRotationAxis()
447
    {
448
    return ROT_AXIS;
449
    }
450

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452

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

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

    
461
  public ObjectType intGetObjectType(int[] numLayers)
462
    {
463
    return ObjectType.JING_2;
464
    }
465

    
466
///////////////////////////////////////////////////////////////////////////////////////////////////
467

    
468
  public String getObjectName()
469
    {
470
    return "Jing Pyraminx";
471
    }
472

    
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474

    
475
  public String getInventor()
476
    {
477
    return "Tony Fisher";
478
    }
479

    
480
///////////////////////////////////////////////////////////////////////////////////////////////////
481

    
482
  public int getYearOfInvention()
483
    {
484
    return 1991;
485
    }
486

    
487
///////////////////////////////////////////////////////////////////////////////////////////////////
488

    
489
  public int getComplexity()
490
    {
491
    return 1;
492
    }
493
}
(13-13/26)