Project

General

Profile

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

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

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 7b832206 Leszek Koltunski
  public 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 7b832206 Leszek Koltunski
  public 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 e30c522a Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
248 29b82486 Leszek Koltunski
    {
249
    if( variant==0 )
250
      {
251
      final float angle = (float)Math.PI/(2*IVY_N);
252
      final float CORR  = 1.0f - 2*IVY_D;
253
254
      float[][] centers= new float[][] { {-1.0f,-1.0f,-1.0f} };
255
      float[][] corners= new float[][] { {0.05f,0.20f}, {0.04f,0.20f} };
256
      int[] cornerIndices= new int[3*(IVY_N+1)+4];
257
      int[] centerIndices= new int[3*(IVY_N+1)+4];
258
      double[][] vertices= new double[3*(IVY_N+1)+4][3];
259
      int[][] vertIndices= new int[6][IVY_N+4];
260
      int[] bandIndices  = new int[] { 0,0,0,1,1,1 };
261
262
      float[][] bands =
263
        {
264
          {+0.015f,20,0.2f,0.5f,7,1,2},
265
          {-0.100f,20,0.2f,0.0f,2,1,2}
266
        };
267
268
      for(int i=0; i<3*(IVY_N+1); i++)
269
        {
270
        cornerIndices[i+4] = -1;
271
        centerIndices[i+4] = -1;
272
        }
273
274
      cornerIndices[0] = 1;
275
      cornerIndices[1] = 0;
276
      cornerIndices[2] = 0;
277
      cornerIndices[3] = 0;
278
279
      centerIndices[0] = 0;
280
      centerIndices[1] = 0;
281
      centerIndices[2] = 0;
282
      centerIndices[3] = 0;
283
284
      vertices[0][0] = 0.0;
285
      vertices[0][1] = 0.0;
286
      vertices[0][2] = 0.0;
287
      vertices[1][0] =-2.0;
288
      vertices[1][1] = 0.0;
289
      vertices[1][2] = 0.0;
290
      vertices[2][0] = 0.0;
291
      vertices[2][1] =-2.0;
292
      vertices[2][2] = 0.0;
293
      vertices[3][0] = 0.0;
294
      vertices[3][1] = 0.0;
295
      vertices[3][2] =-2.0;
296
297
      vertIndices[0][0] = 2;
298
      vertIndices[0][1] = 0;
299
      vertIndices[0][2] = 1;
300
      vertIndices[3][0] = 2;
301
      vertIndices[3][1] = 0;
302
      vertIndices[3][2] = 1;
303
304
      vertIndices[1][0] = 3;
305
      vertIndices[1][1] = 0;
306
      vertIndices[1][2] = 2;
307
      vertIndices[4][0] = 3;
308
      vertIndices[4][1] = 0;
309
      vertIndices[4][2] = 2;
310
311
      vertIndices[2][0] = 1;
312
      vertIndices[2][1] = 0;
313
      vertIndices[2][2] = 3;
314
      vertIndices[5][0] = 1;
315
      vertIndices[5][1] = 0;
316
      vertIndices[5][2] = 3;
317
318
      int N1 = 4;
319
      int N2 = N1 + IVY_N + 1;
320
      int N3 = N2 + IVY_N + 1;
321
322
      for(int i=0; i<=IVY_N; i++)
323
        {
324
        double cos1 = Math.cos((IVY_N-i)*angle);
325
        double sin1 = Math.sin((IVY_N-i)*angle);
326
        double cos2 = Math.cos((      i)*angle);
327
        double sin2 = Math.sin((      i)*angle);
328
329
        vertices[N1+i][0] = CORR*(2*cos1-1.0) - 1.0;
330
        vertices[N1+i][1] = CORR*(2*sin1-1.0) - 1.0;
331
        vertices[N1+i][2] = 0.0;
332
333
        vertices[N2+i][0] = 0.0;
334
        vertices[N2+i][1] = CORR*(2*sin2-1.0) - 1.0;
335
        vertices[N2+i][2] = CORR*(2*cos2-1.0) - 1.0;
336
337
        vertices[N3+i][0] = CORR*(2*cos2-1.0) - 1.0;
338
        vertices[N3+i][1] = 0.0;
339
        vertices[N3+i][2] = CORR*(2*sin2-1.0) - 1.0;
340
341
        vertIndices[0][i+3] = N1 + i;
342
        vertIndices[1][i+3] = N2 + i;
343
        vertIndices[2][i+3] = N3 + i;
344
        vertIndices[3][i+3] = N1 + i;
345
        vertIndices[4][i+3] = N2 + i;
346
        vertIndices[5][i+3] = N3 + i;
347
        }
348
349
      float C = 1.0f - SQ2/2;
350
      float[] convexCenter = new float[] {-C,-C,-C};
351
      return new ObjectShape(vertices,vertIndices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), convexCenter);
352
      }
353
    else
354
      {
355
      final float angle = (float)Math.PI/(2*IVY_N);
356
      final float CORR  = 1.0f - 2*IVY_D;
357
      double[][] vertices = new double[2*IVY_N][3];
358
      int[][] vert_indices = new int[2][2*IVY_N];
359
360
      int[] bandIndices= new int[] { 0,1 };
361
      int[] indexes    = new int[2*IVY_N];
362
      float[][] corners= new float[][] { {0.05f,0.20f} };
363
      float[][] centers= new float[][] { {-0.0f,-0.0f,-1.0f} };
364
365
      for(int i=0; i<IVY_N; i++)
366
        {
367
        double sin = Math.sin(i*angle);
368
        double cos = Math.cos(i*angle);
369
370
        vertices[i      ][0] = CORR*(1.0f-2*cos);
371
        vertices[i      ][1] = CORR*(1.0f-2*sin);
372
        vertices[i      ][2] = 0;
373
        vertices[i+IVY_N][0] = CORR*(2*cos-1.0f);
374
        vertices[i+IVY_N][1] = CORR*(2*sin-1.0f);
375
        vertices[i+IVY_N][2] = 0;
376
        }
377
378
      for(int i=0; i<2*IVY_N; i++)
379
        {
380
        vert_indices[0][i] = i;
381
        vert_indices[1][i] = 2*IVY_N-1-i;
382
        }
383
384
      for(int i=0; i<2*IVY_N; i++)
385
        {
386
        indexes[i] = -1;
387
        }
388
      indexes[0] = indexes[IVY_N] = 0;
389
390
      float[][] bands =
391
        {
392
          {+0.03f,35,0.5f,0.5f,5,0,0},
393
          {+0.10f,45,0.5f,0.0f,2,0,0}
394
        };
395
396
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,indexes,centers,indexes,getNumCubitFaces(), null);
397
      }
398
    }
399
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401
402 7b832206 Leszek Koltunski
  public Static4D getQuat(int cubit, int[] numLayers)
403 29b82486 Leszek Koltunski
    {
404
    if( mQuats==null ) initializeQuats();
405
406
    switch(cubit)
407
      {
408
      case  0: return mQuats[0];
409
      case  1: return mQuats[2];
410
      case  2: return mQuats[3];
411
      case  3: return mQuats[1];
412
413
      case  4: return mQuats[8];
414
      case  5: return mQuats[11];
415
      case  6: return mQuats[10];
416
      case  7: return mQuats[9];
417
      case  8: return mQuats[0];
418
      case  9: return mQuats[2];
419
      }
420
421
    return mQuats[0];
422
    }
423
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425
426 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
427 29b82486 Leszek Koltunski
    {
428
    return 2;
429
    }
430
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432
433 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
434 29b82486 Leszek Koltunski
    {
435
    return cubit<4 ? 0:1;
436
    }
437
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439
440 a57e6870 Leszek Koltunski
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
441 29b82486 Leszek Koltunski
    {
442
    if( mFaceMap==null )
443
      {
444
      mFaceMap = new int[][]
445
         {
446
           {  4, 0, 2, 12,12,12 },
447
           {  5, 1, 2, 12,12,12 },
448
           {  4, 1, 3, 12,12,12 },
449
           {  5, 0, 3, 12,12,12 },
450
451
           {  6, 12,12,12,12,12 },
452
           {  7, 12,12,12,12,12 },
453
           {  8, 12,12,12,12,12 },
454
           {  9, 12,12,12,12,12 },
455
           { 10, 12,12,12,12,12 },
456
           { 11, 12,12,12,12,12 },
457
         };
458
      }
459
460
    return mFaceMap[cubit][cubitface];
461
    }
462
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464
465 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
466 29b82486 Leszek Koltunski
    {
467
    if( mStickers==null )
468
      {
469
      float[][] STICKERS = new float[][] { { 0.29258922f, -0.5f, 0.29258922f, 0.29258922f, -0.5f, 0.29258922f }, { -0.5f, 0.5f, 0.5f, -0.5f } };
470
      mStickers = new ObjectSticker[NUM_STICKERS];
471
      float D = (float)(Math.PI/4);
472
      final float[][] angles = { { 0,0,D },{ D,D } };
473
      final float[][] radii  = { { 0,0.04f,0 },{ 0.06f,0.06f } };
474
      final float[] strokes = { 0.03f, 0.08f };
475 8592461c Leszek Koltunski
476
      if( ObjectControl.isInIconMode() )
477
        {
478
        float mult = 1.5f;
479
        strokes[0]*=mult;
480
        strokes[1]*=mult;
481
        }
482
483 29b82486 Leszek Koltunski
      for(int s=0; s<NUM_STICKERS; s++) mStickers[s] = new ObjectSticker(STICKERS[s], angles[s],radii[s],strokes[s]);
484
      }
485
486 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
487
    }
488
489 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
490
// PUBLIC API
491
492
  public Static3D[] getRotationAxis()
493
    {
494
    return ROT_AXIS;
495
    }
496
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498
499
  public int[] getBasicAngle()
500
    {
501
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
502
    return mBasicAngle;
503
    }
504
505 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
506
507 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
508 61aa85e4 Leszek Koltunski
    {
509 8005e762 Leszek Koltunski
    return ObjectType.IVY_2;
510 61aa85e4 Leszek Koltunski
    }
511
512 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
513
514 a57e6870 Leszek Koltunski
  public int getObjectName(int[] numLayers)
515 29b82486 Leszek Koltunski
    {
516
    return R.string.ivy2;
517
    }
518
519
///////////////////////////////////////////////////////////////////////////////////////////////////
520
521 a57e6870 Leszek Koltunski
  public int getInventor(int[] numLayers)
522 29b82486 Leszek Koltunski
    {
523
    return R.string.ivy2_inventor;
524
    }
525
526 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
527
528
  public int getYearOfInvention(int[] numLayers)
529
    {
530
    return 2009;
531
    }
532
533 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
534
535 a57e6870 Leszek Koltunski
  public int getComplexity(int[] numLayers)
536 29b82486 Leszek Koltunski
    {
537
    return 1;
538
    }
539
}