Project

General

Profile

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

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

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 8592461c Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
36 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
37 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
38
import org.distorted.objectlib.helpers.ObjectSticker;
39
import org.distorted.objectlib.helpers.ScrambleState;
40 29b82486 Leszek Koltunski
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
  private static final int[][][] ENABLED = new int[][][]
55
      {
56
          {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}}
57
      };
58
59
  static final float F = 0.48f;  // length of the edge of the corner cubit. Keep<0.5
60
                                 // Assuming the length of the edge of the whole
61
                                 // tetrahedron is 2.0 (ie standard, equal to numLayers
62
63
  private ScrambleState[] mStates;
64
  private int[] mBasicAngle;
65
  private int[] mRotQuat;
66
  private Static4D[] mQuats;
67
  private float[][] mCuts;
68
  private boolean[][] mLayerRotatable;
69
  private float[][] mCenters;
70
  private int[][] mFaceMap;
71
  private ObjectSticker[] mStickers;
72
  private Movement mMovement;
73
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
76 a57e6870 Leszek Koltunski
  public TwistyJing(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
77 ecf3d6e3 Leszek Koltunski
                    MeshSquare mesh, DistortedEffects effects, Resources res, int scrWidth)
78 29b82486 Leszek Koltunski
    {
79 a57e6870 Leszek Koltunski
    super(numL, numL[0], quat, move, texture, mesh, effects, res, scrWidth);
80 29b82486 Leszek Koltunski
    }
81
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
84
  protected ScrambleState[] getScrambleStates()
85
    {
86
    if( mStates==null )
87
      {
88
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
89
90
      mStates = new ScrambleState[]
91
        {
92
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
93
        };
94
      }
95
96
    return mStates;
97
    }
98
99 4e1dc313 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
100
101 a57e6870 Leszek Koltunski
  protected int getResource(int[] numLayers)
102 4e1dc313 Leszek Koltunski
    {
103
    return R.raw.jing;
104
    }
105
106 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
107
108
  private void initializeQuats()
109
    {
110
    mQuats = new Static4D[]
111
         {
112
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
113
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
114
         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
115
         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
116
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
117
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
118
         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
119
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
120
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
121
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
122
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
123
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
124
         };
125
    }
126
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
129 a57e6870 Leszek Koltunski
  protected int[] getSolvedQuats(int cubit, int[] numLayers)
130 29b82486 Leszek Koltunski
    {
131
    if( mQuats==null ) initializeQuats();
132
    int status = retCubitSolvedStatus(cubit,numLayers);
133
    return status<0 ? null : buildSolvedQuats(Movement4.FACE_AXIS[status],mQuats);
134
    }
135
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137
138 a57e6870 Leszek Koltunski
  protected float[][] getCubitPositions(int[] numLayers)
139 29b82486 Leszek Koltunski
    {
140
    if( mCenters==null )
141
      {
142
      mCenters = new float[][]
143
         {
144
           { 0.000f, -SQ2/2, 1.000f },
145
           { 0.000f, -SQ2/2,-1.000f },
146
           {-1.000f,  SQ2/2, 0.000f },
147
           { 1.000f,  SQ2/2, 0.000f },
148
149
           { 0.000f, -SQ2/2, 0.000f },
150
           {-0.500f, 0.000f, 0.500f },
151
           { 0.500f, 0.000f, 0.500f },
152
           {-0.500f, 0.000f,-0.500f },
153
           { 0.500f, 0.000f,-0.500f },
154
           { 0.000f,  SQ2/2, 0.000f },
155
156
           { 0.000f,  SQ2/6, 1.0f/3 },
157
           { 0.000f,  SQ2/6,-1.0f/3 },
158
           {-1.0f/3, -SQ2/6, 0.000f },
159
           { 1.0f/3, -SQ2/6, 0.000f },
160
         };
161
      }
162
163
    return mCenters;
164
    }
165
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167
168
  protected Static4D[] getQuats()
169
    {
170
    if( mQuats==null ) initializeQuats();
171
    return mQuats;
172
    }
173
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175
176
  protected int getSolvedFunctionIndex()
177
    {
178
    return 0;
179
    }
180
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
183 a57e6870 Leszek Koltunski
  protected int getNumStickerTypes(int[] numLayers)
184 29b82486 Leszek Koltunski
    {
185
    return 3;
186
    }
187
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
190 a57e6870 Leszek Koltunski
  protected float[][] getCuts(int[] numLayers)
191 29b82486 Leszek Koltunski
    {
192
    if( mCuts==null )
193
      {
194
      float[] cut = { (F-0.5f)*(SQ6/3) };
195
      mCuts = new float[][] { cut,cut,cut,cut };
196
      }
197
198
    return mCuts;
199
    }
200
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202
203 a57e6870 Leszek Koltunski
  private void getLayerRotatable(int[] numLayers)
204 29b82486 Leszek Koltunski
    {
205
    if( mLayerRotatable==null )
206
      {
207
      int numAxis = ROT_AXIS.length;
208
      mLayerRotatable = new boolean[numAxis][];
209 a57e6870 Leszek Koltunski
210
      for(int i=0; i<numAxis; i++)
211
        {
212
        mLayerRotatable[i] = new boolean[numLayers[i]];
213
        for(int j=0; j<numLayers[i]; j++) mLayerRotatable[i][j] = true;
214
        }
215 29b82486 Leszek Koltunski
      }
216
    }
217
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
220
  protected int getNumCubitFaces()
221
    {
222
    return 6;
223
    }
224
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226
227 a57e6870 Leszek Koltunski
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
228 29b82486 Leszek Koltunski
    {
229
    if( mFaceMap==null )
230
      {
231
      // Colors of the faces of cubits.
232
      // GREEN 0 YELLOW 1 BLUE  2 RED 3
233
      // GREEN 4 YELLOW 5 BLUE  6 RED 7
234
      // GREEN 8 YELLOW 9 BLUE 10 RED 11
235
      mFaceMap = new int[][]
236
         {
237
           {  0,  3,  2, 12, 12, 12 },
238
           {  1,  2,  3, 12, 12, 12 },
239
           {  1,  0,  2, 12, 12, 12 },
240
           {  1,  3,  0, 12, 12, 12 },
241
242
           {  7,  6, 12, 12, 12, 12 },
243
           {  4,  6, 12, 12, 12, 12 },
244
           {  7,  4, 12, 12, 12, 12 },
245
           {  5,  6, 12, 12, 12, 12 },
246
           {  7,  5, 12, 12, 12, 12 },
247
           {  4,  5, 12, 12, 12, 12 },
248
249
           {  8, 12, 12, 12, 12, 12 },
250
           {  9, 12, 12, 12, 12, 12 },
251
           { 10, 12, 12, 12, 12, 12 },
252
           { 11, 12, 12, 12, 12, 12 },
253
         };
254
      }
255
256
    return mFaceMap[cubit][cubitface];
257
    }
258
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260
261 a57e6870 Leszek Koltunski
  protected ObjectShape getObjectShape(int cubit, int[] numLayers)
262 29b82486 Leszek Koltunski
    {
263
    int variant = getCubitVariant(cubit,numLayers);
264
265
    final float X = F/2;
266
    final float Y = F*SQ2/2;
267
    final float Z =-F/2;
268
    final float L = (2.0f-3*F);
269
    final float X2= L/2;
270
    final float Y2= L*SQ2/2;
271
    final float Z2=-L/2;
272
    final float D = F/L;
273
    final float G = 1.0f-F;
274
275
    if( variant==0 )
276
      {
277
      double[][] vertices = new double[][]
278
          {
279
             { 0.0, 0.0, 0.0 },
280
             {   X,   Y,   Z },
281
             { 0.0, 2*Y, 2*Z },
282
             {  -X,   Y,   Z },
283
             { 0.0, 0.0,    -F },
284
             {   X,   Y,   Z-F },
285
             { 0.0, 2*Y, 2*Z-F },
286
             {  -X,   Y,   Z-F },
287
          };
288
      int[][] vert_indices = new int[][]
289
          {
290
             {0,1,2,3},
291
             {1,0,4,5},
292
             {7,4,0,3},
293
             {1,5,6,2},
294
             {7,3,2,6},
295
             {4,7,6,5}
296
          };
297
298 2289cab1 Leszek Koltunski
      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} };
299 29b82486 Leszek Koltunski
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
300
      float[][] corners   = new float[][] { {0.08f,0.20f*F},{0.07f,0.20f*F} };
301
      int[] cornerIndices = new int[] { 0,1,1,-1,1,-1,-1,-1 };
302 854b09be Leszek Koltunski
      float[][] centers   = new float[][] { { 0.0f, Y, Z-F/2} };
303 29b82486 Leszek Koltunski
      int[] centerIndices = new int[] { 0,0,0,-1,0,-1,-1,-1 };
304
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
305
      }
306
    else if( variant==1 )
307
      {
308
      double[][] vertices = new double[][]
309
          {
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
             { 0.0, 0.0,    -G },
315
             {   X,   Y,  -Z-G },
316
             { 0.0, 2*Y,-2*Z-G },
317
             {  -X,   Y,  -Z-G },
318
          };
319
      int[][] vert_indices = new int[][]
320
          {
321
             {0,4,5,1},
322
             {3,7,4,0},
323
             {0,1,2,3},
324
             {4,7,6,5},
325
             {1,5,6,2},
326
             {2,6,7,3}
327
          };
328
329
      float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
330
      int[] bandIndices   = new int[] { 0,0,1,1,1,1 };
331
      float[][] corners   = new float[][] { {0.07f,0.20f*F} };
332
      int[] cornerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
333
      float[][] centers   = new float[][] { { 0, F*SQ2/2, 0 } };
334
      int[] centerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
335
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
336
      }
337
    else
338
      {
339
      double[][] vertices = new double[][]
340
          {
341
             {    0.0,     -2*Y2/3,   -2*Z2/3 },
342
             {      X2,       Y2/3,      Z2/3 },
343
             {     -X2,       Y2/3,      Z2/3 },
344
             {    0.0,     -2*Y2/3,-2*Z2/3+2*D*Z2 },
345
             {  X2-D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
346
             { -X2+D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
347
          };
348
      int[][] vert_indices = new int[][]
349
          {
350
             {0,1,2},
351
             {3,5,4},
352
             {0,3,4,1},
353
             {5,3,0,2},
354
             {4,5,2,1}
355
          };
356
357
      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} };
358
      int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
359
      float[][] corners   = new float[][] { {0.04f,0.6f*F} };
360
      int[] cornerIndices = new int[] { 0,0,0,-1,-1,-1 };
361
      float[][] centers   = new float[][] { { 0, -2*Y/3, 4*Z/3 } };
362
      int[] centerIndices = new int[] { 0,0,0,-1,-1,-1 };
363
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
364
      }
365
    }
366
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368
369 a57e6870 Leszek Koltunski
  protected Static4D getQuat(int cubit, int[] numLayers)
370 29b82486 Leszek Koltunski
    {
371
    if( mQuats==null ) initializeQuats();
372
    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
373
    return mQuats[mRotQuat[cubit]];
374
    }
375
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377
378 a57e6870 Leszek Koltunski
  protected int getNumCubitVariants(int[] numLayers)
379 29b82486 Leszek Koltunski
    {
380
    return 3;
381
    }
382
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384
385 a57e6870 Leszek Koltunski
  protected int getCubitVariant(int cubit, int[] numLayers)
386 29b82486 Leszek Koltunski
    {
387
    return cubit<4 ? 0 : (cubit<10?1:2);
388
    }
389
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391
392
  protected ObjectSticker retSticker(int face)
393
    {
394
    if( mStickers==null )
395
      {
396
      float[][] STICKERS = new float[][]
397
          {
398
             { 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
399
             { -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
400
             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
401
          };
402
403
      mStickers = new ObjectSticker[STICKERS.length];
404
      final float R1 = 0.05f;
405
      final float R2 = 0.10f;
406
      final float R3 = 0.03f;
407
      final float[][] radii  = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
408 8592461c Leszek Koltunski
      float[] strokes = { 0.06f, 0.03f, 0.05f };
409
410
      if( ObjectControl.isInIconMode() )
411
        {
412
        strokes[0]*=2.0f;
413
        strokes[1]*=2.0f;
414
        strokes[2]*=2.0f;
415
        }
416 29b82486 Leszek Koltunski
417
      for(int s=0; s<STICKERS.length; s++)
418
        {
419
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
420
        }
421
      }
422
423
    return mStickers[face/NUM_FACE_COLORS];
424
    }
425
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427
// PUBLIC API
428
429
  public Static3D[] getRotationAxis()
430
    {
431
    return ROT_AXIS;
432
    }
433
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435
436
  public Movement getMovement()
437
    {
438
    if( mMovement==null )
439
      {
440 a57e6870 Leszek Koltunski
      int[] numLayers = getNumLayers();
441 29b82486 Leszek Koltunski
      if( mCuts==null ) getCuts(numLayers);
442
      getLayerRotatable(numLayers);
443 a57e6870 Leszek Koltunski
      mMovement = new Movement4(ROT_AXIS,mCuts,mLayerRotatable,numLayers[0],TYPE_NOT_SPLIT,ENABLED);
444 29b82486 Leszek Koltunski
      }
445
    return mMovement;
446
    }
447
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449
450
  public int[] getBasicAngle()
451
    {
452
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
453
    return mBasicAngle;
454
    }
455
456 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
457
458 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
459 61aa85e4 Leszek Koltunski
    {
460 8005e762 Leszek Koltunski
    return ObjectType.JING_2;
461 61aa85e4 Leszek Koltunski
    }
462
463 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
464
465 a57e6870 Leszek Koltunski
  public int getObjectName(int[] numLayers)
466 29b82486 Leszek Koltunski
    {
467
    return R.string.jing;
468
    }
469
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471
472 a57e6870 Leszek Koltunski
  public int getInventor(int[] numLayers)
473 29b82486 Leszek Koltunski
    {
474
    return R.string.jing_inventor;
475
    }
476
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478
479 a57e6870 Leszek Koltunski
  public int getComplexity(int[] numLayers)
480 29b82486 Leszek Koltunski
    {
481
    return 4;
482
    }
483
}