Project

General

Profile

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

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

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.ObjectType;
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, 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
  protected int getResource(int numLayers)
101
    {
102
    return R.raw.jing;
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  private void initializeQuats()
108
    {
109
    mQuats = new Static4D[]
110
         {
111
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
112
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
113
         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
114
         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
115
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
116
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
117
         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
118
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
119
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
120
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
121
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
122
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
123
         };
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
  protected int[] getSolvedQuats(int cubit, int numLayers)
129
    {
130
    if( mQuats==null ) initializeQuats();
131
    int status = retCubitSolvedStatus(cubit,numLayers);
132
    return status<0 ? null : buildSolvedQuats(Movement4.FACE_AXIS[status],mQuats);
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  protected float[][] getCubitPositions(int size)
138
    {
139
    if( mCenters==null )
140
      {
141
      mCenters = new float[][]
142
         {
143
           { 0.000f, -SQ2/2, 1.000f },
144
           { 0.000f, -SQ2/2,-1.000f },
145
           {-1.000f,  SQ2/2, 0.000f },
146
           { 1.000f,  SQ2/2, 0.000f },
147

    
148
           { 0.000f, -SQ2/2, 0.000f },
149
           {-0.500f, 0.000f, 0.500f },
150
           { 0.500f, 0.000f, 0.500f },
151
           {-0.500f, 0.000f,-0.500f },
152
           { 0.500f, 0.000f,-0.500f },
153
           { 0.000f,  SQ2/2, 0.000f },
154

    
155
           { 0.000f,  SQ2/6, 1.0f/3 },
156
           { 0.000f,  SQ2/6,-1.0f/3 },
157
           {-1.0f/3, -SQ2/6, 0.000f },
158
           { 1.0f/3, -SQ2/6, 0.000f },
159
         };
160
      }
161

    
162
    return mCenters;
163
    }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

    
167
  protected Static4D[] getQuats()
168
    {
169
    if( mQuats==null ) initializeQuats();
170
    return mQuats;
171
    }
172

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

    
175
  protected int getSolvedFunctionIndex()
176
    {
177
    return 0;
178
    }
179

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

    
182
  protected int getNumStickerTypes(int numLayers)
183
    {
184
    return 3;
185
    }
186

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

    
189
  protected float[][] getCuts(int size)
190
    {
191
    if( mCuts==null )
192
      {
193
      float[] cut = { (F-0.5f)*(SQ6/3) };
194
      mCuts = new float[][] { cut,cut,cut,cut };
195
      }
196

    
197
    return mCuts;
198
    }
199

    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

    
202
  private void getLayerRotatable(int numLayers)
203
    {
204
    if( mLayerRotatable==null )
205
      {
206
      int numAxis = ROT_AXIS.length;
207
      boolean[] tmp = new boolean[numLayers];
208
      for(int i=0; i<numLayers; i++) tmp[i] = true;
209
      mLayerRotatable = new boolean[numAxis][];
210
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
211
      }
212
    }
213

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

    
216
  protected int getNumCubitFaces()
217
    {
218
    return 6;
219
    }
220

    
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

    
223
  protected int getFaceColor(int cubit, int cubitface, int size)
224
    {
225
    if( mFaceMap==null )
226
      {
227
      // Colors of the faces of cubits.
228
      // GREEN 0 YELLOW 1 BLUE  2 RED 3
229
      // GREEN 4 YELLOW 5 BLUE  6 RED 7
230
      // GREEN 8 YELLOW 9 BLUE 10 RED 11
231
      mFaceMap = new int[][]
232
         {
233
           {  0,  3,  2, 12, 12, 12 },
234
           {  1,  2,  3, 12, 12, 12 },
235
           {  1,  0,  2, 12, 12, 12 },
236
           {  1,  3,  0, 12, 12, 12 },
237

    
238
           {  7,  6, 12, 12, 12, 12 },
239
           {  4,  6, 12, 12, 12, 12 },
240
           {  7,  4, 12, 12, 12, 12 },
241
           {  5,  6, 12, 12, 12, 12 },
242
           {  7,  5, 12, 12, 12, 12 },
243
           {  4,  5, 12, 12, 12, 12 },
244

    
245
           {  8, 12, 12, 12, 12, 12 },
246
           {  9, 12, 12, 12, 12, 12 },
247
           { 10, 12, 12, 12, 12, 12 },
248
           { 11, 12, 12, 12, 12, 12 },
249
         };
250
      }
251

    
252
    return mFaceMap[cubit][cubitface];
253
    }
254

    
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

    
257
  protected ObjectShape getObjectShape(int cubit, int numLayers)
258
    {
259
    int variant = getCubitVariant(cubit,numLayers);
260

    
261
    final float X = F/2;
262
    final float Y = F*SQ2/2;
263
    final float Z =-F/2;
264
    final float L = (2.0f-3*F);
265
    final float X2= L/2;
266
    final float Y2= L*SQ2/2;
267
    final float Z2=-L/2;
268
    final float D = F/L;
269
    final float G = 1.0f-F;
270

    
271
    if( variant==0 )
272
      {
273
      double[][] vertices = new double[][]
274
          {
275
             { 0.0, 0.0, 0.0 },
276
             {   X,   Y,   Z },
277
             { 0.0, 2*Y, 2*Z },
278
             {  -X,   Y,   Z },
279
             { 0.0, 0.0,    -F },
280
             {   X,   Y,   Z-F },
281
             { 0.0, 2*Y, 2*Z-F },
282
             {  -X,   Y,   Z-F },
283
          };
284
      int[][] vert_indices = new int[][]
285
          {
286
             {0,1,2,3},
287
             {1,0,4,5},
288
             {7,4,0,3},
289
             {1,5,6,2},
290
             {7,3,2,6},
291
             {4,7,6,5}
292
          };
293

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

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

    
353
      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} };
354
      int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
355
      float[][] corners   = new float[][] { {0.04f,0.6f*F} };
356
      int[] cornerIndices = new int[] { 0,0,0,-1,-1,-1 };
357
      float[][] centers   = new float[][] { { 0, -2*Y/3, 4*Z/3 } };
358
      int[] centerIndices = new int[] { 0,0,0,-1,-1,-1 };
359
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
360
      }
361
    }
362

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

    
365
  protected Static4D getQuat(int cubit, int numLayers)
366
    {
367
    if( mQuats==null ) initializeQuats();
368
    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
369
    return mQuats[mRotQuat[cubit]];
370
    }
371

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

    
374
  protected int getNumCubitVariants(int numLayers)
375
    {
376
    return 3;
377
    }
378

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

    
381
  protected int getCubitVariant(int cubit, int numLayers)
382
    {
383
    return cubit<4 ? 0 : (cubit<10?1:2);
384
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

    
388
  protected ObjectSticker retSticker(int face)
389
    {
390
    if( mStickers==null )
391
      {
392
      float[][] STICKERS = new float[][]
393
          {
394
             { 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
395
             { -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
396
             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
397
          };
398

    
399
      mStickers = new ObjectSticker[STICKERS.length];
400
      final float R1 = 0.05f;
401
      final float R2 = 0.10f;
402
      final float R3 = 0.03f;
403
      final float[][] radii  = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
404
      final float[] strokes = { 0.06f, 0.03f, 0.05f };
405

    
406
      for(int s=0; s<STICKERS.length; s++)
407
        {
408
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
409
        }
410
      }
411

    
412
    return mStickers[face/NUM_FACE_COLORS];
413
    }
414

    
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416
// PUBLIC API
417

    
418
  public Static3D[] getRotationAxis()
419
    {
420
    return ROT_AXIS;
421
    }
422

    
423
///////////////////////////////////////////////////////////////////////////////////////////////////
424

    
425
  public Movement getMovement()
426
    {
427
    if( mMovement==null )
428
      {
429
      int numLayers = getNumLayers();
430
      if( mCuts==null ) getCuts(numLayers);
431
      getLayerRotatable(numLayers);
432
      mMovement = new Movement4(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_NOT_SPLIT,ENABLED);
433
      }
434
    return mMovement;
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

    
439
  public int[] getBasicAngle()
440
    {
441
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
442
    return mBasicAngle;
443
    }
444

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

    
447
  public ObjectType intGetObjectList(int numLayers)
448
    {
449
    return ObjectType.JING_2;
450
    }
451

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

    
454
  public int getObjectName(int numLayers)
455
    {
456
    return R.string.jing;
457
    }
458

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

    
461
  public int getInventor(int numLayers)
462
    {
463
    return R.string.jing_inventor;
464
    }
465

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

    
468
  public int getComplexity(int numLayers)
469
    {
470
    return 4;
471
    }
472
}
(13-13/25)