Project

General

Profile

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

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

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