Project

General

Profile

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

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

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.metadata.Metadata;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitAssets;
23
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
24
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
25
import org.distorted.objectlib.metadata.ListObjects;
26
import org.distorted.objectlib.helpers.ObjectShape;
27
import org.distorted.objectlib.shape.ShapeHexahedron;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

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

    
41
  public static final float IVY_D = 0.006f;
42
  private static final int  IVY_N = 8;
43

    
44
  private int[][] mEdges;
45
  private int[][] mBasicAngle;
46
  private float[][] mCuts;
47
  private int[] mQuatIndex;
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
  public TwistyIvy(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
52
    {
53
    super(iconMode, meta.getNumLayers()[0], quat, move, scale, meta, asset);
54
    }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

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

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
// ditto, manually provide the sticker coordinates.
68

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

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

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

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

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

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

    
103
    return mCuts;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

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

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

    
119
    return layerRotatable;
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
  public int getTouchControlType()
125
    {
126
    return TC_HEXAHEDRON;
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public int getTouchControlSplit()
132
    {
133
    return TYPE_SPLIT_CORNER;
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

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

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

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

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

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

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

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

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

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

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

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

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

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

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

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

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

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

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

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

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

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

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

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

    
272
      return vertices;
273
      }
274
    }
275

    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

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

    
284
      indices[0] = new int[IVY_N+4];
285
      indices[1] = new int[IVY_N+4];
286
      indices[2] = new int[IVY_N+4];
287

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

    
298
      int N1 = 4;
299
      int N2 = N1 + IVY_N + 1;
300
      int N3 = N2 + IVY_N + 1;
301

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

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

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

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

    
330
      return new ObjectShape(getVertices(variant), indices);
331
      }
332
    }
333

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

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

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

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

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

    
361
      return new ObjectFaceShape(bands,indices,null);
362
      }
363
    }
364

    
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366

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

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

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

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

    
386
      cornerIndices[0] = 1;
387
      cornerIndices[1] = 0;
388
      cornerIndices[2] = 0;
389
      cornerIndices[3] = 0;
390

    
391
      centerIndices[0] = 0;
392
      centerIndices[1] = 0;
393
      centerIndices[2] = 0;
394
      centerIndices[3] = 0;
395

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

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410

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

    
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417

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

    
423
///////////////////////////////////////////////////////////////////////////////////////////////////
424

    
425
  public float getStickerRadius()
426
    {
427
    return 0.19f;
428
    }
429

    
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431

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

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

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

    
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446
// PUBLIC API
447

    
448
  public Static3D[] getRotationAxis()
449
    {
450
    return ROT_AXIS;
451
    }
452

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

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

    
465
    return mBasicAngle;
466
    }
467

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469

    
470
  public String getShortName()
471
    {
472
    return ListObjects.IVY_2.name();
473
    }
474

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

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