Project

General

Profile

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

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

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[][] mCenters;
55
  private int[][] mFaceMap;
56
  private ObjectSticker[] mStickers;
57
  private Movement mMovement;
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

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

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

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

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

    
81
    return mStates;
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

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

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

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

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

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

    
127
           { 0.000f, -SQ2/2, 0.000f },
128
           {-0.500f, 0.000f, 0.500f },
129
           { 0.500f, 0.000f, 0.500f },
130
           {-0.500f, 0.000f,-0.500f },
131
           { 0.500f, 0.000f,-0.500f },
132
           { 0.000f,  SQ2/2, 0.000f },
133

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

    
141
    return mCenters;
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

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

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
  int getSolvedFunctionIndex()
155
    {
156
    return 0;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  int getNumStickerTypes(int numLayers)
162
    {
163
    return 3;
164
    }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
  float[][] getCuts(int size)
169
    {
170
    float[] cut = { (F-0.5f)*(SQ6/3) };
171
    return new float[][] { cut,cut,cut,cut };
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  int getNumCubitFaces()
177
    {
178
    return 6;
179
    }
180

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

    
183
  int getFaceColor(int cubit, int cubitface, int size)
184
    {
185
    if( mFaceMap==null )
186
      {
187
      // Colors of the faces of cubits.
188
      // GREEN 0 YELLOW 1 BLUE  2 RED 3
189
      // GREEN 4 YELLOW 5 BLUE  6 RED 7
190
      // GREEN 8 YELLOW 9 BLUE 10 RED 11
191
      mFaceMap = new int[][]
192
         {
193
           {  0,  3,  2, 12, 12, 12 },
194
           {  1,  2,  3, 12, 12, 12 },
195
           {  1,  0,  2, 12, 12, 12 },
196
           {  1,  3,  0, 12, 12, 12 },
197

    
198
           {  7,  6, 12, 12, 12, 12 },
199
           {  4,  6, 12, 12, 12, 12 },
200
           {  7,  4, 12, 12, 12, 12 },
201
           {  5,  6, 12, 12, 12, 12 },
202
           {  7,  5, 12, 12, 12, 12 },
203
           {  4,  5, 12, 12, 12, 12 },
204

    
205
           {  8, 12, 12, 12, 12, 12 },
206
           {  9, 12, 12, 12, 12, 12 },
207
           { 10, 12, 12, 12, 12, 12 },
208
           { 11, 12, 12, 12, 12, 12 },
209
         };
210
      }
211

    
212
    return mFaceMap[cubit][cubitface];
213
    }
214

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

    
217
  ObjectShape getObjectShape(int cubit, int numLayers)
218
    {
219
    int variant = getCubitVariant(cubit,numLayers);
220

    
221
    final float X = F/2;
222
    final float Y = F*SQ2/2;
223
    final float Z =-F/2;
224
    final float L = (2.0f-3*F);
225
    final float X2= L/2;
226
    final float Y2= L*SQ2/2;
227
    final float Z2=-L/2;
228
    final float D = F/L;
229
    final float G = 1.0f-F;
230

    
231
    if( variant==0 )
232
      {
233
      double[][] vertices = new double[][]
234
          {
235
             { 0.0, 0.0, 0.0 },
236
             {   X,   Y,   Z },
237
             { 0.0, 2*Y, 2*Z },
238
             {  -X,   Y,   Z },
239
             { 0.0, 0.0,    -F },
240
             {   X,   Y,   Z-F },
241
             { 0.0, 2*Y, 2*Z-F },
242
             {  -X,   Y,   Z-F },
243
          };
244
      int[][] vert_indices = new int[][]
245
          {
246
             {0,1,2,3},
247
             {1,0,4,5},
248
             {7,4,0,3},
249
             {1,5,6,2},
250
             {7,3,2,6},
251
             {4,7,6,5}
252
          };
253

    
254
      float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
255
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
256
      float[][] corners   = new float[][] { {0.08f,0.20f*F},{0.07f,0.20f*F} };
257
      int[] cornerIndices = new int[] { 0,1,1,-1,1,-1,-1,-1 };
258
      float[][] centers   = new float[][] { { 0.0f, F*SQ2/2, -F} };
259
      int[] centerIndices = new int[] { 0,0,0,-1,0,-1,-1,-1 };
260
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
261
      }
262
    else if( variant==1 )
263
      {
264
      double[][] vertices = new double[][]
265
          {
266
             { 0.0, 0.0,     G },
267
             {   X,   Y,   Z+G },
268
             { 0.0, 2*Y, 2*Z+G },
269
             {  -X,   Y,   Z+G },
270
             { 0.0, 0.0,    -G },
271
             {   X,   Y,  -Z-G },
272
             { 0.0, 2*Y,-2*Z-G },
273
             {  -X,   Y,  -Z-G },
274
          };
275
      int[][] vert_indices = new int[][]
276
          {
277
             {0,4,5,1},
278
             {3,7,4,0},
279
             {0,1,2,3},
280
             {4,7,6,5},
281
             {1,5,6,2},
282
             {2,6,7,3}
283
          };
284

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

    
313
      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} };
314
      int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
315
      float[][] corners   = new float[][] { {0.04f,0.6f*F} };
316
      int[] cornerIndices = new int[] { 0,0,0,-1,-1,-1 };
317
      float[][] centers   = new float[][] { { 0, -2*Y/3, 4*Z/3 } };
318
      int[] centerIndices = new int[] { 0,0,0,-1,-1,-1 };
319
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
320
      }
321
    }
322

    
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324

    
325
  Static4D getQuat(int cubit, int numLayers)
326
    {
327
    if( mQuats==null ) initializeQuats();
328
    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
329
    return mQuats[mRotQuat[cubit]];
330
    }
331

    
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

    
334
  int getNumCubitVariants(int numLayers)
335
    {
336
    return 3;
337
    }
338

    
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340

    
341
  int getCubitVariant(int cubit, int numLayers)
342
    {
343
    return cubit<4 ? 0 : (cubit<10?1:2);
344
    }
345

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

    
348
  ObjectSticker retSticker(int face)
349
    {
350
    if( mStickers==null )
351
      {
352
      float[][] STICKERS = new float[][]
353
          {
354
             { 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
355
             { -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
356
             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
357
          };
358

    
359
      mStickers = new ObjectSticker[STICKERS.length];
360
      final float R1 = 0.05f;
361
      final float R2 = 0.10f;
362
      final float R3 = 0.03f;
363
      final float[][] radii  = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
364
      final float[] strokes = { 0.06f, 0.03f, 0.05f };
365

    
366
      for(int s=0; s<STICKERS.length; s++)
367
        {
368
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
369
        }
370
      }
371

    
372
    return mStickers[face/NUM_FACE_COLORS];
373
    }
374

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376
// PUBLIC API
377

    
378
  public Static3D[] getRotationAxis()
379
    {
380
    return ROT_AXIS;
381
    }
382

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

    
385
  public Movement getMovement()
386
    {
387
    if( mMovement==null ) mMovement = new MovementJing();
388
    return mMovement;
389
    }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

    
393
  public int[] getBasicAngle()
394
    {
395
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
396
    return mBasicAngle;
397
    }
398

    
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400

    
401
  public int getObjectName(int numLayers)
402
    {
403
    return R.string.jing;
404
    }
405

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

    
408
  public int getInventor(int numLayers)
409
    {
410
    return R.string.jing_inventor;
411
    }
412

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

    
415
  public int getComplexity(int numLayers)
416
    {
417
    return 4;
418
    }
419
}
(34-34/48)