Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyJing.java @ 588ace55

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.objectlib.Movement.TYPE_NOT_SPLIT;
23

    
24
import android.content.res.Resources;
25

    
26
import org.distorted.objectlib.ObjectShape;
27
import org.distorted.objectlib.ObjectSticker;
28
import org.distorted.objectlib.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
import org.distorted.objectlib.Movement;
36
import org.distorted.objectlib.Movement4;
37
import org.distorted.objectlib.ObjectList;
38
import org.distorted.objectlib.Twisty4;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

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

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

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

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

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

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

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

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

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

    
94
    return mStates;
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
  private void initializeQuats()
100
    {
101
    mQuats = new Static4D[]
102
         {
103
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
104
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
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.5f,   0.0f, -0.5f),
110
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
111
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
112
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
113
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
114
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
115
         };
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  protected int[] getSolvedQuats(int cubit, int numLayers)
121
    {
122
    if( mQuats==null ) initializeQuats();
123
    int status = retCubitSolvedStatus(cubit,numLayers);
124
    return status<0 ? null : buildSolvedQuats(Movement4.FACE_AXIS[status],mQuats);
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
  protected float[][] getCubitPositions(int size)
130
    {
131
    if( mCenters==null )
132
      {
133
      mCenters = new float[][]
134
         {
135
           { 0.000f, -SQ2/2, 1.000f },
136
           { 0.000f, -SQ2/2,-1.000f },
137
           {-1.000f,  SQ2/2, 0.000f },
138
           { 1.000f,  SQ2/2, 0.000f },
139

    
140
           { 0.000f, -SQ2/2, 0.000f },
141
           {-0.500f, 0.000f, 0.500f },
142
           { 0.500f, 0.000f, 0.500f },
143
           {-0.500f, 0.000f,-0.500f },
144
           { 0.500f, 0.000f,-0.500f },
145
           { 0.000f,  SQ2/2, 0.000f },
146

    
147
           { 0.000f,  SQ2/6, 1.0f/3 },
148
           { 0.000f,  SQ2/6,-1.0f/3 },
149
           {-1.0f/3, -SQ2/6, 0.000f },
150
           { 1.0f/3, -SQ2/6, 0.000f },
151
         };
152
      }
153

    
154
    return mCenters;
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  protected Static4D[] getQuats()
160
    {
161
    if( mQuats==null ) initializeQuats();
162
    return mQuats;
163
    }
164

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

    
167
  protected int getSolvedFunctionIndex()
168
    {
169
    return 0;
170
    }
171

    
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

    
174
  protected int getNumStickerTypes(int numLayers)
175
    {
176
    return 3;
177
    }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

    
181
  protected float[][] getCuts(int size)
182
    {
183
    if( mCuts==null )
184
      {
185
      float[] cut = { (F-0.5f)*(SQ6/3) };
186
      mCuts = new float[][] { cut,cut,cut,cut };
187
      }
188

    
189
    return mCuts;
190
    }
191

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

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

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  protected int getNumCubitFaces()
209
    {
210
    return 6;
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

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

    
230
           {  7,  6, 12, 12, 12, 12 },
231
           {  4,  6, 12, 12, 12, 12 },
232
           {  7,  4, 12, 12, 12, 12 },
233
           {  5,  6, 12, 12, 12, 12 },
234
           {  7,  5, 12, 12, 12, 12 },
235
           {  4,  5, 12, 12, 12, 12 },
236

    
237
           {  8, 12, 12, 12, 12, 12 },
238
           {  9, 12, 12, 12, 12, 12 },
239
           { 10, 12, 12, 12, 12, 12 },
240
           { 11, 12, 12, 12, 12, 12 },
241
         };
242
      }
243

    
244
    return mFaceMap[cubit][cubitface];
245
    }
246

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

    
249
  protected ObjectShape getObjectShape(int cubit, int numLayers)
250
    {
251
    int variant = getCubitVariant(cubit,numLayers);
252

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

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

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

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

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

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

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

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

    
366
  protected int getNumCubitVariants(int numLayers)
367
    {
368
    return 3;
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

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

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

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

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

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

    
404
    return mStickers[face/NUM_FACE_COLORS];
405
    }
406

    
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408
// PUBLIC API
409

    
410
  public Static3D[] getRotationAxis()
411
    {
412
    return ROT_AXIS;
413
    }
414

    
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416

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

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

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

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

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

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445

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

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452

    
453
  public int getComplexity(int numLayers)
454
    {
455
    return 4;
456
    }
457
}
(13-13/25)