Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.objects;
11

    
12
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
14

    
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17

    
18
import org.distorted.objectlib.helpers.FactoryCubit;
19
import org.distorted.objectlib.helpers.ObjectFaceShape;
20
import org.distorted.objectlib.signature.ObjectSignature;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitAssets;
23
import org.distorted.objectlib.signature.ObjectConstants;
24
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
25
import org.distorted.objectlib.main.InitData;
26
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
27
import org.distorted.objectlib.main.ObjectType;
28
import org.distorted.objectlib.helpers.ObjectShape;
29
import org.distorted.objectlib.shape.ShapeHexahedron;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class TwistyIvy extends ShapeHexahedron
34
{
35
  static final Static3D[] ROT_AXIS = new Static3D[]
36
         {
37
           new Static3D( SQ3/3, SQ3/3, SQ3/3),
38
           new Static3D( SQ3/3, SQ3/3,-SQ3/3),
39
           new Static3D( SQ3/3,-SQ3/3, SQ3/3),
40
           new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
41
         };
42

    
43
  public static final float IVY_D = 0.006f;
44
  private static final int  IVY_N = 8;
45

    
46
  private int[][] mEdges;
47
  private int[][] mBasicAngle;
48
  private float[][] mCuts;
49
  private int[] mQuatIndex;
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  public TwistyIvy(int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
54
    {
55
    super(iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
56
    }
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
  @Override
61
  public float[][] returnRotationFactor()
62
    {
63
    float C = 1.5f;
64
    float[] f = new float[] { C,C };
65
    return new float[][] { f,f,f,f };
66
    }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
// ditto, manually provide the sticker coordinates.
70

    
71
  @Override
72
  public void adjustStickerCoords()
73
    {
74
    final float A = 0.29258922f;
75
    final float B = 0.5f;
76
    final float H = 1.08f;
77
    final float C = H*0.41f;
78
    final float D = H*0.46f;
79

    
80
    mStickerCoords = new float[][][][]
81
          {
82
            { { { A,-B},{ A, A},{-B, A} } },
83
            { { {-C, C},{ D,-D} } }
84
          };
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  public int[][] getScrambleEdges()
90
    {
91
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
92
    return mEdges;
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  public float[][] getCuts(int[] numLayers)
98
    {
99
    if( mCuts==null )
100
      {
101
      float[] cut = new float[] {0.0f};
102
      mCuts = new float[][] { cut,cut,cut,cut };
103
      }
104

    
105
    return mCuts;
106
    }
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

    
110
  public boolean[][] getLayerRotatable(int[] numLayers)
111
    {
112
    int numAxis = ROT_AXIS.length;
113
    boolean[][] layerRotatable = new boolean[numAxis][];
114

    
115
    for(int i=0; i<numAxis; i++)
116
      {
117
      layerRotatable[i] = new boolean[numLayers[i]];
118
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
119
      }
120

    
121
    return layerRotatable;
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  public int getTouchControlType()
127
    {
128
    return TC_HEXAHEDRON;
129
    }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
  public int getTouchControlSplit()
134
    {
135
    return TYPE_SPLIT_CORNER;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  public int[][][] getEnabled()
141
    {
142
    return new int[][][]
143
      {
144
          {{0},{3},{3},{0}},
145
          {{2},{1},{1},{2}},
146
          {{2},{0},{0},{2}},
147
          {{1},{3},{3},{1}},
148
          {{0},{0},{1},{1}},
149
          {{2},{2},{3},{3}},
150
      };
151
    }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

    
155
  public float[] getDist3D(int[] numLayers)
156
    {
157
    return TouchControlHexahedron.D3D;
158
    }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

    
162
  public Static3D[] getFaceAxis()
163
    {
164
    return TouchControlHexahedron.FACE_AXIS;
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  public float[][] getCubitPositions(int[] numLayers)
170
    {
171
    final float DIST_CORNER = numLayers[0]-1;
172
    final float DIST_CENTER = numLayers[0]-1;
173

    
174
    return new float[][]
175
      {
176
        { DIST_CORNER, DIST_CORNER, DIST_CORNER },
177
        {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
178
        {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
179
        { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
180
        { DIST_CENTER,           0,           0 },
181
        {-DIST_CENTER,           0,           0 },
182
        {           0, DIST_CENTER,           0 },
183
        {           0,-DIST_CENTER,           0 },
184
        {           0,           0, DIST_CENTER },
185
        {           0,           0,-DIST_CENTER },
186
      };
187
    }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

    
191
  public Static4D getCubitQuats(int cubit, int[] numLayers)
192
    {
193
    if( mQuatIndex==null ) mQuatIndex = new int[] { 0,11,10, 9,
194
                                                    5, 8, 7, 6, 0, 11
195
                                                  };
196
    return mObjectQuats[mQuatIndex[cubit]];
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
  private float[][] getVertices(int variant)
202
    {
203
    final float angle = (float)Math.PI/(2*IVY_N);
204
    final float CORR  = 1-2*IVY_D;
205

    
206
    if( variant==0 )
207
      {
208
      final float A = 0.3f;
209
      final int N1 = 4;
210
      final int N2 = N1 + IVY_N + 1;
211
      final int N3 = N2 + IVY_N + 1;
212
      float[][] vertices= new float[3*(IVY_N+1)+5][3];
213

    
214
      vertices[3*(IVY_N+1)+4][0] = -A;
215
      vertices[3*(IVY_N+1)+4][1] = -A;
216
      vertices[3*(IVY_N+1)+4][2] = -A;
217

    
218
      vertices[0][0] = 0;
219
      vertices[0][1] = 0;
220
      vertices[0][2] = 0;
221
      vertices[1][0] =-2;
222
      vertices[1][1] = 0;
223
      vertices[1][2] = 0;
224
      vertices[2][0] = 0;
225
      vertices[2][1] =-2;
226
      vertices[2][2] = 0;
227
      vertices[3][0] = 0;
228
      vertices[3][1] = 0;
229
      vertices[3][2] =-2;
230

    
231
      for(int i=0; i<=IVY_N; i++)
232
        {
233
        float cos1 = (float)Math.cos((IVY_N-i)*angle);
234
        float sin1 = (float)Math.sin((IVY_N-i)*angle);
235
        float cos2 = (float)Math.cos((      i)*angle);
236
        float sin2 = (float)Math.sin((      i)*angle);
237

    
238
        vertices[N1+i][0] = CORR*(2*cos1-1) - 1;
239
        vertices[N1+i][1] = CORR*(2*sin1-1) - 1;
240
        vertices[N1+i][2] = 0;
241

    
242
        vertices[N2+i][0] = 0;
243
        vertices[N2+i][1] = CORR*(2*sin2-1) - 1;
244
        vertices[N2+i][2] = CORR*(2*cos2-1) - 1;
245

    
246
        vertices[N3+i][0] = CORR*(2*cos2-1) - 1;
247
        vertices[N3+i][1] = 0;
248
        vertices[N3+i][2] = CORR*(2*sin2-1) - 1;
249
        }
250

    
251
      return vertices;
252
      }
253
    else
254
      {
255
      float[][] vertices= new float[2*IVY_N+1][3];
256

    
257
      for(int i=0; i<IVY_N; i++)
258
        {
259
        float sin = (float)Math.sin(i*angle);
260
        float cos = (float)Math.cos(i*angle);
261

    
262
        vertices[i      ][0] = CORR*(1-2*cos);
263
        vertices[i      ][1] = CORR*(1-2*sin);
264
        vertices[i      ][2] = 0;
265
        vertices[i+IVY_N][0] = CORR*(2*cos-1);
266
        vertices[i+IVY_N][1] = CORR*(2*sin-1);
267
        vertices[i+IVY_N][2] = 0;
268
        }
269

    
270
      vertices[2*IVY_N][0] = 0.0f;
271
      vertices[2*IVY_N][1] = 0.0f;
272
      vertices[2*IVY_N][2] =-0.1f;
273

    
274
      return vertices;
275
      }
276
    }
277

    
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279

    
280
  public ObjectShape getObjectShape(int variant)
281
    {
282
    if( variant==0 )
283
      {
284
      int[][] indices = new int[3*IVY_N+3][];
285

    
286
      indices[0] = new int[IVY_N+4];
287
      indices[1] = new int[IVY_N+4];
288
      indices[2] = new int[IVY_N+4];
289

    
290
      indices[0][0] = 2;
291
      indices[0][1] = 0;
292
      indices[0][2] = 1;
293
      indices[1][0] = 3;
294
      indices[1][1] = 0;
295
      indices[1][2] = 2;
296
      indices[2][0] = 1;
297
      indices[2][1] = 0;
298
      indices[2][2] = 3;
299

    
300
      int N1 = 4;
301
      int N2 = N1 + IVY_N + 1;
302
      int N3 = N2 + IVY_N + 1;
303

    
304
      for(int i=0; i<=IVY_N; i++)
305
        {
306
        indices[0][i+3] = N1 + i;
307
        indices[1][i+3] = N2 + i;
308
        indices[2][i+3] = N3 + i;
309
        }
310

    
311
      for(int i=0; i<IVY_N; i++)
312
        {
313
        indices[3*i+3] = new int[] { N1+i+1, N1+i, 3*(IVY_N+1)+4 };
314
        indices[3*i+4] = new int[] { N2+i+1, N2+i, 3*(IVY_N+1)+4 };
315
        indices[3*i+5] = new int[] { N3+i+1, N3+i, 3*(IVY_N+1)+4 };
316
        }
317

    
318
      return new ObjectShape(getVertices(variant), indices);
319
      }
320
    else
321
      {
322
      int[][] indices= new int[2*IVY_N+1][];
323

    
324
      indices[0] = new int[2*IVY_N+1];
325
      for(int i=0; i<2*IVY_N; i++)
326
        {
327
        indices[0][i] = i;
328
        indices[i+1]  = new int[] {i+1,i,2*IVY_N};
329
        }
330
      indices[2*IVY_N][0] = 0;
331

    
332
      return new ObjectShape(getVertices(variant), indices);
333
      }
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  public ObjectFaceShape getObjectFaceShape(int variant)
339
    {
340
    if( variant==0 )
341
      {
342
      float height = isInIconMode() ? 0.001f : 0.015f;
343
      float[][] bands = { {height,25,0.5f,0.5f,7,1,2}, {0.001f,25,0.5f,0.5f,2,0,0} };
344

    
345
      int[] indices   = new int[3*(IVY_N+1)];
346
      for(int i=0; i<3*(IVY_N+1); i++) indices[i] = 1;
347
      indices[0] = indices[1] = indices[2] = 0;
348

    
349
      float C = 1-SQ2/2;
350
      float[] convexCenter = {-C,-C,-C};
351
      return new ObjectFaceShape(bands,indices,convexCenter);
352
      }
353
    else
354
      {
355
      float h1 = isInIconMode() ? 0.001f : 0.03f;
356
      float h2 = isInIconMode() ? 0.001f : 0.01f;
357
      float[][] bands = { { h1,25,0.5f,0.5f,5,0,0}, {h2,25,0.5f,0.5f,2,0,0} };
358

    
359
      int[] indices= new int[2*IVY_N+1];
360
      for(int i=0; i<2*IVY_N+1; i++) indices[i] = 1;
361
      indices[0] = 0;
362

    
363
      return new ObjectFaceShape(bands,indices,null);
364
      }
365
    }
366

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

    
369
  public ObjectVertexEffects getVertexEffects(int variant)
370
    {
371
    if( variant==0 )
372
      {
373
      float[][] centers  = { {-1.0f,-1.0f,-1.0f} };
374
      float[][] corners  = { {0.04f,0.20f}, {0.03f,0.20f} };
375

    
376
      int[] cornerIndices= new int[3*(IVY_N+1)+5];
377
      int[] centerIndices= new int[3*(IVY_N+1)+5];
378

    
379
      for(int i=0; i<3*(IVY_N+1); i++)
380
        {
381
        cornerIndices[i+4] = -1;
382
        centerIndices[i+4] = -1;
383
        }
384

    
385
      cornerIndices[3*(IVY_N+1)+4] = -1;
386
      centerIndices[3*(IVY_N+1)+4] = -1;
387

    
388
      cornerIndices[0] = 1;
389
      cornerIndices[1] = 0;
390
      cornerIndices[2] = 0;
391
      cornerIndices[3] = 0;
392

    
393
      centerIndices[0] = 0;
394
      centerIndices[1] = 0;
395
      centerIndices[2] = 0;
396
      centerIndices[3] = 0;
397

    
398
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,cornerIndices,centers,centerIndices);
399
      }
400
    else
401
      {
402
      float[][] corners= { {0.04f,0.20f} };
403
      float[][] centers= { {-0.0f,-0.0f,-1.0f} };
404
      int[] indices = new int[2*IVY_N+1];
405
      for(int i=0; i<2*IVY_N+1; i++) indices[i] = -1;
406
      indices[0] = indices[IVY_N] = 0;
407
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
408
      }
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

    
413
  public int getNumCubitVariants(int[] numLayers)
414
    {
415
    return 2;
416
    }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419

    
420
  public int getCubitVariant(int cubit, int[] numLayers)
421
    {
422
    return cubit<4 ? 0:1;
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

    
427
  public float getStickerRadius()
428
    {
429
    return 0.19f;
430
    }
431

    
432
///////////////////////////////////////////////////////////////////////////////////////////////////
433

    
434
  public float getStickerStroke()
435
    {
436
    return isInIconMode() ? 0.16f : 0.12f;
437
    }
438

    
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

    
441
  public float[][][] getStickerAngles()
442
    {
443
    float D = (float)(Math.PI/4);
444
    return new float[][][] { {{ 0,0,-D }} , {{ D,D }} };
445
    }
446

    
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448
// PUBLIC API
449

    
450
  public Static3D[] getRotationAxis()
451
    {
452
    return ROT_AXIS;
453
    }
454

    
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456

    
457
  public int[][] getBasicAngles()
458
    {
459
    if( mBasicAngle ==null )
460
      {
461
      int num = getNumLayers()[0];
462
      int[] tmp = new int[num];
463
      for(int i=0; i<num; i++) tmp[i] = 3;
464
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
465
      }
466

    
467
    return mBasicAngle;
468
    }
469

    
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471

    
472
  public String getShortName()
473
    {
474
    return ObjectType.IVY_2.name();
475
    }
476

    
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478

    
479
  public ObjectSignature getSignature()
480
    {
481
    return new ObjectSignature(ObjectConstants.IVY_2);
482
    }
483

    
484
///////////////////////////////////////////////////////////////////////////////////////////////////
485

    
486
  public String getObjectName()
487
    {
488
    return "Ivy Cube";
489
    }
490

    
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492

    
493
  public String getInventor()
494
    {
495
    return "Eitan Cher";
496
    }
497

    
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499

    
500
  public int getYearOfInvention()
501
    {
502
    return 2009;
503
    }
504

    
505
///////////////////////////////////////////////////////////////////////////////////////////////////
506

    
507
  public int getComplexity()
508
    {
509
    return 0;
510
    }
511

    
512
///////////////////////////////////////////////////////////////////////////////////////////////////
513

    
514
  public String[][] getTutorials()
515
    {
516
    return new String[][]{
517
                          {"gb","QMzeJobSu1M","How to Solve the Ivy Cube","Z3"},
518
                          {"es","2-Gf2cmEJDs","Resolver Ivy Cube","Cuby"},
519
                          {"ru","pbkfOCnnfsA","Как собрать Иви куб","Алексей Ярыгин"},
520
                          {"fr","mn7YTnYu3Uc","Comment résoudre le Ivy Cube","ValentinoCube"},
521
                          {"de","vaW5fSUG_O8","Ivy Cube","ThomasStadler"},
522
                          {"pl","8s_0VxNvFA8","Jak ułożyć Ivy Cube","DubiCube"},
523
                          {"kr","TmSPgjtSFac","15분만에 아이비큐브 완전정복하기!","초등취미생활"},
524
                          {"vn","Ktx9KQr_8qo","Tutorial N.29 - Ivy Cube","Duy Thích Rubik"},
525
                          {"tw","Gbq_KAc0ii0","楓葉方塊 (方圓方塊) 教學","不正常魔術方塊研究中心"},
526
                         };
527
    }
528
}
(25-25/53)