Project

General

Profile

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

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

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.ObjectControl;
36
import org.distorted.objectlib.main.ObjectType;
37
import org.distorted.objectlib.helpers.ObjectShape;
38
import org.distorted.objectlib.helpers.ObjectSticker;
39
import org.distorted.objectlib.helpers.ScrambleState;
40
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
  public TwistyJing(int size, Static4D quat, Static3D move, DistortedTexture texture,
77
                    MeshSquare mesh, DistortedEffects effects, Resources res, int scrWidth)
78
    {
79
    super(size, size, quat, move, texture, mesh, effects, res, scrWidth);
80
    }
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
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  protected int getResource(int numLayers)
102
    {
103
    return R.raw.jing;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
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
  protected int[] getSolvedQuats(int cubit, int numLayers)
130
    {
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
  protected float[][] getCubitPositions(int size)
139
    {
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
  protected int getNumStickerTypes(int numLayers)
184
    {
185
    return 3;
186
    }
187

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

    
190
  protected float[][] getCuts(int size)
191
    {
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
  private void getLayerRotatable(int numLayers)
204
    {
205
    if( mLayerRotatable==null )
206
      {
207
      int numAxis = ROT_AXIS.length;
208
      boolean[] tmp = new boolean[numLayers];
209
      for(int i=0; i<numLayers; i++) tmp[i] = true;
210
      mLayerRotatable = new boolean[numAxis][];
211
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
212
      }
213
    }
214

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

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

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

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

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

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

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

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

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

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

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

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

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

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

    
364
///////////////////////////////////////////////////////////////////////////////////////////////////
365

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

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

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

    
380
///////////////////////////////////////////////////////////////////////////////////////////////////
381

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

    
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388

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

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

    
407
      if( ObjectControl.isInIconMode() )
408
        {
409
        strokes[0]*=2.0f;
410
        strokes[1]*=2.0f;
411
        strokes[2]*=2.0f;
412
        }
413

    
414
      for(int s=0; s<STICKERS.length; s++)
415
        {
416
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
417
        }
418
      }
419

    
420
    return mStickers[face/NUM_FACE_COLORS];
421
    }
422

    
423
///////////////////////////////////////////////////////////////////////////////////////////////////
424
// PUBLIC API
425

    
426
  public Static3D[] getRotationAxis()
427
    {
428
    return ROT_AXIS;
429
    }
430

    
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432

    
433
  public Movement getMovement()
434
    {
435
    if( mMovement==null )
436
      {
437
      int numLayers = getNumLayers();
438
      if( mCuts==null ) getCuts(numLayers);
439
      getLayerRotatable(numLayers);
440
      mMovement = new Movement4(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_NOT_SPLIT,ENABLED);
441
      }
442
    return mMovement;
443
    }
444

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

    
447
  public int[] getBasicAngle()
448
    {
449
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
450
    return mBasicAngle;
451
    }
452

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

    
455
  public ObjectType intGetObjectType(int numLayers)
456
    {
457
    return ObjectType.JING_2;
458
    }
459

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

    
462
  public int getObjectName(int numLayers)
463
    {
464
    return R.string.jing;
465
    }
466

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

    
469
  public int getInventor(int numLayers)
470
    {
471
    return R.string.jing_inventor;
472
    }
473

    
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475

    
476
  public int getComplexity(int numLayers)
477
    {
478
    return 4;
479
    }
480
}
(13-13/25)