Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyJing.java @ 6cf89a3e

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
import java.util.Random;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
public class TwistyJing extends TwistyObject
39
{
40
  static final float F = 0.24f;  // length of the edge of the corner cubit divided by
41
                                 // the length of the edge of the whole tetrahedron.
42
                                 // keep < 0.25.
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[] BASIC_ANGLE = new int[] { 3,3,3,3 };
53

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
202
  private static final ObjectSticker[] mStickers;
203

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

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

    
219
  private int mCurrState;
220
  private int mIndexExcluded;
221
  private final ScrambleState[] mStates;
222

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

    
225
  TwistyJing(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
226
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
227
    {
228
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.JING, res, scrWidth);
229

    
230
    int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
231

    
232
    mStates = new ScrambleState[]
233
      {
234
      new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
235
      };
236
    }
237

    
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

    
240
  int[] getSolvedQuats(int cubit, int numLayers)
241
    {
242
    int status = retCubitSolvedStatus(cubit,numLayers);
243
    return status<0 ? null : buildSolvedQuats(MovementJing.FACE_AXIS[status],QUATS);
244
    }
245

    
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

    
248
  float[][] getCubitPositions(int size)
249
    {
250
    return CENTERS;
251
    }
252

    
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

    
255
  Static4D[] getQuats()
256
    {
257
    return QUATS;
258
    }
259

    
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

    
262
  int getNumFaces()
263
    {
264
    return FACE_COLORS.length;
265
    }
266

    
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

    
269
  int getSolvedFunctionIndex()
270
    {
271
    return 0;
272
    }
273

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

    
276
  int getNumStickerTypes(int numLayers)
277
    {
278
    return STICKERS.length;
279
    }
280

    
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

    
283
  float[][] getCuts(int size)
284
    {
285
    float[] cut = { (F-0.25f)*(SQ6/3) };
286
    return new float[][] { cut,cut,cut,cut };
287
    }
288

    
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

    
291
  int getNumCubitFaces()
292
    {
293
    return 6;
294
    }
295

    
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

    
298
  float getScreenRatio()
299
    {
300
    return 2*TwistyPyraminx.SCREEN_RATIO;
301
    }
302

    
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

    
305
  boolean shouldResetTextureMaps()
306
    {
307
    return false;
308
    }
309

    
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311

    
312
  int getFaceColor(int cubit, int cubitface, int size)
313
    {
314
    return mFaceMap[cubit][cubitface];
315
    }
316

    
317
///////////////////////////////////////////////////////////////////////////////////////////////////
318

    
319
  ObjectShape getObjectShape(int cubit, int numLayers)
320
    {
321
    int variant = getCubitVariant(cubit,numLayers);
322

    
323
    if( variant==0 )
324
      {
325
      float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
326
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
327
      float[][] corners   = new float[][] { {0.08f,0.20f*F},{0.07f,0.20f*F} };
328
      int[] cornerIndices = new int[] { 0,1,1,-1,1,-1,-1,-1 };
329
      float[][] centers   = new float[][] { { 0.0f, F*SQ2/2, -F} };
330
      int[] centerIndices = new int[] { 0,0,0,-1,0,-1,-1,-1 };
331
      return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
332
      }
333
    else if( variant==1 )
334
      {
335
      float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
336
      int[] bandIndices   = new int[] { 0,0,1,1,1,1 };
337
      float[][] corners   = new float[][] { {0.07f,0.20f*F} };
338
      int[] cornerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
339
      float[][] centers   = new float[][] { { 0, F*SQ2/2, 0 } };
340
      int[] centerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
341
      return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
342
      }
343
    else
344
      {
345
      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} };
346
      int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
347
      float[][] corners   = new float[][] { {0.04f,0.15f} };
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_FACE,VERT_INDEXES_FACE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
352
      }
353
    }
354

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

    
357
  Static4D getQuat(int cubit, int numLayers)
358
    {
359
    return QUATS[ROT_QUAT[cubit]];
360
    }
361

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

    
364
  int getNumCubitVariants(int numLayers)
365
    {
366
    return 3;
367
    }
368

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

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

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

    
378
  int getColor(int face)
379
    {
380
    return FACE_COLORS[face];
381
    }
382

    
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384

    
385
  ObjectSticker retSticker(int face)
386
    {
387
    return mStickers[face/NUM_FACES];
388
    }
389

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391
// SQ6/3 = height of the tetrahedron
392

    
393
  float returnMultiplier()
394
    {
395
    return getNumLayers()/(SQ6/3);
396
    }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399
// PUBLIC API
400

    
401
  public Static3D[] getRotationAxis()
402
    {
403
    return ROT_AXIS;
404
    }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
  public int[] getBasicAngle()
409
    {
410
    return BASIC_ANGLE;
411
    }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

    
415
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
416
    {
417
    if( curr==0 )
418
      {
419
      mCurrState     = 0;
420
      mIndexExcluded =-1;
421
      }
422

    
423
    int total = mStates[mCurrState].getTotal(mIndexExcluded);
424
    int random= rnd.nextInt(total);
425
    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
426

    
427
    scramble[curr][0] = info[0];
428
    scramble[curr][1] = info[1];
429
    scramble[curr][2] = info[2];
430

    
431
    mCurrState     = info[3];
432
    mIndexExcluded = info[0];
433
    }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

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

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

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

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450

    
451
  public int getComplexity(int numLayers)
452
    {
453
    return 4;
454
    }
455
}
(29-29/41)