Project

General

Profile

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

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

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 android.content.res.Resources;
26

    
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32

    
33
import org.distorted.objectlib.R;
34
import org.distorted.objectlib.main.Movement4;
35
import org.distorted.objectlib.main.ObjectControl;
36
import org.distorted.objectlib.main.ObjectType;
37
import org.distorted.objectlib.helpers.ObjectShape;
38
import org.distorted.objectlib.helpers.ObjectSticker;
39
import org.distorted.objectlib.helpers.ScrambleState;
40
import org.distorted.objectlib.main.Twisty4;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
public class TwistyJing extends Twisty4
45
{
46
  static final Static3D[] ROT_AXIS = new Static3D[]
47
         {
48
           new Static3D(     0,-SQ3/3,-SQ6/3),
49
           new Static3D(     0,-SQ3/3,+SQ6/3),
50
           new Static3D(+SQ6/3,+SQ3/3,     0),
51
           new Static3D(-SQ6/3,+SQ3/3,     0),
52
         };
53

    
54
  static final float F = 0.48f;  // length of the edge of the corner cubit. Keep<0.5
55
                                 // Assuming the length of the edge of the whole
56
                                 // tetrahedron is 2.0 (ie standard, equal to numLayers
57

    
58
  private ScrambleState[] mStates;
59
  private int[] mBasicAngle;
60
  private int[] mRotQuat;
61
  private Static4D[] mQuats;
62
  private float[][] mCuts;
63
  private float[][] mCenters;
64
  private int[][] mFaceMap;
65
  private ObjectSticker[] mStickers;
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  public TwistyJing(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
70
                    MeshSquare mesh, DistortedEffects effects, Resources res, int surfaceW, int surfaceH)
71
    {
72
    super(numL, numL[0], quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  public ScrambleState[] getScrambleStates()
78
    {
79
    if( mStates==null )
80
      {
81
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
82

    
83
      mStates = new ScrambleState[]
84
        {
85
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
86
        };
87
      }
88

    
89
    return mStates;
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  protected int getResource(int[] numLayers)
95
    {
96
    return R.raw.jing_2;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  private void initializeQuats()
102
    {
103
    mQuats = new Static4D[]
104
         {
105
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
106
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
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.5f,   0.0f, -0.5f),
112
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
113
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
114
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
115
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
116
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
117
         };
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  public int[] getSolvedQuats(int cubit, int[] numLayers)
123
    {
124
    if( mQuats==null ) initializeQuats();
125
    int status = retCubitSolvedStatus(cubit,numLayers);
126
    return status<0 ? null : buildSolvedQuats(Movement4.FACE_AXIS[status],mQuats);
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public float[][] getCubitPositions(int[] numLayers)
132
    {
133
    if( mCenters==null )
134
      {
135
      mCenters = new float[][]
136
         {
137
           { 0.000f, -SQ2/2, 1.000f },
138
           { 0.000f, -SQ2/2,-1.000f },
139
           {-1.000f,  SQ2/2, 0.000f },
140
           { 1.000f,  SQ2/2, 0.000f },
141

    
142
           { 0.000f, -SQ2/2, 0.000f },
143
           {-0.500f, 0.000f, 0.500f },
144
           { 0.500f, 0.000f, 0.500f },
145
           {-0.500f, 0.000f,-0.500f },
146
           { 0.500f, 0.000f,-0.500f },
147
           { 0.000f,  SQ2/2, 0.000f },
148

    
149
           { 0.000f,  SQ2/6, 1.0f/3 },
150
           { 0.000f,  SQ2/6,-1.0f/3 },
151
           {-1.0f/3, -SQ2/6, 0.000f },
152
           { 1.0f/3, -SQ2/6, 0.000f },
153
         };
154
      }
155

    
156
    return mCenters;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  public Static4D[] getQuats()
162
    {
163
    if( mQuats==null ) initializeQuats();
164
    return mQuats;
165
    }
166

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

    
169
  public int getSolvedFunctionIndex()
170
    {
171
    return 0;
172
    }
173

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

    
176
  public int getNumStickerTypes(int[] numLayers)
177
    {
178
    return 3;
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  public float[][] getCuts(int[] numLayers)
184
    {
185
    if( mCuts==null )
186
      {
187
      float[] cut = { (F-0.5f)*(SQ6/3) };
188
      mCuts = new float[][] { cut,cut,cut,cut };
189
      }
190

    
191
    return mCuts;
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

    
196
  public boolean[][] getLayerRotatable(int[] numLayers)
197
    {
198
    int numAxis = ROT_AXIS.length;
199
    boolean[][] layerRotatable = new boolean[numAxis][];
200

    
201
    for(int i=0; i<numAxis; i++)
202
      {
203
      layerRotatable[i] = new boolean[numLayers[i]];
204
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
205
      }
206

    
207
    return layerRotatable;
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

    
212
  public int getMovementType()
213
    {
214
    return MOVEMENT_TETRAHEDRON;
215
    }
216

    
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

    
219
  public int getMovementSplit()
220
    {
221
    return TYPE_NOT_SPLIT;
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  public int[][][] getEnabled()
227
    {
228
    return new int[][][]
229
      {
230
          {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}}
231
      };
232
    }
233

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

    
236
  public float[] getDist3D(int[] numLayers)
237
    {
238
    return null;
239
    }
240

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

    
243
  public int getNumCubitFaces()
244
    {
245
    return 6;
246
    }
247

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

    
250
  public ObjectShape getObjectShape(int variant)
251
    {
252
    final float X = F/2;
253
    final float Y = F*SQ2/2;
254
    final float Z =-F/2;
255
    final float L = (2.0f-3*F);
256
    final float X2= L/2;
257
    final float Y2= L*SQ2/2;
258
    final float Z2=-L/2;
259
    final float D = F/L;
260
    final float G = 1.0f-F;
261

    
262
    if( variant==0 )
263
      {
264
      double[][] vertices = new double[][]
265
          {
266
             { 0.0, 0.0, 0.0 },
267
             {   X,   Y,   Z },
268
             { 0.0, 2*Y, 2*Z },
269
             {  -X,   Y,   Z },
270
             { 0.0, 0.0,    -F },
271
             {   X,   Y,   Z-F },
272
             { 0.0, 2*Y, 2*Z-F },
273
             {  -X,   Y,   Z-F },
274
          };
275
      int[][] vert_indices = new int[][]
276
          {
277
             {0,1,2,3},
278
             {1,0,4,5},
279
             {7,4,0,3},
280
             {1,5,6,2},
281
             {7,3,2,6},
282
             {4,7,6,5}
283
          };
284

    
285
      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} };
286
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
287
      float[][] corners   = new float[][] { {0.08f,0.20f*F},{0.07f,0.20f*F} };
288
      int[] cornerIndices = new int[] { 0,1,1,-1,1,-1,-1,-1 };
289
      float[][] centers   = new float[][] { { 0.0f, Y, Z-F/2} };
290
      int[] centerIndices = new int[] { 0,0,0,-1,0,-1,-1,-1 };
291
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
292
      }
293
    else if( variant==1 )
294
      {
295
      double[][] vertices = new double[][]
296
          {
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
             { 0.0, 0.0,    -G },
302
             {   X,   Y,  -Z-G },
303
             { 0.0, 2*Y,-2*Z-G },
304
             {  -X,   Y,  -Z-G },
305
          };
306
      int[][] vert_indices = new int[][]
307
          {
308
             {0,4,5,1},
309
             {3,7,4,0},
310
             {0,1,2,3},
311
             {4,7,6,5},
312
             {1,5,6,2},
313
             {2,6,7,3}
314
          };
315

    
316
      float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
317
      int[] bandIndices   = new int[] { 0,0,1,1,1,1 };
318
      float[][] corners   = new float[][] { {0.07f,0.20f*F} };
319
      int[] cornerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
320
      float[][] centers   = new float[][] { { 0, F*SQ2/2, 0 } };
321
      int[] centerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
322
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
323
      }
324
    else
325
      {
326
      double[][] vertices = new double[][]
327
          {
328
             {    0.0,     -2*Y2/3,   -2*Z2/3 },
329
             {      X2,       Y2/3,      Z2/3 },
330
             {     -X2,       Y2/3,      Z2/3 },
331
             {    0.0,     -2*Y2/3,-2*Z2/3+2*D*Z2 },
332
             {  X2-D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
333
             { -X2+D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
334
          };
335
      int[][] vert_indices = new int[][]
336
          {
337
             {0,1,2},
338
             {3,5,4},
339
             {0,3,4,1},
340
             {5,3,0,2},
341
             {4,5,2,1}
342
          };
343

    
344
      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} };
345
      int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
346
      float[][] corners   = new float[][] { {0.04f,0.6f*F} };
347
      int[] cornerIndices = new int[] { 0,0,0,-1,-1,-1 };
348
      float[][] centers   = new float[][] { { 0, -2*Y/3, 4*Z/3 } };
349
      int[] centerIndices = new int[] { 0,0,0,-1,-1,-1 };
350
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
351
      }
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

    
356
  public Static4D getQuat(int cubit, int[] numLayers)
357
    {
358
    if( mQuats==null ) initializeQuats();
359
    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
360
    return mQuats[mRotQuat[cubit]];
361
    }
362

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

    
365
  public int getNumCubitVariants(int[] numLayers)
366
    {
367
    return 3;
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  public int getCubitVariant(int cubit, int[] numLayers)
373
    {
374
    return cubit<4 ? 0 : (cubit<10?1:2);
375
    }
376

    
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

    
379
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
380
    {
381
    return face+variant<3 ? variant : -1;
382
    }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

    
386
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
387
    {
388
    if( mFaceMap==null )
389
      {
390
      mFaceMap = new int[][]
391
         {
392
           { 0,  3,  2, -1, -1, -1 },
393
           { 1,  2,  3, -1, -1, -1 },
394
           { 1,  0,  2, -1, -1, -1 },
395
           { 1,  3,  0, -1, -1, -1 },
396

    
397
           { 3,  2, -1, -1, -1, -1 },
398
           { 0,  2, -1, -1, -1, -1 },
399
           { 3,  0, -1, -1, -1, -1 },
400
           { 1,  2, -1, -1, -1, -1 },
401
           { 3,  1, -1, -1, -1, -1 },
402
           { 0,  1, -1, -1, -1, -1 },
403

    
404
           { 0, -1, -1, -1, -1, -1 },
405
           { 1, -1, -1, -1, -1, -1 },
406
           { 2, -1, -1, -1, -1, -1 },
407
           { 3, -1, -1, -1, -1, -1 },
408
         };
409
      }
410

    
411
    return mFaceMap[cubit][face];
412
    }
413

    
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415

    
416
  public ObjectSticker retSticker(int sticker)
417
    {
418
    if( mStickers==null )
419
      {
420
      float[][] STICKERS = new float[][]
421
          {
422
             { 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
423
             { -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
424
             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
425
          };
426

    
427
      mStickers = new ObjectSticker[STICKERS.length];
428
      final float R1 = 0.05f;
429
      final float R2 = 0.10f;
430
      final float R3 = 0.03f;
431
      final float[][] radii  = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
432
      float[] strokes = { 0.06f, 0.03f, 0.05f };
433

    
434
      if( ObjectControl.isInIconMode() )
435
        {
436
        strokes[0]*=2.0f;
437
        strokes[1]*=2.0f;
438
        strokes[2]*=2.0f;
439
        }
440

    
441
      for(int s=0; s<STICKERS.length; s++)
442
        {
443
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
444
        }
445
      }
446

    
447
    return mStickers[sticker];
448
    }
449

    
450
///////////////////////////////////////////////////////////////////////////////////////////////////
451
// PUBLIC API
452

    
453
  public Static3D[] getRotationAxis()
454
    {
455
    return ROT_AXIS;
456
    }
457

    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

    
460
  public int[] getBasicAngle()
461
    {
462
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
463
    return mBasicAngle;
464
    }
465

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

    
468
  public ObjectType intGetObjectType(int[] numLayers)
469
    {
470
    return ObjectType.JING_2;
471
    }
472

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

    
475
  public int getObjectName(int[] numLayers)
476
    {
477
    return R.string.jing;
478
    }
479

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

    
482
  public int getInventor(int[] numLayers)
483
    {
484
    return R.string.jing_inventor;
485
    }
486

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

    
489
  public int getYearOfInvention(int[] numLayers)
490
    {
491
    return 1991;
492
    }
493

    
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495

    
496
  public int getComplexity(int[] numLayers)
497
    {
498
    return 4;
499
    }
500
}
(13-13/25)