Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyJing.java @ 7ee89540

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[][][] ENABLED = new int[][][]
49
      {
50
          {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}}
51
      };
52

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

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

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

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

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

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

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

    
90
    return mStates;
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
  private void initializeQuats()
96
    {
97
    mQuats = new Static4D[]
98
         {
99
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
100
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
101
         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
102
         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
103
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
104
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
105
         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
106
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
107
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
108
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
109
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
110
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
111
         };
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  int[] getSolvedQuats(int cubit, int numLayers)
117
    {
118
    if( mQuats==null ) initializeQuats();
119
    int status = retCubitSolvedStatus(cubit,numLayers);
120
    return status<0 ? null : buildSolvedQuats(Movement4.FACE_AXIS[status],mQuats);
121
    }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
  float[][] getCubitPositions(int size)
126
    {
127
    if( mCenters==null )
128
      {
129
      mCenters = new float[][]
130
         {
131
           { 0.000f, -SQ2/2, 1.000f },
132
           { 0.000f, -SQ2/2,-1.000f },
133
           {-1.000f,  SQ2/2, 0.000f },
134
           { 1.000f,  SQ2/2, 0.000f },
135

    
136
           { 0.000f, -SQ2/2, 0.000f },
137
           {-0.500f, 0.000f, 0.500f },
138
           { 0.500f, 0.000f, 0.500f },
139
           {-0.500f, 0.000f,-0.500f },
140
           { 0.500f, 0.000f,-0.500f },
141
           { 0.000f,  SQ2/2, 0.000f },
142

    
143
           { 0.000f,  SQ2/6, 1.0f/3 },
144
           { 0.000f,  SQ2/6,-1.0f/3 },
145
           {-1.0f/3, -SQ2/6, 0.000f },
146
           { 1.0f/3, -SQ2/6, 0.000f },
147
         };
148
      }
149

    
150
    return mCenters;
151
    }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

    
155
  Static4D[] getQuats()
156
    {
157
    if( mQuats==null ) initializeQuats();
158
    return mQuats;
159
    }
160

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

    
163
  int getSolvedFunctionIndex()
164
    {
165
    return 0;
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
  int getNumStickerTypes(int numLayers)
171
    {
172
    return 3;
173
    }
174

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

    
177
  float[][] getCuts(int size)
178
    {
179
    if( mCuts==null )
180
      {
181
      float[] cut = { (F-0.5f)*(SQ6/3) };
182
      mCuts = new float[][] { cut,cut,cut,cut };
183
      }
184

    
185
    return mCuts;
186
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

    
190
  private void getLayerRotatable(int numLayers)
191
    {
192
    if( mLayerRotatable==null )
193
      {
194
      int numAxis = ROT_AXIS.length;
195
      boolean[] tmp = new boolean[numLayers];
196
      for(int i=0; i<numLayers; i++) tmp[i] = true;
197
      mLayerRotatable = new boolean[numAxis][];
198
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
199
      }
200
    }
201

    
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

    
204
  int getNumCubitFaces()
205
    {
206
    return 6;
207
    }
208

    
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210

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

    
226
           {  7,  6, 12, 12, 12, 12 },
227
           {  4,  6, 12, 12, 12, 12 },
228
           {  7,  4, 12, 12, 12, 12 },
229
           {  5,  6, 12, 12, 12, 12 },
230
           {  7,  5, 12, 12, 12, 12 },
231
           {  4,  5, 12, 12, 12, 12 },
232

    
233
           {  8, 12, 12, 12, 12, 12 },
234
           {  9, 12, 12, 12, 12, 12 },
235
           { 10, 12, 12, 12, 12, 12 },
236
           { 11, 12, 12, 12, 12, 12 },
237
         };
238
      }
239

    
240
    return mFaceMap[cubit][cubitface];
241
    }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

    
245
  ObjectShape getObjectShape(int cubit, int numLayers)
246
    {
247
    int variant = getCubitVariant(cubit,numLayers);
248

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

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

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

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

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

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

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

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

    
362
  int getNumCubitVariants(int numLayers)
363
    {
364
    return 3;
365
    }
366

    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368

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

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

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

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

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

    
400
    return mStickers[face/NUM_FACE_COLORS];
401
    }
402

    
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404
// PUBLIC API
405

    
406
  public Static3D[] getRotationAxis()
407
    {
408
    return ROT_AXIS;
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

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

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

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

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

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

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

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

    
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448

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