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 java.io.InputStream;
|
16
|
|
17
|
import org.distorted.library.type.Static3D;
|
18
|
import org.distorted.library.type.Static4D;
|
19
|
|
20
|
import org.distorted.objectlib.helpers.FactoryCubit;
|
21
|
import org.distorted.objectlib.helpers.ObjectFaceShape;
|
22
|
import org.distorted.objectlib.helpers.ObjectSignature;
|
23
|
import org.distorted.objectlib.helpers.ObjectVertexEffects;
|
24
|
import org.distorted.objectlib.main.ObjectSignatures;
|
25
|
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
|
26
|
import org.distorted.objectlib.main.InitData;
|
27
|
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
|
28
|
import org.distorted.objectlib.main.ObjectType;
|
29
|
import org.distorted.objectlib.helpers.ObjectShape;
|
30
|
import org.distorted.objectlib.shape.ShapeHexahedron;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
public class TwistyIvy extends ShapeHexahedron
|
35
|
{
|
36
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
37
|
{
|
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
|
new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
|
42
|
};
|
43
|
|
44
|
public static final float IVY_D = 0.006f;
|
45
|
private static final int IVY_N = 8;
|
46
|
|
47
|
private int[][] mEdges;
|
48
|
private int[][] mBasicAngle;
|
49
|
private float[][] mCuts;
|
50
|
private int[] mQuatIndex;
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
public TwistyIvy(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
|
55
|
{
|
56
|
super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
|
57
|
}
|
58
|
|
59
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60
|
// ditto, manually provide the sticker coordinates.
|
61
|
|
62
|
@Override
|
63
|
public void adjustStickerCoords()
|
64
|
{
|
65
|
float B = 1.08f;
|
66
|
float A1 = B*0.41f;
|
67
|
float A2 = B*0.46f;
|
68
|
|
69
|
mStickerCoords = new float[][]
|
70
|
{
|
71
|
{ 0.29258922f, -0.5f, 0.29258922f, 0.29258922f, -0.5f, 0.29258922f },
|
72
|
{ -A1,A1,A2,-A2 }
|
73
|
};
|
74
|
}
|
75
|
|
76
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77
|
|
78
|
public int[][] getScrambleEdges()
|
79
|
{
|
80
|
if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
|
81
|
return mEdges;
|
82
|
}
|
83
|
|
84
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85
|
|
86
|
public float[][] getCuts(int[] numLayers)
|
87
|
{
|
88
|
if( mCuts==null )
|
89
|
{
|
90
|
float[] cut = new float[] {0.0f};
|
91
|
mCuts = new float[][] { cut,cut,cut,cut };
|
92
|
}
|
93
|
|
94
|
return mCuts;
|
95
|
}
|
96
|
|
97
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98
|
|
99
|
public boolean[][] getLayerRotatable(int[] numLayers)
|
100
|
{
|
101
|
int numAxis = ROT_AXIS.length;
|
102
|
boolean[][] layerRotatable = new boolean[numAxis][];
|
103
|
|
104
|
for(int i=0; i<numAxis; i++)
|
105
|
{
|
106
|
layerRotatable[i] = new boolean[numLayers[i]];
|
107
|
for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
|
108
|
}
|
109
|
|
110
|
return layerRotatable;
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
public int getTouchControlType()
|
116
|
{
|
117
|
return TC_HEXAHEDRON;
|
118
|
}
|
119
|
|
120
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
121
|
|
122
|
public int getTouchControlSplit()
|
123
|
{
|
124
|
return TYPE_SPLIT_CORNER;
|
125
|
}
|
126
|
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
|
129
|
public int[][][] getEnabled()
|
130
|
{
|
131
|
return new int[][][]
|
132
|
{
|
133
|
{{0},{3},{3},{0}},
|
134
|
{{2},{1},{1},{2}},
|
135
|
{{2},{0},{0},{2}},
|
136
|
{{1},{3},{3},{1}},
|
137
|
{{0},{0},{1},{1}},
|
138
|
{{2},{2},{3},{3}},
|
139
|
};
|
140
|
}
|
141
|
|
142
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
143
|
|
144
|
public float[] getDist3D(int[] numLayers)
|
145
|
{
|
146
|
return TouchControlHexahedron.D3D;
|
147
|
}
|
148
|
|
149
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150
|
|
151
|
public Static3D[] getFaceAxis()
|
152
|
{
|
153
|
return TouchControlHexahedron.FACE_AXIS;
|
154
|
}
|
155
|
|
156
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
157
|
|
158
|
public float[][] getCubitPositions(int[] numLayers)
|
159
|
{
|
160
|
final float DIST_CORNER = numLayers[0]-1;
|
161
|
final float DIST_CENTER = numLayers[0]-1;
|
162
|
|
163
|
return new float[][]
|
164
|
{
|
165
|
{ DIST_CORNER, DIST_CORNER, DIST_CORNER },
|
166
|
{-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
|
167
|
{-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
|
168
|
{ DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
|
169
|
{ 0, 0, DIST_CENTER },
|
170
|
{ 0, 0,-DIST_CENTER },
|
171
|
{ 0, DIST_CENTER, 0 },
|
172
|
{ 0,-DIST_CENTER, 0 },
|
173
|
{ DIST_CENTER, 0, 0 },
|
174
|
{-DIST_CENTER, 0, 0 },
|
175
|
};
|
176
|
}
|
177
|
|
178
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
179
|
|
180
|
public Static4D getCubitQuats(int cubit, int[] numLayers)
|
181
|
{
|
182
|
if( mQuatIndex==null ) mQuatIndex = new int[] { 0,11,10, 9,
|
183
|
0,11, 7, 6, 5, 8
|
184
|
};
|
185
|
return mObjectQuats[mQuatIndex[cubit]];
|
186
|
}
|
187
|
|
188
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
189
|
|
190
|
private float[][] getVertices(int variant)
|
191
|
{
|
192
|
final float angle = (float)Math.PI/(2*IVY_N);
|
193
|
final float CORR = 1-2*IVY_D;
|
194
|
|
195
|
if( variant==0 )
|
196
|
{
|
197
|
final float A = 0.3f;
|
198
|
final int N1 = 4;
|
199
|
final int N2 = N1 + IVY_N + 1;
|
200
|
final int N3 = N2 + IVY_N + 1;
|
201
|
float[][] vertices= new float[3*(IVY_N+1)+5][3];
|
202
|
|
203
|
vertices[3*(IVY_N+1)+4][0] = -A;
|
204
|
vertices[3*(IVY_N+1)+4][1] = -A;
|
205
|
vertices[3*(IVY_N+1)+4][2] = -A;
|
206
|
|
207
|
vertices[0][0] = 0;
|
208
|
vertices[0][1] = 0;
|
209
|
vertices[0][2] = 0;
|
210
|
vertices[1][0] =-2;
|
211
|
vertices[1][1] = 0;
|
212
|
vertices[1][2] = 0;
|
213
|
vertices[2][0] = 0;
|
214
|
vertices[2][1] =-2;
|
215
|
vertices[2][2] = 0;
|
216
|
vertices[3][0] = 0;
|
217
|
vertices[3][1] = 0;
|
218
|
vertices[3][2] =-2;
|
219
|
|
220
|
for(int i=0; i<=IVY_N; i++)
|
221
|
{
|
222
|
float cos1 = (float)Math.cos((IVY_N-i)*angle);
|
223
|
float sin1 = (float)Math.sin((IVY_N-i)*angle);
|
224
|
float cos2 = (float)Math.cos(( i)*angle);
|
225
|
float sin2 = (float)Math.sin(( i)*angle);
|
226
|
|
227
|
vertices[N1+i][0] = CORR*(2*cos1-1) - 1;
|
228
|
vertices[N1+i][1] = CORR*(2*sin1-1) - 1;
|
229
|
vertices[N1+i][2] = 0;
|
230
|
|
231
|
vertices[N2+i][0] = 0;
|
232
|
vertices[N2+i][1] = CORR*(2*sin2-1) - 1;
|
233
|
vertices[N2+i][2] = CORR*(2*cos2-1) - 1;
|
234
|
|
235
|
vertices[N3+i][0] = CORR*(2*cos2-1) - 1;
|
236
|
vertices[N3+i][1] = 0;
|
237
|
vertices[N3+i][2] = CORR*(2*sin2-1) - 1;
|
238
|
}
|
239
|
|
240
|
return vertices;
|
241
|
}
|
242
|
else
|
243
|
{
|
244
|
float[][] vertices= new float[2*IVY_N+1][3];
|
245
|
|
246
|
for(int i=0; i<IVY_N; i++)
|
247
|
{
|
248
|
float sin = (float)Math.sin(i*angle);
|
249
|
float cos = (float)Math.cos(i*angle);
|
250
|
|
251
|
vertices[i ][0] = CORR*(1-2*cos);
|
252
|
vertices[i ][1] = CORR*(1-2*sin);
|
253
|
vertices[i ][2] = 0;
|
254
|
vertices[i+IVY_N][0] = CORR*(2*cos-1);
|
255
|
vertices[i+IVY_N][1] = CORR*(2*sin-1);
|
256
|
vertices[i+IVY_N][2] = 0;
|
257
|
}
|
258
|
|
259
|
vertices[2*IVY_N][0] = 0.0f;
|
260
|
vertices[2*IVY_N][1] = 0.0f;
|
261
|
vertices[2*IVY_N][2] =-0.1f;
|
262
|
|
263
|
return vertices;
|
264
|
}
|
265
|
}
|
266
|
|
267
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
268
|
|
269
|
public ObjectShape getObjectShape(int variant)
|
270
|
{
|
271
|
if( variant==0 )
|
272
|
{
|
273
|
int[][] indices = new int[3*IVY_N+3][];
|
274
|
|
275
|
indices[0] = new int[IVY_N+4];
|
276
|
indices[1] = new int[IVY_N+4];
|
277
|
indices[2] = new int[IVY_N+4];
|
278
|
|
279
|
indices[0][0] = 2;
|
280
|
indices[0][1] = 0;
|
281
|
indices[0][2] = 1;
|
282
|
indices[1][0] = 3;
|
283
|
indices[1][1] = 0;
|
284
|
indices[1][2] = 2;
|
285
|
indices[2][0] = 1;
|
286
|
indices[2][1] = 0;
|
287
|
indices[2][2] = 3;
|
288
|
|
289
|
int N1 = 4;
|
290
|
int N2 = N1 + IVY_N + 1;
|
291
|
int N3 = N2 + IVY_N + 1;
|
292
|
|
293
|
for(int i=0; i<=IVY_N; i++)
|
294
|
{
|
295
|
indices[0][i+3] = N1 + i;
|
296
|
indices[1][i+3] = N2 + i;
|
297
|
indices[2][i+3] = N3 + i;
|
298
|
}
|
299
|
|
300
|
for(int i=0; i<IVY_N; i++)
|
301
|
{
|
302
|
indices[3*i+3] = new int[] { N1+i+1, N1+i, 3*(IVY_N+1)+4 };
|
303
|
indices[3*i+4] = new int[] { N2+i+1, N2+i, 3*(IVY_N+1)+4 };
|
304
|
indices[3*i+5] = new int[] { N3+i+1, N3+i, 3*(IVY_N+1)+4 };
|
305
|
}
|
306
|
|
307
|
return new ObjectShape(getVertices(variant), indices);
|
308
|
}
|
309
|
else
|
310
|
{
|
311
|
int[][] indices= new int[2*IVY_N+1][];
|
312
|
|
313
|
indices[0] = new int[2*IVY_N+1];
|
314
|
for(int i=0; i<2*IVY_N; i++)
|
315
|
{
|
316
|
indices[0][i] = i;
|
317
|
indices[i+1] = new int[] {i+1,i,2*IVY_N};
|
318
|
}
|
319
|
indices[2*IVY_N][0] = 0;
|
320
|
|
321
|
return new ObjectShape(getVertices(variant), indices);
|
322
|
}
|
323
|
}
|
324
|
|
325
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
326
|
|
327
|
public ObjectFaceShape getObjectFaceShape(int variant)
|
328
|
{
|
329
|
if( variant==0 )
|
330
|
{
|
331
|
float height = isInIconMode() ? 0.001f : 0.015f;
|
332
|
float[][] bands = { {height,20,0.2f,0.5f,7,1,2}, {0.001f,1,0.2f,0.0f,2,0,0} };
|
333
|
|
334
|
int[] indices = new int[3*(IVY_N+1)];
|
335
|
for(int i=0; i<3*(IVY_N+1); i++) indices[i] = 1;
|
336
|
indices[0] = indices[1] = indices[2] = 0;
|
337
|
|
338
|
float C = 1-SQ2/2;
|
339
|
float[] convexCenter = {-C,-C,-C};
|
340
|
return new ObjectFaceShape(bands,indices,convexCenter);
|
341
|
}
|
342
|
else
|
343
|
{
|
344
|
float h1 = isInIconMode() ? 0.001f : 0.03f;
|
345
|
float h2 = isInIconMode() ? 0.001f : 0.01f;
|
346
|
float[][] bands = { { h1,35,0.5f,0.5f,5,0,0}, {h2,1,0.5f,0.8f,2,0,0} };
|
347
|
|
348
|
int[] indices= new int[2*IVY_N+1];
|
349
|
for(int i=0; i<2*IVY_N+1; i++) indices[i] = 1;
|
350
|
indices[0] = 0;
|
351
|
|
352
|
return new ObjectFaceShape(bands,indices,null);
|
353
|
}
|
354
|
}
|
355
|
|
356
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
357
|
|
358
|
public ObjectVertexEffects getVertexEffects(int variant)
|
359
|
{
|
360
|
if( variant==0 )
|
361
|
{
|
362
|
float[][] centers = { {-1.0f,-1.0f,-1.0f} };
|
363
|
float[][] corners = { {0.04f,0.20f}, {0.03f,0.20f} };
|
364
|
|
365
|
int[] cornerIndices= new int[3*(IVY_N+1)+5];
|
366
|
int[] centerIndices= new int[3*(IVY_N+1)+5];
|
367
|
|
368
|
for(int i=0; i<3*(IVY_N+1); i++)
|
369
|
{
|
370
|
cornerIndices[i+4] = -1;
|
371
|
centerIndices[i+4] = -1;
|
372
|
}
|
373
|
|
374
|
cornerIndices[3*(IVY_N+1)+4] = -1;
|
375
|
centerIndices[3*(IVY_N+1)+4] = -1;
|
376
|
|
377
|
cornerIndices[0] = 1;
|
378
|
cornerIndices[1] = 0;
|
379
|
cornerIndices[2] = 0;
|
380
|
cornerIndices[3] = 0;
|
381
|
|
382
|
centerIndices[0] = 0;
|
383
|
centerIndices[1] = 0;
|
384
|
centerIndices[2] = 0;
|
385
|
centerIndices[3] = 0;
|
386
|
|
387
|
return FactoryCubit.generateVertexEffect(getVertices(variant),corners,cornerIndices,centers,centerIndices);
|
388
|
}
|
389
|
else
|
390
|
{
|
391
|
float[][] corners= { {0.04f,0.20f} };
|
392
|
float[][] centers= { {-0.0f,-0.0f,-1.0f} };
|
393
|
int[] indices = new int[2*IVY_N+1];
|
394
|
for(int i=0; i<2*IVY_N+1; i++) indices[i] = -1;
|
395
|
indices[0] = indices[IVY_N] = 0;
|
396
|
return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
|
397
|
}
|
398
|
}
|
399
|
|
400
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
401
|
|
402
|
public int getNumCubitVariants(int[] numLayers)
|
403
|
{
|
404
|
return 2;
|
405
|
}
|
406
|
|
407
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
408
|
|
409
|
public int getCubitVariant(int cubit, int[] numLayers)
|
410
|
{
|
411
|
return cubit<4 ? 0:1;
|
412
|
}
|
413
|
|
414
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
415
|
|
416
|
public float getStickerRadius()
|
417
|
{
|
418
|
return 0.19f;
|
419
|
}
|
420
|
|
421
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
422
|
|
423
|
public float getStickerStroke()
|
424
|
{
|
425
|
return isInIconMode() ? 0.16f : 0.12f;
|
426
|
}
|
427
|
|
428
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
429
|
|
430
|
public float[][] getStickerAngles()
|
431
|
{
|
432
|
float D = (float)(Math.PI/4);
|
433
|
return new float[][] { { 0,0,-D },{ D,D } };
|
434
|
}
|
435
|
|
436
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
437
|
// PUBLIC API
|
438
|
|
439
|
public Static3D[] getRotationAxis()
|
440
|
{
|
441
|
return ROT_AXIS;
|
442
|
}
|
443
|
|
444
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
445
|
|
446
|
public int[][] getBasicAngles()
|
447
|
{
|
448
|
if( mBasicAngle ==null )
|
449
|
{
|
450
|
int num = getNumLayers()[0];
|
451
|
int[] tmp = new int[num];
|
452
|
for(int i=0; i<num; i++) tmp[i] = 3;
|
453
|
mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
|
454
|
}
|
455
|
|
456
|
return mBasicAngle;
|
457
|
}
|
458
|
|
459
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
460
|
|
461
|
public String getShortName()
|
462
|
{
|
463
|
return ObjectType.IVY_2.name();
|
464
|
}
|
465
|
|
466
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
467
|
|
468
|
public ObjectSignature getSignature()
|
469
|
{
|
470
|
return new ObjectSignature(ObjectSignatures.IVY_2);
|
471
|
}
|
472
|
|
473
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
474
|
|
475
|
public String getObjectName()
|
476
|
{
|
477
|
return "Ivy Cube";
|
478
|
}
|
479
|
|
480
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
481
|
|
482
|
public String getInventor()
|
483
|
{
|
484
|
return "Eitan Cher";
|
485
|
}
|
486
|
|
487
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
488
|
|
489
|
public int getYearOfInvention()
|
490
|
{
|
491
|
return 2009;
|
492
|
}
|
493
|
|
494
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
495
|
|
496
|
public int getComplexity()
|
497
|
{
|
498
|
return 0;
|
499
|
}
|
500
|
|
501
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
502
|
|
503
|
public String[][] getTutorials()
|
504
|
{
|
505
|
return new String[][]{
|
506
|
{"gb","QMzeJobSu1M","How to Solve the Ivy Cube","Z3"},
|
507
|
{"es","2-Gf2cmEJDs","Resolver Ivy Cube","Cuby"},
|
508
|
{"ru","pbkfOCnnfsA","Как собрать Иви куб","Алексей Ярыгин"},
|
509
|
{"fr","mn7YTnYu3Uc","Comment résoudre le Ivy Cube","ValentinoCube"},
|
510
|
{"de","vaW5fSUG_O8","Ivy Cube","ThomasStadler"},
|
511
|
{"pl","8s_0VxNvFA8","Jak ułożyć Ivy Cube","DubiCube"},
|
512
|
{"kr","TmSPgjtSFac","15분만에 아이비큐브 완전정복하기!","초등취미생활"},
|
513
|
{"vn","Ktx9KQr_8qo","Tutorial N.29 - Ivy Cube","Duy Thích Rubik"},
|
514
|
};
|
515
|
}
|
516
|
}
|