Project

General

Profile

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

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

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.helpers.ObjectSignature;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitAssets;
23
import org.distorted.objectlib.main.ObjectSignatures;
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 meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
54
    {
55
    super(meshState, iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
56
    }
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59
// ditto, manually provide the sticker coordinates.
60

    
61
  @Override
62
  public void adjustStickerCoords()
63
    {
64
    float B = 1.08f;
65
    float A1 = B*0.41f;
66
    float A2 = B*0.46f;
67

    
68
    mStickerCoords = new float[][]
69
          {
70
            { 0.29258922f, -0.5f, 0.29258922f, 0.29258922f, -0.5f, 0.29258922f },
71
            { -A1,A1,A2,-A2 }
72
          };
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  public int[][] getScrambleEdges()
78
    {
79
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
80
    return mEdges;
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  public float[][] getCuts(int[] numLayers)
86
    {
87
    if( mCuts==null )
88
      {
89
      float[] cut = new float[] {0.0f};
90
      mCuts = new float[][] { cut,cut,cut,cut };
91
      }
92

    
93
    return mCuts;
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
  public boolean[][] getLayerRotatable(int[] numLayers)
99
    {
100
    int numAxis = ROT_AXIS.length;
101
    boolean[][] layerRotatable = new boolean[numAxis][];
102

    
103
    for(int i=0; i<numAxis; i++)
104
      {
105
      layerRotatable[i] = new boolean[numLayers[i]];
106
      for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
107
      }
108

    
109
    return layerRotatable;
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  public int getTouchControlType()
115
    {
116
    return TC_HEXAHEDRON;
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
  public int getTouchControlSplit()
122
    {
123
    return TYPE_SPLIT_CORNER;
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
  public int[][][] getEnabled()
129
    {
130
    return new int[][][]
131
      {
132
          {{0},{3},{3},{0}},
133
          {{2},{1},{1},{2}},
134
          {{2},{0},{0},{2}},
135
          {{1},{3},{3},{1}},
136
          {{0},{0},{1},{1}},
137
          {{2},{2},{3},{3}},
138
      };
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
  public float[] getDist3D(int[] numLayers)
144
    {
145
    return TouchControlHexahedron.D3D;
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  public Static3D[] getFaceAxis()
151
    {
152
    return TouchControlHexahedron.FACE_AXIS;
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  public float[][] getCubitPositions(int[] numLayers)
158
    {
159
    final float DIST_CORNER = numLayers[0]-1;
160
    final float DIST_CENTER = numLayers[0]-1;
161

    
162
    return new float[][]
163
      {
164
        { DIST_CORNER, DIST_CORNER, DIST_CORNER },
165
        {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
166
        {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
167
        { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
168
        { DIST_CENTER,           0,           0 },
169
        {-DIST_CENTER,           0,           0 },
170
        {           0, DIST_CENTER,           0 },
171
        {           0,-DIST_CENTER,           0 },
172
        {           0,           0, DIST_CENTER },
173
        {           0,           0,-DIST_CENTER },
174
      };
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  public Static4D getCubitQuats(int cubit, int[] numLayers)
180
    {
181
    if( mQuatIndex==null ) mQuatIndex = new int[] { 0,11,10, 9,
182
                                                    5, 8, 7, 6, 0, 11
183
                                                  };
184
    return mObjectQuats[mQuatIndex[cubit]];
185
    }
186

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

    
189
  private float[][] getVertices(int variant)
190
    {
191
    final float angle = (float)Math.PI/(2*IVY_N);
192
    final float CORR  = 1-2*IVY_D;
193

    
194
    if( variant==0 )
195
      {
196
      final float A = 0.3f;
197
      final int N1 = 4;
198
      final int N2 = N1 + IVY_N + 1;
199
      final int N3 = N2 + IVY_N + 1;
200
      float[][] vertices= new float[3*(IVY_N+1)+5][3];
201

    
202
      vertices[3*(IVY_N+1)+4][0] = -A;
203
      vertices[3*(IVY_N+1)+4][1] = -A;
204
      vertices[3*(IVY_N+1)+4][2] = -A;
205

    
206
      vertices[0][0] = 0;
207
      vertices[0][1] = 0;
208
      vertices[0][2] = 0;
209
      vertices[1][0] =-2;
210
      vertices[1][1] = 0;
211
      vertices[1][2] = 0;
212
      vertices[2][0] = 0;
213
      vertices[2][1] =-2;
214
      vertices[2][2] = 0;
215
      vertices[3][0] = 0;
216
      vertices[3][1] = 0;
217
      vertices[3][2] =-2;
218

    
219
      for(int i=0; i<=IVY_N; i++)
220
        {
221
        float cos1 = (float)Math.cos((IVY_N-i)*angle);
222
        float sin1 = (float)Math.sin((IVY_N-i)*angle);
223
        float cos2 = (float)Math.cos((      i)*angle);
224
        float sin2 = (float)Math.sin((      i)*angle);
225

    
226
        vertices[N1+i][0] = CORR*(2*cos1-1) - 1;
227
        vertices[N1+i][1] = CORR*(2*sin1-1) - 1;
228
        vertices[N1+i][2] = 0;
229

    
230
        vertices[N2+i][0] = 0;
231
        vertices[N2+i][1] = CORR*(2*sin2-1) - 1;
232
        vertices[N2+i][2] = CORR*(2*cos2-1) - 1;
233

    
234
        vertices[N3+i][0] = CORR*(2*cos2-1) - 1;
235
        vertices[N3+i][1] = 0;
236
        vertices[N3+i][2] = CORR*(2*sin2-1) - 1;
237
        }
238

    
239
      return vertices;
240
      }
241
    else
242
      {
243
      float[][] vertices= new float[2*IVY_N+1][3];
244

    
245
      for(int i=0; i<IVY_N; i++)
246
        {
247
        float sin = (float)Math.sin(i*angle);
248
        float cos = (float)Math.cos(i*angle);
249

    
250
        vertices[i      ][0] = CORR*(1-2*cos);
251
        vertices[i      ][1] = CORR*(1-2*sin);
252
        vertices[i      ][2] = 0;
253
        vertices[i+IVY_N][0] = CORR*(2*cos-1);
254
        vertices[i+IVY_N][1] = CORR*(2*sin-1);
255
        vertices[i+IVY_N][2] = 0;
256
        }
257

    
258
      vertices[2*IVY_N][0] = 0.0f;
259
      vertices[2*IVY_N][1] = 0.0f;
260
      vertices[2*IVY_N][2] =-0.1f;
261

    
262
      return vertices;
263
      }
264
    }
265

    
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

    
268
  public ObjectShape getObjectShape(int variant)
269
    {
270
    if( variant==0 )
271
      {
272
      int[][] indices = new int[3*IVY_N+3][];
273

    
274
      indices[0] = new int[IVY_N+4];
275
      indices[1] = new int[IVY_N+4];
276
      indices[2] = new int[IVY_N+4];
277

    
278
      indices[0][0] = 2;
279
      indices[0][1] = 0;
280
      indices[0][2] = 1;
281
      indices[1][0] = 3;
282
      indices[1][1] = 0;
283
      indices[1][2] = 2;
284
      indices[2][0] = 1;
285
      indices[2][1] = 0;
286
      indices[2][2] = 3;
287

    
288
      int N1 = 4;
289
      int N2 = N1 + IVY_N + 1;
290
      int N3 = N2 + IVY_N + 1;
291

    
292
      for(int i=0; i<=IVY_N; i++)
293
        {
294
        indices[0][i+3] = N1 + i;
295
        indices[1][i+3] = N2 + i;
296
        indices[2][i+3] = N3 + i;
297
        }
298

    
299
      for(int i=0; i<IVY_N; i++)
300
        {
301
        indices[3*i+3] = new int[] { N1+i+1, N1+i, 3*(IVY_N+1)+4 };
302
        indices[3*i+4] = new int[] { N2+i+1, N2+i, 3*(IVY_N+1)+4 };
303
        indices[3*i+5] = new int[] { N3+i+1, N3+i, 3*(IVY_N+1)+4 };
304
        }
305

    
306
      return new ObjectShape(getVertices(variant), indices);
307
      }
308
    else
309
      {
310
      int[][] indices= new int[2*IVY_N+1][];
311

    
312
      indices[0] = new int[2*IVY_N+1];
313
      for(int i=0; i<2*IVY_N; i++)
314
        {
315
        indices[0][i] = i;
316
        indices[i+1]  = new int[] {i+1,i,2*IVY_N};
317
        }
318
      indices[2*IVY_N][0] = 0;
319

    
320
      return new ObjectShape(getVertices(variant), indices);
321
      }
322
    }
323

    
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

    
326
  public ObjectFaceShape getObjectFaceShape(int variant)
327
    {
328
    if( variant==0 )
329
      {
330
      float height = isInIconMode() ? 0.001f : 0.015f;
331
      float[][] bands = { {height,20,0.2f,0.5f,7,1,2}, {0.001f,1,0.2f,0.0f,2,0,0} };
332

    
333
      int[] indices   = new int[3*(IVY_N+1)];
334
      for(int i=0; i<3*(IVY_N+1); i++) indices[i] = 1;
335
      indices[0] = indices[1] = indices[2] = 0;
336

    
337
      float C = 1-SQ2/2;
338
      float[] convexCenter = {-C,-C,-C};
339
      return new ObjectFaceShape(bands,indices,convexCenter);
340
      }
341
    else
342
      {
343
      float h1 = isInIconMode() ? 0.001f : 0.03f;
344
      float h2 = isInIconMode() ? 0.001f : 0.01f;
345
      float[][] bands = { { h1,35,0.5f,0.5f,5,0,0}, {h2,1,0.5f,0.8f,2,0,0} };
346

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

    
351
      return new ObjectFaceShape(bands,indices,null);
352
      }
353
    }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

    
357
  public ObjectVertexEffects getVertexEffects(int variant)
358
    {
359
    if( variant==0 )
360
      {
361
      float[][] centers  = { {-1.0f,-1.0f,-1.0f} };
362
      float[][] corners  = { {0.04f,0.20f}, {0.03f,0.20f} };
363

    
364
      int[] cornerIndices= new int[3*(IVY_N+1)+5];
365
      int[] centerIndices= new int[3*(IVY_N+1)+5];
366

    
367
      for(int i=0; i<3*(IVY_N+1); i++)
368
        {
369
        cornerIndices[i+4] = -1;
370
        centerIndices[i+4] = -1;
371
        }
372

    
373
      cornerIndices[3*(IVY_N+1)+4] = -1;
374
      centerIndices[3*(IVY_N+1)+4] = -1;
375

    
376
      cornerIndices[0] = 1;
377
      cornerIndices[1] = 0;
378
      cornerIndices[2] = 0;
379
      cornerIndices[3] = 0;
380

    
381
      centerIndices[0] = 0;
382
      centerIndices[1] = 0;
383
      centerIndices[2] = 0;
384
      centerIndices[3] = 0;
385

    
386
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,cornerIndices,centers,centerIndices);
387
      }
388
    else
389
      {
390
      float[][] corners= { {0.04f,0.20f} };
391
      float[][] centers= { {-0.0f,-0.0f,-1.0f} };
392
      int[] indices = new int[2*IVY_N+1];
393
      for(int i=0; i<2*IVY_N+1; i++) indices[i] = -1;
394
      indices[0] = indices[IVY_N] = 0;
395
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
396
      }
397
    }
398

    
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400

    
401
  public int getNumCubitVariants(int[] numLayers)
402
    {
403
    return 2;
404
    }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
  public int getCubitVariant(int cubit, int[] numLayers)
409
    {
410
    return cubit<4 ? 0:1;
411
    }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

    
415
  public float getStickerRadius()
416
    {
417
    return 0.19f;
418
    }
419

    
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421

    
422
  public float getStickerStroke()
423
    {
424
    return isInIconMode() ? 0.16f : 0.12f;
425
    }
426

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

    
429
  public float[][] getStickerAngles()
430
    {
431
    float D = (float)(Math.PI/4);
432
    return new float[][] { { 0,0,-D },{ D,D } };
433
    }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436
// PUBLIC API
437

    
438
  public Static3D[] getRotationAxis()
439
    {
440
    return ROT_AXIS;
441
    }
442

    
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444

    
445
  public int[][] getBasicAngles()
446
    {
447
    if( mBasicAngle ==null )
448
      {
449
      int num = getNumLayers()[0];
450
      int[] tmp = new int[num];
451
      for(int i=0; i<num; i++) tmp[i] = 3;
452
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
453
      }
454

    
455
    return mBasicAngle;
456
    }
457

    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

    
460
  public String getShortName()
461
    {
462
    return ObjectType.IVY_2.name();
463
    }
464

    
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466

    
467
  public ObjectSignature getSignature()
468
    {
469
    return new ObjectSignature(ObjectSignatures.IVY_2);
470
    }
471

    
472
///////////////////////////////////////////////////////////////////////////////////////////////////
473

    
474
  public String getObjectName()
475
    {
476
    return "Ivy Cube";
477
    }
478

    
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480

    
481
  public String getInventor()
482
    {
483
    return "Eitan Cher";
484
    }
485

    
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487

    
488
  public int getYearOfInvention()
489
    {
490
    return 2009;
491
    }
492

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494

    
495
  public int getComplexity()
496
    {
497
    return 0;
498
    }
499

    
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501

    
502
  public String[][] getTutorials()
503
    {
504
    return new String[][]{
505
                          {"gb","QMzeJobSu1M","How to Solve the Ivy Cube","Z3"},
506
                          {"es","2-Gf2cmEJDs","Resolver Ivy Cube","Cuby"},
507
                          {"ru","pbkfOCnnfsA","Как собрать Иви куб","Алексей Ярыгин"},
508
                          {"fr","mn7YTnYu3Uc","Comment résoudre le Ivy Cube","ValentinoCube"},
509
                          {"de","vaW5fSUG_O8","Ivy Cube","ThomasStadler"},
510
                          {"pl","8s_0VxNvFA8","Jak ułożyć Ivy Cube","DubiCube"},
511
                          {"kr","TmSPgjtSFac","15분만에 아이비큐브 완전정복하기!","초등취미생활"},
512
                          {"vn","Ktx9KQr_8qo","Tutorial N.29 - Ivy Cube","Duy Thích Rubik"},
513
                         };
514
    }
515
}
(17-17/41)