Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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
class TwistyUltimate extends Twisty12
37
{
38
  private static final float A = (float)Math.sqrt(21*SQ5+47);
39
  private static final float B = SQ6*(5*SQ5+11)/(6*A);
40
  private static final float C = SQ6*(  SQ5+ 2)/(3*A);
41
  private static final float D = SQ3/3;
42
  private static final float E = (SQ5+1)/4;
43
  private static final float F = (SQ5-1)/4;
44
  private static final float G = (SQ5+3)/4;
45

    
46
  static final Static3D[] ROT_AXIS = new Static3D[]
47
         {
48
           new Static3D( B,0,C ),
49
           new Static3D( C,B,0 ),
50
           new Static3D(-D,D,D ),
51
           new Static3D( 0,C,-B)
52
         };
53

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

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  TwistyUltimate(int size, Static4D quat, DistortedTexture texture,
66
                 MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
67
    {
68
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.ULTI, res, scrWidth);
69
    }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

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

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

    
85
    return mStates;
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  private void initializeQuats()
91
    {
92
    mQuats = new Static4D[]
93
         {
94
         new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
95
         new Static4D(-0.5f, 0.5f, 0.5f, 0.5f ),
96
         new Static4D( 0.5f,-0.5f,-0.5f, 0.5f ),
97
         new Static4D( 0.0f,    F,   -E, 0.5f ),
98
         new Static4D( 0.0f,   -F,    E, 0.5f ),
99
         new Static4D(    E, 0.0f,    F, 0.5f ),
100
         new Static4D(   -E, 0.0f,   -F, 0.5f ),
101
         new Static4D(    F,    E, 0.0f, 0.5f ),
102
         new Static4D(   -F,   -E, 0.0f, 0.5f ),
103
         new Static4D(    E,    F,-0.5f, 0.0f ),
104
         new Static4D( 0.5f,   -E,    F, 0.0f ),
105
         new Static4D(    F, 0.5f,    E, 0.0f )
106
         };
107
    }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

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

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  ObjectShape getObjectShape(int cubit, int numLayers)
121
    {
122
    int variant = getCubitVariant(cubit,numLayers);
123

    
124
    if( variant==0 )
125
      {
126
      double[][] vertices = new double[][]
127
         {
128
           { 0.0  , 0.0  , 0.0   },
129
           { -E   , E+0.5, -0.5  },
130
           {-0.5  , -E   , -E-0.5},
131
           { E+0.5, 0.5  , -E    },
132
           { 0.0  , 1    , -2*E-1},
133
           { 0.0  , 1    , 0.0   },
134
           { -E   ,-E+0.5, -0.5  },
135
           {  E   ,-E+0.5, -0.5  }
136
         };
137
      int[][] vert_indices = new int[][]
138
         {
139
           {6,0,5,1},
140
           {0,7,3,5},
141
           {0,6,2,7},
142
           {4,3,5,1},
143
           {4,2,7,3},
144
           {4,1,6,2},
145
         };
146

    
147
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
148
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
149
      float[][] corners   = new float[][] {  { 0.013f, 0.16f } };
150
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
151
      float[][] centers   = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
152
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
153
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
154
      }
155
    else if( variant==1 )
156
      {
157
      double[][] vertices = new double[][]
158
         {
159
            {         0.00,         0.00,         0.00},
160
            {       - 0.50,-SQ5/4 - 0.25,-SQ5/4 - 0.75},
161
            { SQ5/4 + 0.25,-SQ5/4 - 0.75,       + 0.50},
162
            { SQ5/4 + 0.75,       + 0.50,-SQ5/4 - 0.25},
163
            { SQ5/2 + 0.50,-SQ5/2 - 0.50,-SQ5/2 - 0.50},
164
            { SQ5/4 - 0.25,       + 0.50,-SQ5/4 - 0.25},
165
            {       - 0.50,-SQ5/4 - 0.25,-SQ5/4 + 0.25},
166
            { SQ5/4 + 0.25,-SQ5/4 + 0.25,       + 0.50}
167
         };
168
      int[][] vert_indices  = new int[][]
169
         {
170
           {6,0,5,1},
171
           {0,7,3,5},
172
           {0,6,2,7},
173
           {1,5,3,4},
174
           {3,7,2,4},
175
           {2,6,1,4},
176
         };
177

    
178
      float[][] bands     = new float[][] { {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
179
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
180
      float[][] corners   = new float[][] {  { 0.013f, 0.16f } };
181
      int[] cornerIndices = new int[] { 0, 0, 0, 0,-1, 0, 0, 0 };
182
      float[][] centers   = new float[][] { { 0.0f,-1.0f, -(SQ5+3)/2 } };
183
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
184
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
185
      }
186
    else
187
      {
188
      double[][] vertices = new double[][]
189
         {
190
           {  -E    ,-E+0.5,     0.5},
191
           {   E    , E-0.5,    -0.5},
192
           {-2*E    ,   0.0,     0.0},
193
           {     0.5, E    ,  -E-0.5},
194
           {  -E    ,-E-0.5,     0.5},
195
           {   E+0.5,  -0.5,  -E    },
196
           {-2*E    ,  -1.0,     0.0},
197
           {     1.0,   0.0,-2*E    },
198
           {-2*E+0.5, E    ,  -E-0.5},
199
           {     0.5,-E-1.0,  -E+0.5},
200
           {  -E    ,-E-0.5,-2*E-0.5}
201
         };
202
      int[][] vert_indices = new int[][]
203
         {
204
           {0,1,3,8,2},   // counterclockwise!
205
           {0,4,9,5,1},
206
           { 0,2,6,4},
207
           { 1,5,7,3},
208
           {10,9,4,6},
209
           {10,9,5,7},
210
           {10,8,3,7},
211
           {10,8,2,6}
212
         };
213

    
214
      float[][] bands     = new float[][] { {0.04f,17,0.5f,0.2f,5,2,2}, {0.03f,17,0.5f,0.2f,5,2,2}, {0.01f, 1,0.5f,0.2f,5,2,2} };
215
      int[] bandIndices   = new int[] { 0,0,1,1,2,2,2,2 };
216
      float[][] corners   = new float[][] { { 0.013f, 0.16f } };
217
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
218
      float[][] centers   = new float[][] { { -(SQ5+1)/4, 0.5f, -(SQ5+5)/4 } };
219
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
220
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
221
      }
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  Static4D getQuat(int cubit, int numLayers)
227
    {
228
    if( mQuats     ==null ) initializeQuats();
229
    if( mQuatIndex ==null ) mQuatIndex = new int[] { 0,6,1,2,0,4,6,5,0,1,4,9,5,2 };
230
    return mQuats[mQuatIndex[cubit]];
231
    }
232

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

    
235
  int getNumCubitVariants(int numLayers)
236
    {
237
    return 3;
238
    }
239

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

    
242
  int getCubitVariant(int cubit, int numLayers)
243
    {
244
    return cubit<4 ? 0 : (cubit<8 ? 1:2);
245
    }
246

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

    
249
  float[][] getCubitPositions(int numLayers)
250
    {
251
    if( mCenters==null )
252
      {
253
      mCenters = new float[][]
254
         {
255
           {   0,  -1, 2*G },
256
           { 2*E,-2*E,-2*E },
257
           {-2*G,   0,  -1 },
258
           {   1, 2*G,   0 },
259

    
260
           {-2*E,  2*E, 2*E },
261
           { 2*G,    0,   1 },
262
           {  -1, -2*G,   0 },
263
           {   0,    1,-2*G },
264

    
265
           {        E, (E+0.5f),    (E+G) },
266
           {   -(E+G),       -E, (E+0.5f) },
267
           { (E+0.5f),   -(E+G),        E },
268
           {       -E,-(E+0.5f),   -(E+G) },
269
           {    (E+G),        E,-(E+0.5f) },
270
           {-(E+0.5f),    (E+G),       -E }
271
         };
272
      }
273

    
274
    return mCenters;
275
    }
276

    
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

    
279
  int getFaceColor(int cubit, int cubitface, int size)
280
    {
281
    if( mFaceMap==null )
282
      {
283
      mFaceMap = new int[][]
284
         {
285
           { 25,24,35, 36,36,36,36,36 },
286
           { 27,28,29, 36,36,36,36,36 },
287
           { 31,26,30, 36,36,36,36,36 },
288
           { 32,34,33, 36,36,36,36,36 },
289

    
290
           { 31,32,25, 36,36,36,36,36 },
291
           { 33,28,24, 36,36,36,36,36 },
292
           { 26,35,27, 36,36,36,36,36 },
293
           { 30,29,34, 36,36,36,36,36 },
294

    
295
           {  8, 0,13,21, 36,36,36,36 },
296
           {  1, 2,19,23, 36,36,36,36 },
297
           {  4,11,12,15, 36,36,36,36 },
298
           {  3, 6,14,17, 36,36,36,36 },
299
           {  5, 9,22,16, 36,36,36,36 },
300
           {  7,10,20,18, 36,36,36,36 }
301
         };
302
      }
303

    
304
    return mFaceMap[cubit][cubitface];
305
    }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

    
309
  ObjectSticker retSticker(int face)
310
    {
311
    if( mStickers==null )
312
      {
313
      float[][] STICKERS = new float[][]
314
         {
315
           { -0.14400357f, -0.47894150f, 0.50000000f,-0.011045523f, 0.37700626f, 0.36749030f,-0.26699730f, 0.36749026f, -0.46600536f, -0.24499352f }, // Big cubit 1st
316
           {  0.36327127f,  0.26393202f,-0.36327127f, 0.500000000f,-0.36327127f,-0.26393202f, 0.36327127f,-0.50000000f },                             // Big cubit 2nd
317
           { -0.29389262f, -0.50000000f, 0.29389262f,-0.309017000f, 0.29389262f, 0.30901700f,-0.29389262f, 0.50000000f },                             // Small cubit 1st
318
         };
319

    
320
      final float R1 = 0.08f;
321
      final float R2 = 0.13f;
322
      final float R3 = 0.11f;
323
      final float[][] radii  = { {R1,R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3} };
324
      final float[] strokes = { 0.07f, 0.09f, 0.08f };
325

    
326
      mStickers = new ObjectSticker[STICKERS.length];
327

    
328
      for(int s=0; s<STICKERS.length; s++)
329
        {
330
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
331
        }
332
      }
333

    
334
    return mStickers[face/NUM_FACE_COLORS];
335
    }
336

    
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

    
339
  Static4D[] getQuats()
340
    {
341
    if( mQuats==null ) initializeQuats();
342
    return mQuats;
343
    }
344

    
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346

    
347
  int getSolvedFunctionIndex()
348
    {
349
    return 0;
350
    }
351

    
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

    
354
  float[][] getCuts(int numLayers)
355
    {
356
    float[] cut = new float[] {0.0f};
357
    return new float[][] { cut,cut,cut,cut };
358
    }
359

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

    
362
  int getNumStickerTypes(int numLayers)
363
    {
364
    return 3;
365
    }
366

    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368

    
369
  int getNumCubitFaces()
370
    {
371
    return 8;
372
    }
373

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375
// PUBLIC API
376

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

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

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

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

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

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

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

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

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

    
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413

    
414
  public int getComplexity(int numLayers)
415
    {
416
    return 6;
417
    }
418
}
(48-48/48)