Project

General

Profile

Download (16.9 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyIvy.java @ e26eb4e7

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.objectlib.objects;
21
22
import static org.distorted.objectlib.main.Movement.TYPE_SPLIT_CORNER;
23 59c20632 Leszek Koltunski
import static org.distorted.objectlib.main.Movement.MOVEMENT_HEXAHEDRON;
24 29b82486 Leszek Koltunski
25
import android.content.res.Resources;
26
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29
30
import org.distorted.objectlib.R;
31
import org.distorted.objectlib.main.Movement6;
32 8592461c Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
33 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
34 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ObjectSticker;
36
import org.distorted.objectlib.helpers.ScrambleState;
37 29b82486 Leszek Koltunski
import org.distorted.objectlib.main.Twisty6;
38
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41
public class TwistyIvy extends Twisty6
42
{
43
  static final Static3D[] ROT_AXIS = new Static3D[]
44
         {
45
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
46
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
47
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
48
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
49
         };
50
51
  private static final int NUM_STICKERS = 2;
52
  public static final float IVY_D = 0.006f;
53
  private static final int  IVY_N = 8;
54
55
  private ScrambleState[] mStates;
56
  private int[] mBasicAngle;
57
  private Static4D[] mQuats;
58
  private float[][] mCuts;
59
  private int[][] mFaceMap;
60
  private ObjectSticker[] mStickers;
61
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
64 7ba38dd4 Leszek Koltunski
  public TwistyIvy(int[] numL, Static4D quat, Static3D move, Resources res)
65 29b82486 Leszek Koltunski
    {
66 7ba38dd4 Leszek Koltunski
    super(numL, numL[0], quat, move, res);
67 29b82486 Leszek Koltunski
    }
68
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
71 f9a81f52 Leszek Koltunski
  public ScrambleState[] getScrambleStates()
72 29b82486 Leszek Koltunski
    {
73
    if( mStates==null )
74
      {
75
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
76
77
      mStates = new ScrambleState[]
78
        {
79
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
80
        };
81
      }
82
83
    return mStates;
84
    }
85
86 4e1dc313 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
87
88 a57e6870 Leszek Koltunski
  protected int getResource(int[] numLayers)
89 4e1dc313 Leszek Koltunski
    {
90 55fa6993 Leszek Koltunski
    return R.raw.ivy_2;
91 4e1dc313 Leszek Koltunski
    }
92
93 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
94
95
  private void initializeQuats()
96
    {
97
    mQuats = new Static4D[]
98
         {
99
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
100
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
101
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
102
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
103
104
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
105
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
106
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
107
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
108
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
109
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
110
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
111
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
112
         };
113
    }
114
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116
117 7b832206 Leszek Koltunski
  public int[] getSolvedQuats(int cubit, int[] numLayers)
118 29b82486 Leszek Koltunski
    {
119
    if( mQuats==null ) initializeQuats();
120
    int status = retCubitSolvedStatus(cubit,numLayers);
121
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status],mQuats);
122
    }
123
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125
126 1bb09f88 Leszek Koltunski
  public Static4D[] getQuats()
127 29b82486 Leszek Koltunski
    {
128
    if( mQuats==null ) initializeQuats();
129
    return mQuats;
130
    }
131
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133
134 59c20632 Leszek Koltunski
  public int getSolvedFunctionIndex()
135 29b82486 Leszek Koltunski
    {
136
    return 0;
137
    }
138
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140
141 1bb09f88 Leszek Koltunski
  public int getNumStickerTypes(int[] numLayers)
142 29b82486 Leszek Koltunski
    {
143
    return NUM_STICKERS;
144
    }
145
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147
148 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
149 29b82486 Leszek Koltunski
    {
150
    if( mCuts==null )
151
      {
152
      float[] cut = new float[] {0.0f};
153
      mCuts = new float[][] { cut,cut,cut,cut };
154
      }
155
156
    return mCuts;
157
    }
158
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
161 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
162 29b82486 Leszek Koltunski
    {
163 59c20632 Leszek Koltunski
    int numAxis = ROT_AXIS.length;
164
    boolean[][] layerRotatable = new boolean[numAxis][];
165 a57e6870 Leszek Koltunski
166 59c20632 Leszek Koltunski
    for(int i=0; i<numAxis; i++)
167
      {
168
      layerRotatable[i] = new boolean[numLayers[i]];
169
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
170 29b82486 Leszek Koltunski
      }
171 59c20632 Leszek Koltunski
172
    return layerRotatable;
173
    }
174
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176
177
  public int getMovementType()
178
    {
179
    return MOVEMENT_HEXAHEDRON;
180
    }
181
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183
184
  public int getMovementSplit()
185
    {
186
    return TYPE_SPLIT_CORNER;
187
    }
188
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190
191
  public int[][][] getEnabled()
192
    {
193
    return new int[][][]
194
      {
195
          {{0},{3},{3},{0}},
196
          {{2},{1},{1},{2}},
197
          {{2},{0},{0},{2}},
198
          {{1},{3},{3},{1}},
199
          {{0},{0},{1},{1}},
200
          {{2},{2},{3},{3}},
201
      };
202
    }
203
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205
206
  public float[] getDist3D(int[] numLayers)
207
    {
208
    return null;
209 29b82486 Leszek Koltunski
    }
210
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212
213 a75ae1ee Leszek Koltunski
  public int getNumCubitFaces()
214 29b82486 Leszek Koltunski
    {
215
    return 6;
216
    }
217
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
220 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
221 29b82486 Leszek Koltunski
    {
222 a57e6870 Leszek Koltunski
    final float DIST_CORNER = numLayers[0]-1;
223
    final float DIST_CENTER = numLayers[0]-1;
224 29b82486 Leszek Koltunski
225
    final float[][] CENTERS = new float[10][];
226
227
    CENTERS[0] = new float[] { DIST_CORNER, DIST_CORNER, DIST_CORNER };
228
    CENTERS[1] = new float[] {-DIST_CORNER, DIST_CORNER,-DIST_CORNER };
229
    CENTERS[2] = new float[] {-DIST_CORNER,-DIST_CORNER, DIST_CORNER };
230
    CENTERS[3] = new float[] { DIST_CORNER,-DIST_CORNER,-DIST_CORNER };
231
    CENTERS[4] = new float[] { DIST_CENTER,           0,           0 };
232
    CENTERS[5] = new float[] {-DIST_CENTER,           0,           0 };
233
    CENTERS[6] = new float[] {           0, DIST_CENTER,           0 };
234
    CENTERS[7] = new float[] {           0,-DIST_CENTER,           0 };
235
    CENTERS[8] = new float[] {           0,           0, DIST_CENTER };
236
    CENTERS[9] = new float[] {           0,           0,-DIST_CENTER };
237
238
    return CENTERS;
239
    }
240
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242
243 e30c522a Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
244 29b82486 Leszek Koltunski
    {
245
    if( variant==0 )
246
      {
247
      final float angle = (float)Math.PI/(2*IVY_N);
248
      final float CORR  = 1.0f - 2*IVY_D;
249
250
      float[][] centers= new float[][] { {-1.0f,-1.0f,-1.0f} };
251
      float[][] corners= new float[][] { {0.05f,0.20f}, {0.04f,0.20f} };
252
      int[] cornerIndices= new int[3*(IVY_N+1)+4];
253
      int[] centerIndices= new int[3*(IVY_N+1)+4];
254
      double[][] vertices= new double[3*(IVY_N+1)+4][3];
255
      int[][] vertIndices= new int[6][IVY_N+4];
256
      int[] bandIndices  = new int[] { 0,0,0,1,1,1 };
257
258
      float[][] bands =
259
        {
260
          {+0.015f,20,0.2f,0.5f,7,1,2},
261
          {-0.100f,20,0.2f,0.0f,2,1,2}
262
        };
263
264
      for(int i=0; i<3*(IVY_N+1); i++)
265
        {
266
        cornerIndices[i+4] = -1;
267
        centerIndices[i+4] = -1;
268
        }
269
270
      cornerIndices[0] = 1;
271
      cornerIndices[1] = 0;
272
      cornerIndices[2] = 0;
273
      cornerIndices[3] = 0;
274
275
      centerIndices[0] = 0;
276
      centerIndices[1] = 0;
277
      centerIndices[2] = 0;
278
      centerIndices[3] = 0;
279
280
      vertices[0][0] = 0.0;
281
      vertices[0][1] = 0.0;
282
      vertices[0][2] = 0.0;
283
      vertices[1][0] =-2.0;
284
      vertices[1][1] = 0.0;
285
      vertices[1][2] = 0.0;
286
      vertices[2][0] = 0.0;
287
      vertices[2][1] =-2.0;
288
      vertices[2][2] = 0.0;
289
      vertices[3][0] = 0.0;
290
      vertices[3][1] = 0.0;
291
      vertices[3][2] =-2.0;
292
293
      vertIndices[0][0] = 2;
294
      vertIndices[0][1] = 0;
295
      vertIndices[0][2] = 1;
296
      vertIndices[3][0] = 2;
297
      vertIndices[3][1] = 0;
298
      vertIndices[3][2] = 1;
299
300
      vertIndices[1][0] = 3;
301
      vertIndices[1][1] = 0;
302
      vertIndices[1][2] = 2;
303
      vertIndices[4][0] = 3;
304
      vertIndices[4][1] = 0;
305
      vertIndices[4][2] = 2;
306
307
      vertIndices[2][0] = 1;
308
      vertIndices[2][1] = 0;
309
      vertIndices[2][2] = 3;
310
      vertIndices[5][0] = 1;
311
      vertIndices[5][1] = 0;
312
      vertIndices[5][2] = 3;
313
314
      int N1 = 4;
315
      int N2 = N1 + IVY_N + 1;
316
      int N3 = N2 + IVY_N + 1;
317
318
      for(int i=0; i<=IVY_N; i++)
319
        {
320
        double cos1 = Math.cos((IVY_N-i)*angle);
321
        double sin1 = Math.sin((IVY_N-i)*angle);
322
        double cos2 = Math.cos((      i)*angle);
323
        double sin2 = Math.sin((      i)*angle);
324
325
        vertices[N1+i][0] = CORR*(2*cos1-1.0) - 1.0;
326
        vertices[N1+i][1] = CORR*(2*sin1-1.0) - 1.0;
327
        vertices[N1+i][2] = 0.0;
328
329
        vertices[N2+i][0] = 0.0;
330
        vertices[N2+i][1] = CORR*(2*sin2-1.0) - 1.0;
331
        vertices[N2+i][2] = CORR*(2*cos2-1.0) - 1.0;
332
333
        vertices[N3+i][0] = CORR*(2*cos2-1.0) - 1.0;
334
        vertices[N3+i][1] = 0.0;
335
        vertices[N3+i][2] = CORR*(2*sin2-1.0) - 1.0;
336
337
        vertIndices[0][i+3] = N1 + i;
338
        vertIndices[1][i+3] = N2 + i;
339
        vertIndices[2][i+3] = N3 + i;
340
        vertIndices[3][i+3] = N1 + i;
341
        vertIndices[4][i+3] = N2 + i;
342
        vertIndices[5][i+3] = N3 + i;
343
        }
344
345
      float C = 1.0f - SQ2/2;
346
      float[] convexCenter = new float[] {-C,-C,-C};
347
      return new ObjectShape(vertices,vertIndices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), convexCenter);
348
      }
349
    else
350
      {
351
      final float angle = (float)Math.PI/(2*IVY_N);
352
      final float CORR  = 1.0f - 2*IVY_D;
353
      double[][] vertices = new double[2*IVY_N][3];
354
      int[][] vert_indices = new int[2][2*IVY_N];
355
356
      int[] bandIndices= new int[] { 0,1 };
357
      int[] indexes    = new int[2*IVY_N];
358
      float[][] corners= new float[][] { {0.05f,0.20f} };
359
      float[][] centers= new float[][] { {-0.0f,-0.0f,-1.0f} };
360
361
      for(int i=0; i<IVY_N; i++)
362
        {
363
        double sin = Math.sin(i*angle);
364
        double cos = Math.cos(i*angle);
365
366
        vertices[i      ][0] = CORR*(1.0f-2*cos);
367
        vertices[i      ][1] = CORR*(1.0f-2*sin);
368
        vertices[i      ][2] = 0;
369
        vertices[i+IVY_N][0] = CORR*(2*cos-1.0f);
370
        vertices[i+IVY_N][1] = CORR*(2*sin-1.0f);
371
        vertices[i+IVY_N][2] = 0;
372
        }
373
374
      for(int i=0; i<2*IVY_N; i++)
375
        {
376
        vert_indices[0][i] = i;
377
        vert_indices[1][i] = 2*IVY_N-1-i;
378
        }
379
380
      for(int i=0; i<2*IVY_N; i++)
381
        {
382
        indexes[i] = -1;
383
        }
384
      indexes[0] = indexes[IVY_N] = 0;
385
386
      float[][] bands =
387
        {
388
          {+0.03f,35,0.5f,0.5f,5,0,0},
389
          {+0.10f,45,0.5f,0.0f,2,0,0}
390
        };
391
392
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,indexes,centers,indexes,getNumCubitFaces(), null);
393
      }
394
    }
395
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
398 7b832206 Leszek Koltunski
  public Static4D getQuat(int cubit, int[] numLayers)
399 29b82486 Leszek Koltunski
    {
400
    if( mQuats==null ) initializeQuats();
401
402
    switch(cubit)
403
      {
404
      case  0: return mQuats[0];
405
      case  1: return mQuats[2];
406
      case  2: return mQuats[3];
407
      case  3: return mQuats[1];
408
409
      case  4: return mQuats[8];
410
      case  5: return mQuats[11];
411
      case  6: return mQuats[10];
412
      case  7: return mQuats[9];
413
      case  8: return mQuats[0];
414
      case  9: return mQuats[2];
415
      }
416
417
    return mQuats[0];
418
    }
419
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421
422 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
423 29b82486 Leszek Koltunski
    {
424
    return 2;
425
    }
426
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428
429 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
430 29b82486 Leszek Koltunski
    {
431
    return cubit<4 ? 0:1;
432
    }
433
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435
436 a75ae1ee Leszek Koltunski
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
437
    {
438
    if( variant==0 ) return face<3 ? 0 : -1;
439
    else             return face<1 ? 1 : -1;
440
    }
441
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443
444
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
445 29b82486 Leszek Koltunski
    {
446
    if( mFaceMap==null )
447
      {
448
      mFaceMap = new int[][]
449
         {
450 a75ae1ee Leszek Koltunski
           { 4, 0, 2, -1,-1,-1 },
451
           { 5, 1, 2, -1,-1,-1 },
452
           { 4, 1, 3, -1,-1,-1 },
453
           { 5, 0, 3, -1,-1,-1 },
454
455
           { 0, -1,-1,-1,-1,-1 },
456
           { 1, -1,-1,-1,-1,-1 },
457
           { 2, -1,-1,-1,-1,-1 },
458
           { 3, -1,-1,-1,-1,-1 },
459
           { 4, -1,-1,-1,-1,-1 },
460
           { 5, -1,-1,-1,-1,-1 },
461 29b82486 Leszek Koltunski
         };
462
      }
463
464 a75ae1ee Leszek Koltunski
    return mFaceMap[cubit][face];
465 29b82486 Leszek Koltunski
    }
466
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468
469 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
470 29b82486 Leszek Koltunski
    {
471
    if( mStickers==null )
472
      {
473
      float[][] STICKERS = new float[][] { { 0.29258922f, -0.5f, 0.29258922f, 0.29258922f, -0.5f, 0.29258922f }, { -0.5f, 0.5f, 0.5f, -0.5f } };
474
      mStickers = new ObjectSticker[NUM_STICKERS];
475
      float D = (float)(Math.PI/4);
476
      final float[][] angles = { { 0,0,D },{ D,D } };
477
      final float[][] radii  = { { 0,0.04f,0 },{ 0.06f,0.06f } };
478
      final float[] strokes = { 0.03f, 0.08f };
479 8592461c Leszek Koltunski
480
      if( ObjectControl.isInIconMode() )
481
        {
482
        float mult = 1.5f;
483
        strokes[0]*=mult;
484
        strokes[1]*=mult;
485
        }
486
487 29b82486 Leszek Koltunski
      for(int s=0; s<NUM_STICKERS; s++) mStickers[s] = new ObjectSticker(STICKERS[s], angles[s],radii[s],strokes[s]);
488
      }
489
490 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
491
    }
492
493 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
494
// PUBLIC API
495
496
  public Static3D[] getRotationAxis()
497
    {
498
    return ROT_AXIS;
499
    }
500
501
///////////////////////////////////////////////////////////////////////////////////////////////////
502
503
  public int[] getBasicAngle()
504
    {
505
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
506
    return mBasicAngle;
507
    }
508
509 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
510
511 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
512 61aa85e4 Leszek Koltunski
    {
513 8005e762 Leszek Koltunski
    return ObjectType.IVY_2;
514 61aa85e4 Leszek Koltunski
    }
515
516 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
517
518 e26eb4e7 Leszek Koltunski
  public String getObjectName()
519 29b82486 Leszek Koltunski
    {
520 e26eb4e7 Leszek Koltunski
    return "Ivy Cube";
521 29b82486 Leszek Koltunski
    }
522
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524
525 e26eb4e7 Leszek Koltunski
  public String getInventor()
526 29b82486 Leszek Koltunski
    {
527 e26eb4e7 Leszek Koltunski
    return "Eitan Cher";
528 29b82486 Leszek Koltunski
    }
529
530 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
531
532 e26eb4e7 Leszek Koltunski
  public int getYearOfInvention()
533 59c20632 Leszek Koltunski
    {
534
    return 2009;
535
    }
536
537 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
538
539 e26eb4e7 Leszek Koltunski
  public int getComplexity()
540 29b82486 Leszek Koltunski
    {
541
    return 1;
542
    }
543
}