Project

General

Profile

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

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

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.TYPE_NOT_SPLIT;
23

    
24
import android.content.res.Resources;
25

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

    
32
import org.distorted.objectlib.R;
33
import org.distorted.objectlib.main.Movement;
34
import org.distorted.objectlib.main.Movement4;
35
import org.distorted.objectlib.main.ObjectList;
36
import org.distorted.objectlib.main.ObjectShape;
37
import org.distorted.objectlib.main.ObjectSticker;
38
import org.distorted.objectlib.main.ScrambleState;
39
import org.distorted.objectlib.main.Twisty4;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

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

    
53
  private static final int[][][] ENABLED = new int[][][]
54
      {
55
          {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}}
56
      };
57

    
58
  static final float F = 0.48f;  // length of the edge of the corner cubit. Keep<0.5
59
                                 // Assuming the length of the edge of the whole
60
                                 // tetrahedron is 2.0 (ie standard, equal to numLayers
61

    
62
  private ScrambleState[] mStates;
63
  private int[] mBasicAngle;
64
  private int[] mRotQuat;
65
  private Static4D[] mQuats;
66
  private float[][] mCuts;
67
  private boolean[][] mLayerRotatable;
68
  private float[][] mCenters;
69
  private int[][] mFaceMap;
70
  private ObjectSticker[] mStickers;
71
  private Movement mMovement;
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  public TwistyJing(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
76
                    DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
77
    {
78
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.JING, res, scrWidth);
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
  protected ScrambleState[] getScrambleStates()
84
    {
85
    if( mStates==null )
86
      {
87
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
88

    
89
      mStates = new ScrambleState[]
90
        {
91
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
92
        };
93
      }
94

    
95
    return mStates;
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  private void initializeQuats()
101
    {
102
    mQuats = new Static4D[]
103
         {
104
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
105
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
106
         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
107
         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
108
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
109
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
110
         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
111
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
112
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
113
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
114
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
115
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
116
         };
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

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

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

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

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

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

    
155
    return mCenters;
156
    }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

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

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
  protected int getSolvedFunctionIndex()
169
    {
170
    return 0;
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  protected int getNumStickerTypes(int numLayers)
176
    {
177
    return 3;
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

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

    
190
    return mCuts;
191
    }
192

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

    
195
  private void getLayerRotatable(int numLayers)
196
    {
197
    if( mLayerRotatable==null )
198
      {
199
      int numAxis = ROT_AXIS.length;
200
      boolean[] tmp = new boolean[numLayers];
201
      for(int i=0; i<numLayers; i++) tmp[i] = true;
202
      mLayerRotatable = new boolean[numAxis][];
203
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
204
      }
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

    
209
  protected int getNumCubitFaces()
210
    {
211
    return 6;
212
    }
213

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

    
216
  protected int getFaceColor(int cubit, int cubitface, int size)
217
    {
218
    if( mFaceMap==null )
219
      {
220
      // Colors of the faces of cubits.
221
      // GREEN 0 YELLOW 1 BLUE  2 RED 3
222
      // GREEN 4 YELLOW 5 BLUE  6 RED 7
223
      // GREEN 8 YELLOW 9 BLUE 10 RED 11
224
      mFaceMap = new int[][]
225
         {
226
           {  0,  3,  2, 12, 12, 12 },
227
           {  1,  2,  3, 12, 12, 12 },
228
           {  1,  0,  2, 12, 12, 12 },
229
           {  1,  3,  0, 12, 12, 12 },
230

    
231
           {  7,  6, 12, 12, 12, 12 },
232
           {  4,  6, 12, 12, 12, 12 },
233
           {  7,  4, 12, 12, 12, 12 },
234
           {  5,  6, 12, 12, 12, 12 },
235
           {  7,  5, 12, 12, 12, 12 },
236
           {  4,  5, 12, 12, 12, 12 },
237

    
238
           {  8, 12, 12, 12, 12, 12 },
239
           {  9, 12, 12, 12, 12, 12 },
240
           { 10, 12, 12, 12, 12, 12 },
241
           { 11, 12, 12, 12, 12, 12 },
242
         };
243
      }
244

    
245
    return mFaceMap[cubit][cubitface];
246
    }
247

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

    
250
  protected ObjectShape getObjectShape(int cubit, int numLayers)
251
    {
252
    int variant = getCubitVariant(cubit,numLayers);
253

    
254
    final float X = F/2;
255
    final float Y = F*SQ2/2;
256
    final float Z =-F/2;
257
    final float L = (2.0f-3*F);
258
    final float X2= L/2;
259
    final float Y2= L*SQ2/2;
260
    final float Z2=-L/2;
261
    final float D = F/L;
262
    final float G = 1.0f-F;
263

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

    
287
      float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
288
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
289
      float[][] corners   = new float[][] { {0.08f,0.20f*F},{0.07f,0.20f*F} };
290
      int[] cornerIndices = new int[] { 0,1,1,-1,1,-1,-1,-1 };
291
      float[][] centers   = new float[][] { { 0.0f, F*SQ2/2, -F} };
292
      int[] centerIndices = new int[] { 0,0,0,-1,0,-1,-1,-1 };
293
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
294
      }
295
    else if( variant==1 )
296
      {
297
      double[][] vertices = new double[][]
298
          {
299
             { 0.0, 0.0,     G },
300
             {   X,   Y,   Z+G },
301
             { 0.0, 2*Y, 2*Z+G },
302
             {  -X,   Y,   Z+G },
303
             { 0.0, 0.0,    -G },
304
             {   X,   Y,  -Z-G },
305
             { 0.0, 2*Y,-2*Z-G },
306
             {  -X,   Y,  -Z-G },
307
          };
308
      int[][] vert_indices = new int[][]
309
          {
310
             {0,4,5,1},
311
             {3,7,4,0},
312
             {0,1,2,3},
313
             {4,7,6,5},
314
             {1,5,6,2},
315
             {2,6,7,3}
316
          };
317

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

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

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

    
358
  protected 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
  protected int getNumCubitVariants(int numLayers)
368
    {
369
    return 3;
370
    }
371

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

    
374
  protected int getCubitVariant(int cubit, int numLayers)
375
    {
376
    return cubit<4 ? 0 : (cubit<10?1:2);
377
    }
378

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

    
381
  protected ObjectSticker retSticker(int face)
382
    {
383
    if( mStickers==null )
384
      {
385
      float[][] STICKERS = new float[][]
386
          {
387
             { 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
388
             { -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
389
             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
390
          };
391

    
392
      mStickers = new ObjectSticker[STICKERS.length];
393
      final float R1 = 0.05f;
394
      final float R2 = 0.10f;
395
      final float R3 = 0.03f;
396
      final float[][] radii  = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
397
      final float[] strokes = { 0.06f, 0.03f, 0.05f };
398

    
399
      for(int s=0; s<STICKERS.length; s++)
400
        {
401
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
402
        }
403
      }
404

    
405
    return mStickers[face/NUM_FACE_COLORS];
406
    }
407

    
408
///////////////////////////////////////////////////////////////////////////////////////////////////
409
// PUBLIC API
410

    
411
  public Static3D[] getRotationAxis()
412
    {
413
    return ROT_AXIS;
414
    }
415

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

    
418
  public Movement getMovement()
419
    {
420
    if( mMovement==null )
421
      {
422
      int numLayers = getNumLayers();
423
      if( mCuts==null ) getCuts(numLayers);
424
      getLayerRotatable(numLayers);
425
      mMovement = new Movement4(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_NOT_SPLIT,ENABLED);
426
      }
427
    return mMovement;
428
    }
429

    
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431

    
432
  public int[] getBasicAngle()
433
    {
434
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
435
    return mBasicAngle;
436
    }
437

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

    
440
  public int getObjectName(int numLayers)
441
    {
442
    return R.string.jing;
443
    }
444

    
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446

    
447
  public int getInventor(int numLayers)
448
    {
449
    return R.string.jing_inventor;
450
    }
451

    
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453

    
454
  public int getComplexity(int numLayers)
455
    {
456
    return 4;
457
    }
458
}
(13-13/25)