Project

General

Profile

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

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

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