Project

General

Profile

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

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

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 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
  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

    
56
  private ScrambleState[] mStates;
57
  private int[] mBasicAngle;
58
  private int[] mRotQuat;
59
  private Static4D[] mQuats;
60
  private float[][] mCenters;
61
  private int[][] mFaceMap;
62
  private ObjectSticker[] mStickers;
63
  private Movement mMovement;
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  TwistyJing(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
68
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
69
    {
70
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.JING, res, scrWidth);
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  ScrambleState[] getScrambleStates()
76
    {
77
    if( mStates==null )
78
      {
79
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
80

    
81
      mStates = new ScrambleState[]
82
        {
83
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
84
        };
85
      }
86

    
87
    return mStates;
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  private void initializeQuats()
93
    {
94
    mQuats = new Static4D[]
95
         {
96
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
97
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
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.5f,   0.0f, -0.5f),
103
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
104
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
105
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
106
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
107
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
108
         };
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  int[] getSolvedQuats(int cubit, int numLayers)
114
    {
115
    if( mQuats==null ) initializeQuats();
116
    int status = retCubitSolvedStatus(cubit,numLayers);
117
    return status<0 ? null : buildSolvedQuats(MovementJing.FACE_AXIS[status],mQuats);
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  float[][] getCubitPositions(int size)
123
    {
124
    if( mCenters==null )
125
      {
126
      mCenters = new float[][]
127
         {
128
           { 0.000f, -SQ2/2, 1.000f },
129
           { 0.000f, -SQ2/2,-1.000f },
130
           {-1.000f,  SQ2/2, 0.000f },
131
           { 1.000f,  SQ2/2, 0.000f },
132

    
133
           { 0.000f, -SQ2/2, 0.000f },
134
           {-0.500f, 0.000f, 0.500f },
135
           { 0.500f, 0.000f, 0.500f },
136
           {-0.500f, 0.000f,-0.500f },
137
           { 0.500f, 0.000f,-0.500f },
138
           { 0.000f,  SQ2/2, 0.000f },
139

    
140
           { 0.000f,  SQ2/6, 1.0f/3 },
141
           { 0.000f,  SQ2/6,-1.0f/3 },
142
           {-1.0f/3, -SQ2/6, 0.000f },
143
           { 1.0f/3, -SQ2/6, 0.000f },
144
         };
145
      }
146

    
147
    return mCenters;
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  Static4D[] getQuats()
153
    {
154
    if( mQuats==null ) initializeQuats();
155
    return mQuats;
156
    }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

    
160
  int getNumFaceColors()
161
    {
162
    return FACE_COLORS.length;
163
    }
164

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

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

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

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

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

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

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

    
189
  int getNumCubitFaces()
190
    {
191
    return 6;
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

    
196
  float getScreenRatio()
197
    {
198
    return 0.88f;
199
    }
200

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

    
203
  boolean shouldResetTextureMaps()
204
    {
205
    return false;
206
    }
207

    
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209

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

    
225
           {  7,  6, 12, 12, 12, 12 },
226
           {  4,  6, 12, 12, 12, 12 },
227
           {  7,  4, 12, 12, 12, 12 },
228
           {  5,  6, 12, 12, 12, 12 },
229
           {  7,  5, 12, 12, 12, 12 },
230
           {  4,  5, 12, 12, 12, 12 },
231

    
232
           {  8, 12, 12, 12, 12, 12 },
233
           {  9, 12, 12, 12, 12, 12 },
234
           { 10, 12, 12, 12, 12, 12 },
235
           { 11, 12, 12, 12, 12, 12 },
236
         };
237
      }
238

    
239
    return mFaceMap[cubit][cubitface];
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
  ObjectShape getObjectShape(int cubit, int numLayers)
245
    {
246
    int variant = getCubitVariant(cubit,numLayers);
247

    
248
    final float X = F/2;
249
    final float Y = F*SQ2/2;
250
    final float Z =-F/2;
251
    final float L = (2.0f-3*F);
252
    final float X2= L/2;
253
    final float Y2= L*SQ2/2;
254
    final float Z2=-L/2;
255
    final float D = F/L;
256
    final float G = 1.0f-F;
257

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

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

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

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

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351

    
352
  Static4D getQuat(int cubit, int numLayers)
353
    {
354
    if( mQuats==null ) initializeQuats();
355
    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
356
    return mQuats[mRotQuat[cubit]];
357
    }
358

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360

    
361
  int getNumCubitVariants(int numLayers)
362
    {
363
    return 3;
364
    }
365

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

    
368
  int getCubitVariant(int cubit, int numLayers)
369
    {
370
    return cubit<4 ? 0 : (cubit<10?1:2);
371
    }
372

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

    
375
  int getColor(int face)
376
    {
377
    return FACE_COLORS[face];
378
    }
379

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

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

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

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

    
406
    return mStickers[face/NUM_FACE_COLORS];
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410
// SQ6/3 = height of the tetrahedron
411

    
412
  float returnMultiplier()
413
    {
414
    return getNumLayers()/(SQ6/3);
415
    }
416

    
417
///////////////////////////////////////////////////////////////////////////////////////////////////
418
// PUBLIC API
419

    
420
  public Static3D[] getRotationAxis()
421
    {
422
    return ROT_AXIS;
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

    
427
  public Movement getMovement()
428
    {
429
    if( mMovement==null ) mMovement = new MovementJing();
430
    return mMovement;
431
    }
432

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

    
435
  public int[] getBasicAngle()
436
    {
437
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
438
    return mBasicAngle;
439
    }
440

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

    
443
  public int getObjectName(int numLayers)
444
    {
445
    return R.string.jing;
446
    }
447

    
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449

    
450
  public int getInventor(int numLayers)
451
    {
452
    return R.string.jing_inventor;
453
    }
454

    
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456

    
457
  public int getComplexity(int numLayers)
458
    {
459
    return 4;
460
    }
461
}
(30-30/44)