Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyJing.java @ ef018c1b

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 android.content.res.Resources;
23

    
24
import org.distorted.helpers.ObjectShape;
25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.ScrambleState;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32
import org.distorted.main.R;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class TwistyJing extends Twisty4
37
{
38
  static final Static3D[] ROT_AXIS = new Static3D[]
39
         {
40
           new Static3D(     0,-SQ3/3,-SQ6/3),
41
           new Static3D(     0,-SQ3/3,+SQ6/3),
42
           new Static3D(+SQ6/3,+SQ3/3,     0),
43
           new Static3D(-SQ6/3,+SQ3/3,     0),
44
         };
45

    
46
  static final float F = 0.48f;  // length of the edge of the corner cubit. Keep<0.5
47
                                 // Assuming the length of the edge of the whole
48
                                 // tetrahedron is 2.0 (ie standard, equal to numLayers
49

    
50
  private ScrambleState[] mStates;
51
  private int[] mBasicAngle;
52
  private int[] mRotQuat;
53
  private Static4D[] mQuats;
54
  private float[][] mCuts;
55
  private boolean[][] mLayerRotatable;
56
  private float[][] mCenters;
57
  private int[][] mFaceMap;
58
  private ObjectSticker[] mStickers;
59
  private Movement mMovement;
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  TwistyJing(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
64
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
65
    {
66
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.JING, res, scrWidth);
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  ScrambleState[] getScrambleStates()
72
    {
73
    if( mStates==null )
74
      {
75
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
76

    
77
      mStates = new ScrambleState[]
78
        {
79
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
80
        };
81
      }
82

    
83
    return mStates;
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  private void initializeQuats()
89
    {
90
    mQuats = new Static4D[]
91
         {
92
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
93
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
94
         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
95
         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
96
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
97
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
98
         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
99
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
100
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
101
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
102
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
103
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
104
         };
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  int[] getSolvedQuats(int cubit, int numLayers)
110
    {
111
    if( mQuats==null ) initializeQuats();
112
    int status = retCubitSolvedStatus(cubit,numLayers);
113
    return status<0 ? null : buildSolvedQuats(MovementJing.FACE_AXIS[status],mQuats);
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  float[][] getCubitPositions(int size)
119
    {
120
    if( mCenters==null )
121
      {
122
      mCenters = new float[][]
123
         {
124
           { 0.000f, -SQ2/2, 1.000f },
125
           { 0.000f, -SQ2/2,-1.000f },
126
           {-1.000f,  SQ2/2, 0.000f },
127
           { 1.000f,  SQ2/2, 0.000f },
128

    
129
           { 0.000f, -SQ2/2, 0.000f },
130
           {-0.500f, 0.000f, 0.500f },
131
           { 0.500f, 0.000f, 0.500f },
132
           {-0.500f, 0.000f,-0.500f },
133
           { 0.500f, 0.000f,-0.500f },
134
           { 0.000f,  SQ2/2, 0.000f },
135

    
136
           { 0.000f,  SQ2/6, 1.0f/3 },
137
           { 0.000f,  SQ2/6,-1.0f/3 },
138
           {-1.0f/3, -SQ2/6, 0.000f },
139
           { 1.0f/3, -SQ2/6, 0.000f },
140
         };
141
      }
142

    
143
    return mCenters;
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  Static4D[] getQuats()
149
    {
150
    if( mQuats==null ) initializeQuats();
151
    return mQuats;
152
    }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
  int getSolvedFunctionIndex()
157
    {
158
    return 0;
159
    }
160

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

    
163
  int getNumStickerTypes(int numLayers)
164
    {
165
    return 3;
166
    }
167

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

    
170
  float[][] getCuts(int size)
171
    {
172
    if( mCuts==null )
173
      {
174
      float[] cut = { (F-0.5f)*(SQ6/3) };
175
      mCuts = new float[][] { cut,cut,cut,cut };
176
      }
177

    
178
    return mCuts;
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  private void getLayerRotatable(int numLayers)
184
    {
185
    if( mLayerRotatable==null )
186
      {
187
      int numAxis = ROT_AXIS.length;
188
      boolean[] tmp = new boolean[numLayers];
189
      for(int i=0; i<numLayers; i++) tmp[i] = true;
190
      mLayerRotatable = new boolean[numAxis][];
191
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
192
      }
193
    }
194

    
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

    
197
  int getNumCubitFaces()
198
    {
199
    return 6;
200
    }
201

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

    
204
  int getFaceColor(int cubit, int cubitface, int size)
205
    {
206
    if( mFaceMap==null )
207
      {
208
      // Colors of the faces of cubits.
209
      // GREEN 0 YELLOW 1 BLUE  2 RED 3
210
      // GREEN 4 YELLOW 5 BLUE  6 RED 7
211
      // GREEN 8 YELLOW 9 BLUE 10 RED 11
212
      mFaceMap = new int[][]
213
         {
214
           {  0,  3,  2, 12, 12, 12 },
215
           {  1,  2,  3, 12, 12, 12 },
216
           {  1,  0,  2, 12, 12, 12 },
217
           {  1,  3,  0, 12, 12, 12 },
218

    
219
           {  7,  6, 12, 12, 12, 12 },
220
           {  4,  6, 12, 12, 12, 12 },
221
           {  7,  4, 12, 12, 12, 12 },
222
           {  5,  6, 12, 12, 12, 12 },
223
           {  7,  5, 12, 12, 12, 12 },
224
           {  4,  5, 12, 12, 12, 12 },
225

    
226
           {  8, 12, 12, 12, 12, 12 },
227
           {  9, 12, 12, 12, 12, 12 },
228
           { 10, 12, 12, 12, 12, 12 },
229
           { 11, 12, 12, 12, 12, 12 },
230
         };
231
      }
232

    
233
    return mFaceMap[cubit][cubitface];
234
    }
235

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

    
238
  ObjectShape getObjectShape(int cubit, int numLayers)
239
    {
240
    int variant = getCubitVariant(cubit,numLayers);
241

    
242
    final float X = F/2;
243
    final float Y = F*SQ2/2;
244
    final float Z =-F/2;
245
    final float L = (2.0f-3*F);
246
    final float X2= L/2;
247
    final float Y2= L*SQ2/2;
248
    final float Z2=-L/2;
249
    final float D = F/L;
250
    final float G = 1.0f-F;
251

    
252
    if( variant==0 )
253
      {
254
      double[][] vertices = new double[][]
255
          {
256
             { 0.0, 0.0, 0.0 },
257
             {   X,   Y,   Z },
258
             { 0.0, 2*Y, 2*Z },
259
             {  -X,   Y,   Z },
260
             { 0.0, 0.0,    -F },
261
             {   X,   Y,   Z-F },
262
             { 0.0, 2*Y, 2*Z-F },
263
             {  -X,   Y,   Z-F },
264
          };
265
      int[][] vert_indices = new int[][]
266
          {
267
             {0,1,2,3},
268
             {1,0,4,5},
269
             {7,4,0,3},
270
             {1,5,6,2},
271
             {7,3,2,6},
272
             {4,7,6,5}
273
          };
274

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

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

    
334
      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} };
335
      int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
336
      float[][] corners   = new float[][] { {0.04f,0.6f*F} };
337
      int[] cornerIndices = new int[] { 0,0,0,-1,-1,-1 };
338
      float[][] centers   = new float[][] { { 0, -2*Y/3, 4*Z/3 } };
339
      int[] centerIndices = new int[] { 0,0,0,-1,-1,-1 };
340
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
341
      }
342
    }
343

    
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345

    
346
  Static4D getQuat(int cubit, int numLayers)
347
    {
348
    if( mQuats==null ) initializeQuats();
349
    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
350
    return mQuats[mRotQuat[cubit]];
351
    }
352

    
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354

    
355
  int getNumCubitVariants(int numLayers)
356
    {
357
    return 3;
358
    }
359

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

    
362
  int getCubitVariant(int cubit, int numLayers)
363
    {
364
    return cubit<4 ? 0 : (cubit<10?1:2);
365
    }
366

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

    
369
  ObjectSticker retSticker(int face)
370
    {
371
    if( mStickers==null )
372
      {
373
      float[][] STICKERS = new float[][]
374
          {
375
             { 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
376
             { -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
377
             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
378
          };
379

    
380
      mStickers = new ObjectSticker[STICKERS.length];
381
      final float R1 = 0.05f;
382
      final float R2 = 0.10f;
383
      final float R3 = 0.03f;
384
      final float[][] radii  = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
385
      final float[] strokes = { 0.06f, 0.03f, 0.05f };
386

    
387
      for(int s=0; s<STICKERS.length; s++)
388
        {
389
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
390
        }
391
      }
392

    
393
    return mStickers[face/NUM_FACE_COLORS];
394
    }
395

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
// PUBLIC API
398

    
399
  public Static3D[] getRotationAxis()
400
    {
401
    return ROT_AXIS;
402
    }
403

    
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405

    
406
  public Movement getMovement()
407
    {
408
    if( mMovement==null )
409
      {
410
      int numLayers = getNumLayers();
411
      if( mCuts==null ) getCuts(numLayers);
412
      getLayerRotatable(numLayers);
413

    
414
      mMovement = new MovementJing(mCuts,mLayerRotatable,numLayers);
415
      }
416
    return mMovement;
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

    
421
  public int[] getBasicAngle()
422
    {
423
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
424
    return mBasicAngle;
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  public int getObjectName(int numLayers)
430
    {
431
    return R.string.jing;
432
    }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
  public int getInventor(int numLayers)
437
    {
438
    return R.string.jing_inventor;
439
    }
440

    
441
///////////////////////////////////////////////////////////////////////////////////////////////////
442

    
443
  public int getComplexity(int numLayers)
444
    {
445
    return 4;
446
    }
447
}
(34-34/48)