Project

General

Profile

Download (15.3 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyJing.java @ 967c1d17

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.objects;
21

    
22
import static org.distorted.objects.Movement.TYPE_NOT_SPLIT;
23

    
24
import android.content.res.Resources;
25

    
26
import org.distorted.helpers.ObjectShape;
27
import org.distorted.helpers.ObjectSticker;
28
import org.distorted.helpers.ScrambleState;
29
import org.distorted.library.main.DistortedEffects;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshSquare;
32
import org.distorted.library.type.Static3D;
33
import org.distorted.library.type.Static4D;
34
import org.distorted.main.R;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
public class TwistyJing extends Twisty4
39
{
40
  static final Static3D[] ROT_AXIS = new Static3D[]
41
         {
42
           new Static3D(     0,-SQ3/3,-SQ6/3),
43
           new Static3D(     0,-SQ3/3,+SQ6/3),
44
           new Static3D(+SQ6/3,+SQ3/3,     0),
45
           new Static3D(-SQ6/3,+SQ3/3,     0),
46
         };
47

    
48
  private static final int[] NUM_ENABLED = {3,3,3,3};
49

    
50
  private static final int[][][] ENABLED = new int[][][]
51
      {
52
          {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}}
53
      };
54

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

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

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

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

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
  ScrambleState[] getScrambleStates()
81
    {
82
    if( mStates==null )
83
      {
84
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
85

    
86
      mStates = new ScrambleState[]
87
        {
88
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
89
        };
90
      }
91

    
92
    return mStates;
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
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
  int[] getSolvedQuats(int cubit, int numLayers)
119
    {
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
  float[][] getCubitPositions(int size)
128
    {
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
  Static4D[] getQuats()
158
    {
159
    if( mQuats==null ) initializeQuats();
160
    return mQuats;
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  int getSolvedFunctionIndex()
166
    {
167
    return 0;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  int getNumStickerTypes(int numLayers)
173
    {
174
    return 3;
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  float[][] getCuts(int size)
180
    {
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
  private void getLayerRotatable(int numLayers)
193
    {
194
    if( mLayerRotatable==null )
195
      {
196
      int numAxis = ROT_AXIS.length;
197
      boolean[] tmp = new boolean[numLayers];
198
      for(int i=0; i<numLayers; i++) tmp[i] = true;
199
      mLayerRotatable = new boolean[numAxis][];
200
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
201
      }
202
    }
203

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

    
206
  int getNumCubitFaces()
207
    {
208
    return 6;
209
    }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

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

    
228
           {  7,  6, 12, 12, 12, 12 },
229
           {  4,  6, 12, 12, 12, 12 },
230
           {  7,  4, 12, 12, 12, 12 },
231
           {  5,  6, 12, 12, 12, 12 },
232
           {  7,  5, 12, 12, 12, 12 },
233
           {  4,  5, 12, 12, 12, 12 },
234

    
235
           {  8, 12, 12, 12, 12, 12 },
236
           {  9, 12, 12, 12, 12, 12 },
237
           { 10, 12, 12, 12, 12, 12 },
238
           { 11, 12, 12, 12, 12, 12 },
239
         };
240
      }
241

    
242
    return mFaceMap[cubit][cubitface];
243
    }
244

    
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

    
247
  ObjectShape getObjectShape(int cubit, int numLayers)
248
    {
249
    int variant = getCubitVariant(cubit,numLayers);
250

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

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

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

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

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

    
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354

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

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

    
364
  int getNumCubitVariants(int numLayers)
365
    {
366
    return 3;
367
    }
368

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

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

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

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

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

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

    
402
    return mStickers[face/NUM_FACE_COLORS];
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406
// PUBLIC API
407

    
408
  public Static3D[] getRotationAxis()
409
    {
410
    return ROT_AXIS;
411
    }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

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

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  public int[] getBasicAngle()
430
    {
431
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
432
    return mBasicAngle;
433
    }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

    
437
  public int getObjectName(int numLayers)
438
    {
439
    return R.string.jing;
440
    }
441

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

    
444
  public int getInventor(int numLayers)
445
    {
446
    return R.string.jing_inventor;
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450

    
451
  public int getComplexity(int numLayers)
452
    {
453
    return 4;
454
    }
455
}
(24-24/38)