Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyJing.java @ 668423be

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.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
import org.distorted.main.R;
32

    
33
import java.util.Random;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class TwistyJing extends TwistyObject
38
{
39
  static final float F = 0.24f;  // length of the edge of the corner cubit divided by
40
                                 // the length of the edge of the whole tetrahedron.
41
                                 // keep < 0.25.
42

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

    
51
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
52

    
53
  private static final int[] FACE_COLORS = new int[]
54
         {
55
           COLOR_GREEN , COLOR_YELLOW,
56
           COLOR_BLUE  , COLOR_RED
57
         };
58

    
59
  private static final int[] ROT_QUAT = {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
60

    
61
  // computed with res/raw/compute_quats.c
62
  private static final Static4D[] QUATS = new Static4D[]
63
         {
64
           new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
65
           new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
66
           new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
67
           new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
68
           new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
69
           new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
70
           new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
71
           new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
72
           new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
73
           new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
74
           new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
75
           new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
76
         };
77

    
78
  static final float[][] CENTERS = new float[][]
79
         {
80
           { 0.000f, -SQ2/4, 0.500f },
81
           { 0.000f, -SQ2/4,-0.500f },
82
           {-0.500f,  SQ2/4, 0.000f },
83
           { 0.500f,  SQ2/4, 0.000f },
84

    
85
           { 0.000f, -SQ2/4, 0.000f },
86
           {-0.250f, 0.000f, 0.250f },
87
           { 0.250f, 0.000f, 0.250f },
88
           {-0.250f, 0.000f,-0.250f },
89
           { 0.250f, 0.000f,-0.250f },
90
           { 0.000f,  SQ2/4, 0.000f },
91

    
92
           { 0.000f, SQ2/12, 1.0f/6 },
93
           { 0.000f, SQ2/12,-1.0f/6 },
94
           {-1.0f/6,-SQ2/12, 0.000f },
95
           { 1.0f/6,-SQ2/12, 0.000f },
96
         };
97

    
98
  // Colors of the faces of cubits.
99
  // GREEN 0 YELLOW 1 BLUE  2 RED 3
100
  // GREEN 4 YELLOW 5 BLUE  6 RED 7
101
  // GREEN 8 YELLOW 9 BLUE 10 RED 11
102
  private static final int[][] mFaceMap = new int[][]
103
         {
104
           {  0,  3,  2, 12, 12, 12 },
105
           {  1,  2,  3, 12, 12, 12 },
106
           {  1,  0,  2, 12, 12, 12 },
107
           {  1,  3,  0, 12, 12, 12 },
108

    
109
           {  7,  6, 12, 12, 12, 12 },
110
           {  4,  6, 12, 12, 12, 12 },
111
           {  7,  4, 12, 12, 12, 12 },
112
           {  5,  6, 12, 12, 12, 12 },
113
           {  7,  5, 12, 12, 12, 12 },
114
           {  4,  5, 12, 12, 12, 12 },
115

    
116
           {  8, 12, 12, 12, 12, 12 },
117
           {  9, 12, 12, 12, 12, 12 },
118
           { 10, 12, 12, 12, 12, 12 },
119
           { 11, 12, 12, 12, 12, 12 },
120
         };
121

    
122
  private static final float X = F/2;
123
  private static final float Y = F*SQ2/2;
124
  private static final float Z =-F/2;
125
  private static final float L = (1-3*F);
126
  private static final float X2= L/2;
127
  private static final float Y2= L*SQ2/2;
128
  private static final float Z2=-L/2;
129
  private static final float D = F/L;
130

    
131
  private static final double[][] VERTICES_CORNER = new double[][]
132
          {
133
             { 0.0, 0.0, 0.0 },
134
             {   X,   Y,   Z },
135
             { 0.0, 2*Y, 2*Z },
136
             {  -X,   Y,   Z },
137
             { 0.0, 0.0,    -F },
138
             {   X,   Y,   Z-F },
139
             { 0.0, 2*Y, 2*Z-F },
140
             {  -X,   Y,   Z-F },
141
          };
142

    
143
  private static final int[][] VERT_INDEXES_CORNER = new int[][]
144
          {
145
             {0,1,2,3},
146
             {1,0,4,5},
147
             {7,4,0,3},
148
             {1,5,6,2},
149
             {7,3,2,6},
150
             {4,7,6,5}
151
          };
152

    
153
  private static final double[][] VERTICES_EDGE = new double[][]
154
          {
155
             { 0.0, 0.0,     0.5-F },
156
             {   X,   Y,   Z+0.5-F },
157
             { 0.0, 2*Y, 2*Z+0.5-F },
158
             {  -X,   Y,   Z+0.5-F },
159
             { 0.0, 0.0,    -0.5+F },
160
             {   X,   Y,  -Z-0.5+F },
161
             { 0.0, 2*Y,-2*Z-0.5+F },
162
             {  -X,   Y,  -Z-0.5+F },
163
          };
164

    
165
  private static final int[][] VERT_INDEXES_EDGE = new int[][]
166
          {
167
             {0,4,5,1},
168
             {3,7,4,0},
169
             {0,1,2,3},
170
             {4,7,6,5},
171
             {1,5,6,2},
172
             {2,6,7,3}
173
          };
174

    
175
  private static final double[][] VERTICES_FACE = new double[][]
176
          {
177
             {    0.0,     -2*Y2/3,   -2*Z2/3 },
178
             {      X2,       Y2/3,      Z2/3 },
179
             {     -X2,       Y2/3,      Z2/3 },
180
             {    0.0,     -2*Y2/3,-2*Z2/3+2*D*Z2 },
181
             {  X2-D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
182
             { -X2+D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
183
          };
184

    
185
  private static final int[][] VERT_INDEXES_FACE = new int[][]
186
          {
187
             {0,1,2},
188
             {3,5,4},
189
             {0,3,4,1},
190
             {5,3,0,2},
191
             {4,5,2,1}
192
          };
193

    
194
  private static final float[][] STICKERS = new float[][]
195
          {
196
             { 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
197
             { -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
198
             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
199
          };
200

    
201
  private static final ObjectSticker[] mStickers;
202

    
203
  static
204
    {
205
    mStickers = new ObjectSticker[STICKERS.length];
206
    final float R1 = 0.05f;
207
    final float R2 = 0.10f;
208
    final float R3 = 0.03f;
209
    final float[][] radii  = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
210
    final float[] strokes = { 0.06f, 0.03f, 0.05f };
211

    
212
    for(int s=0; s<STICKERS.length; s++)
213
      {
214
      mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
215
      }
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

    
220
  TwistyJing(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
221
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
222
    {
223
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.JING, res, scrWidth);
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
  float[][] getCubitPositions(int size)
229
    {
230
    return CENTERS;
231
    }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
  Static4D[] getQuats()
236
    {
237
    return QUATS;
238
    }
239

    
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

    
242
  int getNumFaces()
243
    {
244
    return FACE_COLORS.length;
245
    }
246

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

    
249
  int getNumStickerTypes(int numLayers)
250
    {
251
    return STICKERS.length;
252
    }
253

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

    
256
  float[][] getCuts(int size)
257
    {
258
    float[] cut = { (F-0.25f)*(SQ6/3) };
259
    return new float[][] { cut,cut,cut,cut };
260
    }
261

    
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

    
264
  int getNumCubitFaces()
265
    {
266
    return 6;
267
    }
268

    
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270

    
271
  float getScreenRatio()
272
    {
273
    return 2*TwistyPyraminx.SCREEN_RATIO;
274
    }
275

    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

    
278
  boolean shouldResetTextureMaps()
279
    {
280
    return false;
281
    }
282

    
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

    
285
  int getFaceColor(int cubit, int cubitface, int size)
286
    {
287
    return mFaceMap[cubit][cubitface];
288
    }
289

    
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

    
292
  ObjectShape getObjectShape(int cubit, int numLayers)
293
    {
294
    int variant = getCubitVariant(cubit,numLayers);
295

    
296
    if( variant==0 )
297
      {
298
      float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
299
      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
      float[][] centers   = new float[][] { { 0.0f, F*SQ2/2, -F} };
303
      int[] centerIndices = new int[] { 0,0,0,-1,0,-1,-1,-1 };
304
      return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
305
      }
306
    else if( variant==1 )
307
      {
308
      float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
309
      int[] bandIndices   = new int[] { 0,0,1,1,1,1 };
310
      float[][] corners   = new float[][] { {0.07f,0.20f*F} };
311
      int[] cornerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
312
      float[][] centers   = new float[][] { { 0, F*SQ2/2, 0 } };
313
      int[] centerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
314
      return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
315
      }
316
    else
317
      {
318
      float[][] bands     = new float[][] { {0.020f,35,0.20f*(1-3*F),0.6f*(1-3*F),5,1,1}, {0.001f,35,0.05f*(1-3*F),0.1f*(1-3*F),5,1,1} };
319
      int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
320
      float[][] corners   = new float[][] { {0.04f,0.15f} };
321
      int[] cornerIndices = new int[] { 0,0,0,-1,-1,-1 };
322
      float[][] centers   = new float[][] { { 0, -2*Y/3, 4*Z/3 } };
323
      int[] centerIndices = new int[] { 0,0,0,-1,-1,-1 };
324
      return new ObjectShape(VERTICES_FACE,VERT_INDEXES_FACE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
325
      }
326
    }
327

    
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329

    
330
  Static4D getQuat(int cubit, int numLayers)
331
    {
332
    return QUATS[ROT_QUAT[cubit]];
333
    }
334

    
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336

    
337
  int getNumCubitVariants(int numLayers)
338
    {
339
    return 3;
340
    }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343

    
344
  int getCubitVariant(int cubit, int numLayers)
345
    {
346
    return cubit<4 ? 0 : (cubit<10?1:2);
347
    }
348

    
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350

    
351
  int getColor(int face)
352
    {
353
    return FACE_COLORS[face];
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

    
358
  ObjectSticker retSticker(int face)
359
    {
360
    return mStickers[face/NUM_FACES];
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364
// SQ6/3 = height of the tetrahedron
365

    
366
  float returnMultiplier()
367
    {
368
    return getNumLayers()/(SQ6/3);
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372
// PUBLIC API
373

    
374
  public Static3D[] getRotationAxis()
375
    {
376
    return ROT_AXIS;
377
    }
378

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

    
381
  public int[] getBasicAngle()
382
    {
383
    return BASIC_ANGLE;
384
    }
385

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

    
388
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
389
    {
390
    if( curr==0 )
391
      {
392
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
393
      }
394
    else
395
      {
396
      int newVector = rnd.nextInt(NUM_AXIS-1);
397
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
398
      }
399

    
400
    scramble[curr][1] = rnd.nextInt(2);
401

    
402
    switch( rnd.nextInt(2) )
403
      {
404
      case 0: scramble[curr][2] = -1; break;
405
      case 1: scramble[curr][2] =  1; break;
406
      }
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410
// JingPyraminx is solved iff
411
// a) all of its corner and edge cubits are rotated with the same quat
412
// b) its 4 face cubits might also be rotated along the axis perpendicular to the face.
413
//
414
// So:
415
// [10] might be extra QUAT[4] or QUAT[8]
416
// [11] might be extra QUAT[5] or QUAT[9]
417
// [12] might be extra QUAT[2] or QUAT[6]
418
// [13] might be extra QUAT[3] or QUAT[7]
419

    
420
  public boolean isSolved()
421
    {
422
    int q1, q = CUBITS[0].mQuatIndex;
423

    
424
    if( CUBITS[1].mQuatIndex != q ) return false;
425
    if( CUBITS[2].mQuatIndex != q ) return false;
426
    if( CUBITS[3].mQuatIndex != q ) return false;
427
    if( CUBITS[4].mQuatIndex != q ) return false;
428
    if( CUBITS[5].mQuatIndex != q ) return false;
429
    if( CUBITS[6].mQuatIndex != q ) return false;
430
    if( CUBITS[7].mQuatIndex != q ) return false;
431
    if( CUBITS[8].mQuatIndex != q ) return false;
432
    if( CUBITS[9].mQuatIndex != q ) return false;
433

    
434
    q1 = CUBITS[10].mQuatIndex;
435
    if( q1!=q && q1!=mulQuat(q,4) && q1!=mulQuat(q,8) ) return false;
436
    q1 = CUBITS[11].mQuatIndex;
437
    if( q1!=q && q1!=mulQuat(q,5) && q1!=mulQuat(q,9) ) return false;
438
    q1 = CUBITS[12].mQuatIndex;
439
    if( q1!=q && q1!=mulQuat(q,2) && q1!=mulQuat(q,6) ) return false;
440
    q1 = CUBITS[13].mQuatIndex;
441
    if( q1!=q && q1!=mulQuat(q,3) && q1!=mulQuat(q,7) ) return false;
442

    
443
    return true;
444
    }
445

    
446
///////////////////////////////////////////////////////////////////////////////////////////////////
447

    
448
  public int getObjectName(int numLayers)
449
    {
450
    return R.string.jing;
451
    }
452

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

    
455
  public int getInventor(int numLayers)
456
    {
457
    return R.string.jing_inventor;
458
    }
459

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

    
462
  public int getComplexity(int numLayers)
463
    {
464
    return 4;
465
    }
466
}
(29-29/41)