Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import static org.distorted.objectlib.main.Movement.MOVEMENT_HEXAHEDRON;
24

    
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
import org.distorted.objectlib.main.ObjectControl;
33
import org.distorted.objectlib.main.ObjectType;
34
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ObjectSticker;
36
import org.distorted.objectlib.helpers.ScrambleState;
37
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
  public TwistyIvy(int[] numL, Static4D quat, Static3D move, Resources res)
65
    {
66
    super(numL, numL[0], quat, move, res);
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  public ScrambleState[] getScrambleStates()
72
    {
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
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  protected int getResource(int[] numLayers)
89
    {
90
    return R.raw.ivy_2;
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
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
  public int[] getSolvedQuats(int cubit, int[] numLayers)
118
    {
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
  public Static4D[] getQuats()
127
    {
128
    if( mQuats==null ) initializeQuats();
129
    return mQuats;
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  public int getSolvedFunctionIndex()
135
    {
136
    return 0;
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  public int getNumStickerTypes(int[] numLayers)
142
    {
143
    return NUM_STICKERS;
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  public float[][] getCuts(int[] numLayers)
149
    {
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
  public boolean[][] getLayerRotatable(int[] numLayers)
162
    {
163
    int numAxis = ROT_AXIS.length;
164
    boolean[][] layerRotatable = new boolean[numAxis][];
165

    
166
    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
      }
171

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

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

    
213
  public int getNumCubitFaces()
214
    {
215
    return 6;
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

    
220
  public float[][] getCubitPositions(int[] numLayers)
221
    {
222
    final float DIST_CORNER = numLayers[0]-1;
223
    final float DIST_CENTER = numLayers[0]-1;
224

    
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
  public ObjectShape getObjectShape(int variant)
244
    {
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
  public Static4D getQuat(int cubit, int[] numLayers)
399
    {
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
  public int getNumCubitVariants(int[] numLayers)
423
    {
424
    return 2;
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  public int getCubitVariant(int cubit, int[] numLayers)
430
    {
431
    return cubit<4 ? 0:1;
432
    }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
  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
    {
446
    if( mFaceMap==null )
447
      {
448
      mFaceMap = new int[][]
449
         {
450
           { 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
         };
462
      }
463

    
464
    return mFaceMap[cubit][face];
465
    }
466

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

    
469
  public ObjectSticker retSticker(int sticker)
470
    {
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

    
480
      if( ObjectControl.isInIconMode() )
481
        {
482
        float mult = 1.5f;
483
        strokes[0]*=mult;
484
        strokes[1]*=mult;
485
        }
486

    
487
      for(int s=0; s<NUM_STICKERS; s++) mStickers[s] = new ObjectSticker(STICKERS[s], angles[s],radii[s],strokes[s]);
488
      }
489

    
490
    return mStickers[sticker];
491
    }
492

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
510

    
511
  public ObjectType intGetObjectType(int[] numLayers)
512
    {
513
    return ObjectType.IVY_2;
514
    }
515

    
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517

    
518
  public int getObjectName(int[] numLayers)
519
    {
520
    return R.string.ivy2;
521
    }
522

    
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524

    
525
  public int getInventor(int[] numLayers)
526
    {
527
    return R.string.ivy2_inventor;
528
    }
529

    
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531

    
532
  public int getYearOfInvention(int[] numLayers)
533
    {
534
    return 2009;
535
    }
536

    
537
///////////////////////////////////////////////////////////////////////////////////////////////////
538

    
539
  public int getComplexity(int[] numLayers)
540
    {
541
    return 1;
542
    }
543
}
(12-12/25)