Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
23
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
24

    
25
import java.io.InputStream;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.helpers.ObjectFaceShape;
31
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
32
import org.distorted.objectlib.main.ObjectType;
33
import org.distorted.objectlib.helpers.ObjectShape;
34
import org.distorted.objectlib.scrambling.ScrambleState;
35
import org.distorted.objectlib.main.ShapeHexahedron;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
public class TwistyIvy extends ShapeHexahedron
40
{
41
  static final Static3D[] ROT_AXIS = new Static3D[]
42
         {
43
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
44
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
45
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
46
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
47
         };
48

    
49
  public static final float IVY_D = 0.006f;
50
  private static final int  IVY_N = 8;
51

    
52
  private ScrambleState[] mStates;
53
  private int[] mBasicAngle;
54
  private float[][] mCuts;
55
  private int[] mQuatIndex;
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  public TwistyIvy(int[] numL, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
60
    {
61
    super(numL, meshState, iconMode, numL[0], quat, move, scale, stream);
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
// ditto, manually provide the sticker coordinates.
66

    
67
  @Override
68
  public void adjustStickerCoords()
69
    {
70
    float B = 1.08f;
71
    float A1 = B*0.41f;
72
    float A2 = B*0.46f;
73

    
74
    mStickerCoords = new float[][]
75
          {
76
            { 0.29258922f, -0.5f, 0.29258922f, 0.29258922f, -0.5f, 0.29258922f },
77
            { -A1,A1,A2,-A2 }
78
          };
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
  public ScrambleState[] getScrambleStates()
84
    {
85
    if( mStates==null )
86
      {
87
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
88

    
89
      mStates = new ScrambleState[]
90
        {
91
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
92
        };
93
      }
94

    
95
    return mStates;
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

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

    
108
    return mCuts;
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  public boolean[][] getLayerRotatable(int[] numLayers)
114
    {
115
    int numAxis = ROT_AXIS.length;
116
    boolean[][] layerRotatable = new boolean[numAxis][];
117

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

    
124
    return layerRotatable;
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
  public int getTouchControlType()
130
    {
131
    return TC_HEXAHEDRON;
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
  public int getTouchControlSplit()
137
    {
138
    return TYPE_SPLIT_CORNER;
139
    }
140

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

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

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

    
158
  public float[] getDist3D(int[] numLayers)
159
    {
160
    return TouchControlHexahedron.D3D;
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  public Static3D[] getFaceAxis()
166
    {
167
    return TouchControlHexahedron.FACE_AXIS;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  public float[][] getCubitPositions(int[] numLayers)
173
    {
174
    final float DIST_CORNER = numLayers[0]-1;
175
    final float DIST_CENTER = numLayers[0]-1;
176

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

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

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

    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

    
202
  public ObjectShape getObjectShape(int variant)
203
    {
204
    if( variant==0 )
205
      {
206
      final float A = 0.3f;
207
      final float angle = (float)Math.PI/(2*IVY_N);
208
      final float CORR  = 1-2*IVY_D;
209
      float[][] vertices= new float[3*(IVY_N+1)+5][3];
210
      int[][] indices   = new int[3*IVY_N+3][];
211

    
212
      indices[0] = new int[IVY_N+4];
213
      indices[1] = new int[IVY_N+4];
214
      indices[2] = new int[IVY_N+4];
215

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

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

    
233
      indices[0][0] = 2;
234
      indices[0][1] = 0;
235
      indices[0][2] = 1;
236
      indices[1][0] = 3;
237
      indices[1][1] = 0;
238
      indices[1][2] = 2;
239
      indices[2][0] = 1;
240
      indices[2][1] = 0;
241
      indices[2][2] = 3;
242

    
243
      int N1 = 4;
244
      int N2 = N1 + IVY_N + 1;
245
      int N3 = N2 + IVY_N + 1;
246

    
247
      for(int i=0; i<=IVY_N; i++)
248
        {
249
        float cos1 = (float)Math.cos((IVY_N-i)*angle);
250
        float sin1 = (float)Math.sin((IVY_N-i)*angle);
251
        float cos2 = (float)Math.cos((      i)*angle);
252
        float sin2 = (float)Math.sin((      i)*angle);
253

    
254
        vertices[N1+i][0] = CORR*(2*cos1-1) - 1;
255
        vertices[N1+i][1] = CORR*(2*sin1-1) - 1;
256
        vertices[N1+i][2] = 0;
257

    
258
        vertices[N2+i][0] = 0;
259
        vertices[N2+i][1] = CORR*(2*sin2-1) - 1;
260
        vertices[N2+i][2] = CORR*(2*cos2-1) - 1;
261

    
262
        vertices[N3+i][0] = CORR*(2*cos2-1) - 1;
263
        vertices[N3+i][1] = 0;
264
        vertices[N3+i][2] = CORR*(2*sin2-1) - 1;
265

    
266
        indices[0][i+3] = N1 + i;
267
        indices[1][i+3] = N2 + i;
268
        indices[2][i+3] = N3 + i;
269
        }
270

    
271
      for(int i=0; i<IVY_N; i++)
272
        {
273
        indices[3*i+3] = new int[] { N1+i+1, N1+i, 3*(IVY_N+1)+4 };
274
        indices[3*i+4] = new int[] { N2+i+1, N2+i, 3*(IVY_N+1)+4 };
275
        indices[3*i+5] = new int[] { N3+i+1, N3+i, 3*(IVY_N+1)+4 };
276
        }
277

    
278
      return new ObjectShape(vertices, indices);
279
      }
280
    else
281
      {
282
      final float angle = (float)Math.PI/(2*IVY_N);
283
      final float CORR  = 1-2*IVY_D;
284
      float[][] vertices= new float[2*IVY_N+1][3];
285
      int[][] indices   = new int[2*IVY_N+1][];
286

    
287
      for(int i=0; i<IVY_N; i++)
288
        {
289
        float sin = (float)Math.sin(i*angle);
290
        float cos = (float)Math.cos(i*angle);
291

    
292
        vertices[i      ][0] = CORR*(1-2*cos);
293
        vertices[i      ][1] = CORR*(1-2*sin);
294
        vertices[i      ][2] = 0;
295
        vertices[i+IVY_N][0] = CORR*(2*cos-1);
296
        vertices[i+IVY_N][1] = CORR*(2*sin-1);
297
        vertices[i+IVY_N][2] = 0;
298
        }
299

    
300
      vertices[2*IVY_N][0] = 0.0f;
301
      vertices[2*IVY_N][1] = 0.0f;
302
      vertices[2*IVY_N][2] =-0.1f;
303

    
304
      indices[0] = new int[2*IVY_N+1];
305
      for(int i=0; i<2*IVY_N; i++)
306
        {
307
        indices[0][i] = i;
308
        indices[i+1]  = new int[] {i+1,i,2*IVY_N};
309
        }
310
      indices[2*IVY_N][0] = 0;
311

    
312
      return new ObjectShape(vertices, indices);
313
      }
314
    }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

    
318
  public ObjectFaceShape getObjectFaceShape(int variant)
319
    {
320
    if( variant==0 )
321
      {
322
      float height = isInIconMode() ? 0.001f : 0.015f;
323
      float[][] centers  = { {-1.0f,-1.0f,-1.0f} };
324
      float[][] corners  = { {0.04f,0.20f}, {0.03f,0.20f} };
325
      float[][] bands    = { {height,20,0.2f,0.5f,7,1,2}, {0.001f,1,0.2f,0.0f,2,0,0} };
326

    
327
      int[] cornerIndices= new int[3*(IVY_N+1)+5];
328
      int[] centerIndices= new int[3*(IVY_N+1)+5];
329
      int[] bandIndices  = new int[3*(IVY_N+1)  ];
330

    
331
      for(int i=0; i<3*(IVY_N+1); i++)
332
        {
333
        cornerIndices[i+4] = -1;
334
        centerIndices[i+4] = -1;
335
        bandIndices[i] = 1;
336
        }
337

    
338
      cornerIndices[3*(IVY_N+1)+4] = -1;
339
      centerIndices[3*(IVY_N+1)+4] = -1;
340

    
341
      bandIndices[0] = 0;
342
      bandIndices[1] = 0;
343
      bandIndices[2] = 0;
344

    
345
      cornerIndices[0] = 1;
346
      cornerIndices[1] = 0;
347
      cornerIndices[2] = 0;
348
      cornerIndices[3] = 0;
349

    
350
      centerIndices[0] = 0;
351
      centerIndices[1] = 0;
352
      centerIndices[2] = 0;
353
      centerIndices[3] = 0;
354

    
355
      float C = 1-SQ2/2;
356
      float[] convexCenter = {-C,-C,-C};
357
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,convexCenter);
358
      }
359
    else
360
      {
361
      float h1 = isInIconMode() ? 0.001f : 0.03f;
362
      float h2 = isInIconMode() ? 0.001f : 0.01f;
363
      float[][] corners= { {0.04f,0.20f} };
364
      float[][] centers= { {-0.0f,-0.0f,-1.0f} };
365
      float[][] bands  = { { h1,35,0.5f,0.5f,5,0,0}, {h2,1,0.5f,0.8f,2,0,0} };
366

    
367
      int[] bandIndices= new int[2*IVY_N+1];
368
      int[] indexes = new int[2*IVY_N+1];
369
      for(int i=0; i<2*IVY_N+1; i++)
370
        {
371
        indexes[i] = -1;
372
        bandIndices[i] = 1;
373
        }
374
      indexes[0] = indexes[IVY_N] = 0;
375
      bandIndices[0] = 0;
376

    
377
      return new ObjectFaceShape(bands,bandIndices,corners,indexes,centers,indexes, null);
378
      }
379
    }
380

    
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382

    
383
  public int getNumCubitVariants(int[] numLayers)
384
    {
385
    return 2;
386
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

    
390
  public int getCubitVariant(int cubit, int[] numLayers)
391
    {
392
    return cubit<4 ? 0:1;
393
    }
394

    
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396

    
397
  public float getStickerRadius()
398
    {
399
    return 0.19f;
400
    }
401

    
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403

    
404
  public float getStickerStroke()
405
    {
406
    return isInIconMode() ? 0.16f : 0.12f;
407
    }
408

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

    
411
  public float[][] getStickerAngles()
412
    {
413
    float D = (float)(Math.PI/4);
414
    return new float[][] { { 0,0,-D },{ D,D } };
415
    }
416

    
417
///////////////////////////////////////////////////////////////////////////////////////////////////
418
// PUBLIC API
419

    
420
  public Static3D[] getRotationAxis()
421
    {
422
    return ROT_AXIS;
423
    }
424

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

    
427
  public int[] getBasicAngles()
428
    {
429
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
430
    return mBasicAngle;
431
    }
432

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

    
435
  public String getShortName()
436
    {
437
    return ObjectType.IVY_2.name();
438
    }
439

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

    
442
  public long getSignature()
443
    {
444
    return ObjectType.IVY_2.ordinal();
445
    }
446

    
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448

    
449
  public String getObjectName()
450
    {
451
    return "Ivy Cube";
452
    }
453

    
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455

    
456
  public String getInventor()
457
    {
458
    return "Eitan Cher";
459
    }
460

    
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462

    
463
  public int getYearOfInvention()
464
    {
465
    return 2009;
466
    }
467

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

    
470
  public int getComplexity()
471
    {
472
    return 0;
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
                         };
489
    }
490
}
(17-17/36)